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"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -476,10 +477,8 @@ func returnLogs(logs []*types.Log) []*types.Log {
|
||||||
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 *rpc.BlockNumber `json:"fromBlock"`
|
FromBlock *string `json:"fromBlock"`
|
||||||
FromBlockHash *common.Hash `json:"fromBlockHash"`
|
ToBlock *string `json:"toBlock"`
|
||||||
ToBlock *rpc.BlockNumber `json:"toBlock"`
|
|
||||||
ToBlockHash *common.Hash `json:"toBlockHash"`
|
|
||||||
Addresses interface{} `json:"address"`
|
Addresses interface{} `json:"address"`
|
||||||
Topics []interface{} `json:"topics"`
|
Topics []interface{} `json:"topics"`
|
||||||
}
|
}
|
||||||
|
|
@ -497,16 +496,20 @@ 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 {
|
||||||
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 {
|
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)
|
ancestor, mainChain, err := f.findCommonAncestor(ctx, begin, end)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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) {
|
func (f *Filter) unindexedLogs(ctx context.Context, begin, end common.Hash) ([]*types.Log, error) {
|
||||||
var logs []*types.Log
|
var logs []*types.Log
|
||||||
|
|
||||||
for begin != end {
|
for {
|
||||||
header, err := f.backend.HeaderByHash(ctx, end)
|
header, err := f.backend.HeaderByHash(ctx, end)
|
||||||
if header == nil || err != nil {
|
if header == nil || err != nil {
|
||||||
return logs, err
|
return logs, err
|
||||||
|
|
@ -297,6 +301,9 @@ func (f *Filter) unindexedLogs(ctx context.Context, begin, end common.Hash) ([]*
|
||||||
return logs, err
|
return logs, err
|
||||||
}
|
}
|
||||||
logs = append(logs, found...)
|
logs = append(logs, found...)
|
||||||
|
if begin == end {
|
||||||
|
break
|
||||||
|
}
|
||||||
end = header.ParentHash
|
end = header.ParentHash
|
||||||
}
|
}
|
||||||
return logs, nil
|
return logs, nil
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -5431,6 +5431,12 @@ var methods = function () {
|
||||||
params: 0
|
params: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var getLogs = new Method({
|
||||||
|
name: 'getLogs',
|
||||||
|
call: 'eth_getLogs',
|
||||||
|
params: 1
|
||||||
|
})
|
||||||
|
|
||||||
return [
|
return [
|
||||||
getBalance,
|
getBalance,
|
||||||
getStorageAt,
|
getStorageAt,
|
||||||
|
|
@ -5454,7 +5460,8 @@ var methods = function () {
|
||||||
compileLLL,
|
compileLLL,
|
||||||
compileSerpent,
|
compileSerpent,
|
||||||
submitWork,
|
submitWork,
|
||||||
getWork
|
getWork,
|
||||||
|
getLogs
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue