Skip to content

Commit

Permalink
Support getting M or N dimensions
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Broadhurst <[email protected]>
  • Loading branch information
peterbroadhurst committed Jul 17, 2024
1 parent a947511 commit 5aafe81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/abi/abidecode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ func TestDecodeABISignedIntOk(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, ElementaryTypeInt, cv.Children[0].Component.ElementaryType())
assert.Equal(t, uint16(256), cv.Children[0].Component.ElementaryM())
assert.Equal(t, int64(-0x12345), cv.Children[0].Value.(*big.Int).Int64())

}
Expand Down Expand Up @@ -667,6 +668,8 @@ func TestDecodeABIFixedOk(t *testing.T) {
cv, err := p.DecodeABIData(d, 0)
assert.NoError(t, err)
assert.Equal(t, ElementaryTypeFixed, cv.Children[0].Component.ElementaryType())
assert.Equal(t, uint16(64), cv.Children[0].Component.ElementaryM())
assert.Equal(t, uint16(4), cv.Children[0].Component.ElementaryN())
assert.Equal(t, "-7.4565", cv.Children[0].Value.(*big.Float).String())

}
Expand Down Expand Up @@ -1046,7 +1049,7 @@ func TestDecodeAddressWithNonZeroPadding(t *testing.T) {
"ffffffffffffffffffffffffab0974bbed8afc5212e951c8498873319d02d025" + // (uint256) 0xffffffffffffffffffffffffab0974bbed8afc5212e951c8498873319d02d025
"ffffffffffffffffffffffffab0974bbed8afc5212e951c8498873319d02d025" + // (uint160) 0xab0974bbed8afc5212e951c8498873319d02d025
"ffffffffffffffffffffffffab0974bbed8afc5212e951c8498873319d02d025" + // ( uint64) 0x498873319d02d025
"ffffffffffffffffffffffffab0974bbed8afc5212e951c8498873319d02d025") // ( uint8) 0x25
"ffffffffffffffffffffffffab0974bbed8afc5212e951c8498873319d02d025") // ( uint8) 0x25
assert.NoError(t, err)

cv, err := f.DecodeCallData(d)
Expand Down
12 changes: 12 additions & 0 deletions pkg/abi/typecomponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type TypeComponent interface {
String() string // gives the signature for this type level of the type component hierarchy
ComponentType() ComponentType // classification of the component type (tuple, array or elemental)
ElementaryType() ElementaryTypeInfo // only non-nil for elementary components
ElementaryM() uint16 // only for N dimensioned elementary types
ElementaryN() uint16 // only for M dimensioned elementary types
ElementarySuffix() string // only on elementary types with a suffix - expands "aliases" (so "uint" would have "256")
ElementaryFixed() bool // whether the elementary type if fixed
ArrayChild() TypeComponent // only non-nil for array components
Expand Down Expand Up @@ -380,6 +382,16 @@ func (tc *typeComponent) ElementaryFixed() bool {
return false
}

// M dimension of elementary type (if applicable)
func (tc *typeComponent) ElementaryM() uint16 {
return tc.m
}

// N dimension of elementary type (if applicable)
func (tc *typeComponent) ElementaryN() uint16 {
return tc.n
}

func (tc *typeComponent) KeyName() string {
return tc.keyName
}
Expand Down

0 comments on commit 5aafe81

Please sign in to comment.