当前位置: 首页 > 工具软件 > Burrow > 使用案例 >

burrow, RPC

宓博实
2023-12-01

gRPC

KeyClient

type KeyClient interface {
	// Sign returns the signature bytes for given message signed with the key associated with signAddress
	Sign(signAddress crypto.Address, message []byte) (*crypto.Signature, error)

	// PublicKey returns the public key associated with a given address
	PublicKey(address crypto.Address) (publicKey crypto.PublicKey, err error)

	// Generate requests that a key be generate within the keys instance and returns the address
	Generate(keyName string, keyType crypto.CurveType) (keyAddress crypto.Address, err error)

	// Get the address for a keyname or the adress itself
	GetAddressForKeyName(keyName string) (keyAddress crypto.Address, err error)

	// Returns nil if the keys instance is healthy, error otherwise
	HealthCheck() error
}

QueryClient


// QueryClient is the client API for Query service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type QueryClient interface {
	Status(ctx context.Context, in *StatusParam, opts ...grpc.CallOption) (*rpc.ResultStatus, error)
	GetAccount(ctx context.Context, in *GetAccountParam, opts ...grpc.CallOption) (*acm.Account, error)
	GetMetadata(ctx context.Context, in *GetMetadataParam, opts ...grpc.CallOption) (*MetadataResult, error)
	GetStorage(ctx context.Context, in *GetStorageParam, opts ...grpc.CallOption) (*StorageValue, error)
	ListAccounts(ctx context.Context, in *ListAccountsParam, opts ...grpc.CallOption) (Query_ListAccountsClient, error)
	GetName(ctx context.Context, in *GetNameParam, opts ...grpc.CallOption) (*names.Entry, error)
	ListNames(ctx context.Context, in *ListNamesParam, opts ...grpc.CallOption) (Query_ListNamesClient, error)
	// GetNetworkRegistry returns for each validator address, the list of their identified node at the current state
	GetNetworkRegistry(ctx context.Context, in *GetNetworkRegistryParam, opts ...grpc.CallOption) (*NetworkRegistry, error)
	GetValidatorSet(ctx context.Context, in *GetValidatorSetParam, opts ...grpc.CallOption) (*ValidatorSet, error)
	GetValidatorSetHistory(ctx context.Context, in *GetValidatorSetHistoryParam, opts ...grpc.CallOption) (*ValidatorSetHistory, error)
	GetProposal(ctx context.Context, in *GetProposalParam, opts ...grpc.CallOption) (*payload.Ballot, error)
	ListProposals(ctx context.Context, in *ListProposalsParam, opts ...grpc.CallOption) (Query_ListProposalsClient, error)
	GetStats(ctx context.Context, in *GetStatsParam, opts ...grpc.CallOption) (*Stats, error)
	GetBlockHeader(ctx context.Context, in *GetBlockParam, opts ...grpc.CallOption) (*types.Header, error)
}

TransactClient


// TransactClient is the client API for Transact service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type TransactClient interface {
	// Broadcast a transaction to the mempool - if the transaction is not signed signing will be attempted server-side
	// and wait for it to be included in block
	BroadcastTxSync(ctx context.Context, in *TxEnvelopeParam, opts ...grpc.CallOption) (*exec.TxExecution, error)
	// Broadcast a transaction to the mempool - if the transaction is not signed signing will be attempted server-side
	BroadcastTxAsync(ctx context.Context, in *TxEnvelopeParam, opts ...grpc.CallOption) (*txs.Receipt, error)
	// Sign transaction server-side
	SignTx(ctx context.Context, in *TxEnvelopeParam, opts ...grpc.CallOption) (*TxEnvelope, error)
	// Formulate a transaction from a Payload and retrun the envelop with the Tx bytes ready to sign
	FormulateTx(ctx context.Context, in *payload.Any, opts ...grpc.CallOption) (*TxEnvelope, error)
	// Formulate and sign a CallTx transaction signed server-side and wait for it to be included in a block, retrieving response
	CallTxSync(ctx context.Context, in *payload.CallTx, opts ...grpc.CallOption) (*exec.TxExecution, error)
	// Formulate and sign a CallTx transaction signed server-side
	CallTxAsync(ctx context.Context, in *payload.CallTx, opts ...grpc.CallOption) (*txs.Receipt, error)
	// Perform a 'simulated' call of a contract against the current committed EVM state without any changes been saved
	// and wait for the transaction to be included in a block
	CallTxSim(ctx context.Context, in *payload.CallTx, opts ...grpc.CallOption) (*exec.TxExecution, error)
	// Perform a 'simulated' execution of provided code against the current committed EVM state without any changes been saved
	CallCodeSim(ctx context.Context, in *CallCodeParam, opts ...grpc.CallOption) (*exec.TxExecution, error)
	// Formulate a SendTx transaction signed server-side and wait for it to be included in a block, retrieving response
	SendTxSync(ctx context.Context, in *payload.SendTx, opts ...grpc.CallOption) (*exec.TxExecution, error)
	// Formulate and  SendTx transaction signed server-side
	SendTxAsync(ctx context.Context, in *payload.SendTx, opts ...grpc.CallOption) (*txs.Receipt, error)
	// Formulate a NameTx signed server-side and wait for it to be included in a block returning the registered name
	NameTxSync(ctx context.Context, in *payload.NameTx, opts ...grpc.CallOption) (*exec.TxExecution, error)
	// Formulate a NameTx signed server-side
	NameTxAsync(ctx context.Context, in *payload.NameTx, opts ...grpc.CallOption) (*txs.Receipt, error)
}

