accounts/abi: fix bigInt topic encoding (#28764)
This commit is contained in:
parent
1010a79c7c
commit
d0edc5af4a
|
@ -24,6 +24,7 @@ import (
|
|||
"reflect"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/math"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
)
|
||||
|
||||
|
@ -41,8 +42,7 @@ func MakeTopics(query ...[]interface{}) ([][]common.Hash, error) {
|
|||
case common.Address:
|
||||
copy(topic[common.HashLength-common.AddressLength:], rule[:])
|
||||
case *big.Int:
|
||||
blob := rule.Bytes()
|
||||
copy(topic[common.HashLength-len(blob):], blob)
|
||||
copy(topic[:], math.U256Bytes(rule))
|
||||
case bool:
|
||||
if rule {
|
||||
topic[common.HashLength-1] = 1
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package abi
|
||||
|
||||
import (
|
||||
"math"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
@ -55,9 +56,27 @@ func TestMakeTopics(t *testing.T) {
|
|||
false,
|
||||
},
|
||||
{
|
||||
"support *big.Int types in topics",
|
||||
args{[][]interface{}{{big.NewInt(1).Lsh(big.NewInt(2), 254)}}},
|
||||
[][]common.Hash{{common.Hash{128}}},
|
||||
"support positive *big.Int types in topics",
|
||||
args{[][]interface{}{
|
||||
{big.NewInt(1)},
|
||||
{big.NewInt(1).Lsh(big.NewInt(2), 254)},
|
||||
}},
|
||||
[][]common.Hash{
|
||||
{common.HexToHash("0000000000000000000000000000000000000000000000000000000000000001")},
|
||||
{common.Hash{128}},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"support negative *big.Int types in topics",
|
||||
args{[][]interface{}{
|
||||
{big.NewInt(-1)},
|
||||
{big.NewInt(math.MinInt64)},
|
||||
}},
|
||||
[][]common.Hash{
|
||||
{common.MaxHash},
|
||||
{common.HexToHash("ffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000")},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue