client

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package client provides a client for the FISCO BCOS RPC API.

Index

Constants

View Source
const (
	Secp256k1 = "secp256k1"
	Sm2p256v1 = "sm2p256v1"
)
View Source
const (
	BlockLimit int64 = 600
)

Variables

View Source
var (
	ErrClientQuit                = errors.New("client is closed")
	ErrNoResult                  = errors.New("no result in JSON-RPC response")
	ErrNoRpcMethod               = errors.New("no rpc method")
	ErrSubscriptionQueueOverflow = errors.New("subscription queue overflow")
)

Functions

func LoadECPrivateKeyFromPEM

func LoadECPrivateKeyFromPEM(path string) ([]byte, string, error)

LoadECPrivateKeyFromPEM reads file, divides into key and certificates

func LoadECPublicKeyFromPEM

func LoadECPublicKeyFromPEM(path string) ([]byte, string, error)

LoadECPublicKeyFromPEM reads file, divides into key and certificates

Types

type Client

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

Client defines typed wrappers for the Ethereum RPC API.

func Dial

func Dial(configFile, groupID string, privateKey []byte) (*Client, error)

Dial connects a client to the given URL and groupID.

func DialContext

func DialContext(ctx context.Context, config *Config) (*Client, error)

DialContext pass the context to the rpc client

func (*Client) AsyncSendEncodedTransaction

func (c *Client) AsyncSendEncodedTransaction(ctx context.Context, encodedTransaction []byte, withProof bool, handler func(*types.Receipt, error)) error

func (*Client) AsyncSendTransaction

func (c *Client) AsyncSendTransaction(ctx context.Context, tx *types.Transaction, handler func(*types.Receipt, error)) error

AsyncSendTransaction send transaction async

func (*Client) BroadcastAMOPMsg

func (c *Client) BroadcastAMOPMsg(topic string, data []byte) error

func (*Client) CallContract

func (c *Client) CallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)

CallContract invoke the call method of rpc api

func (*Client) Close

func (c *Client) Close()

Close disconnects the rpc

func (*Client) CodeAt

func (c *Client) CodeAt(ctx context.Context, address common.Address) ([]byte, error)

CodeAt returns the contract code of the given account. The block number can be nil, in which case the code is taken from the latest known block.

func (*Client) CreateEncodedSignature

func (c *Client) CreateEncodedSignature(hash []byte) ([]byte, error)

func (*Client) CreateEncodedTransaction

func (c *Client) CreateEncodedTransaction(transactionData, transactionDataHash, signature []byte, attribute int32, extraData string) ([]byte, error)

func (*Client) CreateEncodedTransactionDataV1

func (c *Client) CreateEncodedTransactionDataV1(to *common.Address, input []byte, blockLimit int64, abi string) ([]byte, []byte, error)

func (*Client) GetABI

func (c *Client) GetABI(ctx context.Context, address common.Address) (string, error)

func (*Client) GetBlockByHash

func (c *Client) GetBlockByHash(ctx context.Context, blockHash common.Hash, onlyHeader, onlyTxHash bool) (*types.Block, error)

GetBlockByHash returns the block information according to the given block hash

func (*Client) GetBlockByNumber

func (c *Client) GetBlockByNumber(ctx context.Context, blockNumber int64, onlyHeader, onlyTxHash bool) (*types.Block, error)

GetBlockByNumber returns the block information according to the given block number(hex format)

func (*Client) GetBlockHashByNumber

func (c *Client) GetBlockHashByNumber(ctx context.Context, blockNumber int64) (*common.Hash, error)

GetBlockHashByNumber returns the block hash according to the given block number

func (*Client) GetBlockNumber

func (c *Client) GetBlockNumber(ctx context.Context) (int64, error)

GetBlockNumber returns the latest block height(hex format) on a given groupID.

func (*Client) GetCallOpts

func (c *Client) GetCallOpts() *bind.CallOpts

GetCallOpts return *bind.CallOpts

func (*Client) GetChainID

func (c *Client) GetChainID(ctx context.Context) (string, error)

GetChainID returns the Chain ID of the FISCO BCOS running on the nodes.

func (*Client) GetCode

func (c *Client) GetCode(ctx context.Context, address common.Address) ([]byte, error)

GetCode returns the contract code according to the contract address

func (*Client) GetConsensusStatus

func (c *Client) GetConsensusStatus(ctx context.Context) ([]byte, error)

GetConsensusStatus returns the status information about the consensus algorithm on a specific groupID

func (*Client) GetContractAddress

func (c *Client) GetContractAddress(ctx context.Context, txHash common.Hash) (common.Address, error)

GetContractAddress returns a contract address according to the transaction hash

func (*Client) GetGroupID

func (c *Client) GetGroupID() string

GetGroupID returns the groupID of the client

func (*Client) GetGroupInfo

