rpc

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2019 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClientCodec

func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec

NewClientCodec returns a new rpc.ClientCodec using JSON-RPC 2.0 on conn.

func NewJSONCodec

func NewJSONCodec(conn io.ReadWriteCloser, srv *rpc.Server) rpc.ServerCodec

NewJSONCodec returns a new rpc.ServerCodec using JSON-RPC on conn.

func ServeConn

func ServeConn(conn io.ReadWriteCloser)

ServeConn runs the JSON-RPC server on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn with go-routine.

Types

type BatchArg

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

BatchArg is a param for internal RPC JSONRPC2.Batch.

type BlockInfo

type BlockInfo struct {
	Hash            string        `json:"hash"`
	ParentHash      string        `json:"parentHash"`
	Height          uint64        `json:"height"`
	StateHash       string        `json:"stateHash"`
	Timestamp       *big.Int      `json:"timestamp"`
	Difficulty      *big.Int      `json:"difficulty"`
	TotalDifficulty *big.Int      `json:"totaldifficulty"`
	Creator         string        `json:"creator"`
	Nonce           uint64        `json:"nonce"`
	TxHash          string        `json:"txHash"`
	Txs             []Transaction `json:"txs"`
	Debts           []Debt        `json:"debts"`
	TxDebts         []TxDebt      `json:"txDebts"`
}

BlockInfo is the block data send from seele node

type Client

type Client struct {
	*rpc.Client
	// contains filtered or unexported fields
}

Client represents a JSON RPC 2.0 Client. There may be multiple outstanding Calls associated with a single Client, and a Client may be used by multiple goroutines simultaneously.

It also provides all methods of net/rpc Client.

func Dial

func Dial(network, address string) (*Client, error)

Dial connects to a JSON-RPC 2.0 server at the specified network address.

func NewClient

func NewClient(conn io.ReadWriteCloser) *Client

NewClient returns a new Client to handle requests to the set of services at the other end of the connection.

func NewClientWithCodec

func NewClientWithCodec(codec rpc.ClientCodec) *Client

NewClientWithCodec returns a new Client using the given rpc.ClientCodec.

func (Client) Notify

func (c Client) Notify(serviceMethod string, args interface{}) error

Notify try to invoke the named function. It return error only in case it wasn't able to send request.

type CurrentBlock

type CurrentBlock struct {
	HeadHash  string   `json:"headHash"`
	Height    uint64   `json:"height"`
	Timestamp *big.Int `json:"timestamp"`
	Difficult *big.Int `json:"difficult"`
	Creator   string   `json:"creator"`
	TxCount   int      `json:"txcount"`
}

CurrentBlock is the informations about the best block

type Debt

type Debt struct {
	Hash        string   `json:"hash"`
	TxHash      string   `json:"txhash"`
	To          string   `json:"to"`
	Block       uint64   `json:"block"`
	Idx         uint64   `json:"idx"`
	ShardNumber int      `json:"shardNumber"`
	Fee         int64    `json:"fee"`
	Payload     string   `json:"payload"`
	Amount      *big.Int `json:"amount"`
}

type Error

type Error struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

Error represent JSON-RPC 2.0 "Error object".

func NewError

func NewError(code int, message string) *Error

NewError returns an Error with given code and message.

func ServerError

func ServerError(rpcerr error) *Error

ServerError convert errors returned by Client.Call() into Error. User should check for rpc.ErrShutdown and io.ErrUnexpectedEOF before calling ServerError.

func (*Error) Error

func (e *Error) Error() string

Error returns JSON representation of Error.

type GetBlockByHeightRequest

type GetBlockByHeightRequest struct {
	Height int64 `json:"height"`
	FullTx bool  `json:"fullTx"`
}

GetBlockByHeightRequest request param for GetBlockByHeight api

type Header struct {
	PreviousBlockHash string
	Creator           string
	StateHash         string
	TxHash            string
	ReceiptHash       string
	TxDebtHash        string
	DebtHash          string
	Difficulty        *big.Int
	Height            *big.Int
	CreateTimestamp   *big.Int
	Nonce             *big.Int
	ExtraData         string
}

