apiv1

package
v1.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2020 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIncorrectChainID is an incorrect chain ID.
	ErrIncorrectChainID = errors.New("Incorrect chain ID")
)

Functions

func RPCMarshalBlock

func RPCMarshalBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error)

RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain transaction hashes.

func SubmitStakingTransaction

func SubmitStakingTransaction(
	ctx context.Context, b Backend, tx *staking.StakingTransaction,
) (common.Hash, error)

SubmitStakingTransaction is a helper function that submits tx to txPool and logs a message.

func SubmitTransaction

func SubmitTransaction(
	ctx context.Context, b Backend, tx *types.Transaction,
) (common.Hash, error)

SubmitTransaction is a helper function that submits tx to txPool and logs a message.

Types

type AddrLocker

type AddrLocker struct {
	// contains filtered or unexported fields
}

AddrLocker ...

func (*AddrLocker) LockAddr

func (l *AddrLocker) LockAddr(address common.Address)

LockAddr locks an account's mutex. This is used to prevent another tx getting the same nonce until the lock is released. The mutex prevents the (an identical nonce) from being read again during the time that the first transaction is being signed.

func (*AddrLocker) UnlockAddr

func (l *AddrLocker) UnlockAddr(address common.Address)

UnlockAddr unlocks the mutex of the given account.

type Backend

type Backend interface {
	// NOTE(ricl): this is not in ETH Backend inteface. They put it directly in eth object.
	NetVersion() uint64
	// General Ethereum API
	// Downloader() *downloader.Downloader
	ProtocolVersion() int
	// SuggestPrice(ctx context.Context) (*big.Int, error)
	ChainDb() ethdb.Database
	EventMux() *event.TypeMux
	AccountManager() *accounts.Manager
	// ExtRPCEnabled() bool
	RPCGasCap() *big.Int // global gas cap for hmy_call over rpc: DoS protection

	// BlockChain API
	// SetHead(number uint64)
	HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*block.Header, error)
	BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error)
	StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.DB, *block.Header, error)
	GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error)
	GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error)
	// GetTd(blockHash common.Hash) *big.Int
	GetEVM(ctx context.Context, msg core.Message, state *state.DB, header *block.Header) (*vm.EVM, func() error, error)
	SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
	SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription

	// TxPool API
	SendTx(ctx context.Context, signedTx *types.Transaction) error
	// GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)
	GetPoolTransactions() (types.Transactions, error)
	GetPoolTransaction(txHash common.Hash) *types.Transaction
	GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
	// Stats() (pending int, queued int)
	// TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
	SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription

	ChainConfig() *params.ChainConfig
	CurrentBlock() *types.Block
	// Get balance
	GetBalance(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (*big.Int, error)
	// Get committee for a particular epoch
	GetCommittee(epoch *big.Int) (*shard.Committee, error)
	GetShardID() uint32
	// Get transactions history for an address
	GetTransactionsHistory(address, txType, order string) ([]common.Hash, error)
	// retrieve the blockHash using txID and add blockHash to CxPool for resending
	ResendCx(ctx context.Context, txID common.Hash) (uint64, bool)
	IsLeader() bool
	SendStakingTx(ctx context.Context, newStakingTx *staking.StakingTransaction) error
	GetCurrentTransactionErrorSink() []types.RPCTransactionError
	GetPendingCrossLinks() []*block.Header
	GetPendingCXReceipts() []*types.CXReceiptsProof
	GetCrossShardTransactionsHistory(address string) ([]types.CrossShardTx, error)
}

Backend interface provides the common API services (that are provided by both full and light clients) with access to necessary functions. implementations:

  • hmy/api_backend.go

type CallArgs

type CallArgs struct {
	From     *common.Address `json:"from"`
	To       *common.Address `json:"to"`
	Gas      *hexutil.Uint64 `json:"gas"`
	GasPrice *hexutil.Big    `json:"gasPrice"`
	Value    *hexutil.Big    `json:"value"`
	Data     *hexutil.Bytes  `json:"data"`
}

CallArgs represents the arguments for a call.

type DebugAPI

type DebugAPI struct {
	// contains filtered or unexported fields
}

DebugAPI Internal JSON RPC for debugging purpose

func NewDebugAPI

func NewDebugAPI(b Backend) *DebugAPI

NewDebugAPI Creates a new DebugAPI instance

func (*DebugAPI) SetLogVerbosity

func (*DebugAPI) SetLogVerbosity(ctx context.Context, level int) (map[string]interface{}, error)

SetLogVerbosity Sets log verbosity on runtime Example usage:

curl -H "Content-Type: application/json" -d '{"method":"debug_setLogVerbosity","params":[0],"id":1}' http://localhost:9123

type HeaderInformation

type HeaderInformation struct {
	BlockHash        common.Hash `json:"blockHash"`
	BlockNumber      uint64      `json:"blockNumber"`
	ShardID          uint32      `json:"shardID"`
	Leader           string      `json:"leader"`
	ViewID           uint64      `json:"viewID"`
	Epoch            uint64      `json:"epoch"`
	Timestamp        string      `json:"timestamp"`
	UnixTime         uint64      `json:"unixtime"`
	LastCommitSig    string      `json:"lastCommitSig"`
	LastCommitBitmap string      `json:"lastCommitBitmap"`
}

HeaderInformation represents the latest consensus information

type NodeMetadata

type NodeMetadata struct {
	BLSPublicKey []string `json:"blskey"`
	Version      string   `json:"version"`
	NetworkType  string   `json:"network"`
	ChainID      string   `json:"chainid"`
	IsLeader     bool     `json:"is-leader"`
	ShardID      uint32   `json:"shard-id"`
	Role         string   `json:"role"`
	Archival     bool     `json:"is-archival"`
}

NodeMetadata captures select metadata of the RPC answering node

type PrivateAccountAPI

type PrivateAccountAPI struct {
	// contains filtered or unexported fields
}

PrivateAccountAPI 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.

func (*PrivateAccountAPI) NewAccount

func (s *PrivateAccountAPI) NewAccount(password string) (common.Address, error)

NewAccount will create a new account and returns the address for the new account.

func (*PrivateAccountAPI) SendTransaction

func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs, passwd string) (common.Hash, error)

SendTransaction will create a transaction from the given arguments and tries to sign it with the key associated with args.To. If the given passwd isn't able to decrypt the key it fails.

type PublicAccountAPI

type PublicAccountAPI struct {
	// contains filtered or unexported fields
}

PublicAccountAPI provides an API to access accounts managed by this node. It offers only methods that can retrieve accounts.

func NewPublicAccountAPI

func NewPublicAccountAPI(am *accounts.Manager) *PublicAccountAPI

NewPublicAccountAPI creates a new PublicAccountAPI.

func (*PublicAccountAPI) Accounts

func (s *PublicAccountAPI) Accounts() []common.Address

Accounts returns the collection of accounts this node manages

type PublicBlockChainAPI

type PublicBlockChainAPI struct {
	// contains filtered or unexported fields
}

PublicBlockChainAPI provides an API to access the Harmony blockchain. It offers only methods that operate on public data that is freely available to anyone.

func NewPublicBlockChainAPI

func NewPublicBlockChainAPI(b Backend) *PublicBlockChainAPI

NewPublicBlockChainAPI creates a new Harmony blockchain API.

func (*PublicBlockChainAPI) BlockNumber

func (s *PublicBlockChainAPI) BlockNumber() hexutil.Uint64

BlockNumber returns the block number of the chain head.

func (*PublicBlockChainAPI) Call

func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNr rpc.BlockNumber) (hexutil.Bytes, error)

Call executes the given transaction on the state for the given block number. It doesn't make and changes in the state/blockchain and is useful to execute and retrieve values.

func (*PublicBlockChainAPI) EstimateGas added in v1.2.3

func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs) (hexutil.Uint64, error)

EstimateGas returns an estimate of the amount of gas needed to execute the given transaction against the current pending block.

func (*PublicBlockChainAPI) GetBalance

func (s *PublicBlockChainAPI) GetBalance(ctx context.Context, address string, blockNr rpc.BlockNumber) (*hexutil.Big, error)

GetBalance returns the amount of Nano 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 (*PublicBlockChainAPI) GetBalanceByBlockNumber added in v1.2.4

func (s *PublicBlockChainAPI) GetBalanceByBlockNumber(ctx context.Context, address string, blockNr rpc.BlockNumber) (*hexutil.Big, error)

GetBalanceByBlockNumber returns balance by block number.

func (*PublicBlockChainAPI) GetBlockByHash

func (s *PublicBlockChainAPI) GetBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool) (map[string]interface{}, error)

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 (*PublicBlockChainAPI) GetBlockByNumber

func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, blockNr rpc.BlockNumber, fullTx bool) (map[string]interface{}, error)

GetBlockByNumber returns the requested block. When blockNr is -1 the chain head is returned. When fullTx is true all transactions in the block are returned in full detail, otherwise only the transaction hash is returned.

func (*PublicBlockChainAPI) GetBlockSigners added in v1.2.6

func (s *PublicBlockChainAPI) GetBlockSigners(ctx context.Context, blockNr rpc.BlockNumber) ([]string, error)

GetBlockSigners returns signers for a particular block.

func (*PublicBlockChainAPI) GetCode

func (s *PublicBlockChainAPI) GetCode(ctx context.Context, addr string, blockNr rpc.BlockNumber) (hexutil.Bytes, error)

GetCode returns the code stored at the given address in the state for the given block number.

func (*PublicBlockChainAPI) GetCommittee

func (s *PublicBlockChainAPI) GetCommittee(ctx context.Context, epoch int64) (map[string]interface{}, error)

GetCommittee returns committee for a particular epoch.

func (*PublicBlockChainAPI) GetShardID

func (s *PublicBlockChainAPI) GetShardID(ctx context.Context) (int, error)

GetShardID returns shard ID of the requested node.

func (*PublicBlockChainAPI) GetShardingStructure

func (s *PublicBlockChainAPI) GetShardingStructure(ctx context.Context) ([]map[string]interface{}, error)

GetShardingStructure returns an array of sharding structures.

func (*PublicBlockChainAPI) GetStorageAt

func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, addr string, key string, blockNr rpc.BlockNumber) (hexutil.Bytes, error)

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 (*PublicBlockChainAPI) LatestHeader

func (s *PublicBlockChainAPI) LatestHeader(ctx context.Context) *HeaderInformation

LatestHeader returns the latest header information

func (*PublicBlockChainAPI) ResendCx

func (s *PublicBlockChainAPI) ResendCx(ctx context.Context, txID common.Hash) (bool, error)

ResendCx requests that the egress receipt for the given cross-shard transaction be sent to the destination shard for credit. This is used for unblocking a half-complete cross-shard transaction whose fund has been withdrawn already from the source shard but not credited yet in the destination account due to transient failures.

type PublicHarmonyAPI

type PublicHarmonyAPI struct {
	// contains filtered or unexported fields
}

PublicHarmonyAPI provides an API to access Harmony related information. It offers only methods that operate on public data that is freely available to anyone.

func NewPublicHarmonyAPI

func NewPublicHarmonyAPI(b Backend) *PublicHarmonyAPI

NewPublicHarmonyAPI ...

func (*PublicHarmonyAPI) GasPrice

func (s *PublicHarmonyAPI) GasPrice(ctx context.Context) (*hexutil.Big, error)

GasPrice returns a suggestion for a gas price.

func (*PublicHarmonyAPI) GetNodeMetadata

func (s *PublicHarmonyAPI) GetNodeMetadata() NodeMetadata

GetNodeMetadata produces a NodeMetadata record, data is from the answering RPC node

func (*PublicHarmonyAPI) ProtocolVersion

func (s *PublicHarmonyAPI) ProtocolVersion() hexutil.Uint

ProtocolVersion returns the current Harmony protocol version this node supports

func (*PublicHarmonyAPI) Syncing

func (s *PublicHarmonyAPI) Syncing() (interface{}, error)

Syncing returns false in case the node is currently not syncing with the network. It can be up to date or has not yet received the latest block headers from its pears. In case it is synchronizing: - startingBlock: block number this node started to synchronise from - currentBlock: block number this node is currently importing - 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

type PublicNetAPI

type PublicNetAPI struct {
	// contains filtered or unexported fields
}

PublicNetAPI offers network related RPC methods

func NewPublicNetAPI

func NewPublicNetAPI(net p2p.Host, networkVersion uint64) *PublicNetAPI

NewPublicNetAPI creates a new net API instance.

