|
|
@ -37,26 +37,26 @@ import ( |
|
|
|
"github.com/ethereum/go-ethereum/rpc" |
|
|
|
"github.com/ethereum/go-ethereum/rpc" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// EthApiBackend implements ethapi.Backend for full nodes
|
|
|
|
// EthAPIBackend implements ethapi.Backend for full nodes
|
|
|
|
type EthApiBackend struct { |
|
|
|
type EthAPIBackend struct { |
|
|
|
eth *Ethereum |
|
|
|
eth *Ethereum |
|
|
|
gpo *gasprice.Oracle |
|
|
|
gpo *gasprice.Oracle |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) ChainConfig() *params.ChainConfig { |
|
|
|
func (b *EthAPIBackend) ChainConfig() *params.ChainConfig { |
|
|
|
return b.eth.chainConfig |
|
|
|
return b.eth.chainConfig |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) CurrentBlock() *types.Block { |
|
|
|
func (b *EthAPIBackend) CurrentBlock() *types.Block { |
|
|
|
return b.eth.blockchain.CurrentBlock() |
|
|
|
return b.eth.blockchain.CurrentBlock() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) SetHead(number uint64) { |
|
|
|
func (b *EthAPIBackend) SetHead(number uint64) { |
|
|
|
b.eth.protocolManager.downloader.Cancel() |
|
|
|
b.eth.protocolManager.downloader.Cancel() |
|
|
|
b.eth.blockchain.SetHead(number) |
|
|
|
b.eth.blockchain.SetHead(number) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) { |
|
|
|
func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) { |
|
|
|
// Pending block is only known by the miner
|
|
|
|
// Pending block is only known by the miner
|
|
|
|
if blockNr == rpc.PendingBlockNumber { |
|
|
|
if blockNr == rpc.PendingBlockNumber { |
|
|
|
block := b.eth.miner.PendingBlock() |
|
|
|
block := b.eth.miner.PendingBlock() |
|
|
@ -69,7 +69,7 @@ func (b *EthApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNum |
|
|
|
return b.eth.blockchain.GetHeaderByNumber(uint64(blockNr)), nil |
|
|
|
return b.eth.blockchain.GetHeaderByNumber(uint64(blockNr)), nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error) { |
|
|
|
func (b *EthAPIBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error) { |
|
|
|
// Pending block is only known by the miner
|
|
|
|
// Pending block is only known by the miner
|
|
|
|
if blockNr == rpc.PendingBlockNumber { |
|
|
|
if blockNr == rpc.PendingBlockNumber { |
|
|
|
block := b.eth.miner.PendingBlock() |
|
|
|
block := b.eth.miner.PendingBlock() |
|
|
@ -82,7 +82,7 @@ func (b *EthApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumb |
|
|
|
return b.eth.blockchain.GetBlockByNumber(uint64(blockNr)), nil |
|
|
|
return b.eth.blockchain.GetBlockByNumber(uint64(blockNr)), nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) { |
|
|
|
func (b *EthAPIBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) { |
|
|
|
// Pending state is only known by the miner
|
|
|
|
// Pending state is only known by the miner
|
|
|
|
if blockNr == rpc.PendingBlockNumber { |
|
|
|
if blockNr == rpc.PendingBlockNumber { |
|
|
|
block, state := b.eth.miner.Pending() |
|
|
|
block, state := b.eth.miner.Pending() |
|
|
@ -97,18 +97,18 @@ func (b *EthApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc. |
|
|
|
return stateDb, header, err |
|
|
|
return stateDb, header, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) GetBlock(ctx context.Context, hash common.Hash) (*types.Block, error) { |
|
|
|
func (b *EthAPIBackend) GetBlock(ctx context.Context, hash common.Hash) (*types.Block, error) { |
|
|
|
return b.eth.blockchain.GetBlockByHash(hash), nil |
|
|
|
return b.eth.blockchain.GetBlockByHash(hash), nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) { |
|
|
|
func (b *EthAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) { |
|
|
|
if number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash); number != nil { |
|
|
|
if number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash); number != nil { |
|
|
|
return rawdb.ReadReceipts(b.eth.chainDb, hash, *number), nil |
|
|
|
return rawdb.ReadReceipts(b.eth.chainDb, hash, *number), nil |
|
|
|
} |
|
|
|
} |
|
|
|
return nil, nil |
|
|
|
return nil, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) { |
|
|
|
func (b *EthAPIBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) { |
|
|
|
number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash) |
|
|
|
number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash) |
|
|
|
if number == nil { |
|
|
|
if number == nil { |
|
|
|
return nil, nil |
|
|
|
return nil, nil |
|
|
@ -124,11 +124,11 @@ func (b *EthApiBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*typ |
|
|
|
return logs, nil |
|
|
|
return logs, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) GetTd(blockHash common.Hash) *big.Int { |
|
|
|
func (b *EthAPIBackend) GetTd(blockHash common.Hash) *big.Int { |
|
|
|
return b.eth.blockchain.GetTdByHash(blockHash) |
|
|
|
return b.eth.blockchain.GetTdByHash(blockHash) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error) { |
|
|
|
func (b *EthAPIBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error) { |
|
|
|
state.SetBalance(msg.From(), math.MaxBig256) |
|
|
|
state.SetBalance(msg.From(), math.MaxBig256) |
|
|
|
vmError := func() error { return nil } |
|
|
|
vmError := func() error { return nil } |
|
|
|
|
|
|
|
|
|
|
@ -136,31 +136,31 @@ func (b *EthApiBackend) GetEVM(ctx context.Context, msg core.Message, state *sta |
|
|
|
return vm.NewEVM(context, state, b.eth.chainConfig, vmCfg), vmError, nil |
|
|
|
return vm.NewEVM(context, state, b.eth.chainConfig, vmCfg), vmError, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription { |
|
|
|
func (b *EthAPIBackend) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription { |
|
|
|
return b.eth.BlockChain().SubscribeRemovedLogsEvent(ch) |
|
|
|
return b.eth.BlockChain().SubscribeRemovedLogsEvent(ch) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription { |
|
|
|
func (b *EthAPIBackend) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription { |
|
|
|
return b.eth.BlockChain().SubscribeChainEvent(ch) |
|
|
|
return b.eth.BlockChain().SubscribeChainEvent(ch) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription { |
|
|
|
func (b *EthAPIBackend) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription { |
|
|
|
return b.eth.BlockChain().SubscribeChainHeadEvent(ch) |
|
|
|
return b.eth.BlockChain().SubscribeChainHeadEvent(ch) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription { |
|
|
|
func (b *EthAPIBackend) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription { |
|
|
|
return b.eth.BlockChain().SubscribeChainSideEvent(ch) |
|
|
|
return b.eth.BlockChain().SubscribeChainSideEvent(ch) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription { |
|
|
|
func (b *EthAPIBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription { |
|
|
|
return b.eth.BlockChain().SubscribeLogsEvent(ch) |
|
|
|
return b.eth.BlockChain().SubscribeLogsEvent(ch) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error { |
|
|
|
func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error { |
|
|
|
return b.eth.txPool.AddLocal(signedTx) |
|
|
|
return b.eth.txPool.AddLocal(signedTx) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) GetPoolTransactions() (types.Transactions, error) { |
|
|
|
func (b *EthAPIBackend) GetPoolTransactions() (types.Transactions, error) { |
|
|
|
pending, err := b.eth.txPool.Pending() |
|
|
|
pending, err := b.eth.txPool.Pending() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
@ -172,56 +172,56 @@ func (b *EthApiBackend) GetPoolTransactions() (types.Transactions, error) { |
|
|
|
return txs, nil |
|
|
|
return txs, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) GetPoolTransaction(hash common.Hash) *types.Transaction { |
|
|
|
func (b *EthAPIBackend) GetPoolTransaction(hash common.Hash) *types.Transaction { |
|
|
|
return b.eth.txPool.Get(hash) |
|
|
|
return b.eth.txPool.Get(hash) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) { |
|
|
|
func (b *EthAPIBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) { |
|
|
|
return b.eth.txPool.State().GetNonce(addr), nil |
|
|
|
return b.eth.txPool.State().GetNonce(addr), nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) Stats() (pending int, queued int) { |
|
|
|
func (b *EthAPIBackend) Stats() (pending int, queued int) { |
|
|
|
return b.eth.txPool.Stats() |
|
|
|
return b.eth.txPool.Stats() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions) { |
|
|
|
func (b *EthAPIBackend) TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions) { |
|
|
|
return b.eth.TxPool().Content() |
|
|
|
return b.eth.TxPool().Content() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) SubscribeTxPreEvent(ch chan<- core.TxPreEvent) event.Subscription { |
|
|
|
func (b *EthAPIBackend) SubscribeTxPreEvent(ch chan<- core.TxPreEvent) event.Subscription { |
|
|
|
return b.eth.TxPool().SubscribeTxPreEvent(ch) |
|
|
|
return b.eth.TxPool().SubscribeTxPreEvent(ch) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) Downloader() *downloader.Downloader { |
|
|
|
func (b *EthAPIBackend) Downloader() *downloader.Downloader { |
|
|
|
return b.eth.Downloader() |
|
|
|
return b.eth.Downloader() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) ProtocolVersion() int { |
|
|
|
func (b *EthAPIBackend) ProtocolVersion() int { |
|
|
|
return b.eth.EthVersion() |
|
|
|
return b.eth.EthVersion() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) SuggestPrice(ctx context.Context) (*big.Int, error) { |
|
|
|
func (b *EthAPIBackend) SuggestPrice(ctx context.Context) (*big.Int, error) { |
|
|
|
return b.gpo.SuggestPrice(ctx) |
|
|
|
return b.gpo.SuggestPrice(ctx) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) ChainDb() ethdb.Database { |
|
|
|
func (b *EthAPIBackend) ChainDb() ethdb.Database { |
|
|
|
return b.eth.ChainDb() |
|
|
|
return b.eth.ChainDb() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) EventMux() *event.TypeMux { |
|
|
|
func (b *EthAPIBackend) EventMux() *event.TypeMux { |
|
|
|
return b.eth.EventMux() |
|
|
|
return b.eth.EventMux() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) AccountManager() *accounts.Manager { |
|
|
|
func (b *EthAPIBackend) AccountManager() *accounts.Manager { |
|
|
|
return b.eth.AccountManager() |
|
|
|
return b.eth.AccountManager() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) BloomStatus() (uint64, uint64) { |
|
|
|
func (b *EthAPIBackend) BloomStatus() (uint64, uint64) { |
|
|
|
sections, _, _ := b.eth.bloomIndexer.Sections() |
|
|
|
sections, _, _ := b.eth.bloomIndexer.Sections() |
|
|
|
return params.BloomBitsBlocks, sections |
|
|
|
return params.BloomBitsBlocks, sections |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *EthApiBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) { |
|
|
|
func (b *EthAPIBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) { |
|
|
|
for i := 0; i < bloomFilterThreads; i++ { |
|
|
|
for i := 0; i < bloomFilterThreads; i++ { |
|
|
|
go session.Multiplex(bloomRetrievalBatch, bloomRetrievalWait, b.eth.bloomRequests) |
|
|
|
go session.Multiplex(bloomRetrievalBatch, bloomRetrievalWait, b.eth.bloomRequests) |
|
|
|
} |
|
|
|
} |
|
|
|