type JSONRPC2

type JSONRPC2 struct{}

JSONRPC2 is an internal RPC service used to process batch requests.

func (JSONRPC2) Batch

func (JSONRPC2) Batch(arg BatchArg, replies *[]*json.RawMessage) (err error)

Batch is an internal RPC method used to process batch requests.

type PeerInfo

type PeerInfo struct {
	ID            string   `json:"id"`            // Unique of the node
	Caps          []string `json:"caps"`          // Sum-protocols advertised by this particular peer
	LocalAddress  string   `json:"localAddress"`  // Local endpoint of the TCP data connection
	RemoteAddress string   `json:"remoteAddress"` // Remote endpoint of the TCP data connection
	ShardNumber   int      `json:"shardNumber"`
}

PeerInfo is the peer info send from seele node

type Receipt

type Receipt struct {
	Result          string `json:"result"`
	PostState       string `json:"poststate"`
	TxHash          string `json:"txhash"`
	ContractAddress string `json:"contractaddress"`
	Failed          bool   `json:"failed"`
	TotalFee        int64  `json:"totalFee"`
	UsedGas         int64  `json:"usedGas"`
}

Receipt is the receipt information of tx

type SeeleRPC

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

SeeleRPC json_rpc client

func NewRPC

func NewRPC(url string, options ...func(rpc *SeeleRPC)) *SeeleRPC

NewRPC create new json_rpc client with given url

func (*SeeleRPC) Connect

func (rpc *SeeleRPC) Connect() error

Connect Create tcp connect

func (*SeeleRPC) CurrentBlockHeight

func (rpc *SeeleRPC) CurrentBlockHeight() (uint64, error)

CurrentBlockHeight gets the current blockchain height

func (*SeeleRPC) GetBalance

func (rpc *SeeleRPC) GetBalance(account string) (int64, error)

GetBalance get the balance of the account

func (*SeeleRPC) GetBlockByHeight

func (rpc *SeeleRPC) GetBlockByHeight(h uint64, fullTx bool) (block *BlockInfo, err error)

GetBlockByHeight get block and transaction data from seele node

func (*SeeleRPC) GetPeersInfo

func (rpc *SeeleRPC) GetPeersInfo() (result []PeerInfo, err error)

GetPeersInfo get peers info from connected seele node

func (*SeeleRPC) GetPendingTransactions

func (rpc *SeeleRPC) GetPendingTransactions() ([]Transaction, error)

GetPendingTransactions get pending transactions on seele node

func (*SeeleRPC) GetReceiptByTxHash

func (rpc *SeeleRPC) GetReceiptByTxHash(txhash string) (*Receipt, error)

GetReceiptByTxHash get the receipt by tx hash

func (*SeeleRPC) Release

func (rpc *SeeleRPC) Release()

Release release current rpc

type Transaction

type Transaction struct {
	Hash         string   `json:"hash"`
	DebtTxHash   string   `json:"debtTxHash"`
	From         string   `json:"from"`
	To           string   `json:"to"`
	Amount       *big.Int `json:"amount"`
	AccountNonce uint64   `json:"accountNonce"`
	Payload      string   `json:"payload"`
	Timestamp    uint64   `json:"timestamp"`
	Fee          int64    `json:"fee"`
	Block        uint64   `json:"block"`
	Idx          uint64   `json:"idx"`
	TxType       int      `json:"txtype"`
	GasLimit     int64    `json:"gasLimit"`
	GasPrice     int64    `json:"gasPrice"`
}

Transaction is the transaction data send from seele node

type TxDebt

type TxDebt struct {
	Hash        string   `json:"hash"`
	TxHash      string   `json:"txhash"`
	To          string   `json:"to"`
	ShardNumber int      `json:"shardNumber"`
	Fee         int64    `json:"fee"`
	Payload     string   `json:"payload"`
	Amount      *big.Int `json:"amount"`
}

Jump to

Keyboard shortcuts

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