func (*PublicNetAPI) PeerCount

func (s *PublicNetAPI) PeerCount() hexutil.Uint

PeerCount returns the number of connected peers

func (*PublicNetAPI) Version

func (s *PublicNetAPI) Version() string

Version returns the network version, i.e. network ID identifying which network we are using

type PublicTransactionPoolAPI

type PublicTransactionPoolAPI struct {
	// contains filtered or unexported fields
}

PublicTransactionPoolAPI exposes methods for the RPC interface

func NewPublicTransactionPoolAPI

func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicTransactionPoolAPI

NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool.

func (*PublicTransactionPoolAPI) GetBlockTransactionCountByHash

func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHash common.Hash) *hexutil.Uint

GetBlockTransactionCountByHash returns the number of transactions in the block with the given hash.

func (*PublicTransactionPoolAPI) GetBlockTransactionCountByNumber

func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint

GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.

func (*PublicTransactionPoolAPI) GetCXReceiptByHash

func (s *PublicTransactionPoolAPI) GetCXReceiptByHash(ctx context.Context, hash common.Hash) *RPCCXReceipt

GetCXReceiptByHash returns the transaction for the given hash

func (*PublicTransactionPoolAPI) GetCrossShardTransactionsHistory added in v1.2.5

func (s *PublicTransactionPoolAPI) GetCrossShardTransactionsHistory(ctx context.Context, args TxHistoryArgs) (map[string]interface{}, error)

GetCrossShardTransactionsHistory returns the list of cross shard transactions that involve a particular address.

func (*PublicTransactionPoolAPI) GetCurrentTransactionErrorSink added in v1.2.2

func (s *PublicTransactionPoolAPI) GetCurrentTransactionErrorSink() []types.RPCTransactionError

GetCurrentTransactionErrorSink ..

func (*PublicTransactionPoolAPI) GetPendingCXReceipts

func (s *PublicTransactionPoolAPI) GetPendingCXReceipts(ctx context.Context) []*types.CXReceiptsProof

GetPendingCXReceipts ..

func (s *PublicTransactionPoolAPI) GetPendingCrossLinks(ctx context.Context) []*block.Header

GetPendingCrossLinks ..

func (*PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex

func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) *RPCTransaction

GetTransactionByBlockHashAndIndex returns the transaction for the given block hash and index.

func (*PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex

func (s *PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) *RPCTransaction

GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index.

func (*PublicTransactionPoolAPI) GetTransactionByHash

func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) *RPCTransaction

GetTransactionByHash returns the transaction for the given hash

func (*PublicTransactionPoolAPI) GetTransactionCount

func (s *PublicTransactionPoolAPI) GetTransactionCount(ctx context.Context, addr string, blockNr rpc.BlockNumber) (*hexutil.Uint64, error)

GetTransactionCount returns the number of transactions the given address has sent for the given block number

func (*PublicTransactionPoolAPI) GetTransactionReceipt

func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error)

GetTransactionReceipt returns the transaction receipt for the given transaction hash.

func (*PublicTransactionPoolAPI) GetTransactionsHistory

func (s *PublicTransactionPoolAPI) GetTransactionsHistory(ctx context.Context, args TxHistoryArgs) (map[string]interface{}, error)

GetTransactionsHistory returns the list of transactions hashes that involve a particular address.

func (*PublicTransactionPoolAPI) PendingTransactions

func (s *PublicTransactionPoolAPI) PendingTransactions() ([]*RPCTransaction, error)

PendingTransactions returns the transactions that are in the transaction pool

func (*PublicTransactionPoolAPI) SendRawStakingTransaction

func (s *PublicTransactionPoolAPI) SendRawStakingTransaction(
	ctx context.Context, encodedTx hexutil.Bytes,
) (common.Hash, error)

SendRawStakingTransaction will add the signed transaction to the transaction pool. The sender is responsible for signing the transaction and using the correct nonce.

func (*PublicTransactionPoolAPI) SendRawTransaction

func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error)

SendRawTransaction will add the signed transaction to the transaction pool. The sender is responsible for signing the transaction and using the correct nonce.

func (*PublicTransactionPoolAPI) SendTransaction

func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args SendTxArgs) (common.Hash, error)

SendTransaction creates a transaction for the given argument, sign it and submit it to the transaction pool.

