mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
Repurpose fromBlock/toBlock RPC parameters, update web3.js
This commit is contained in:
parent
6d019710ef
commit
b68c3ddfef
4 changed files with 90 additions and 69 deletions
|
|
@ -22,6 +22,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
|
@ -476,10 +477,8 @@ func returnLogs(logs []*types.Log) []*types.Log {
|
|||
func (args *FilterCriteria) UnmarshalJSON(data []byte) error {
|
||||
type input struct {
|
||||
BlockHash *common.Hash `json:"blockHash"`
|
||||
FromBlock *rpc.BlockNumber `json:"fromBlock"`
|
||||
FromBlockHash *common.Hash `json:"fromBlockHash"`
|
||||
ToBlock *rpc.BlockNumber `json:"toBlock"`
|
||||
ToBlockHash *common.Hash `json:"toBlockHash"`
|
||||
FromBlock *string `json:"fromBlock"`
|
||||
ToBlock *string `json:"toBlock"`
|
||||
Addresses interface{} `json:"address"`
|
||||
Topics []interface{} `json:"topics"`
|
||||
}
|
||||
|
|
@ -497,16 +496,20 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error {
|
|||
args.BlockHash = raw.BlockHash
|
||||
} else {
|
||||
if raw.FromBlock != nil {
|
||||
args.FromBlock = big.NewInt(raw.FromBlock.Int64())
|
||||
if strings.HasPrefix(*raw.FromBlock, "0x") {
|
||||
hash := common.HexToHash(*raw.FromBlock)
|
||||
args.FromBlockHash = &hash
|
||||
} else {
|
||||
args.FromBlock.UnmarshalJSON([]byte(*raw.FromBlock))
|
||||
}
|
||||
if raw.FromBlockHash != nil {
|
||||
args.FromBlockHash = raw.FromBlockHash
|
||||
}
|
||||
if raw.ToBlock != nil {
|
||||
args.ToBlock = big.NewInt(raw.ToBlock.Int64())
|
||||
if strings.HasPrefix(*raw.ToBlock, "0x") {
|
||||
hash := common.HexToHash(*raw.ToBlock)
|
||||
args.ToBlockHash = &hash
|
||||
} else {
|
||||
args.ToBlock.UnmarshalJSON([]byte(*raw.ToBlock))
|
||||
}
|
||||
if raw.ToBlockHash != nil {
|
||||
args.ToBlockHash = raw.ToBlockHash
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -200,6 +200,10 @@ func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if end.Number.Cmp(begin.Number) < 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
ancestor, mainChain, err := f.findCommonAncestor(ctx, begin, end)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -287,7 +291,7 @@ func (f *Filter) indexedLogs(ctx context.Context, begin, end uint64) ([]*types.L
|
|||
func (f *Filter) unindexedLogs(ctx context.Context, begin, end common.Hash) ([]*types.Log, error) {
|
||||
var logs []*types.Log
|
||||
|
||||
for begin != end {
|
||||
for {
|
||||
header, err := f.backend.HeaderByHash(ctx, end)
|
||||
if header == nil || err != nil {
|
||||
return logs, err
|
||||
|
|
@ -297,6 +301,9 @@ func (f *Filter) unindexedLogs(ctx context.Context, begin, end common.Hash) ([]*
|
|||
return logs, err
|
||||
}
|
||||
logs = append(logs, found...)
|
||||
if begin == end {
|
||||
break
|
||||
}
|
||||
end = header.ParentHash
|
||||
}
|
||||
return logs, nil
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -5431,6 +5431,12 @@ var methods = function () {
|
|||
params: 0
|
||||
});
|
||||
|
||||
var getLogs = new Method({
|
||||
name: 'getLogs',
|
||||
call: 'eth_getLogs',
|
||||
params: 1
|
||||
})
|
||||
|
||||
return [
|
||||
getBalance,
|
||||
getStorageAt,
|
||||
|
|
@ -5454,7 +5460,8 @@ var methods = function () {
|
|||
compileLLL,
|
||||
compileSerpent,
|
||||
submitWork,
|
||||
getWork
|
||||
getWork,
|
||||
getLogs
|
||||
];
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue