Skip to content

Commit 7f32e9a

Browse files
committedDec 18, 2024·
u256 decode return decimals
1 parent e51683b commit 7f32e9a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
 

‎types/Uint.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ type U256 struct {
202202
}
203203

204204
func (u *U256) Process() {
205-
u.Value = utiles.AddHex(utiles.BytesToHex(u.NextBytes(32)))
205+
reverseData := u.NextBytes(32)
206+
Reverse(reverseData)
207+
u.Value = decimal.NewFromBigInt(utiles.U256(utiles.BytesToHex(reverseData)), 0)
206208
}
207209

208210
func (u *U256) Encode(value interface{}) string {

‎types/types_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ func TestU256(t *testing.T) {
368368
raw := "0x1001000000000000000000000000000000000000000000000000000000000000"
369369
m := ScaleDecoder{}
370370
m.Init(scaleBytes.ScaleBytes{Data: utiles.HexToBytes(raw)}, nil)
371-
assert.Equal(t, raw, utiles.AddHex(Encode("U256", utiles.U256DecoderToBigInt(m.ProcessAndUpdateData("U256").(string)))))
371+
assert.Equal(t, raw, utiles.AddHex(Encode("U256", m.ProcessAndUpdateData("U256").(decimal.Decimal))))
372372
assert.Equal(t, raw, utiles.AddHex(Encode("U256", "0x1001000000000000000000000000000000000000000000000000000000000000")))
373+
m.Init(scaleBytes.ScaleBytes{Data: utiles.HexToBytes("0x00b5070000000000000000000000000000000000000000000000000000000000")}, nil)
374+
assert.Equal(t, int64(505088), m.ProcessAndUpdateData("U256").(decimal.Decimal).IntPart())
373375
}

0 commit comments

Comments
 (0)
Please sign in to comment.