diff --git a/cmd/rpcdaemon/README.md b/cmd/rpcdaemon/README.md index 0cb8a2764..ee14487d1 100644 --- a/cmd/rpcdaemon/README.md +++ b/cmd/rpcdaemon/README.md @@ -79,9 +79,9 @@ The following table shows the current implementation status of turbo-geth's RPC | web3_clientVersion | Yes | | | web3_sha3 | Yes | | | | | | -| net_listening | HC | (hard coded returns true) | +| net_listening | HC | (remote only hard coded returns true) | | net_peerCount | HC | (hard coded 25 - work continues on Sentry) | -| net_version | Yes | | +| net_version | Yes | remote only | | | | | | eth_blockNumber | Yes | | | eth_chainID | Yes | | @@ -119,10 +119,10 @@ The following table shows the current implementation status of turbo-geth's RPC | eth_getFilterChanges | - | | | eth_getFilterLogs | - | | | eth_uninstallFilter | - | | -| eth_getLogs | Yes | | +| eth_getLogs | Yes | remote only | | | | | | eth_accounts | - | | -| eth_sendRawTransaction | Yes | | +| eth_sendRawTransaction | Yes | remote only | | eth_sendTransaction | - | | | eth_sign | - | | | eth_signTransaction | - | | diff --git a/cmd/rpcdaemon/commands/coinbase.go b/cmd/rpcdaemon/commands/coinbase.go index ce79537ee..8aebf5b14 100644 --- a/cmd/rpcdaemon/commands/coinbase.go +++ b/cmd/rpcdaemon/commands/coinbase.go @@ -2,11 +2,16 @@ package commands import ( "context" + "fmt" "github.com/ledgerwatch/turbo-geth/common" ) -// Etherbase is the address that mining rewards will be send to +// Coinbase is the address that mining rewards will be sent to func (api *APIImpl) Coinbase(_ context.Context) (common.Address, error) { + if api.ethBackend == nil { + // We're running in --chaindata mode or otherwise cannot get the backend + return common.Address{}, fmt.Errorf(NotAvailableChainData, "eth_coinbase") + } return api.ethBackend.Etherbase() } diff --git a/cmd/rpcdaemon/commands/debug_api.go b/cmd/rpcdaemon/commands/debug_api.go index 8e3dabb7d..74f28466e 100644 --- a/cmd/rpcdaemon/commands/debug_api.go +++ b/cmd/rpcdaemon/commands/debug_api.go @@ -68,7 +68,7 @@ func (api *PrivateDebugAPIImpl) AccountRange(ctx context.Context, blockNrOrHash blockNumber, _, err = stages.GetStageProgress(api.dbReader, stages.Execution) if err != nil { - return state.IteratorDump{}, fmt.Errorf("las block has not found: %w", err) + return state.IteratorDump{}, fmt.Errorf("last block has not found: %w", err) } } else { blockNumber = uint64(number) diff --git a/cmd/rpcdaemon/commands/error_messages.go b/cmd/rpcdaemon/commands/error_messages.go new file mode 100644 index 000000000..22b80c3e9 --- /dev/null +++ b/cmd/rpcdaemon/commands/error_messages.go @@ -0,0 +1,7 @@ +package commands + +// NotImplemented is the URI prefix for smartcard wallets. +const NotImplemented = "the function %s is currently not implemented" + +// NotAvailableChainData x +const NotAvailableChainData = "the function %s is not available, please use --private.api.addr option instead of --chaindata option" diff --git a/cmd/rpcdaemon/commands/get_receipts.go b/cmd/rpcdaemon/commands/get_receipts.go index 888aafb9a..abcd9d7a4 100644 --- a/cmd/rpcdaemon/commands/get_receipts.go +++ b/cmd/rpcdaemon/commands/get_receipts.go @@ -259,6 +259,11 @@ func (f *Filter) Logs(ctx context.Context, api *APIImpl) ([]*types.Log, error) { end = latest } + if api.ethBackend == nil { + // We're running in --chaindata mode or otherwise cannot get the backend + return nil, fmt.Errorf(NotAvailableChainData, "eth_getLogs") + } + // Gather all indexed logs, and finish with non indexed ones var logs []*types.Log size, sections, _ := api.ethBackend.BloomStatus() diff --git a/cmd/rpcdaemon/commands/net_api.go b/cmd/rpcdaemon/commands/net_api.go index 889bd8ba8..e4d30c86e 100644 --- a/cmd/rpcdaemon/commands/net_api.go +++ b/cmd/rpcdaemon/commands/net_api.go @@ -2,6 +2,7 @@ package commands import ( "context" + "fmt" "strconv" "github.com/ledgerwatch/turbo-geth/common/hexutil" @@ -9,24 +10,26 @@ import ( "github.com/ledgerwatch/turbo-geth/ethdb" ) +// NetAPI the interface for the net_ RPC commands type NetAPI interface { Listening(_ context.Context) (bool, error) Version(_ context.Context) (string, error) PeerCount(_ context.Context) (hexutil.Uint, error) } +// NetAPIImpl data structure to store things needed for net_ commands type NetAPIImpl struct { ethBackend ethdb.Backend } -// NewtNetAPIImpl returns NetAPIImplImpl instance +// NewNetAPIImpl returns NetAPIImplImpl instance func NewNetAPIImpl(eth ethdb.Backend) *NetAPIImpl { return &NetAPIImpl{ ethBackend: eth, } } -// Listen implements RPC call for net_listening +// Listening implements RPC call for net_listening // TODO(tjayrush) remove hard coded value func (api *NetAPIImpl) Listening(_ context.Context) (bool, error) { return true, nil @@ -34,10 +37,16 @@ func (api *NetAPIImpl) Listening(_ context.Context) (bool, error) { // Version implements RPC call for net_version func (api *NetAPIImpl) Version(_ context.Context) (string, error) { + if api.ethBackend == nil { + // We're running in --chaindata mode or otherwise cannot get the backend + return "", fmt.Errorf(NotAvailableChainData, "net_version") + } + res, err := api.ethBackend.NetVersion() if err != nil { return "", err } + return strconv.FormatUint(res, 10), nil } diff --git a/cmd/rpcdaemon/commands/send_transaction.go b/cmd/rpcdaemon/commands/send_transaction.go index 9d6226fe9..c307e2c30 100644 --- a/cmd/rpcdaemon/commands/send_transaction.go +++ b/cmd/rpcdaemon/commands/send_transaction.go @@ -2,12 +2,18 @@ package commands import ( "context" + "fmt" "github.com/ledgerwatch/turbo-geth/common" "github.com/ledgerwatch/turbo-geth/common/hexutil" ) +// SendRawTransaction send a raw transaction func (api *APIImpl) SendRawTransaction(_ context.Context, encodedTx hexutil.Bytes) (common.Hash, error) { + if api.ethBackend == nil { + // We're running in --chaindata mode or otherwise cannot get the backend + return common.Hash{}, fmt.Errorf(NotAvailableChainData, "eth_sendRawTransaction") + } res, err := api.ethBackend.AddLocal(encodedTx) return common.BytesToHash(res), err } diff --git a/cmd/rpcdaemon/commands/trace_api_adhoc.go b/cmd/rpcdaemon/commands/trace_api_adhoc.go index b9feabc2c..b33b4dbdb 100644 --- a/cmd/rpcdaemon/commands/trace_api_adhoc.go +++ b/cmd/rpcdaemon/commands/trace_api_adhoc.go @@ -21,29 +21,29 @@ type CallParams []CallParam // Call Implements trace_call func (api *TraceAPIImpl) Call(ctx context.Context, call CallParam, blockNr rpc.BlockNumber) ([]interface{}, error) { var stub []interface{} - return stub, fmt.Errorf("function trace_call not implemented") + return stub, fmt.Errorf(NotImplemented, "trace_call") } // CallMany Implements trace_call func (api *TraceAPIImpl) CallMany(ctx context.Context, calls CallParams) ([]interface{}, error) { var stub []interface{} - return stub, fmt.Errorf("function trace_callMany not implemented") + return stub, fmt.Errorf(NotImplemented, "trace_callMany") } // RawTransaction Implements trace_rawtransaction func (api *TraceAPIImpl) RawTransaction(ctx context.Context, txHash common.Hash, traceTypes []string) ([]interface{}, error) { var stub []interface{} - return stub, fmt.Errorf("function trace_rawTransaction not implemented") + return stub, fmt.Errorf(NotImplemented, "trace_rawTransaction") } // ReplayBlockTransactions Implements trace_replayBlockTransactions func (api *TraceAPIImpl) ReplayBlockTransactions(ctx context.Context, blockNr rpc.BlockNumber, traceTypes []string) ([]interface{}, error) { var stub []interface{} - return stub, fmt.Errorf("function trace_replayBlockTransactions not implemented") + return stub, fmt.Errorf(NotImplemented, "trace_replayBlockTransactions") } // ReplayTransaction Implements trace_replaytransactions func (api *TraceAPIImpl) ReplayTransaction(ctx context.Context, txHash common.Hash, traceTypes []string) ([]interface{}, error) { var stub []interface{} - return stub, fmt.Errorf("function trace_replayTransaction not implemented") + return stub, fmt.Errorf(NotImplemented, "trace_replayTransaction") }