Skip to content

Commit

Permalink
Merge pull request #3115 from nspcc-dev/3030-opcode-dumps
Browse files Browse the repository at this point in the history
Add address and swap endianness to vm opcode dump for hashes
  • Loading branch information
roman-khimov authored Sep 4, 2023
2 parents 5180305 + 259cbc3 commit a59fd50
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 (%q, %q)", parameter, address.Uint160ToString(u), "0x"+hex.EncodeToString(slice.CopyReverse(parameter)))
} else {
desc = fmt.Sprintf("%x", parameter)
}
}
}
}
Expand Down

0 comments on commit a59fd50

Please sign in to comment.