mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
Fix parsing of integer block numbers
This commit is contained in:
parent
b68c3ddfef
commit
18090ea4ed
3 changed files with 41 additions and 18 deletions
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -476,11 +475,11 @@ func returnLogs(logs []*types.Log) []*types.Log {
|
||||||
// UnmarshalJSON sets *args fields with given data.
|
// UnmarshalJSON sets *args fields with given data.
|
||||||
func (args *FilterCriteria) UnmarshalJSON(data []byte) error {
|
func (args *FilterCriteria) UnmarshalJSON(data []byte) error {
|
||||||
type input struct {
|
type input struct {
|
||||||
BlockHash *common.Hash `json:"blockHash"`
|
BlockHash *common.Hash `json:"blockHash"`
|
||||||
FromBlock *string `json:"fromBlock"`
|
FromBlock *rpc.BlockNumberOrHash `json:"fromBlock"`
|
||||||
ToBlock *string `json:"toBlock"`
|
ToBlock *rpc.BlockNumberOrHash `json:"toBlock"`
|
||||||
Addresses interface{} `json:"address"`
|
Addresses interface{} `json:"address"`
|
||||||
Topics []interface{} `json:"topics"`
|
Topics []interface{} `json:"topics"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var raw input
|
var raw input
|
||||||
|
|
@ -496,19 +495,17 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error {
|
||||||
args.BlockHash = raw.BlockHash
|
args.BlockHash = raw.BlockHash
|
||||||
} else {
|
} else {
|
||||||
if raw.FromBlock != nil {
|
if raw.FromBlock != nil {
|
||||||
if strings.HasPrefix(*raw.FromBlock, "0x") {
|
if raw.FromBlock.IsHash() {
|
||||||
hash := common.HexToHash(*raw.FromBlock)
|
args.FromBlockHash = raw.FromBlock.Hash()
|
||||||
args.FromBlockHash = &hash
|
|
||||||
} else {
|
} else {
|
||||||
args.FromBlock.UnmarshalJSON([]byte(*raw.FromBlock))
|
args.FromBlock = big.NewInt(int64(raw.FromBlock.Number()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if raw.ToBlock != nil {
|
if raw.ToBlock != nil {
|
||||||
if strings.HasPrefix(*raw.ToBlock, "0x") {
|
if raw.ToBlock.IsHash() {
|
||||||
hash := common.HexToHash(*raw.ToBlock)
|
args.ToBlockHash = raw.ToBlock.Hash()
|
||||||
args.ToBlockHash = &hash
|
|
||||||
} else {
|
} else {
|
||||||
args.ToBlock.UnmarshalJSON([]byte(*raw.ToBlock))
|
args.ToBlock = big.NewInt(int64(raw.ToBlock.Number()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -223,18 +223,18 @@ func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) {
|
||||||
// Gather all indexed logs, and finish with non indexed ones
|
// Gather all indexed logs, and finish with non indexed ones
|
||||||
if mainChain {
|
if mainChain {
|
||||||
size, sections := f.backend.BloomStatus()
|
size, sections := f.backend.BloomStatus()
|
||||||
if indexed := sections * size; indexed > begin.Number.Uint64() {
|
if indexed := sections * size; indexed > ancestor.Number.Uint64() {
|
||||||
if indexed > end.Number.Uint64() {
|
if indexed > end.Number.Uint64() {
|
||||||
logs, err = f.indexedLogs(ctx, begin.Number.Uint64(), end.Number.Uint64())
|
logs, err = f.indexedLogs(ctx, ancestor.Number.Uint64(), end.Number.Uint64())
|
||||||
} else {
|
} else {
|
||||||
logs, err = f.indexedLogs(ctx, begin.Number.Uint64(), indexed-1)
|
logs, err = f.indexedLogs(ctx, ancestor.Number.Uint64(), indexed-1)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return logs, err
|
return logs, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rest, err := f.unindexedLogs(ctx, begin.Hash(), end.Hash())
|
rest, err := f.unindexedLogs(ctx, ancestor.Hash(), end.Hash())
|
||||||
logs = append(logs, rest...)
|
logs = append(logs, rest...)
|
||||||
sort.Sort(logList(logs))
|
sort.Sort(logList(logs))
|
||||||
|
|
||||||
|
|
|
||||||
26
rpc/types.go
26
rpc/types.go
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
mapset "github.com/deckarep/golang-set"
|
mapset "github.com/deckarep/golang-set"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -163,3 +164,28 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
|
||||||
func (bn BlockNumber) Int64() int64 {
|
func (bn BlockNumber) Int64() int64 {
|
||||||
return (int64)(bn)
|
return (int64)(bn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BlockNumberOrHash string
|
||||||
|
|
||||||
|
func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
|
||||||
|
*bnh = BlockNumberOrHash(data)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bnh BlockNumberOrHash) IsHash() bool {
|
||||||
|
return bnh[0] == '"' && bnh[len(bnh)-1] == '"' && len(bnh) == 44
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bnh BlockNumberOrHash) Hash() *common.Hash {
|
||||||
|
if !bnh.IsHash() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
hash := common.HexToHash(string(bnh[1 : len(bnh)-1]))
|
||||||
|
return &hash
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bnh BlockNumberOrHash) Number() int64 {
|
||||||
|
var bn BlockNumber
|
||||||
|
(&bn).UnmarshalJSON([]byte(bnh))
|
||||||
|
return bn.Int64()
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue