Skip to content

Commit

Permalink
u256 decode return decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
freehere107 committed Dec 18, 2024
1 parent e51683b commit 7f32e9a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion types/Uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ type U256 struct {
}

func (u *U256) Process() {
u.Value = utiles.AddHex(utiles.BytesToHex(u.NextBytes(32)))
reverseData := u.NextBytes(32)
Reverse(reverseData)
u.Value = decimal.NewFromBigInt(utiles.U256(utiles.BytesToHex(reverseData)), 0)
}

func (u *U256) Encode(value interface{}) string {
Expand Down
4 changes: 3 additions & 1 deletion types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ func TestU256(t *testing.T) {
raw := "0x1001000000000000000000000000000000000000000000000000000000000000"
m := ScaleDecoder{}
m.Init(scaleBytes.ScaleBytes{Data: utiles.HexToBytes(raw)}, nil)
assert.Equal(t, raw, utiles.AddHex(Encode("U256", utiles.U256DecoderToBigInt(m.ProcessAndUpdateData("U256").(string)))))
assert.Equal(t, raw, utiles.AddHex(Encode("U256", m.ProcessAndUpdateData("U256").(decimal.Decimal))))
assert.Equal(t, raw, utiles.AddHex(Encode("U256", "0x1001000000000000000000000000000000000000000000000000000000000000")))
m.Init(scaleBytes.ScaleBytes{Data: utiles.HexToBytes("0x00b5070000000000000000000000000000000000000000000000000000000000")}, nil)
assert.Equal(t, int64(505088), m.ProcessAndUpdateData("U256").(decimal.Decimal).IntPart())
}

0 comments on commit 7f32e9a

Please sign in to comment.