Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get logs #1028

Merged
merged 24 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/ledgerwatch/turbo-geth/core/types"
"github.com/ledgerwatch/turbo-geth/crypto"
"github.com/ledgerwatch/turbo-geth/event"
"github.com/ledgerwatch/turbo-geth/rpc"
)

// SignerFn is a signer function callback when a contract requires a method to
Expand Down Expand Up @@ -279,10 +280,10 @@ func (c *BoundContract) FilterLogs(opts *FilterOpts, name string, query ...[]int
config := ethereum.FilterQuery{
Addresses: []common.Address{c.address},
Topics: topics,
FromBlock: new(big.Int).SetUint64(opts.Start),
FromBlock: rpc.NewRPCBlockNumber(int(opts.Start)),
}
if opts.End != nil {
config.ToBlock = new(big.Int).SetUint64(*opts.End)
config.ToBlock = rpc.NewRPCBlockNumber(int(*opts.End))
}
/* TODO(karalabe): Replace the rest of the method below with this when supported
sub, err := c.filterer.SubscribeFilterLogs(ensureContext(opts.Context), config, logs)
Expand Down Expand Up @@ -330,7 +331,7 @@ func (c *BoundContract) WatchLogs(opts *WatchOpts, name string, query ...[]inter
Topics: topics,
}
if opts.Start != nil {
config.FromBlock = new(big.Int).SetUint64(*opts.Start)
config.FromBlock = rpc.NewRPCBlockNumber(int(*opts.Start))
}
sub, err := c.filterer.SubscribeFilterLogs(ensureContext(opts.Context), config, logs)
if err != nil {
Expand Down
34 changes: 22 additions & 12 deletions cmd/rpcdaemon/commands/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/hexutil"
"github.com/ledgerwatch/turbo-geth/core/rawdb"
"github.com/ledgerwatch/turbo-geth/eth/stagedsync/stages"
"github.com/ledgerwatch/turbo-geth/core/types"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/rpc"
"github.com/ledgerwatch/turbo-geth/turbo/adapter/ethapi"
Expand All @@ -17,17 +17,9 @@ import (
// GetBlockByNumber see https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblockbynumber
// see internal/ethapi.PublicBlockChainAPI.GetBlockByNumber
func (api *APIImpl) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) {
var blockNum uint64
if number == rpc.LatestBlockNumber || number == rpc.PendingBlockNumber {
var err error
blockNum, _, err = stages.GetStageProgress(api.dbReader, stages.Execution)
if err != nil {
return nil, fmt.Errorf("getting latest block number: %v", err)
}
} else if number == rpc.EarliestBlockNumber {
blockNum = 0
} else {
blockNum = uint64(number.Int64())
blockNum, err := getBlockNumber(number, api.dbReader)
if err != nil {
return nil, err
}
additionalFields := make(map[string]interface{})

Expand Down Expand Up @@ -71,6 +63,24 @@ func (api *APIImpl) GetBlockByHash(ctx context.Context, hash common.Hash, fullTx
return response, err
}

func (api *APIImpl) GetHeaderByNumber(_ context.Context, number rpc.BlockNumber) (*types.Header, error) {
header := rawdb.ReadHeaderByNumber(api.dbReader, uint64(number.Int64()))
if header == nil {
return nil, fmt.Errorf("block header not found: %d", number.Int64())
}

return header, nil
}

func (api *APIImpl) GetHeaderByHash(_ context.Context, hash common.Hash) (*types.Header, error) {
header := rawdb.ReadHeaderByHash(api.dbReader, hash)
if header == nil {
return nil, fmt.Errorf("block header not found: %s", hash.String())
}

return header, nil
}

func APIList(db ethdb.KV, eth ethdb.Backend, cfg cli.Flags, customApiList []rpc.API) []rpc.API {
var defaultAPIList []rpc.API

Expand Down
19 changes: 7 additions & 12 deletions cmd/rpcdaemon/commands/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"github.com/ledgerwatch/turbo-geth/eth/filters"

"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/hexutil"
"github.com/ledgerwatch/turbo-geth/core"
Expand All @@ -23,7 +25,7 @@ type EthAPI interface {
GetBlockByHash(ctx context.Context, hash common.Hash, fullTx bool) (map[string]interface{}, error)
GetBalance(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error)
GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error)
GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error)
GetLogs(ctx context.Context, crit filters.FilterCriteria) ([]*types.Log, error)
Call(ctx context.Context, args ethapi.CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *map[common.Address]ethapi.Account) (hexutil.Bytes, error)
EstimateGas(ctx context.Context, args ethapi.CallArgs) (hexutil.Uint64, error)
SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error)
Expand Down Expand Up @@ -83,18 +85,11 @@ func (api *APIImpl) Syncing(ctx context.Context) (interface{}, error) {
}

func (api *APIImpl) GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*hexutil.Uint, error) {
var blockNum uint64
if blockNr == rpc.LatestBlockNumber || blockNr == rpc.PendingBlockNumber {
var err error
blockNum, _, err = stages.GetStageProgress(api.dbReader, stages.Execution)
if err != nil {
return nil, fmt.Errorf("getting latest block number: %v", err)
}
} else if blockNr == rpc.EarliestBlockNumber {
blockNum = 0
} else {
blockNum = uint64(blockNr.Int64())
blockNum, err := getBlockNumber(blockNr, api.dbReader)
if err != nil {
return nil, err
}

block := rawdb.ReadBlockByNumber(api.dbReader, blockNum)
if block == nil {
return nil, fmt.Errorf("block not found: %d", blockNum)
Expand Down
Loading