diff --git a/pkg/util/uint160.go b/pkg/util/uint160.go index 01de6a2f5..2be0819cf 100644 --- a/pkg/util/uint160.go +++ b/pkg/util/uint160.go @@ -60,6 +60,15 @@ func (u Uint160) StringLE() string { return hex.EncodeToString(u.BytesLE()) } +// Reverse returns reversed representation of u. +func (u Uint160) Reverse() (r Uint160) { + for i := 0; i < Uint160Size; i++ { + r[i] = u[Uint160Size-i-1] + } + + return +} + // Equals returns true if both Uint256 values are the same. func (u Uint160) Equals(other Uint160) bool { return u == other diff --git a/pkg/util/uint160_test.go b/pkg/util/uint160_test.go index 6a489f1a7..9519f4f70 100644 --- a/pkg/util/uint160_test.go +++ b/pkg/util/uint160_test.go @@ -94,3 +94,12 @@ func TestUInt160String(t *testing.T) { assert.Equal(t, hexStr, val.String()) assert.Equal(t, hexRevStr, val.StringLE()) } + +func TestUint160_Reverse(t *testing.T) { + hexStr := "b28427088a3729b2536d10122960394e8be6721f" + val, err := Uint160DecodeStringBE(hexStr) + + require.NoError(t, err) + assert.Equal(t, hexStr, val.Reverse().StringLE()) + assert.Equal(t, val, val.Reverse().Reverse()) +}