mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
accounts/abi/bind: fixed erroneous packing of negative ints
This commit is contained in:
parent
5065cdefff
commit
f070287e78
1 changed files with 17 additions and 8 deletions
|
|
@ -49,17 +49,13 @@ func makeTopics(query ...[]interface{}) ([][]common.Hash, error) {
|
||||||
topic[common.HashLength-1] = 1
|
topic[common.HashLength-1] = 1
|
||||||
}
|
}
|
||||||
case int8:
|
case int8:
|
||||||
blob := big.NewInt(int64(rule)).Bytes()
|
copy(topic[:], genIntType(int64(rule), 1))
|
||||||
copy(topic[common.HashLength-len(blob):], blob)
|
|
||||||
case int16:
|
case int16:
|
||||||
blob := big.NewInt(int64(rule)).Bytes()
|
copy(topic[:], genIntType(int64(rule), 2))
|
||||||
copy(topic[common.HashLength-len(blob):], blob)
|
|
||||||
case int32:
|
case int32:
|
||||||
blob := big.NewInt(int64(rule)).Bytes()
|
copy(topic[:], genIntType(int64(rule), 4))
|
||||||
copy(topic[common.HashLength-len(blob):], blob)
|
|
||||||
case int64:
|
case int64:
|
||||||
blob := big.NewInt(rule).Bytes()
|
copy(topic[:], genIntType(rule, 8))
|
||||||
copy(topic[common.HashLength-len(blob):], blob)
|
|
||||||
case uint8:
|
case uint8:
|
||||||
blob := new(big.Int).SetUint64(uint64(rule)).Bytes()
|
blob := new(big.Int).SetUint64(uint64(rule)).Bytes()
|
||||||
copy(topic[common.HashLength-len(blob):], blob)
|
copy(topic[common.HashLength-len(blob):], blob)
|
||||||
|
|
@ -103,6 +99,19 @@ func makeTopics(query ...[]interface{}) ([][]common.Hash, error) {
|
||||||
return topics, nil
|
return topics, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func genIntType(rule int64, size int) []byte {
|
||||||
|
var topic [common.HashLength]byte
|
||||||
|
if rule < 0 {
|
||||||
|
// if a rule is negative, we need to put it into two's complement.
|
||||||
|
// extended to common.Hashlength bytes.
|
||||||
|
topic = [common.HashLength]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
|
||||||
|
}
|
||||||
|
for i := 0; i < size; i++ {
|
||||||
|
topic[common.HashLength-i-1] = byte(rule >> (i * 8))
|
||||||
|
}
|
||||||
|
return topic[:]
|
||||||
|
}
|
||||||
|
|
||||||
// parseTopics converts the indexed topic fields into actual log field values.
|
// parseTopics converts the indexed topic fields into actual log field values.
|
||||||
func parseTopics(out interface{}, fields abi.Arguments, topics []common.Hash) error {
|
func parseTopics(out interface{}, fields abi.Arguments, topics []common.Hash) error {
|
||||||
return parseTopicWithSetter(fields, topics,
|
return parseTopicWithSetter(fields, topics,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue