Documentation ¶
Overview ¶
Package bchainapi implements the general BCHAIN API functions.
Index ¶
- func GetAPIs(apiBackend Backend) []rpc.API
- type AddrLocker
- type Backend
- type Certificate
- type ConsensusDataHex
- type PrivateAccountAPI
- func (s *PrivateAccountAPI) DeriveAccount(url string, path string, pin *bool) (accounts.Account, error)
- func (s *PrivateAccountAPI) EcRecover(ctx context.Context, data, sig types.BytesForJson) (types.Address, error)
- func (s *PrivateAccountAPI) ImportRawKey(privkey string, password string) (types.Address, error)
- func (s *PrivateAccountAPI) ListAccounts() []types.Address
- func (s *PrivateAccountAPI) ListWallets() []rawWallet
- func (s *PrivateAccountAPI) LockAccount(addr types.Address) bool
- func (s *PrivateAccountAPI) NewAccount(password string) (types.Address, error)
- func (s *PrivateAccountAPI) OpenWallet(url string, passphrase *string) error
- func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs, passwd string) (types.Hash, error)
- func (s *PrivateAccountAPI) Sign(ctx context.Context, data types.BytesForJson, addr types.Address, ...) (types.BytesForJson, error)
- func (s *PrivateAccountAPI) UnlockAccount(addr types.Address, password string, duration *uint64) (bool, error)
- type PublicAccountAPI
- type PublicBchainAPI
- type PublicBlockChainAPI
- func (s *PublicBlockChainAPI) ActionCall(ctx context.Context, actionArg SendTxAction, blockNr rpc.BlockNumber) ([]types.BytesForJson, error)
- func (s *PublicBlockChainAPI) BlockNumber() *big.Int
- func (s *PublicBlockChainAPI) GetBlockByHash(ctx context.Context, blockHash types.Hash, fullTx bool) (map[string]interface{}, error)
- func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, blockNr rpc.BlockNumber, fullTx bool) (map[string]interface{}, error)
- func (s *PublicBlockChainAPI) GetBlockCertificateByNumber(ctx context.Context, blockNr rpc.BlockNumber) ([]Certificate, error)
- func (s *PublicBlockChainAPI) GetCode(ctx context.Context, address types.Address, blockNr rpc.BlockNumber) (types.BytesForJson, error)
- func (s *PublicBlockChainAPI) GetStatInfoByNumber(ctx context.Context, blockNr rpc.BlockNumber) (map[string]interface{}, error)
- func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, address types.Address, key string, ...) (types.BytesForJson, error)
- type PublicTransactionPoolAPI
- func (s *PublicTransactionPoolAPI) GetAccountNonce(ctx context.Context, address types.Address, blockNr rpc.BlockNumber) (*types.Uint64ForJson, error)
- func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHash types.Hash) *types.UintForJson
- func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) *types.UintForJson
- func (s *PublicTransactionPoolAPI) GetCoinBaseLogByBlockNumber(ctx context.Context, blockNr rpc.BlockNumber) (map[string]interface{}, error)
- func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockHashAndIndex(ctx context.Context, blockHash types.Hash, index types.UintForJson) types.BytesForJson
- func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index types.UintForJson) types.BytesForJson
- func (s *PublicTransactionPoolAPI) GetRawTransactionByHash(ctx context.Context, hash types.Hash) (types.BytesForJson, error)
- func (s *PublicTransactionPoolAPI) GetTransactionByAddress(ctx context.Context, address types.Address, nonce types.Uint64ForJson) *RPCTransaction
- func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash types.Hash, index types.UintForJson) *RPCTransaction
- func (s *PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index types.UintForJson) *RPCTransaction
- func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, hash types.Hash) *RPCTransaction
- func (s *PublicTransactionPoolAPI) GetTransactionReceipt(hash types.Hash) (map[string]interface{}, error)
- func (s *PublicTransactionPoolAPI) PendingTransactions() ([]*RPCTransaction, error)
- func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs SendTxArgs) (types.Hash, error)
- func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encodedTx types.BytesForJson) (types.Hash, error)
- func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args SendTxArgs) (types.Hash, error)
- func (s *PublicTransactionPoolAPI) Sign(addr types.Address, data types.BytesForJson) (types.BytesForJson, error)
- func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error)
- type PublicTxPoolAPI
- type RPCTransaction
- type SendTxAction
- type SendTxArgs
- type SignTransactionResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AddrLocker ¶
type AddrLocker struct {
// contains filtered or unexported fields
}
func (*AddrLocker) LockAddr ¶
func (l *AddrLocker) LockAddr(address types.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 types.Address)
UnlockAddr unlocks the mutex of the given account.
type Backend ¶
type Backend interface { // General bchain API Downloader() *downloader.Downloader ProtocolVersion() int ChainDb() database.IDatabase EventMux() *event.TypeMux AccountManager() *accounts.Manager // BlockChain API SetHead(number uint64) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*block.Header, error) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*block.Block, error) StatInfoByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*blockchain.BlockStat, error) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *block.Header, error) GetBlock(ctx context.Context, blockHash types.Hash) (*block.Block, error) GetReceipts(ctx context.Context, blockHash types.Hash) (transaction.Receipts, error) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription GetBlockCertificate(ctx context.Context, blockNr rpc.BlockNumber) apos.BlockCertificate // TxPool API SendTx(ctx context.Context, signedTx *transaction.Transaction) error GetPoolTransactions() (transaction.Transactions, error) GetPoolTransaction(txHash types.Hash) *transaction.Transaction GetPoolNonce(ctx context.Context, addr types.Address) (uint64, error) Stats() (pending int, queued int) TxPoolContent() (map[types.Address]transaction.Transactions, map[types.Address]transaction.Transactions) SubscribeTxPreEvent(chan<- core.TxPreEvent) event.Subscription ChainConfig() *params.ChainConfig CurrentBlock() *block.Block CurrentBlockNum() uint64 }
Backend interface provides the common API services (that are provided by both full and light clients) with access to necessary functions.
type Certificate ¶
type ConsensusDataHex ¶
type ConsensusDataHex struct { Id string `json:"id"` Para *types.BytesForJson `json:"data"` }
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 NewPrivateAccountAPI ¶
func NewPrivateAccountAPI(b Backend, nonceLock *AddrLocker) *PrivateAccountAPI
NewPrivateAccountAPI create a new PrivateAccountAPI.
func (*PrivateAccountAPI) DeriveAccount ¶
func (s *PrivateAccountAPI) DeriveAccount(url string, path string, pin *bool) (accounts.Account, error)
DeriveAccount requests a HD wallet to derive a new account, optionally pinning it for later reuse.
func (*PrivateAccountAPI) EcRecover ¶
func (s *PrivateAccountAPI) EcRecover(ctx context.Context, data, sig types.BytesForJson) (types.Address, error)
EcRecover returns the address for the account that was used to create the signature. Note, this function is compatible with bchain_sign and personal_sign. As such it recovers the address of: hash = keccak256("\x19Bchain Signed Message:\n"${message length}${message}) addr = ecrecover(hash, signature)
Note, the signature must conform to the secp256k1 curve R, S and V values, where the V value must be be 27 or 28 for legacy reasons.
func (*PrivateAccountAPI) ImportRawKey ¶
ImportRawKey stores the given hex encoded ECDSA key into the key directory, encrypting it with the passphrase.
func (*PrivateAccountAPI) ListAccounts ¶
func (s *PrivateAccountAPI) ListAccounts() []types.Address
ListAccounts will return a list of addresses for accounts this node manages.
func (*PrivateAccountAPI) ListWallets ¶
func (s *PrivateAccountAPI) ListWallets() []rawWallet
ListWallets will return a list of wallets this node manages.
func (*PrivateAccountAPI) LockAccount ¶
func (s *PrivateAccountAPI) LockAccount(addr types.Address) bool
LockAccount will lock the account associated with the given address when it's unlocked.
func (*PrivateAccountAPI) NewAccount ¶
func (s *PrivateAccountAPI) NewAccount(password string) (types.Address, error)
NewAccount will create a new account and returns the address for the new account.
func (*PrivateAccountAPI) OpenWallet ¶
func (s *PrivateAccountAPI) OpenWallet(url string, passphrase *string) error
OpenWallet initiates a hardware wallet opening procedure, establishing a USB 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 (*PrivateAccountAPI) SendTransaction ¶
func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs, passwd string) (types.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.
func (*PrivateAccountAPI) Sign ¶
func (s *PrivateAccountAPI) Sign(ctx context.Context, data types.BytesForJson, addr types.Address, passwd string) (types.BytesForJson, error)
Sign calculates an bchain ECDSA signature for: keccack256("\x19bchain Signed Message:\n" + len(message) + message))
Note, the produced signature conforms to the secp256k1 curve R, S and V values, where the V value will be 27 or 28 for legacy reasons.
The key used to calculate the signature is decrypted with the given password.
func (*PrivateAccountAPI) UnlockAccount ¶
func (s *PrivateAccountAPI) UnlockAccount(addr types.Address, password string, duration *uint64) (bool, error)
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.
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() []types.Address
Accounts returns the collection of accounts this node manages
type PublicBchainAPI ¶
type PublicBchainAPI struct {
// contains filtered or unexported fields
}
PublicBchainAPI provides an API to access bchain related information. It offers only methods that operate on public data that is freely available to anyone.
func NewPublicBchainAPI ¶
func NewPublicBchainAPI(b Backend) *PublicBchainAPI
NewPublicBchainAPI creates a new bchain protocol API.
func (*PublicBchainAPI) ProtocolVersion ¶
func (s *PublicBchainAPI) ProtocolVersion() types.UintForJson
ProtocolVersion returns the current bchain protocol version this node supports
func (*PublicBchainAPI) Syncing ¶
func (s *PublicBchainAPI) 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 PublicBlockChainAPI ¶
type PublicBlockChainAPI struct {
// contains filtered or unexported fields
}
PublicBlockChainAPI provides an API to access the bchain 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 bchain blockchain API.
func (*PublicBlockChainAPI) ActionCall ¶
func (s *PublicBlockChainAPI) ActionCall(ctx context.Context, actionArg SendTxAction, blockNr rpc.BlockNumber) ([]types.BytesForJson, error)
ActionCall returns the result of a certain contract
func (*PublicBlockChainAPI) BlockNumber ¶
func (s *PublicBlockChainAPI) BlockNumber() *big.Int
BlockNumber returns the block number of the chain head.
func (*PublicBlockChainAPI) GetBlockByHash ¶
func (s *PublicBlockChainAPI) GetBlockByHash(ctx context.Context, blockHash types.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) GetBlockCertificateByNumber ¶
func (s *PublicBlockChainAPI) GetBlockCertificateByNumber(ctx context.Context, blockNr rpc.BlockNumber) ([]Certificate, error)
func (*PublicBlockChainAPI) GetCode ¶
func (s *PublicBlockChainAPI) GetCode(ctx context.Context, address types.Address, blockNr rpc.BlockNumber) (types.BytesForJson, error)
GetCode returns the code stored at the given address in the state for the given block number.
func (*PublicBlockChainAPI) GetStatInfoByNumber ¶
func (s *PublicBlockChainAPI) GetStatInfoByNumber(ctx context.Context, blockNr rpc.BlockNumber) (map[string]interface{}, error)
func (*PublicBlockChainAPI) GetStorageAt ¶
func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, address types.Address, key string, blockNr rpc.BlockNumber) (types.BytesForJson, 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.
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) GetAccountNonce ¶
func (s *PublicTransactionPoolAPI) GetAccountNonce(ctx context.Context, address types.Address, blockNr rpc.BlockNumber) (*types.Uint64ForJson, error)
GetTransactionCount returns the number of transactions the given address has sent for the given block number
func (*PublicTransactionPoolAPI) GetBlockTransactionCountByHash ¶
func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHash types.Hash) *types.UintForJson
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) *types.UintForJson
GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.
func (*PublicTransactionPoolAPI) GetCoinBaseLogByBlockNumber ¶
func (s *PublicTransactionPoolAPI) GetCoinBaseLogByBlockNumber(ctx context.Context, blockNr rpc.BlockNumber) (map[string]interface{}, error)
GetCoinBaseLogByBlockNumber returns the coin base transaction for the given block number.
func (*PublicTransactionPoolAPI) GetRawTransactionByBlockHashAndIndex ¶
func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockHashAndIndex(ctx context.Context, blockHash types.Hash, index types.UintForJson) types.BytesForJson
GetRawTransactionByBlockHashAndIndex returns the bytes of the transaction for the given block hash and index.
func (*PublicTransactionPoolAPI) GetRawTransactionByBlockNumberAndIndex ¶
func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index types.UintForJson) types.BytesForJson
GetRawTransactionByBlockNumberAndIndex returns the bytes of the transaction for the given block number and index.
func (*PublicTransactionPoolAPI) GetRawTransactionByHash ¶
func (s *PublicTransactionPoolAPI) GetRawTransactionByHash(ctx context.Context, hash types.Hash) (types.BytesForJson, error)
GetRawTransactionByHash returns the bytes of the transaction for the given hash.
func (*PublicTransactionPoolAPI) GetTransactionByAddress ¶
func (s *PublicTransactionPoolAPI) GetTransactionByAddress(ctx context.Context, address types.Address, nonce types.Uint64ForJson) *RPCTransaction
GetTransactionByHash returns the transaction for the given hash
func (*PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex ¶
func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash types.Hash, index types.UintForJson) *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 types.UintForJson) *RPCTransaction
GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index.
func (*PublicTransactionPoolAPI) GetTransactionByHash ¶
func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, hash types.Hash) *RPCTransaction
GetTransactionByHash returns the transaction for the given hash
func (*PublicTransactionPoolAPI) GetTransactionReceipt ¶
func (s *PublicTransactionPoolAPI) GetTransactionReceipt(hash types.Hash) (map[string]interface{}, error)
GetTransactionReceipt returns the transaction receipt for the given transaction hash.
func (*PublicTransactionPoolAPI) PendingTransactions ¶
func (s *PublicTransactionPoolAPI) PendingTransactions() ([]*RPCTransaction, error)
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 (*PublicTransactionPoolAPI) Resend ¶
func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs SendTxArgs) (types.Hash, error)
func (*PublicTransactionPoolAPI) SendRawTransaction ¶
func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encodedTx types.BytesForJson) (types.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) (types.Hash, error)
SendTransaction creates a transaction for the given argument, sign it and submit it to the transaction pool.
func (*PublicTransactionPoolAPI) Sign ¶
func (s *PublicTransactionPoolAPI) Sign(addr types.Address, data types.BytesForJson) (types.BytesForJson, error)
Sign calculates an ECDSA signature for: keccack256("\x19BchainSigned Message:\n" + len(message) + message).
Note, the produced signature conforms to the secp256k1 curve R, S and V values, where the V value will be 27 or 28 for legacy reasons.
The account associated with addr must be unlocked.
func (*PublicTransactionPoolAPI) SignTransaction ¶
func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error)
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.
type PublicTxPoolAPI ¶
type PublicTxPoolAPI struct {
// contains filtered or unexported fields
}
PublicTxPoolAPI offers and API for the transaction pool. It only operates on data that is non confidential.
func NewPublicTxPoolAPI ¶
func NewPublicTxPoolAPI(b Backend) *PublicTxPoolAPI
NewPublicTxPoolAPI creates a new tx pool service that gives information about the transaction pool.
func (*PublicTxPoolAPI) Content ¶
func (s *PublicTxPoolAPI) Content() map[string]map[string]map[string]*RPCTransaction
Content returns the transactions contained within the transaction pool.
func (*PublicTxPoolAPI) Inspect ¶
func (s *PublicTxPoolAPI) Inspect() map[string]map[string]map[string]string
Inspect retrieves the content of the transaction pool and flattens it into an easily inspectable list.
func (*PublicTxPoolAPI) Status ¶
func (s *PublicTxPoolAPI) Status() map[string]types.UintForJson
Status returns the number of pending and queued transaction in the pool.
type RPCTransaction ¶
type RPCTransaction struct { BlockHash types.Hash `json:"blockHash"` BlockNumber *types.BigInt `json:"blockNumber"` From types.Address `json:"from"` Hash types.Hash `json:"hash"` Nonce types.Uint64ForJson `json:"nonce"` TransactionIndex types.UintForJson `json:"transactionIndex"` Actions []*SendTxAction `json:"actions"` V *types.BigInt `json:"v"` R *types.BigInt `json:"r"` S *types.BigInt `json:"s"` }
RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
type SendTxAction ¶
type SendTxAction struct { Address *types.Address `json:"address"` Params *types.BytesForJson `json:"params"` }
type SendTxArgs ¶
type SendTxArgs struct { From types.Address `json:"from"` Nonce *types.Uint64ForJson `json:"nonce"` Actions []SendTxAction `json:"actions"` }
SendTxArgs represents the arguments to submit a new transaction into the transaction pool.
type SignTransactionResult ¶
type SignTransactionResult struct { Raw types.BytesForJson `json:"raw"` Tx *transaction.Transaction `json:"tx"` }
SignTransactionResult represents a Msgp encoded signed transaction.