func (c *Client) GetGroupInfo(ctx context.Context) ([]byte, error)

func (*Client) GetGroupInfoList

func (c *Client) GetGroupInfoList(ctx context.Context) ([]byte, error)

GetGroupInfoList returns the ID information of the connected peers and itself

func (*Client) GetGroupList

func (c *Client) GetGroupList(ctx context.Context) ([]byte, error)

GetGroupList returns the groupID list that the node belongs to

func (*Client) GetGroupPeers

func (c *Client) GetGroupPeers(ctx context.Context) ([]byte, error)

GetGroupPeers returns the nodes and the observer nodes list on a specific group

func (*Client) GetNodeIDList

func (c *Client) GetNodeIDList(ctx context.Context) ([]byte, error)

GetNodeIDList returns the ID information of the connected peers and itself

func (*Client) GetNodeInfo

func (c *Client) GetNodeInfo(ctx context.Context, nodeId string) ([]byte, error)

func (*Client) GetObserverList

func (c *Client) GetObserverList(ctx context.Context) ([]string, error)

GetObserverList returns the list of observer nodes' ID according to the groupID

func (*Client) GetPBFTView

func (c *Client) GetPBFTView(ctx context.Context) ([]byte, error)

GetPBFTView returns the latest PBFT view(hex format) of the specific group and it will returns a wrong sentence

func (*Client) GetPeers

func (c *Client) GetPeers(ctx context.Context) ([]byte, error)

GetPeers returns the information of the connected peers

func (*Client) GetPendingTxSize

func (c *Client) GetPendingTxSize(ctx context.Context) (int64, error)

GetPendingTxSize returns amount of the pending transactions

func (*Client) GetSealerList

func (c *Client) GetSealerList(ctx context.Context) ([]ConsensusNodeInfo, error)

GetSealerList returns the list of consensus nodes' ID according to the groupID

func (*Client) GetSyncStatus

func (c *Client) GetSyncStatus(ctx context.Context) (*types.SyncStatus, error)

GetSyncStatus returns the synchronization status of the group

func (*Client) GetSystemConfigByKey

func (c *Client) GetSystemConfigByKey(ctx context.Context, configKey string) (*types.SystemConfig, error)

GetSystemConfigByKey returns value according to the key(only tx_count_limit, tx_gas_limit could work)

func (*Client) GetTotalTransactionCount

func (c *Client) GetTotalTransactionCount(ctx context.Context) (*types.TransactionCount, error)

GetTotalTransactionCount returns the total amount of transactions and the block height at present

func (*Client) GetTransactOpts

func (c *Client) GetTransactOpts() *bind.TransactOpts

GetTransactOpts return *bind.TransactOpts

func (*Client) GetTransactionByHash

func (c *Client) GetTransactionByHash(ctx context.Context, txHash common.Hash, withProof bool) (*types.TransactionDetail, error)

GetTransactionByHash returns the transaction information according to the given transaction hash

func (*Client) GetTransactionReceipt

func (c *Client) GetTransactionReceipt(ctx context.Context, txHash common.Hash, withProof bool) (*types.Receipt, error)

GetTransactionReceipt returns the transaction receipt according to the given transaction hash

func (*Client) PendingCodeAt

func (c *Client) PendingCodeAt(ctx context.Context, address common.Address) ([]byte, error)

PendingCodeAt returns the contract code of the given account in the pending state.

func (*Client) PrivateKeyBytes

func (c *Client) PrivateKeyBytes() []byte

func (*Client) PublishAmopTopicMessage

func (c *Client) PublishAmopTopicMessage(ctx context.Context, topic string, data []byte, handler func([]byte, error)) error

func (*Client) SMCrypto

func (c *Client) SMCrypto() bool

SMCrypto returns true if use sm crypto

func (*Client) SendAmopResponse

func (c *Client) SendAmopResponse(peer, seq string, data []byte) error

func (*Client) SendEncodedTransaction

func (c *Client) SendEncodedTransaction(ctx context.Context, encodedTransaction []byte, withProof bool) (*types.Receipt, error)

func (*Client) SendTransaction

func (c *Client) SendTransaction(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)

SendTransaction injects a signed transaction into the pending pool for execution.

If the transaction was a contract creation use the TransactionReceipt method to get the contract address after the transaction has been mined.

func (*Client) SetCallOpts

func (c *Client) SetCallOpts(opts *bind.CallOpts)

SetCallOpts set call opts

func (*Client) SetGroupID

func (c *Client) SetGroupID(newID string)

SetGroupID sets the groupID of the client

func (*Client) SetPrivateKey

func (c *Client) SetPrivateKey(privateKey []byte) error

func (*Client) SetTransactOpts

func (c *Client) SetTransactOpts(opts *bind.TransactOpts)

SetTransactOpts set auth

func (*Client) SubscribeAmopTopic

