|
|
|
@ -48,19 +48,18 @@ import ( |
|
|
|
|
"github.com/tyler-smith/go-bip39" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// PublicEthereumAPI provides an API to access Ethereum related information.
|
|
|
|
|
// It offers only methods that operate on public data that is freely available to anyone.
|
|
|
|
|
type PublicEthereumAPI struct { |
|
|
|
|
// EthereumAPI provides an API to access Ethereum related information.
|
|
|
|
|
type EthereumAPI struct { |
|
|
|
|
b Backend |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewPublicEthereumAPI creates a new Ethereum protocol API.
|
|
|
|
|
func NewPublicEthereumAPI(b Backend) *PublicEthereumAPI { |
|
|
|
|
return &PublicEthereumAPI{b} |
|
|
|
|
// NewEthereumAPI creates a new Ethereum protocol API.
|
|
|
|
|
func NewEthereumAPI(b Backend) *EthereumAPI { |
|
|
|
|
return &EthereumAPI{b} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GasPrice returns a suggestion for a gas price for legacy transactions.
|
|
|
|
|
func (s *PublicEthereumAPI) GasPrice(ctx context.Context) (*hexutil.Big, error) { |
|
|
|
|
func (s *EthereumAPI) GasPrice(ctx context.Context) (*hexutil.Big, error) { |
|
|
|
|
tipcap, err := s.b.SuggestGasTipCap(ctx) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
@ -72,7 +71,7 @@ func (s *PublicEthereumAPI) GasPrice(ctx context.Context) (*hexutil.Big, error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// MaxPriorityFeePerGas returns a suggestion for a gas tip cap for dynamic fee transactions.
|
|
|
|
|
func (s *PublicEthereumAPI) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, error) { |
|
|
|
|
func (s *EthereumAPI) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, error) { |
|
|
|
|
tipcap, err := s.b.SuggestGasTipCap(ctx) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
@ -87,7 +86,7 @@ type feeHistoryResult struct { |
|
|
|
|
GasUsedRatio []float64 `json:"gasUsedRatio"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *PublicEthereumAPI) FeeHistory(ctx context.Context, blockCount rpc.DecimalOrHex, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*feeHistoryResult, error) { |
|
|
|
|
func (s *EthereumAPI) FeeHistory(ctx context.Context, blockCount rpc.DecimalOrHex, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*feeHistoryResult, error) { |
|
|
|
|
oldest, reward, baseFee, gasUsed, err := s.b.FeeHistory(ctx, int(blockCount), lastBlock, rewardPercentiles) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
@ -121,7 +120,7 @@ func (s *PublicEthereumAPI) FeeHistory(ctx context.Context, blockCount rpc.Decim |
|
|
|
|
// - highestBlock: block number of the highest block header this node has received from peers
|
|
|
|
|
// - pulledStates: number of state entries processed until now
|
|
|
|
|
// - knownStates: number of known state entries that still need to be pulled
|
|
|
|
|
func (s *PublicEthereumAPI) Syncing() (interface{}, error) { |
|
|
|
|
func (s *EthereumAPI) Syncing() (interface{}, error) { |
|
|
|
|
progress := s.b.SyncProgress() |
|
|
|
|
|
|
|
|
|
// Return not syncing if the synchronisation already completed
|
|
|
|
@ -148,18 +147,18 @@ func (s *PublicEthereumAPI) Syncing() (interface{}, error) { |
|
|
|
|
}, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PublicTxPoolAPI offers and API for the transaction pool. It only operates on data that is non confidential.
|
|
|
|
|
type PublicTxPoolAPI struct { |
|
|
|
|
// TxPoolAPI offers and API for the transaction pool. It only operates on data that is non confidential.
|
|
|
|
|
type TxPoolAPI struct { |
|
|
|
|
b Backend |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewPublicTxPoolAPI creates a new tx pool service that gives information about the transaction pool.
|
|
|
|
|
func NewPublicTxPoolAPI(b Backend) *PublicTxPoolAPI { |
|
|
|
|
return &PublicTxPoolAPI{b} |
|
|
|
|
// NewTxPoolAPI creates a new tx pool service that gives information about the transaction pool.
|
|
|
|
|
func NewTxPoolAPI(b Backend) *TxPoolAPI { |
|
|
|
|
return &TxPoolAPI{b} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Content returns the transactions contained within the transaction pool.
|
|
|
|
|
func (s *PublicTxPoolAPI) Content() map[string]map[string]map[string]*RPCTransaction { |
|
|
|
|
func (s *TxPoolAPI) Content() map[string]map[string]map[string]*RPCTransaction { |
|
|
|
|
content := map[string]map[string]map[string]*RPCTransaction{ |
|
|
|
|
"pending": make(map[string]map[string]*RPCTransaction), |
|
|
|
|
"queued": make(map[string]map[string]*RPCTransaction), |
|
|
|
@ -186,7 +185,7 @@ func (s *PublicTxPoolAPI) Content() map[string]map[string]map[string]*RPCTransac |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ContentFrom returns the transactions contained within the transaction pool.
|
|
|
|
|
func (s *PublicTxPoolAPI) ContentFrom(addr common.Address) map[string]map[string]*RPCTransaction { |
|
|
|
|
func (s *TxPoolAPI) ContentFrom(addr common.Address) map[string]map[string]*RPCTransaction { |
|
|
|
|
content := make(map[string]map[string]*RPCTransaction, 2) |
|
|
|
|
pending, queue := s.b.TxPoolContentFrom(addr) |
|
|
|
|
curHeader := s.b.CurrentHeader() |
|
|
|
@ -209,7 +208,7 @@ func (s *PublicTxPoolAPI) ContentFrom(addr common.Address) map[string]map[string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Status returns the number of pending and queued transaction in the pool.
|
|
|
|
|
func (s *PublicTxPoolAPI) Status() map[string]hexutil.Uint { |
|
|
|
|
func (s *TxPoolAPI) Status() map[string]hexutil.Uint { |
|
|
|
|
pending, queue := s.b.Stats() |
|
|
|
|
return map[string]hexutil.Uint{ |
|
|
|
|
"pending": hexutil.Uint(pending), |
|
|
|
@ -219,7 +218,7 @@ func (s *PublicTxPoolAPI) Status() map[string]hexutil.Uint { |
|
|
|
|
|
|
|
|
|
// Inspect retrieves the content of the transaction pool and flattens it into an
|
|
|
|
|
// easily inspectable list.
|
|
|
|
|
func (s *PublicTxPoolAPI) Inspect() map[string]map[string]map[string]string { |
|
|
|
|
func (s *TxPoolAPI) Inspect() map[string]map[string]map[string]string { |
|
|
|
|
content := map[string]map[string]map[string]string{ |
|
|
|
|
"pending": make(map[string]map[string]string), |
|
|
|
|
"queued": make(map[string]map[string]string), |
|
|
|
@ -252,34 +251,34 @@ func (s *PublicTxPoolAPI) Inspect() map[string]map[string]map[string]string { |
|
|
|
|
return content |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PublicAccountAPI provides an API to access accounts managed by this node.
|
|
|
|
|
// EthereumAccountAPI provides an API to access accounts managed by this node.
|
|
|
|
|
// It offers only methods that can retrieve accounts.
|
|
|
|
|
type PublicAccountAPI struct { |
|
|
|
|
type EthereumAccountAPI struct { |
|
|
|
|
am *accounts.Manager |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewPublicAccountAPI creates a new PublicAccountAPI.
|
|
|
|
|
func NewPublicAccountAPI(am *accounts.Manager) *PublicAccountAPI { |
|
|
|
|
return &PublicAccountAPI{am: am} |
|
|
|
|
// NewEthereumAccountAPI creates a new EthereumAccountAPI.
|
|
|
|
|
func NewEthereumAccountAPI(am *accounts.Manager) *EthereumAccountAPI { |
|
|
|
|
return &EthereumAccountAPI{am: am} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Accounts returns the collection of accounts this node manages
|
|
|
|
|
func (s *PublicAccountAPI) Accounts() []common.Address { |
|
|
|
|
// Accounts returns the collection of accounts this node manages.
|
|
|
|
|
func (s *EthereumAccountAPI) Accounts() []common.Address { |
|
|
|
|
return s.am.Accounts() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PrivateAccountAPI provides an API to access accounts managed by this node.
|
|
|
|
|
// PersonalAccountAPI provides an API to access accounts managed by this node.
|
|
|
|
|
// It offers methods to create, (un)lock en list accounts. Some methods accept
|
|
|
|
|
// passwords and are therefore considered private by default.
|
|
|
|
|
type PrivateAccountAPI struct { |
|
|
|
|
type PersonalAccountAPI struct { |
|
|
|
|
am *accounts.Manager |
|
|
|
|
nonceLock *AddrLocker |
|
|
|
|
b Backend |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewPrivateAccountAPI create a new PrivateAccountAPI.
|
|
|
|
|
func NewPrivateAccountAPI(b Backend, nonceLock *AddrLocker) *PrivateAccountAPI { |
|
|
|
|
return &PrivateAccountAPI{ |
|
|
|
|
// NewPersonalAccountAPI create a new PersonalAccountAPI.
|
|
|
|
|
func NewPersonalAccountAPI(b Backend, nonceLock *AddrLocker) *PersonalAccountAPI { |
|
|
|
|
return &PersonalAccountAPI{ |
|
|
|
|
am: b.AccountManager(), |
|
|
|
|
nonceLock: nonceLock, |
|
|
|
|
b: b, |
|
|
|
@ -287,7 +286,7 @@ func NewPrivateAccountAPI(b Backend, nonceLock *AddrLocker) *PrivateAccountAPI { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ListAccounts will return a list of addresses for accounts this node manages.
|
|
|
|
|
func (s *PrivateAccountAPI) ListAccounts() []common.Address { |
|
|
|
|
func (s *PersonalAccountAPI) ListAccounts() []common.Address { |
|
|
|
|
return s.am.Accounts() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -301,7 +300,7 @@ type rawWallet struct { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ListWallets will return a list of wallets this node manages.
|
|
|
|
|
func (s *PrivateAccountAPI) ListWallets() []rawWallet { |
|
|
|
|
func (s *PersonalAccountAPI) ListWallets() []rawWallet { |
|
|
|
|
wallets := make([]rawWallet, 0) // return [] instead of nil if empty
|
|
|
|
|
for _, wallet := range s.am.Wallets() { |
|
|
|
|
status, failure := wallet.Status() |
|
|
|
@ -323,7 +322,7 @@ func (s *PrivateAccountAPI) ListWallets() []rawWallet { |
|
|
|
|
// connection and attempting to authenticate via the provided passphrase. Note,
|
|
|
|
|
// the method may return an extra challenge requiring a second open (e.g. the
|
|
|
|
|
// Trezor PIN matrix challenge).
|
|
|
|
|
func (s *PrivateAccountAPI) OpenWallet(url string, passphrase *string) error { |
|
|
|
|
func (s *PersonalAccountAPI) OpenWallet(url string, passphrase *string) error { |
|
|
|
|
wallet, err := s.am.Wallet(url) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
@ -337,7 +336,7 @@ func (s *PrivateAccountAPI) OpenWallet(url string, passphrase *string) error { |
|
|
|
|
|
|
|
|
|
// DeriveAccount requests a HD wallet to derive a new account, optionally pinning
|
|
|
|
|
// it for later reuse.
|
|
|
|
|
func (s *PrivateAccountAPI) DeriveAccount(url string, path string, pin *bool) (accounts.Account, error) { |
|
|
|
|
func (s *PersonalAccountAPI) DeriveAccount(url string, path string, pin *bool) (accounts.Account, error) { |
|
|
|
|
wallet, err := s.am.Wallet(url) |
|
|
|
|
if err != nil { |
|
|
|
|
return accounts.Account{}, err |
|
|
|
@ -353,7 +352,7 @@ func (s *PrivateAccountAPI) DeriveAccount(url string, path string, pin *bool) (a |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewAccount will create a new account and returns the address for the new account.
|
|
|
|
|
func (s *PrivateAccountAPI) NewAccount(password string) (common.Address, error) { |
|
|
|
|
func (s *PersonalAccountAPI) NewAccount(password string) (common.Address, error) { |
|
|
|
|
ks, err := fetchKeystore(s.am) |
|
|
|
|
if err != nil { |
|
|
|
|
return common.Address{}, err |
|
|
|
@ -378,7 +377,7 @@ func fetchKeystore(am *accounts.Manager) (*keystore.KeyStore, error) { |
|
|
|
|
|
|
|
|
|
// ImportRawKey stores the given hex encoded ECDSA key into the key directory,
|
|
|
|
|
// encrypting it with the passphrase.
|
|
|
|
|
func (s *PrivateAccountAPI) ImportRawKey(privkey string, password string) (common.Address, error) { |
|
|
|
|
func (s *PersonalAccountAPI) ImportRawKey(privkey string, password string) (common.Address, error) { |
|
|
|
|
key, err := crypto.HexToECDSA(privkey) |
|
|
|
|
if err != nil { |
|
|
|
|
return common.Address{}, err |
|
|
|
@ -394,7 +393,7 @@ func (s *PrivateAccountAPI) ImportRawKey(privkey string, password string) (commo |
|
|
|
|
// UnlockAccount will unlock the account associated with the given address with
|
|
|
|
|
// the given password for duration seconds. If duration is nil it will use a
|
|
|
|
|
// default of 300 seconds. It returns an indication if the account was unlocked.
|
|
|
|
|
func (s *PrivateAccountAPI) UnlockAccount(ctx context.Context, addr common.Address, password string, duration *uint64) (bool, error) { |
|
|
|
|
func (s *PersonalAccountAPI) UnlockAccount(ctx context.Context, addr common.Address, password string, duration *uint64) (bool, error) { |
|
|
|
|
// When the API is exposed by external RPC(http, ws etc), unless the user
|
|
|
|
|
// explicitly specifies to allow the insecure account unlocking, otherwise
|
|
|
|
|
// it is disabled.
|
|
|
|
@ -423,7 +422,7 @@ func (s *PrivateAccountAPI) UnlockAccount(ctx context.Context, addr common.Addre |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LockAccount will lock the account associated with the given address when it's unlocked.
|
|
|
|
|
func (s *PrivateAccountAPI) LockAccount(addr common.Address) bool { |
|
|
|
|
func (s *PersonalAccountAPI) LockAccount(addr common.Address) bool { |
|
|
|
|
if ks, err := fetchKeystore(s.am); err == nil { |
|
|
|
|
return ks.Lock(addr) == nil |
|
|
|
|
} |
|
|
|
@ -433,7 +432,7 @@ func (s *PrivateAccountAPI) LockAccount(addr common.Address) bool { |
|
|
|
|
// signTransaction sets defaults and signs the given transaction
|
|
|
|
|
// NOTE: the caller needs to ensure that the nonceLock is held, if applicable,
|
|
|
|
|
// and release it after the transaction has been submitted to the tx pool
|
|
|
|
|
func (s *PrivateAccountAPI) signTransaction(ctx context.Context, args *TransactionArgs, passwd string) (*types.Transaction, error) { |
|
|
|
|
func (s *PersonalAccountAPI) signTransaction(ctx context.Context, args *TransactionArgs, passwd string) (*types.Transaction, error) { |
|
|
|
|
// Look up the wallet containing the requested signer
|
|
|
|
|
account := accounts.Account{Address: args.from()} |
|
|
|
|
wallet, err := s.am.Find(account) |
|
|
|
@ -453,7 +452,7 @@ func (s *PrivateAccountAPI) signTransaction(ctx context.Context, args *Transacti |
|
|
|
|
// SendTransaction will create a transaction from the given arguments and
|
|
|
|
|
// tries to sign it with the key associated with args.From. If the given
|
|
|
|
|
// passwd isn't able to decrypt the key it fails.
|
|
|
|
|
func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args TransactionArgs, passwd string) (common.Hash, error) { |
|
|
|
|
func (s *PersonalAccountAPI) SendTransaction(ctx context.Context, args TransactionArgs, passwd string) (common.Hash, error) { |
|
|
|
|
if args.Nonce == nil { |
|
|
|
|
// Hold the addresse's mutex around signing to prevent concurrent assignment of
|
|
|
|
|
// the same nonce to multiple accounts.
|
|
|
|
@ -472,7 +471,7 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args Transactio |
|
|
|
|
// tries to sign it with the key associated with args.From. If the given passwd isn't
|
|
|
|
|
// able to decrypt the key it fails. The transaction is returned in RLP-form, not broadcast
|
|
|
|
|
// to other nodes
|
|
|
|
|
func (s *PrivateAccountAPI) SignTransaction(ctx context.Context, args TransactionArgs, passwd string) (*SignTransactionResult, error) { |
|
|
|
|
func (s *PersonalAccountAPI) SignTransaction(ctx context.Context, args TransactionArgs, passwd string) (*SignTransactionResult, error) { |
|
|
|
|
// No need to obtain the noncelock mutex, since we won't be sending this
|
|
|
|
|
// tx into the transaction pool, but right back to the user
|
|
|
|
|
if args.From == nil { |
|
|
|
@ -513,7 +512,7 @@ func (s *PrivateAccountAPI) SignTransaction(ctx context.Context, args Transactio |
|
|
|
|
// The key used to calculate the signature is decrypted with the given password.
|
|
|
|
|
//
|
|
|
|
|
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
|
|
|
|
|
func (s *PrivateAccountAPI) Sign(ctx context.Context, data hexutil.Bytes, addr common.Address, passwd string) (hexutil.Bytes, error) { |
|
|
|
|
func (s *PersonalAccountAPI) Sign(ctx context.Context, data hexutil.Bytes, addr common.Address, passwd string) (hexutil.Bytes, error) { |
|
|
|
|
// Look up the wallet containing the requested signer
|
|
|
|
|
account := accounts.Account{Address: addr} |
|
|
|
|
|
|
|
|
@ -541,7 +540,7 @@ func (s *PrivateAccountAPI) Sign(ctx context.Context, data hexutil.Bytes, addr c |
|
|
|
|
// the V value must be 27 or 28 for legacy reasons.
|
|
|
|
|
//
|
|
|
|
|
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_ecRecover
|
|
|
|
|
func (s *PrivateAccountAPI) EcRecover(ctx context.Context, data, sig hexutil.Bytes) (common.Address, error) { |
|
|
|
|
func (s *PersonalAccountAPI) EcRecover(ctx context.Context, data, sig hexutil.Bytes) (common.Address, error) { |
|
|
|
|
if len(sig) != crypto.SignatureLength { |
|
|
|
|
return common.Address{}, fmt.Errorf("signature must be %d bytes long", crypto.SignatureLength) |
|
|
|
|
} |
|
|
|
@ -558,7 +557,7 @@ func (s *PrivateAccountAPI) EcRecover(ctx context.Context, data, sig hexutil.Byt |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// InitializeWallet initializes a new wallet at the provided URL, by generating and returning a new private key.
|
|
|
|
|
func (s *PrivateAccountAPI) InitializeWallet(ctx context.Context, url string) (string, error) { |
|
|
|
|
func (s *PersonalAccountAPI) InitializeWallet(ctx context.Context, url string) (string, error) { |
|
|
|
|
wallet, err := s.am.Wallet(url) |
|
|
|
|
if err != nil { |
|
|
|
|
return "", err |
|
|
|
@ -585,7 +584,7 @@ func (s *PrivateAccountAPI) InitializeWallet(ctx context.Context, url string) (s |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Unpair deletes a pairing between wallet and geth.
|
|
|
|
|
func (s *PrivateAccountAPI) Unpair(ctx context.Context, url string, pin string) error { |
|
|
|
|
func (s *PersonalAccountAPI) Unpair(ctx context.Context, url string, pin string) error { |
|
|
|
|
wallet, err := s.am.Wallet(url) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
@ -599,19 +598,18 @@ func (s *PrivateAccountAPI) Unpair(ctx context.Context, url string, pin string) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PublicBlockChainAPI provides an API to access the Ethereum blockchain.
|
|
|
|
|
// It offers only methods that operate on public data that is freely available to anyone.
|
|
|
|
|
type PublicBlockChainAPI struct { |
|
|
|
|
// BlockChainAPI provides an API to access Ethereum blockchain data.
|
|
|
|
|
type BlockChainAPI struct { |
|
|
|
|
b Backend |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewPublicBlockChainAPI creates a new Ethereum blockchain API.
|
|
|
|
|
func NewPublicBlockChainAPI(b Backend) *PublicBlockChainAPI { |
|
|
|
|
return &PublicBlockChainAPI{b} |
|
|
|
|
// NewBlockChainAPI creates a new Ethereum blockchain API.
|
|
|
|
|
func NewBlockChainAPI(b Backend) *BlockChainAPI { |
|
|
|
|
return &BlockChainAPI{b} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config.
|
|
|
|
|
func (api *PublicBlockChainAPI) ChainId() (*hexutil.Big, error) { |
|
|
|
|
// ChainId is the EIP-155 replay-protection chain id for the current Ethereum chain config.
|
|
|
|
|
func (api *BlockChainAPI) ChainId() (*hexutil.Big, error) { |
|
|
|
|
// if current block is at or past the EIP-155 replay-protection fork block, return chainID from config
|
|
|
|
|
if config := api.b.ChainConfig(); config.IsEIP155(api.b.CurrentBlock().Number()) { |
|
|
|
|
return (*hexutil.Big)(config.ChainID), nil |
|
|
|
@ -620,7 +618,7 @@ func (api *PublicBlockChainAPI) ChainId() (*hexutil.Big, error) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// BlockNumber returns the block number of the chain head.
|
|
|
|
|
func (s *PublicBlockChainAPI) BlockNumber() hexutil.Uint64 { |
|
|
|
|
func (s *BlockChainAPI) BlockNumber() hexutil.Uint64 { |
|
|
|
|
header, _ := s.b.HeaderByNumber(context.Background(), rpc.LatestBlockNumber) // latest header should always be available
|
|
|
|
|
return hexutil.Uint64(header.Number.Uint64()) |
|
|
|
|
} |
|
|
|
@ -628,7 +626,7 @@ func (s *PublicBlockChainAPI) BlockNumber() hexutil.Uint64 { |
|
|
|
|
// GetBalance returns the amount of wei for the given address in the state of the
|
|
|
|
|
// given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta
|
|
|
|
|
// block numbers are also allowed.
|
|
|
|
|
func (s *PublicBlockChainAPI) GetBalance(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error) { |
|
|
|
|
func (s *BlockChainAPI) GetBalance(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error) { |
|
|
|
|
state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) |
|
|
|
|
if state == nil || err != nil { |
|
|
|
|
return nil, err |
|
|
|
@ -654,7 +652,7 @@ type StorageResult struct { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetProof returns the Merkle-proof for a given account and optionally some storage keys.
|
|
|
|
|
func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Address, storageKeys []string, blockNrOrHash rpc.BlockNumberOrHash) (*AccountResult, error) { |
|
|
|
|
func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, storageKeys []string, blockNrOrHash rpc.BlockNumberOrHash) (*AccountResult, error) { |
|
|
|
|
state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) |
|
|
|
|
if state == nil || err != nil { |
|
|
|
|
return nil, err |
|
|
|
@ -706,7 +704,7 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre |
|
|
|
|
// GetHeaderByNumber returns the requested canonical block header.
|
|
|
|
|
// * When blockNr is -1 the chain head is returned.
|
|
|
|
|
// * When blockNr is -2 the pending chain head is returned.
|
|
|
|
|
func (s *PublicBlockChainAPI) GetHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (map[string]interface{}, error) { |
|
|
|
|
func (s *BlockChainAPI) GetHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (map[string]interface{}, error) { |
|
|
|
|
header, err := s.b.HeaderByNumber(ctx, number) |
|
|
|
|
if header != nil && err == nil { |
|
|
|
|
response := s.rpcMarshalHeader(ctx, header) |
|
|
|
@ -722,7 +720,7 @@ func (s *PublicBlockChainAPI) GetHeaderByNumber(ctx context.Context, number rpc. |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetHeaderByHash returns the requested header by hash.
|
|
|
|
|
func (s *PublicBlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.Hash) map[string]interface{} { |
|
|
|
|
func (s *BlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.Hash) map[string]interface{} { |
|
|
|
|
header, _ := s.b.HeaderByHash(ctx, hash) |
|
|
|
|
if header != nil { |
|
|
|
|
return s.rpcMarshalHeader(ctx, header) |
|
|
|
@ -735,7 +733,7 @@ func (s *PublicBlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.H |
|
|
|
|
// * When blockNr is -2 the pending chain head is returned.
|
|
|
|
|
// * When fullTx is true all transactions in the block are returned, otherwise
|
|
|
|
|
// only the transaction hash is returned.
|
|
|
|
|
func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) { |
|
|
|
|
func (s *BlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) { |
|
|
|
|
block, err := s.b.BlockByNumber(ctx, number) |
|
|
|
|
if block != nil && err == nil { |
|
|
|
|
response, err := s.rpcMarshalBlock(ctx, block, true, fullTx) |
|
|
|
@ -752,7 +750,7 @@ func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.B |
|
|
|
|
|
|
|
|
|
// GetBlockByHash returns the requested block. When fullTx is true all transactions in the block are returned in full
|
|
|
|
|
// detail, otherwise only the transaction hash is returned.
|
|
|
|
|
func (s *PublicBlockChainAPI) GetBlockByHash(ctx context.Context, hash common.Hash, fullTx bool) (map[string]interface{}, error) { |
|
|
|
|
func (s *BlockChainAPI) GetBlockByHash(ctx context.Context, hash common.Hash, fullTx bool) (map[string]interface{}, error) { |
|
|
|
|
block, err := s.b.BlockByHash(ctx, hash) |
|
|
|
|
if block != nil { |
|
|
|
|
return s.rpcMarshalBlock(ctx, block, true, fullTx) |
|
|
|
@ -761,7 +759,7 @@ func (s *PublicBlockChainAPI) GetBlockByHash(ctx context.Context, hash common.Ha |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetUncleByBlockNumberAndIndex returns the uncle block for the given block hash and index.
|
|
|
|
|
func (s *PublicBlockChainAPI) GetUncleByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) (map[string]interface{}, error) { |
|
|
|
|
func (s *BlockChainAPI) GetUncleByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) (map[string]interface{}, error) { |
|
|
|
|
block, err := s.b.BlockByNumber(ctx, blockNr) |
|
|
|
|
if block != nil { |
|
|
|
|
uncles := block.Uncles() |
|
|
|
@ -776,7 +774,7 @@ func (s *PublicBlockChainAPI) GetUncleByBlockNumberAndIndex(ctx context.Context, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetUncleByBlockHashAndIndex returns the uncle block for the given block hash and index.
|
|
|
|
|
func (s *PublicBlockChainAPI) GetUncleByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) (map[string]interface{}, error) { |
|
|
|
|
func (s *BlockChainAPI) GetUncleByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) (map[string]interface{}, error) { |
|
|
|
|
block, err := s.b.BlockByHash(ctx, blockHash) |
|
|
|
|
if block != nil { |
|
|
|
|
uncles := block.Uncles() |
|
|
|
@ -791,7 +789,7 @@ func (s *PublicBlockChainAPI) GetUncleByBlockHashAndIndex(ctx context.Context, b |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetUncleCountByBlockNumber returns number of uncles in the block for the given block number
|
|
|
|
|
func (s *PublicBlockChainAPI) GetUncleCountByBlockNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint { |
|
|
|
|
func (s *BlockChainAPI) GetUncleCountByBlockNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint { |
|
|
|
|
if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil { |
|
|
|
|
n := hexutil.Uint(len(block.Uncles())) |
|
|
|
|
return &n |
|
|
|
@ -800,7 +798,7 @@ func (s *PublicBlockChainAPI) GetUncleCountByBlockNumber(ctx context.Context, bl |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetUncleCountByBlockHash returns number of uncles in the block for the given block hash
|
|
|
|
|
func (s *PublicBlockChainAPI) GetUncleCountByBlockHash(ctx context.Context, blockHash common.Hash) *hexutil.Uint { |
|
|
|
|
func (s *BlockChainAPI) GetUncleCountByBlockHash(ctx context.Context, blockHash common.Hash) *hexutil.Uint { |
|
|
|
|
if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil { |
|
|
|
|
n := hexutil.Uint(len(block.Uncles())) |
|
|
|
|
return &n |
|
|
|
@ -809,7 +807,7 @@ func (s *PublicBlockChainAPI) GetUncleCountByBlockHash(ctx context.Context, bloc |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetCode returns the code stored at the given address in the state for the given block number.
|
|
|
|
|
func (s *PublicBlockChainAPI) GetCode(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) { |
|
|
|
|
func (s *BlockChainAPI) GetCode(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) { |
|
|
|
|
state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) |
|
|
|
|
if state == nil || err != nil { |
|
|
|
|
return nil, err |
|
|
|
@ -821,7 +819,7 @@ func (s *PublicBlockChainAPI) GetCode(ctx context.Context, address common.Addres |
|
|
|
|
// GetStorageAt returns the storage from the state at the given address, key and
|
|
|
|
|
// block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta block
|
|
|
|
|
// numbers are also allowed.
|
|
|
|
|
func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, address common.Address, key string, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) { |
|
|
|
|
func (s *BlockChainAPI) GetStorageAt(ctx context.Context, address common.Address, key string, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) { |
|
|
|
|
state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) |
|
|
|
|
if state == nil || err != nil { |
|
|
|
|
return nil, err |
|
|
|
@ -1008,7 +1006,7 @@ func (e *revertError) ErrorData() interface{} { |
|
|
|
|
//
|
|
|
|
|
// Note, this function doesn't make and changes in the state/blockchain and is
|
|
|
|
|
// useful to execute and retrieve values.
|
|
|
|
|
func (s *PublicBlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Bytes, error) { |
|
|
|
|
func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Bytes, error) { |
|
|
|
|
result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap()) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
@ -1142,7 +1140,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr |
|
|
|
|
|
|
|
|
|
// EstimateGas returns an estimate of the amount of gas needed to execute the
|
|
|
|
|
// given transaction against the current pending block.
|
|
|
|
|
func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error) { |
|
|
|
|
func (s *BlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error) { |
|
|
|
|
bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber) |
|
|
|
|
if blockNrOrHash != nil { |
|
|
|
|
bNrOrHash = *blockNrOrHash |
|
|
|
@ -1216,16 +1214,16 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// rpcMarshalHeader uses the generalized output filler, then adds the total difficulty field, which requires
|
|
|
|
|
// a `PublicBlockchainAPI`.
|
|
|
|
|
func (s *PublicBlockChainAPI) rpcMarshalHeader(ctx context.Context, header *types.Header) map[string]interface{} { |
|
|
|
|
// a `BlockchainAPI`.
|
|
|
|
|
func (s *BlockChainAPI) rpcMarshalHeader(ctx context.Context, header *types.Header) map[string]interface{} { |
|
|
|
|
fields := RPCMarshalHeader(header) |
|
|
|
|
fields["totalDifficulty"] = (*hexutil.Big)(s.b.GetTd(ctx, header.Hash())) |
|
|
|
|
return fields |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// rpcMarshalBlock uses the generalized output filler, then adds the total difficulty field, which requires
|
|
|
|
|
// a `PublicBlockchainAPI`.
|
|
|
|
|
func (s *PublicBlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) { |
|
|
|
|
// a `BlockchainAPI`.
|
|
|
|
|
func (s *BlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) { |
|
|
|
|
fields, err := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig()) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
@ -1358,7 +1356,7 @@ type accessListResult struct { |
|
|
|
|
|
|
|
|
|
// CreateAccessList creates a EIP-2930 type AccessList for the given transaction.
|
|
|
|
|
// Reexec and BlockNrOrHash can be specified to create the accessList on top of a certain state.
|
|
|
|
|
func (s *PublicBlockChainAPI) CreateAccessList(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash) (*accessListResult, error) { |
|
|
|
|
func (s *BlockChainAPI) CreateAccessList(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash) (*accessListResult, error) { |
|
|
|
|
bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber) |
|
|
|
|
if blockNrOrHash != nil { |
|
|
|
|
bNrOrHash = *blockNrOrHash |
|
|
|
@ -1447,23 +1445,23 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PublicTransactionPoolAPI exposes methods for the RPC interface
|
|
|
|
|
type PublicTransactionPoolAPI struct { |
|
|
|
|
// TransactionAPI exposes methods for reading and creating transaction data.
|
|
|
|
|
type TransactionAPI struct { |
|
|
|
|
b Backend |
|
|
|
|
nonceLock *AddrLocker |
|
|
|
|
signer types.Signer |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool.
|
|
|
|
|
func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicTransactionPoolAPI { |
|
|
|
|
// NewTransactionAPI creates a new RPC service with methods for interacting with transactions.
|
|
|
|
|
func NewTransactionAPI(b Backend, nonceLock *AddrLocker) *TransactionAPI { |
|
|
|
|
// The signer used by the API should always be the 'latest' known one because we expect
|
|
|
|
|
// signers to be backwards-compatible with old transactions.
|
|
|
|
|
signer := types.LatestSigner(b.ChainConfig()) |
|
|
|
|
return &PublicTransactionPoolAPI{b, nonceLock, signer} |
|
|
|
|
return &TransactionAPI{b, nonceLock, signer} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint { |
|
|
|
|
func (s *TransactionAPI) GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint { |
|
|
|
|
if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil { |
|
|
|
|
n := hexutil.Uint(len(block.Transactions())) |
|
|
|
|
return &n |
|
|
|
@ -1472,7 +1470,7 @@ func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByNumber(ctx context. |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetBlockTransactionCountByHash returns the number of transactions in the block with the given hash.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHash common.Hash) *hexutil.Uint { |
|
|
|
|
func (s *TransactionAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHash common.Hash) *hexutil.Uint { |
|
|
|
|
if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil { |
|
|
|
|
n := hexutil.Uint(len(block.Transactions())) |
|
|
|
|
return &n |
|
|
|
@ -1481,7 +1479,7 @@ func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Co |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) *RPCTransaction { |
|
|
|
|
func (s *TransactionAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) *RPCTransaction { |
|
|
|
|
if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil { |
|
|
|
|
return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig()) |
|
|
|
|
} |
|
|
|
@ -1489,7 +1487,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex(ctx conte |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetTransactionByBlockHashAndIndex returns the transaction for the given block hash and index.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) *RPCTransaction { |
|
|
|
|
func (s *TransactionAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) *RPCTransaction { |
|
|
|
|
if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil { |
|
|
|
|
return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig()) |
|
|
|
|
} |
|
|
|
@ -1497,7 +1495,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetRawTransactionByBlockNumberAndIndex returns the bytes of the transaction for the given block number and index.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) hexutil.Bytes { |
|
|
|
|
func (s *TransactionAPI) GetRawTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) hexutil.Bytes { |
|
|
|
|
if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil { |
|
|
|
|
return newRPCRawTransactionFromBlockIndex(block, uint64(index)) |
|
|
|
|
} |
|
|
|
@ -1505,7 +1503,7 @@ func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockNumberAndIndex(ctx co |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetRawTransactionByBlockHashAndIndex returns the bytes of the transaction for the given block hash and index.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) hexutil.Bytes { |
|
|
|
|
func (s *TransactionAPI) GetRawTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) hexutil.Bytes { |
|
|
|
|
if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil { |
|
|
|
|
return newRPCRawTransactionFromBlockIndex(block, uint64(index)) |
|
|
|
|
} |
|
|
|
@ -1513,7 +1511,7 @@ func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockHashAndIndex(ctx cont |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetTransactionCount returns the number of transactions the given address has sent for the given block number
|
|
|
|
|
func (s *PublicTransactionPoolAPI) GetTransactionCount(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Uint64, error) { |
|
|
|
|
func (s *TransactionAPI) GetTransactionCount(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Uint64, error) { |
|
|
|
|
// Ask transaction pool for the nonce which includes pending transactions
|
|
|
|
|
if blockNr, ok := blockNrOrHash.Number(); ok && blockNr == rpc.PendingBlockNumber { |
|
|
|
|
nonce, err := s.b.GetPoolNonce(ctx, address) |
|
|
|
@ -1532,7 +1530,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionCount(ctx context.Context, addr |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetTransactionByHash returns the transaction for the given hash
|
|
|
|
|
func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) (*RPCTransaction, error) { |
|
|
|
|
func (s *TransactionAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) (*RPCTransaction, error) { |
|
|
|
|
// Try to return an already finalized transaction
|
|
|
|
|
tx, blockHash, blockNumber, index, err := s.b.GetTransaction(ctx, hash) |
|
|
|
|
if err != nil { |
|
|
|
@ -1555,7 +1553,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, has |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetRawTransactionByHash returns the bytes of the transaction for the given hash.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) GetRawTransactionByHash(ctx context.Context, hash common.Hash) (hexutil.Bytes, error) { |
|
|
|
|
func (s *TransactionAPI) GetRawTransactionByHash(ctx context.Context, hash common.Hash) (hexutil.Bytes, error) { |
|
|
|
|
// Retrieve a finalized transaction, or a pooled otherwise
|
|
|
|
|
tx, _, _, _, err := s.b.GetTransaction(ctx, hash) |
|
|
|
|
if err != nil { |
|
|
|
@ -1572,7 +1570,7 @@ func (s *PublicTransactionPoolAPI) GetRawTransactionByHash(ctx context.Context, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) { |
|
|
|
|
func (s *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) { |
|
|
|
|
tx, blockHash, blockNumber, index, err := s.b.GetTransaction(ctx, hash) |
|
|
|
|
if err != nil { |
|
|
|
|
// When the transaction doesn't exist, the RPC method should return JSON null
|
|
|
|
@ -1635,7 +1633,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// sign is a helper function that signs a transaction with the private key of the given address.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) sign(addr common.Address, tx *types.Transaction) (*types.Transaction, error) { |
|
|
|
|
func (s *TransactionAPI) sign(addr common.Address, tx *types.Transaction) (*types.Transaction, error) { |
|
|
|
|
// Look up the wallet containing the requested signer
|
|
|
|
|
account := accounts.Account{Address: addr} |
|
|
|
|
|
|
|
|
@ -1679,7 +1677,7 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c |
|
|
|
|
|
|
|
|
|
// SendTransaction creates a transaction for the given argument, sign it and submit it to the
|
|
|
|
|
// transaction pool.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args TransactionArgs) (common.Hash, error) { |
|
|
|
|
func (s *TransactionAPI) SendTransaction(ctx context.Context, args TransactionArgs) (common.Hash, error) { |
|
|
|
|
// Look up the wallet containing the requested signer
|
|
|
|
|
account := accounts.Account{Address: args.from()} |
|
|
|
|
|
|
|
|
@ -1712,7 +1710,7 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Tra |
|
|
|
|
// FillTransaction fills the defaults (nonce, gas, gasPrice or 1559 fields)
|
|
|
|
|
// on a given unsigned transaction, and returns it to the caller for further
|
|
|
|
|
// processing (signing + broadcast).
|
|
|
|
|
func (s *PublicTransactionPoolAPI) FillTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) { |
|
|
|
|
func (s *TransactionAPI) FillTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) { |
|
|
|
|
// Set some sanity defaults and terminate on failure
|
|
|
|
|
if err := args.setDefaults(ctx, s.b); err != nil { |
|
|
|
|
return nil, err |
|
|
|
@ -1728,7 +1726,7 @@ func (s *PublicTransactionPoolAPI) FillTransaction(ctx context.Context, args Tra |
|
|
|
|
|
|
|
|
|
// SendRawTransaction will add the signed transaction to the transaction pool.
|
|
|
|
|
// The sender is responsible for signing the transaction and using the correct nonce.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (common.Hash, error) { |
|
|
|
|
func (s *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (common.Hash, error) { |
|
|
|
|
tx := new(types.Transaction) |
|
|
|
|
if err := tx.UnmarshalBinary(input); err != nil { |
|
|
|
|
return common.Hash{}, err |
|
|
|
@ -1745,7 +1743,7 @@ func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, input |
|
|
|
|
// The account associated with addr must be unlocked.
|
|
|
|
|
//
|
|
|
|
|
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
|
|
|
|
|
func (s *PublicTransactionPoolAPI) Sign(addr common.Address, data hexutil.Bytes) (hexutil.Bytes, error) { |
|
|
|
|
func (s *TransactionAPI) Sign(addr common.Address, data hexutil.Bytes) (hexutil.Bytes, error) { |
|
|
|
|
// Look up the wallet containing the requested signer
|
|
|
|
|
account := accounts.Account{Address: addr} |
|
|
|
|
|
|
|
|
@ -1770,7 +1768,7 @@ type SignTransactionResult struct { |
|
|
|
|
// SignTransaction will sign the given transaction with the from account.
|
|
|
|
|
// The node needs to have the private key of the account corresponding with
|
|
|
|
|
// the given from address and it needs to be unlocked.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) { |
|
|
|
|
func (s *TransactionAPI) SignTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) { |
|
|
|
|
if args.Gas == nil { |
|
|
|
|
return nil, fmt.Errorf("gas not specified") |
|
|
|
|
} |
|
|
|
@ -1801,7 +1799,7 @@ func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args Tra |
|
|
|
|
|
|
|
|
|
// PendingTransactions returns the transactions that are in the transaction pool
|
|
|
|
|
// and have a from address that is one of the accounts this node manages.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) PendingTransactions() ([]*RPCTransaction, error) { |
|
|
|
|
func (s *TransactionAPI) PendingTransactions() ([]*RPCTransaction, error) { |
|
|
|
|
pending, err := s.b.GetPoolTransactions() |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
@ -1825,7 +1823,7 @@ func (s *PublicTransactionPoolAPI) PendingTransactions() ([]*RPCTransaction, err |
|
|
|
|
|
|
|
|
|
// Resend accepts an existing transaction and a new gas price and limit. It will remove
|
|
|
|
|
// the given transaction from the pool and reinsert it with the new gas price and limit.
|
|
|
|
|
func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs TransactionArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error) { |
|
|
|
|
func (s *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error) { |
|
|
|
|
if sendArgs.Nonce == nil { |
|
|
|
|
return common.Hash{}, fmt.Errorf("missing transaction nonce in transaction spec") |
|
|
|
|
} |
|
|
|
@ -1875,20 +1873,19 @@ func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs Transact |
|
|
|
|
return common.Hash{}, fmt.Errorf("transaction %#x not found", matchTx.Hash()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PublicDebugAPI is the collection of Ethereum APIs exposed over the public
|
|
|
|
|
// debugging endpoint.
|
|
|
|
|
type PublicDebugAPI struct { |
|
|
|
|
// DebugAPI is the collection of Ethereum APIs exposed over the debugging
|
|
|
|
|
// namespace.
|
|
|
|
|
type DebugAPI struct { |
|
|
|
|
b Backend |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewPublicDebugAPI creates a new API definition for the public debug methods
|
|
|
|
|
// of the Ethereum service.
|
|
|
|
|
func NewPublicDebugAPI(b Backend) *PublicDebugAPI { |
|
|
|
|
return &PublicDebugAPI{b: b} |
|
|
|
|
// NewDebugAPI creates a new instance of DebugAPI.
|
|
|
|
|
func NewDebugAPI(b Backend) *DebugAPI { |
|
|
|
|
return &DebugAPI{b: b} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetHeaderRlp retrieves the RLP encoded for of a single header.
|
|
|
|
|
func (api *PublicDebugAPI) GetHeaderRlp(ctx context.Context, number uint64) (hexutil.Bytes, error) { |
|
|
|
|
func (api *DebugAPI) GetHeaderRlp(ctx context.Context, number uint64) (hexutil.Bytes, error) { |
|
|
|
|
header, _ := api.b.HeaderByNumber(ctx, rpc.BlockNumber(number)) |
|
|
|
|
if header == nil { |
|
|
|
|
return nil, fmt.Errorf("header #%d not found", number) |
|
|
|
@ -1897,7 +1894,7 @@ func (api *PublicDebugAPI) GetHeaderRlp(ctx context.Context, number uint64) (hex |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetBlockRlp retrieves the RLP encoded for of a single block.
|
|
|
|
|
func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (hexutil.Bytes, error) { |
|
|
|
|
func (api *DebugAPI) GetBlockRlp(ctx context.Context, number uint64) (hexutil.Bytes, error) { |
|
|
|
|
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number)) |
|
|
|
|
if block == nil { |
|
|
|
|
return nil, fmt.Errorf("block #%d not found", number) |
|
|
|
@ -1906,7 +1903,7 @@ func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (hexu |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetRawReceipts retrieves the binary-encoded raw receipts of a single block.
|
|
|
|
|
func (api *PublicDebugAPI) GetRawReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]hexutil.Bytes, error) { |
|
|
|
|
func (api *DebugAPI) GetRawReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]hexutil.Bytes, error) { |
|
|
|
|
var hash common.Hash |
|
|
|
|
if h, ok := blockNrOrHash.Hash(); ok { |
|
|
|
|
hash = h |
|
|
|
@ -1933,7 +1930,7 @@ func (api *PublicDebugAPI) GetRawReceipts(ctx context.Context, blockNrOrHash rpc |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PrintBlock retrieves a block and returns its pretty printed form.
|
|
|
|
|
func (api *PublicDebugAPI) PrintBlock(ctx context.Context, number uint64) (string, error) { |
|
|
|
|
func (api *DebugAPI) PrintBlock(ctx context.Context, number uint64) (string, error) { |
|
|
|
|
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number)) |
|
|
|
|
if block == nil { |
|
|
|
|
return "", fmt.Errorf("block #%d not found", number) |
|
|
|
@ -1942,7 +1939,7 @@ func (api *PublicDebugAPI) PrintBlock(ctx context.Context, number uint64) (strin |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SeedHash retrieves the seed hash of a block.
|
|
|
|
|
func (api *PublicDebugAPI) SeedHash(ctx context.Context, number uint64) (string, error) { |
|
|
|
|
func (api *DebugAPI) SeedHash(ctx context.Context, number uint64) (string, error) { |
|
|
|
|
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number)) |
|
|
|
|
if block == nil { |
|
|
|
|
return "", fmt.Errorf("block #%d not found", number) |
|
|
|
@ -1950,20 +1947,8 @@ func (api *PublicDebugAPI) SeedHash(ctx context.Context, number uint64) (string, |
|
|
|
|
return fmt.Sprintf("0x%x", ethash.SeedHash(number)), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PrivateDebugAPI is the collection of Ethereum APIs exposed over the private
|
|
|
|
|
// debugging endpoint.
|
|
|
|
|
type PrivateDebugAPI struct { |
|
|
|
|
b Backend |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewPrivateDebugAPI creates a new API definition for the private debug methods
|
|
|
|
|
// of the Ethereum service.
|
|
|
|
|
func NewPrivateDebugAPI(b Backend) *PrivateDebugAPI { |
|
|
|
|
return &PrivateDebugAPI{b: b} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ChaindbProperty returns leveldb properties of the key-value database.
|
|
|
|
|
func (api *PrivateDebugAPI) ChaindbProperty(property string) (string, error) { |
|
|
|
|
func (api *DebugAPI) ChaindbProperty(property string) (string, error) { |
|
|
|
|
if property == "" { |
|
|
|
|
property = "leveldb.stats" |
|
|
|
|
} else if !strings.HasPrefix(property, "leveldb.") { |
|
|
|
@ -1974,7 +1959,7 @@ func (api *PrivateDebugAPI) ChaindbProperty(property string) (string, error) { |
|
|
|
|
|
|
|
|
|
// ChaindbCompact flattens the entire key-value database into a single level,
|
|
|
|
|
// removing all unused slots and merging all keys.
|
|
|
|
|
func (api *PrivateDebugAPI) ChaindbCompact() error { |
|
|
|
|
func (api *DebugAPI) ChaindbCompact() error { |
|
|
|
|
for b := byte(0); b < 255; b++ { |
|
|
|
|
log.Info("Compacting chain database", "range", fmt.Sprintf("0x%0.2X-0x%0.2X", b, b+1)) |
|
|
|
|
if err := api.b.ChainDb().Compact([]byte{b}, []byte{b + 1}); err != nil { |
|
|
|
@ -1986,33 +1971,33 @@ func (api *PrivateDebugAPI) ChaindbCompact() error { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SetHead rewinds the head of the blockchain to a previous block.
|
|
|
|
|
func (api *PrivateDebugAPI) SetHead(number hexutil.Uint64) { |
|
|
|
|
func (api *DebugAPI) SetHead(number hexutil.Uint64) { |
|
|
|
|
api.b.SetHead(uint64(number)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PublicNetAPI offers network related RPC methods
|
|
|
|
|
type PublicNetAPI struct { |
|
|
|
|
// NetAPI offers network related RPC methods
|
|
|
|
|
type NetAPI struct { |
|
|
|
|
net *p2p.Server |
|
|
|
|
networkVersion uint64 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewPublicNetAPI creates a new net API instance.
|
|
|
|
|
func NewPublicNetAPI(net *p2p.Server, networkVersion uint64) *PublicNetAPI { |
|
|
|
|
return &PublicNetAPI{net, networkVersion} |
|
|
|
|
// NewNetAPI creates a new net API instance.
|
|
|
|
|
func NewNetAPI(net *p2p.Server, networkVersion uint64) *NetAPI { |
|
|
|
|
return &NetAPI{net, networkVersion} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Listening returns an indication if the node is listening for network connections.
|
|
|
|
|
func (s *PublicNetAPI) Listening() bool { |
|
|
|
|
func (s *NetAPI) Listening() bool { |
|
|
|
|
return true // always listening
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PeerCount returns the number of connected peers
|
|
|
|
|
func (s *PublicNetAPI) PeerCount() hexutil.Uint { |
|
|
|
|
func (s *NetAPI) PeerCount() hexutil.Uint { |
|
|
|
|
return hexutil.Uint(s.net.PeerCount()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Version returns the current ethereum protocol version.
|
|
|
|
|
func (s *PublicNetAPI) Version() string { |
|
|
|
|
func (s *NetAPI) Version() string { |
|
|
|
|
return fmt.Sprintf("%d", s.networkVersion) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|