Skip to content

Commit

Permalink
vm: add address&swap endianness to opcode dump for hashes
Browse files Browse the repository at this point in the history
If the parameter in the opcode dump is a 20-byte value, the converted values,
such as the address and the swapped endianness, have been added.

Signed-off-by: Tatiana Nesterenko <[email protected]>
  • Loading branch information
tatiana-nspcc committed Sep 3, 2023
1 parent 0d30c83 commit 509eeae
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vm
import (
"crypto/elliptic"
"encoding/binary"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand All @@ -15,6 +16,7 @@ import (

"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
Expand Down Expand Up @@ -217,7 +219,14 @@ func (v *VM) PrintOps(out io.Writer) {
if utf8.Valid(parameter) {
desc = fmt.Sprintf("%x (%q)", parameter, parameter)
} else {
desc = fmt.Sprintf("%x", parameter)
// Try converting the parameter to an address and swap the endianness
// if the parameter is a 20-byte value.
u, err := util.Uint160DecodeBytesBE(parameter)
if err == nil {
desc = fmt.Sprintf("%x (Address:%q, Swap Endianness:%q)", parameter, address.Uint160ToString(u), "0x"+hex.EncodeToString(slice.CopyReverse(parameter)))
} else {
desc = fmt.Sprintf("%x", parameter)
}

Check warning on line 229 in pkg/vm/vm.go

View check run for this annotation

Codecov / codecov/patch

pkg/vm/vm.go#L228-L229

Added lines #L228 - L229 were not covered by tests
}
}
}
Expand Down

0 comments on commit 509eeae

Please sign in to comment.