DumpClient

type DumpClient interface {
	GetDump(ctx context.Context, in *GetDumpParam, opts ...grpc.CallOption) (Dump_GetDumpClient, error)
}

ExecutionEventsClient

type ExecutionEventsClient interface {
	// Get StreamEvents (including transactions) for a range of block heights
	Stream(ctx context.Context, in *BlocksRequest, opts ...grpc.CallOption) (ExecutionEvents_StreamClient, error)
	// Get a particular TxExecution by hash
	Tx(ctx context.Context, in *TxRequest, opts ...grpc.CallOption) (*exec.TxExecution, error)
	// GetEvents provides events streaming one block at a time - that is all events emitted in a particular block
	// are guaranteed to be delivered in each GetEventsResponse
	Events(ctx context.Context, in *BlocksRequest, opts ...grpc.CallOption) (ExecutionEvents_EventsClient, error)
}

Info

type RPCClient interface {
	Call(method string, params map[string]interface{}, result interface{}) (interface{}, error)
}

func Status(client RPCClient) (*rpc.ResultStatus, error) {
	res := new(rpc.ResultStatus)
	_, err := client.Call(rpcinfo.Status, pmap(), res)
	if err != nil {
		return nil, err
	}
	return res, nil
}

func ChainId(client RPCClient) (*rpc.ResultChainId, error) {
	res := new(rpc.ResultChainId)
	_, err := client.Call(rpcinfo.ChainID, pmap(), &res)
	if err != nil {
		return nil, err
	}
	return res, nil
}

func Account(client RPCClient, address crypto.Address) (*acm.Account, error) {
	res := new(rpc.ResultAccount)
	_, err := client.Call(rpcinfo.Account, pmap("address", address), res)
	if err != nil {
		return nil, err
	}
	return res.Account, nil
}

func DumpStorage(client RPCClient, address crypto.Address) (*rpc.ResultDumpStorage, error) {
	res := new(rpc.ResultDumpStorage)
	_, err := client.Call(rpcinfo.DumpStorage, pmap("address", address), res)
	if err != nil {
		return nil, err
	}
	return res, nil
}

func Storage(client RPCClient, address crypto.Address, key []byte) ([]byte, error) {
	res := new(rpc.ResultStorage)
	_, err := client.Call(rpcinfo.Storage, pmap("address", address, "key", key), res)
	if err != nil {
		return nil, err
	}
	return res.Value, nil
}

func Name(client RPCClient, name string) (*names.Entry, error) {
	res := new(rpc.ResultName)
	_, err := client.Call(rpcinfo.Name, pmap("name", name), res)
	if err != nil {
		return nil, err
	}
	return res.Entry, nil
}

func Names(client RPCClient, regex string) ([]*names.Entry, error) {
	res := new(rpc.ResultNames)
	_, err := client.Call(rpcinfo.Names, pmap("regex", regex), res)
	if err != nil {
		return nil, err
	}
	return res.Names, nil
}

func Blocks(client RPCClient, minHeight, maxHeight int) (*rpc.ResultBlocks, error) {
	res := new(rpc.ResultBlocks)
	_, err := client.Call(rpcinfo.Blocks, pmap("minHeight", minHeight, "maxHeight", maxHeight), res)
	if err != nil {
		return nil, err
	}
	return res, nil
}

func Block(client RPCClient, height int) (*rpc.ResultBlock, error) {
	res := new(rpc.ResultBlock)
	_, err := client.Call(rpcinfo.Block, pmap("height", height), res)
	if err != nil {
		return nil, err
	}
	return res, nil
}

func UnconfirmedTxs(client RPCClient, maxTxs int) (*rpc.ResultUnconfirmedTxs, error) {
	res := new(rpc.ResultUnconfirmedTxs)
	_, err := client.Call(rpcinfo.UnconfirmedTxs, pmap("maxTxs", maxTxs), res)
	if err != nil {
		return nil, err
	}
	resCon := res
	return resCon, nil
}

func Validators(client RPCClient) (*rpc.ResultValidators, error) {
	res := new(rpc.ResultValidators)
	_, err := client.Call(rpcinfo.Validators, pmap(), res)
	if err != nil {
		return nil, err
	}
	return res, nil
}

func Consensus(client RPCClient) (*rpc.ResultConsensusState, error) {
	res := new(rpc.ResultConsensusState)
	_, err := client.Call(rpcinfo.Consensus, pmap(), res)
	if err != nil {
		return nil, err
	}
	return res, nil
}
 类似资料: