util: add Uint160.Reverse()

This commit is contained in:
Evgenii Stratonikov 2019-12-03 16:07:15 +03:00
parent 9e04e61533
commit 09b295d727
2 changed files with 18 additions and 0 deletions

View file

@ -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

View file

@ -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())
}