type RPCBlock

type RPCBlock struct {
	Number           *hexutil.Big     `json:"number"`
	Hash             common.Hash      `json:"hash"`
	ParentHash       common.Hash      `json:"parentHash"`
	Nonce            types.BlockNonce `json:"nonce"`
	MixHash          common.Hash      `json:"mixHash"`
	LogsBloom        ethtypes.Bloom   `json:"logsBloom"`
	StateRoot        common.Hash      `json:"stateRoot"`
	Miner            common.Address   `json:"miner"`
	Difficulty       *hexutil.Big     `json:"difficulty"`
	ExtraData        []byte           `json:"extraData"`
	Size             hexutil.Uint64   `json:"size"`
	GasLimit         hexutil.Uint64   `json:"gasLimit"`
	GasUsed          hexutil.Uint64   `json:"gasUsed"`
	Timestamp        *big.Int         `json:"timestamp"`
	TransactionsRoot common.Hash      `json:"transactionsRoot"`
	ReceiptsRoot     common.Hash      `json:"receiptsRoot"`
	Transactions     []interface{}    `json:"transactions"`
	Uncles           []common.Hash    `json:"uncles"`
	TotalDifficulty  *big.Int         `json:"totalDifficulty"`
}

RPCBlock represents a block that will serialize to the RPC representation of a block

type RPCCXReceipt

type RPCCXReceipt struct {
	BlockHash   common.Hash  `json:"blockHash"`
	BlockNumber *hexutil.Big `json:"blockNumber"`
	TxHash      common.Hash  `json:"hash"`
	From        string       `json:"from"`
	To          string       `json:"to"`
	ShardID     uint32       `json:"shardID"`
	ToShardID   uint32       `json:"toShardID"`
	Amount      *hexutil.Big `json:"value"`
}

RPCCXReceipt represents a CXReceipt that will serialize to the RPC representation of a CXReceipt

type RPCTransaction

type RPCTransaction struct {
	BlockHash        common.Hash    `json:"blockHash"`
	BlockNumber      *hexutil.Big   `json:"blockNumber"`
	From             string         `json:"from"`
	Timestamp        hexutil.Uint64 `json:"timestamp"`
	Gas              hexutil.Uint64 `json:"gas"`
	GasPrice         *hexutil.Big   `json:"gasPrice"`
	Hash             common.Hash    `json:"hash"`
	Input            hexutil.Bytes  `json:"input"`
	Nonce            hexutil.Uint64 `json:"nonce"`
	To               string         `json:"to"`
	TransactionIndex hexutil.Uint   `json:"transactionIndex"`
	Value            *hexutil.Big   `json:"value"`
	ShardID          uint32         `json:"shardID"`
	ToShardID        uint32         `json:"toShardID"`
	V                *hexutil.Big   `json:"v"`
	R                *hexutil.Big   `json:"r"`
	S                *hexutil.Big   `json:"s"`
}

RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction

type SendTxArgs

type SendTxArgs struct {
	From     common.Address  `json:"from"`
	To       *common.Address `json:"to"`
	ShardID  uint32          `json:"shardID"`
	Gas      *hexutil.Uint64 `json:"gas"`
	GasPrice *hexutil.Big    `json:"gasPrice"`
	Value    *hexutil.Big    `json:"value"`
	Nonce    *hexutil.Uint64 `json:"nonce"`
	// We accept "data" and "input" for backwards-compatibility reasons. "input" is the
	// newer name and should be preferred by clients.
	Data  *hexutil.Bytes `json:"data"`
	Input *hexutil.Bytes `json:"input"`
}

SendTxArgs represents the arguments to sumbit a new transaction into the transaction pool.

type TxHistoryArgs

type TxHistoryArgs struct {
	Address   string `json:"address"`
	PageIndex uint32 `json:"pageIndex"`
	PageSize  uint32 `json:"pageSize"`
	FullTx    bool   `json:"fullTx"`
	TxType    string `json:"txType"`
	Order     string `json:"order"`
}

TxHistoryArgs is struct to make GetTransactionsHistory request

func ReturnPagination added in v1.2.5

func ReturnPagination(length int, args TxHistoryArgs) (int, TxHistoryArgs)

ReturnPagination returns pagination params.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL