rpc

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: MIT Imports: 8 Imported by: 22

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotFound = errors.New("not found")
)

Functions

func TransactionFromString

func TransactionFromString(tx string) (*types.Transaction, error)

func TransactionString

func TransactionString(tx *types.Transaction) (string, error)

Types

type Client

type Client interface {
	////// Chain
	// GetTipBlockNumber returns the number of blocks in the longest blockchain.
	GetTipBlockNumber(ctx context.Context) (uint64, error)

	// GetTipHeader returns the information about the tip header of the longest.
	GetTipHeader(ctx context.Context) (*types.Header, error)

	// GetCurrentEpoch returns the information about the current epoch.
	GetCurrentEpoch(ctx context.Context) (*types.Epoch, error)

	// GetEpochByNumber return the information corresponding the given epoch number.
	GetEpochByNumber(ctx context.Context, number uint64) (*types.Epoch, error)

	// GetBlockHash returns the hash of a block in the best-block-chain by block number; block of No.0 is the genesis block.
	GetBlockHash(ctx context.Context, number uint64) (*types.Hash, error)

	// GetBlock returns the information about a block by hash.
	GetBlock(ctx context.Context, hash types.Hash) (*types.Block, error)

	// GetHeader returns the information about a block header by hash.
	GetHeader(ctx context.Context, hash types.Hash) (*types.Header, error)

	// GetHeaderByNumber returns the information about a block header by block number.
	GetHeaderByNumber(ctx context.Context, number uint64) (*types.Header, error)

	// GetLiveCell returns the information about a cell by out_point if it is live.
	// If second with_data argument set to true, will return cell data and data_hash if it is live.
	GetLiveCell(ctx context.Context, outPoint *types.OutPoint, withData bool) (*types.CellWithStatus, error)

	// GetTransaction returns the information about a transaction requested by transaction hash.
	GetTransaction(ctx context.Context, hash types.Hash) (*types.TransactionWithStatus, error)

	// GetBlockEconomicState return block economic state, It includes the rewards details and when it is finalized.
	GetBlockEconomicState(ctx context.Context, hash types.Hash) (*types.BlockEconomicState, error)

	// GetTransactionProof Returns a Merkle proof that transactions are included in a block.
	GetTransactionProof(ctx context.Context, txHashes []string, blockHash *types.Hash) (*types.TransactionProof, error)

	//VerifyTransactionProof verifies that a proof points to transactions in a block, returning the transaction hashes it commits to.
	VerifyTransactionProof(ctx context.Context, proof *types.TransactionProof) ([]*types.Hash, error)

	// GetBlockByNumber get block by number
	GetBlockByNumber(ctx context.Context, number uint64) (*types.Block, error)

	// GetForkBlock The RPC returns a fork block or null. When the RPC returns a block, the block hash must equal to the parameter block_hash.
	GetForkBlock(ctx context.Context, blockHash types.Hash) (*types.Block, error)

	// GetConsensus Return various consensus parameters.
	GetConsensus(ctx context.Context) (*types.Consensus, error)

	// GetBlockMedianTime When the given block hash is not on the current canonical chain, this RPC returns null;
	// otherwise returns the median time of the consecutive 37 blocks where the given block_hash has the highest height.
	// Note that the given block is included in the median time. The included block number range is [MAX(block - 36, 0), block].
	GetBlockMedianTime(ctx context.Context, blockHash types.Hash) (uint64, error)

	////// Experiment
	// DryRunTransaction dry run transaction and return the execution cycles.
	// This method will not check the transaction validity,
	// but only run the lock script and type script and then return the execution cycles.
	// Used to debug transaction scripts and query how many cycles the scripts consume.
	DryRunTransaction(ctx context.Context, transaction *types.Transaction) (*types.DryRunTransactionResult, error)

	// CalculateDaoMaximumWithdraw calculate the maximum withdraw one can get, given a referenced DAO cell, and a withdraw block hash.
	CalculateDaoMaximumWithdraw(ctx context.Context, point *types.OutPoint, hash types.Hash) (uint64, error)

	// EstimateFeeRate Estimate a fee rate (capacity/KB) for a transaction that to be committed in expect blocks.
	EstimateFeeRate(ctx context.Context, blocks uint64) (*types.EstimateFeeRateResult, error)

	////// Net
	// LocalNodeInfo returns the local node information.
	LocalNodeInfo(ctx context.Context) (*types.Node, error)

	// GetPeers returns the connected peers information.
	GetPeers(ctx context.Context) ([]*types.Node, error)

	// GetBannedAddresses returns all banned IPs/Subnets.
	GetBannedAddresses(ctx context.Context) ([]*types.BannedAddress, error)

	// ClearBannedAddress returns all banned IPs/Subnets.
	ClearBannedAddresses(ctx context.Context) error

	// SetBan insert or delete an IP/Subnet from the banned list
	SetBan(ctx context.Context, address string, command string, banTime uint64, absolute bool, reason string) error

	// SyncState returns chain synchronization state of this node.
	SyncState(ctx context.Context) (*types.SyncState, error)

	// SetNetworkActive state - true to enable networking, false to disable
	SetNetworkActive(ctx context.Context, state bool) error

	// AddNode Attempts to add a node to the peers list and try connecting to it
	AddNode(ctx context.Context, peerId, address string) error

	// RemoveNode Attempts to remove a node from the peers list and try disconnecting from it.
	RemoveNode(ctx context.Context, peerId string) error

	// PingPeers Requests that a ping is sent to all connected peers, to measure ping time.
	PingPeers(ctx context.Context) error

	////// Pool
	// SendTransaction send new transaction into transaction pool.
	SendTransaction(ctx context.Context, tx *types.Transaction) (*types.Hash, error)

	// SendTransactionNoneValidation send new transaction into transaction pool skipping outputs validation.
	SendTransactionNoneValidation(ctx context.Context, tx *types.Transaction) (*types.Hash, error)

	// TxPoolInfo return the transaction pool information
	TxPoolInfo(ctx context.Context) (*types.TxPoolInfo, error)

	// GetRawTxPool Returns all transaction ids in tx pool as a json array of string transaction ids.
	GetRawTxPool(ctx context.Context) (*types.RawTxPool, error)

	// ClearTxPool Removes all transactions from the transaction pool.
	ClearTxPool(ctx context.Context) error

	////// Stats
	// GetBlockchainInfo return state info of blockchain
	GetBlockchainInfo(ctx context.Context) (*types.BlockchainInfo, error)

	////// Batch
	BatchTransactions(ctx context.Context, batch []types.BatchTransactionItem) error

	// Batch Live cells
	BatchLiveCells(ctx context.Context, batch []types.BatchLiveCellItem) error

	///// ckb-indexer
	//GetTip returns the latest height processed by indexer
	GetTip(ctx context.Context) (*indexer.TipHeader, error)

	//GetCellsCapacity returns the live cells capacity by the lock or type script.
	GetCellsCapacity(ctx context.Context, searchKey *indexer.SearchKey) (*indexer.Capacity, error)

	// GetCells returns the live cells collection by the lock or type script.
	GetCells(ctx context.Context, searchKey *indexer.SearchKey, order indexer.SearchOrder, limit uint64, afterCursor string) (*indexer.LiveCells, error)

	// GetTransactions returns the transactions collection by the lock or type script.
	GetTransactions(ctx context.Context, searchKey *indexer.SearchKey, order indexer.SearchOrder, limit uint64, afterCursor string) (*indexer.Transactions, error)

	// Close close client
	Close()

	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
}

Client for the Nervos RPC API.

func Dial

func Dial(url string) (Client, error)

func DialContext

func DialContext(ctx context.Context, url string) (Client, error)

func DialWithIndexer added in v0.2.0

func DialWithIndexer(ckbUrl string, indexerUrl string) (Client, error)

func DialWithIndexerContext added in v0.2.0

func DialWithIndexerContext(ctx context.Context, ckbUrl string, indexerUrl string) (Client, error)

func NewClient

func NewClient(c *rpc.Client) Client

func NewClientWithIndexer added in v0.2.0

func NewClientWithIndexer(c *rpc.Client, indexer indexer.Client) Client

Jump to

Keyboard shortcuts

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