Add unit48 to storage decoder
This commit is contained in:
parent
cdcb90c170
commit
89d152e987
@ -27,6 +27,8 @@ func Decode(row StorageDiffRow, metadata StorageValueMetadata) (interface{}, err
|
|||||||
switch metadata.Type {
|
switch metadata.Type {
|
||||||
case Uint256:
|
case Uint256:
|
||||||
return decodeUint256(row.StorageValue.Bytes()), nil
|
return decodeUint256(row.StorageValue.Bytes()), nil
|
||||||
|
case Uint48:
|
||||||
|
return decodeUint48(row.StorageValue.Bytes()), nil
|
||||||
case Address:
|
case Address:
|
||||||
return decodeAddress(row.StorageValue.Bytes()), nil
|
return decodeAddress(row.StorageValue.Bytes()), nil
|
||||||
case Bytes32:
|
case Bytes32:
|
||||||
@ -41,6 +43,11 @@ func decodeUint256(raw []byte) string {
|
|||||||
return n.String()
|
return n.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func decodeUint48(raw []byte) string {
|
||||||
|
n := big.NewInt(0).SetBytes(raw)
|
||||||
|
return n.String()
|
||||||
|
}
|
||||||
|
|
||||||
func decodeAddress(raw []byte) string {
|
func decodeAddress(raw []byte) string {
|
||||||
return common.BytesToAddress(raw).Hex()
|
return common.BytesToAddress(raw).Hex()
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,17 @@ var _ = Describe("Storage decoder", func() {
|
|||||||
Expect(result).To(Equal(big.NewInt(0).SetBytes(fakeInt.Bytes()).String()))
|
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() {
|
It("decodes address", func() {
|
||||||
fakeAddress := common.HexToAddress("0x12345")
|
fakeAddress := common.HexToAddress("0x12345")
|
||||||
row := utils.StorageDiffRow{StorageValue: fakeAddress.Hash()}
|
row := utils.StorageDiffRow{StorageValue: fakeAddress.Hash()}
|
||||||
|
@ -20,6 +20,7 @@ type ValueType int
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
Uint256 ValueType = iota
|
Uint256 ValueType = iota
|
||||||
|
Uint48
|
||||||
Bytes32
|
Bytes32
|
||||||
Address
|
Address
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user