diff --git a/libraries/shared/storage/utils/decoder.go b/libraries/shared/storage/utils/decoder.go index f179355e..36f9208d 100644 --- a/libraries/shared/storage/utils/decoder.go +++ b/libraries/shared/storage/utils/decoder.go @@ -27,6 +27,8 @@ func Decode(row StorageDiffRow, metadata StorageValueMetadata) (interface{}, err switch metadata.Type { case Uint256: return decodeUint256(row.StorageValue.Bytes()), nil + case Uint48: + return decodeUint48(row.StorageValue.Bytes()), nil case Address: return decodeAddress(row.StorageValue.Bytes()), nil case Bytes32: @@ -41,6 +43,11 @@ func decodeUint256(raw []byte) string { return n.String() } +func decodeUint48(raw []byte) string { + n := big.NewInt(0).SetBytes(raw) + return n.String() +} + func decodeAddress(raw []byte) string { return common.BytesToAddress(raw).Hex() } diff --git a/libraries/shared/storage/utils/decoder_test.go b/libraries/shared/storage/utils/decoder_test.go index 28721d50..ba74a969 100644 --- a/libraries/shared/storage/utils/decoder_test.go +++ b/libraries/shared/storage/utils/decoder_test.go @@ -38,6 +38,17 @@ var _ = Describe("Storage decoder", func() { Expect(result).To(Equal(big.NewInt(0).SetBytes(fakeInt.Bytes()).String())) }) + It("decodes uint48", func() { + fakeInt := common.HexToHash("0000000000000000000000000000000000000000000000000000000000000123") + row := utils.StorageDiffRow{StorageValue: fakeInt} + metadata := utils.StorageValueMetadata{Type: utils.Uint48} + + result, err := utils.Decode(row, metadata) + + Expect(err).NotTo(HaveOccurred()) + Expect(result).To(Equal(big.NewInt(0).SetBytes(fakeInt.Bytes()).String())) + }) + It("decodes address", func() { fakeAddress := common.HexToAddress("0x12345") row := utils.StorageDiffRow{StorageValue: fakeAddress.Hash()} diff --git a/libraries/shared/storage/utils/value.go b/libraries/shared/storage/utils/value.go index bbefb1d7..5241bffe 100644 --- a/libraries/shared/storage/utils/value.go +++ b/libraries/shared/storage/utils/value.go @@ -20,6 +20,7 @@ type ValueType int const ( Uint256 ValueType = iota + Uint48 Bytes32 Address )