func (c *Client) SubscribeAmopTopic(ctx context.Context, topic string, handler func([]byte, *[]byte)) error

func (*Client) SubscribeBlockNumberNotify

func (c *Client) SubscribeBlockNumberNotify(ctx context.Context, handler func(int64)) error

func (*Client) SubscribeEventLogs

func (c *Client) SubscribeEventLogs(ctx context.Context, eventLogParams types.EventLogParams, handler func(int, []types.Log)) (string, error)

func (*Client) TransactionReceipt

func (c *Client) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

TransactionReceipt returns the receipt of a transaction by transaction hash. Note that the receipt is not available for pending transactions.

func (*Client) UnSubscribeEventLogs

func (c *Client) UnSubscribeEventLogs(ctx context.Context, taskId string) error

func (*Client) UnsubscribeAmopTopic

func (c *Client) UnsubscribeAmopTopic(topic string) error

func (*Client) UnsubscribeBlockNumberNotify

func (c *Client) UnsubscribeBlockNumberNotify()

type Config

type Config struct {
	TLSCaFile       string
	TLSKeyFile      string
	TLSCertFile     string
	TLSSmEnKeyFile  string
	TLSSmEnCertFile string
	IsSMCrypto      bool
	PrivateKey      []byte
	GroupID         string
	Host            string
	Port            int
	DisableSsl      bool
}

Config contains configuration items for sdk

func ParseConfigOptions

func ParseConfigOptions(caFile string, key string, cert, keyFile string, groupId string, host string, port int, isSMCrypto bool) (*Config, error)

ParseConfigOptions parses from arguments

type Connection

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

Connection represents a connection to an RPC server.

func NewConnection

func NewConnection(config *Config) (*Connection, error)

func NewConnectionByFile

func NewConnectionByFile(configFile, groupID string, privateKey []byte) (*Connection, error)

func (*Connection) BroadcastAmopMsg

func (c *Connection) BroadcastAmopMsg(topic string, data []byte)

func (*Connection) Call

func (c *Connection) Call(result interface{}, method string, args ...interface{}) error

Call performs a JSON-RPC call with the given arguments and unmarshals into result if no error occurred.

The result must be a pointer so that package json can unmarshal into it. You can also pass nil, in which case the result is ignored.

func (*Connection) CallContext

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

CallContext performs a JSON-RPC call with the given arguments. If the context is canceled before the call has successfully returned, CallContext returns immediately.

The result must be a pointer so that package json can unmarshal into it. You can also pass nil, in which case the result is ignored.

func (*Connection) Close

func (c *Connection) Close()

Close closes the client, aborting any in-flight requests.

func (*Connection) GetCSDK

func (c *Connection) GetCSDK() *csdk.CSDK

func (*Connection) NewMessage

func (c *Connection) NewMessage(method string, paramsIn ...interface{}) (*jsonrpcMessage, error)

func (*Connection) PublishAmopTopicMessage

func (c *Connection) PublishAmopTopicMessage(ctx context.Context, topic string, data []byte, handler func([]byte, error)) error

func (*Connection) SendAmopResponse

func (c *Connection) SendAmopResponse(peer, seq string, data []byte)

func (*Connection) SubscribeAmopTopic

func (c *Connection) SubscribeAmopTopic(topic string, handler func(data []byte, response *[]byte)) error

func (*Connection) SubscribeBlockNumberNotify

func (c *Connection) SubscribeBlockNumberNotify(handler func(int64)) error

func (*Connection) SubscribeEventLogs

func (c *Connection) SubscribeEventLogs(eventLogParams types.EventLogParams, handler func(int, []types.Log)) (string, error)

func (*Connection) UnsubscribeAmopTopic

func (c *Connection) UnsubscribeAmopTopic(topic string)

func (*Connection) UnsubscribeBlockNumberNotify

func (c *Connection) UnsubscribeBlockNumberNotify()

func (*Connection) UnsubscribeEventLogs

func (c *Connection) UnsubscribeEventLogs(taskID string)

type ConsensusNodeInfo

type ConsensusNodeInfo struct {
	ID     string `json:"nodeID"`
	Weight uint   `json:"weight"`
}

type Error

type Error interface {
	Error() string  // returns the message
	ErrorCode() int // returns the code
}

Error wraps RPC errors, which contain an error code in addition to the message.

type EventLogRespResult

type EventLogRespResult struct {
	LogIndex         int    `json:"logIndex"`
	TransactionIndex int    `json:"transactionIndex"`
	TransactionHash  string `json:"transactionHash"`
	//BlockHash        string   `json:"blockHash"`
	BlockNumber uint64   `json:"blockNumber"`
	Address     string   `json:"address"`
	Data        string   `json:"data"`
	Topics      []string `json:"topics"`
}

Jump to

Keyboard shortcuts

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