client

package
v0.0.0-...-b9e1d45 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: LGPL-3.0 Imports: 13 Imported by: 7

Documentation

Index

Constants

View Source
const (
	TypeReceipt     = "receipt"
	TypeTransaction = "transaction"
)

Variables

This section is empty.

Functions

func ContextWithKeyPair

func ContextWithKeyPair(ctx context.Context, keyPair key.KeyPair) context.Context

Types

type AccessKey

type AccessKey struct {
	Nonce types.Nonce `json:"nonce"`

	// Permission holds parsed access key permission info
	Permission AccessKeyPermission `json:"-"`
}

func (*AccessKey) UnmarshalJSON

func (ak *AccessKey) UnmarshalJSON(b []byte) (err error)

type AccessKeyList

type AccessKeyList struct {
	Keys []AccessKeyViewInfo `json:"keys"`
}

type AccessKeyPermission

type AccessKeyPermission struct {
	FullAccess   bool                   `json:"-"`
	FunctionCall FunctionCallPermission `json:"-"`
}

AccessKeyPermission holds info whether access key is a FullAccess, or FunctionCall key

func (*AccessKeyPermission) UnmarshalJSON

func (akp *AccessKeyPermission) UnmarshalJSON(b []byte) (err error)

type AccessKeyView

type AccessKeyView struct {
	AccessKey
	QueryResponse
}

func (*AccessKeyView) UnmarshalJSON

func (a *AccessKeyView) UnmarshalJSON(data []byte) (err error)

type AccessKeyViewInfo

type AccessKeyViewInfo struct {
	PublicKey key.Base58PublicKey `json:"public_key"`
	AccessKey AccessKey           `json:"access_key"`
}

type AccountView

type AccountView struct {
	Amount        types.Balance      `json:"amount"`
	Locked        types.Balance      `json:"locked"`
	CodeHash      hash.CryptoHash    `json:"code_hash"`
	StorageUsage  types.StorageUsage `json:"storage_usage"`
	StoragePaidAt types.BlockHeight  `json:"storage_paid_at"`

	QueryResponse
}

type BlockHeaderInnerLiteView

type BlockHeaderInnerLiteView struct {
	Height           types.BlockHeight `json:"height"`
	EpochID          hash.CryptoHash   `json:"epoch_id"`
	NextEpochId      hash.CryptoHash   `json:"next_epoch_id"`
	PrevStateRoot    hash.CryptoHash   `json:"prev_state_root"`
	OutcomeRoot      hash.CryptoHash   `json:"outcome_root"`
	Timestamp        uint64            `json:"timestamp"`
	TimestampNanoSec string            `json:"timestamp_nanosec"`
	NextBpHash       hash.CryptoHash   `json:"next_bp_hash"`
	BlockMerkleRoot  hash.CryptoHash   `json:"block_merkle_root"`
}

type BlockHeaderView

type BlockHeaderView struct {
	Height                types.BlockHeight            `json:"height"`
	EpochID               hash.CryptoHash              `json:"epoch_id"`
	NextEpochID           hash.CryptoHash              `json:"next_epoch_id"`
	Hash                  hash.CryptoHash              `json:"hash"`
	PrevHash              hash.CryptoHash              `json:"prev_hash"`
	PrevStateRoot         hash.CryptoHash              `json:"prev_state_root"`
	ChunkReceiptsRoot     hash.CryptoHash              `json:"chunk_receipts_root"`
	ChunkHeadersRoot      hash.CryptoHash              `json:"chunk_headers_root"`
	ChunkTxRoot           hash.CryptoHash              `json:"chunk_tx_root"`
	OutcomeRoot           hash.CryptoHash              `json:"outcome_root"`
	ChunksIncluded        uint64                       `json:"chunks_included"`
	ChallengesRoot        hash.CryptoHash              `json:"challenges_root"`
	Timestamp             uint64                       `json:"timestamp"`         // milliseconds
	TimestampNanosec      types.TimeNanos              `json:"timestamp_nanosec"` // nanoseconds, uint128
	RandomValue           hash.CryptoHash              `json:"random_value"`
	ValidatorProposals    []ValidatorStakeView         `json:"validator_proposals"`
	ChunkMask             []bool                       `json:"chunk_mask"`
	GasPrice              types.Balance                `json:"gas_price"`
	RentPaid              types.Balance                `json:"rent_paid"`        // NOTE: deprecated - 2021-05-14
	ValidatorReward       types.Balance                `json:"validator_reward"` // NOTE: deprecated - 2021-05-14
	TotalSupply           types.Balance                `json:"total_supply"`
	ChallengesResult      ChallengesResult             `json:"challenges_result"`
	LastFinalBlock        hash.CryptoHash              `json:"last_final_block"`
	LastDSFinalBlock      hash.CryptoHash              `json:"last_ds_final_block"`
	NextBPHash            hash.CryptoHash              `json:"next_bp_hash"`
	BlockMerkleRoot       hash.CryptoHash              `json:"block_merkle_root"`
	Approvals             []*signature.Base58Signature `json:"approvals"`
	Signature             signature.Base58Signature    `json:"signature"`
	LatestProtocolVersion uint64                       `json:"latest_protocol_version"`
}

type BlockView

type BlockView struct {
	Author types.AccountID   `json:"author"`
	Header BlockHeaderView   `json:"header"`
	Chunks []ChunkHeaderView `json:"chunks"`
}

type CallResult

type CallResult struct {
	Result []byte   `json:"result"`
	Logs   []string `json:"logs"`

	QueryResponse
}

type ChallengesResult

type ChallengesResult = []SlashedValidator

type ChunkHeaderView

type ChunkHeaderView struct {
	ChunkHash            hash.CryptoHash           `json:"chunk_hash"`
	PrevBlockHash        hash.CryptoHash           `json:"prev_block_hash"`
	OutcomeRoot          hash.CryptoHash           `json:"outcome_root"`
	PrevStateRoot        json.RawMessage           `json:"prev_state_root"` // TODO: needs a type!
	EncodedMerkleRoot    hash.CryptoHash           `json:"encoded_merkle_root"`
	EncodedLength        uint64                    `json:"encoded_length"`
	HeightCreated        types.BlockHeight         `json:"height_created"`
	HeightIncluded       types.BlockHeight         `json:"height_included"`
	ShardID              types.ShardID             `json:"shard_id"`
	GasUsed              types.Gas                 `json:"gas_used"`
	GasLimit             types.Gas                 `json:"gas_limit"`
	RentPaid             types.Balance             `json:"rent_paid"`        // TODO: deprecated
	ValidatorReward      types.Balance             `json:"validator_reward"` // TODO: deprecated
	BalanceBurnt         types.Balance             `json:"balance_burnt"`
	OutgoingReceiptsRoot hash.CryptoHash           `json:"outgoing_receipts_root"`
	TxRoot               hash.CryptoHash           `json:"tx_root"`
	ValidatorProposals   []ValidatorStakeView      `json:"validator_proposals"`
	Signature            signature.Base58Signature `json:"signature"`
}

type ChunkView

type ChunkView struct {
	Author       types.AccountID         `json:"author"`
	Header       ChunkHeaderView         `json:"header"`
	Transactions []SignedTransactionView `json:"transactions"`
	Receipts     []ReceiptView           `json:"receipts"`
}

type Client

type Client struct {
	RPCClient jsonrpc.Client
}

func NewClient

func NewClient(networkAddr string) (client Client, err error)

func (*Client) AccessKeyViewChanges

func (c *Client) AccessKeyViewChanges(ctx context.Context, accountID types.AccountID, publicKey key.Base58PublicKey, block block.BlockCharacteristic) (res jsonrpc.Response, err error)

TODO: decode response https://docs.near.org/docs/api/rpc#view-access-key-changes-single

func (*Client) AccessKeyViewChangesAll

func (c *Client) AccessKeyViewChangesAll(ctx context.Context, accountIDs []types.AccountID, block block.BlockCharacteristic) (res jsonrpc.Response, err error)

TODO: decode response https://docs.near.org/docs/api/rpc#view-access-key-changes-all

func (*Client) AccountViewChanges

func (c *Client) AccountViewChanges(ctx context.Context, accountIDs []types.AccountID, block block.BlockCharacteristic) (res jsonrpc.Response, err error)

TODO: decode response https://docs.near.org/docs/api/rpc#view-account-changes

func (*Client) BlockChanges

func (c *Client) BlockChanges(ctx context.Context, block block.BlockCharacteristic) (res jsonrpc.Response, err error)

TODO: decode resposne https://docs.near.org/docs/api/rpc#changes-in-block

func (*Client) ChunkDetails

func (c *Client) ChunkDetails(ctx context.Context, chunkHash hash.CryptoHash) (res ChunkView, err error)

https://docs.near.org/docs/api/rpc#chunk-details

func (*Client) ContractViewCallFunction

func (c *Client) ContractViewCallFunction(ctx context.Context, accountID, methodName, argsBase64 string, block block.BlockCharacteristic) (res CallResult, err error)

https://docs.near.org/docs/api/rpc#call-a-contract-function

func (*Client) ContractViewCodeChanges

func (c *Client) ContractViewCodeChanges(ctx context.Context, accountIDs []types.AccountID, block block.BlockCharacteristic) (res jsonrpc.Response, err error)

TODO: decode response https://docs.near.org/docs/api/rpc#view-contract-code-changes

func (*Client) ContractViewState

func (c *Client) ContractViewState(ctx context.Context, accountID types.AccountID, prefixBase64 string, block block.BlockCharacteristic) (res ViewStateResult, err error)

https://docs.near.org/docs/api/rpc#view-contract-state

func (*Client) ContractViewStateChanges

func (c *Client) ContractViewStateChanges(ctx context.Context, accountIDs []types.AccountID, keyPrefixBase64 string, block block.BlockCharacteristic) (res jsonrpc.Response, err error)

TODO: decode response https://docs.near.org/docs/api/rpc#view-contract-state-changes

func (*Client) GenesisConfig

func (c *Client) GenesisConfig(ctx context.Context) (res map[string]interface{}, err error)

https://docs.near.org/docs/api/rpc#genesis-config

func (*Client) NetworkAddr

func (c *Client) NetworkAddr() string

func (*Client) NextLightClientBlock

func (c *Client) NextLightClientBlock(ctx context.Context, lastHash hash.CryptoHash) (resp LightClientBlockView, err error)

NextLightClientBlock doc: https://nomicon.io/ChainSpec/LightClient#light-client-block

func (*Client) RPCTransactionSend

func (c *Client) RPCTransactionSend(ctx context.Context, signedTxnBase64 string) (resp hash.CryptoHash, err error)

https://docs.near.org/docs/api/rpc#send-transaction-async

func (*Client) RPCTransactionSendAwait

func (c *Client) RPCTransactionSendAwait(ctx context.Context, signedTxnBase64 string) (resp FinalExecutionOutcomeView, err error)

https://docs.near.org/docs/api/rpc#send-transaction-await

func (*Client) TransactionSend

func (c *Client) TransactionSend(ctx context.Context, from, to types.AccountID, actions []action.Action, txnOpts ...TransactionOpt) (res hash.CryptoHash, err error)

https://docs.near.org/docs/api/rpc#send-transaction-async

type CurrentEpochValidatorInfo

type CurrentEpochValidatorInfo struct {
	ValidatorInfo
	PublicKey         key.Base58PublicKey `json:"public_key"`
	Stake             types.Balance       `json:"stake"`
	Shards            []types.ShardID     `json:"shards"`
	NumProducedBlocks types.NumBlocks     `json:"num_produced_blocks"`
	NumExpectedBlocks types.NumBlocks     `json:"num_expected_blocks"`
}

type EdgeInfo

type EdgeInfo struct {
	Nonce     types.Nonce         `json:"nonce"`
	Signature signature.Signature `json:"signature"`
}

EdgeInfo contains information that will be ultimately used to create a new edge. It contains nonce proposed for the edge with signature from peer.

type ExecutionOutcomeView

type ExecutionOutcomeView struct {
	Logs        []string          `json:"logs"`
	ReceiptIDs  []hash.CryptoHash `json:"receipt_ids"`
	GasBurnt    types.Gas         `json:"gas_burnt"`
	TokensBurnt types.Balance     `json:"tokens_burnt"`
	ExecutorID  types.AccountID   `json:"executor_id"`
	Status      TransactionStatus `json:"status"`
}

type ExecutionOutcomeWithIdView

type ExecutionOutcomeWithIdView struct {
	Proof     MerklePath           `json:"proof"`
	BlockHash hash.CryptoHash      `json:"block_hash"`
	ID        hash.CryptoHash      `json:"id"`
	Outcome   ExecutionOutcomeView `json:"outcome"`
}

type FinalExecutionOutcomeView

type FinalExecutionOutcomeView struct {
	Status             TransactionStatus            `json:"status"`
	Transaction        SignedTransactionView        `json:"transaction"`
	TransactionOutcome ExecutionOutcomeWithIdView   `json:"transaction_outcome"`
	ReceiptsOutcome    []ExecutionOutcomeWithIdView `json:"receipts_outcome"`
}

type FinalExecutionOutcomeWithReceiptView

type FinalExecutionOutcomeWithReceiptView struct {
	FinalExecutionOutcomeView
	Receipts []ReceiptView `json:"receipts"`
}

type FullPeerInfo

type FullPeerInfo struct {
	PeerInfo  PeerInfo      `json:"peer_info"`
	ChainInfo PeerChainInfo `json:"chain_info"`
	EdgeInfo  EdgeInfo      `json:"edge_info"`
}

type FunctionCallPermission

type FunctionCallPermission struct {
	// Allowance for this function call (default 0.25 NEAR). Can be absent.
	Allowance *types.Balance `json:"allowance"`
	// ReceiverID holds the contract the key is allowed to call methods on
	ReceiverID types.AccountID `json:"receiver_id"`
	// MethodNames hold which functions are allowed to call. Can be empty (all methods are allowed)
	MethodNames []string `json:"method_names"`
}

FunctionCallPermission represents a function call permission

type GasPrice

type GasPrice struct {
	GasPrice types.Balance `json:"gas_price"`
}

type GenesisID

type GenesisID struct {
	// Chain Id
	ChainID string `json:"chain_id"`
	// Hash of genesis block
	Hash hash.CryptoHash `json:"hash"`
}

type KnownProducer

type KnownProducer struct {
	AccountID types.AccountID `json:"account_id"`
	Addr      *string         `json:"addr"`
	PeerID    key.PeerID      `json:"peer_id"`
}

KnownProducer is basically PeerInfo, but AccountID is known

type LightClientBlockLiteView

type LightClientBlockLiteView struct {
	PrevBlockHash hash.CryptoHash          `json:"prev_block_hash"`
	InnerRestHash hash.CryptoHash          `json:"inner_rest_hash"`
	InnerLite     BlockHeaderInnerLiteView `json:"inner_lite"`
}

type LightClientBlockView

type LightClientBlockView struct {
	PrevBlockHash      hash.CryptoHash              `json:"prev_block_hash"`
	NextBlockInnerHash hash.CryptoHash              `json:"next_block_inner_hash"`
	InnerLite          BlockHeaderInnerLiteView     `json:"inner_lite"`
	InnerRestHash      hash.CryptoHash              `json:"inner_rest_hash"`
	NextBps            []ValidatorStakeWithVersion  `json:"next_bps"`
	ApprovalsAfterNext []*signature.Base58Signature `json:"approvals_after_next"`
}

type MerklePath

type MerklePath = []MerklePathItem

type MerklePathItem

type MerklePathItem struct {
	Hash      hash.CryptoHash `json:"hash"`
	Direction string          `json:"direction"` // TODO: enum type, either 'Left' or 'Right'
}

type MetricRecorder

type MetricRecorder = json.RawMessage

TODO: chain/network/src/recorder.rs

type NetworkInfo

type NetworkInfo struct {
	ActivePeers         []FullPeerInfo  `json:"active_peers"`
	NumActivePeers      uint            `json:"num_active_peers"`
	PeerMaxCount        uint32          `json:"peer_max_count"`
	HighestHeightPeers  []FullPeerInfo  `json:"highest_height_peers"`
	SentBytesPerSec     uint64          `json:"sent_bytes_per_sec"`
	ReceivedBytesPerSec uint64          `json:"received_bytes_per_sec"`
	KnownProducers      []KnownProducer `json:"known_producers"`
	MetricRecorder      MetricRecorder  `json:"metric_recorder"`
	PeerCounter         uint            `json:"peer_counter"`
}

NetworkInfo holds network information

type NodeVersion

type NodeVersion struct {
	Version string `json:"version"`
	Build   string `json:"build"`
}

type PeerChainInfo

type PeerChainInfo struct {
	// Chain Id and hash of genesis block.
	GenesisID GenesisID `json:"genesis_id"`
	// Last known chain height of the peer.
	Height types.BlockHeight `json:"height"`
	// Shards that the peer is tracking.
	TrackedShards []types.ShardID `json:"tracked_shards"`
	// Denote if a node is running in archival mode or not.
	Archival bool `json:"archival"`
}

PeerChainInfo contains peer chain information. This is derived from PeerCHainInfoV2 in nearcore

type PeerInfo

type PeerInfo struct {
	ID        key.PeerID       `json:"id"`
	Addr      *string          `json:"addr"`
	AccountID *types.AccountID `json:"account_id"`
}

PeerInfo holds peer information

type QueryResponse

type QueryResponse struct {
	BlockHeight types.BlockHeight `json:"block_height"`
	BlockHash   hash.CryptoHash   `json:"block_hash"`
	Error       *string           `json:"error"`
	Logs        []interface{}     `json:"logs"` // TODO: use correct type
}

type Receipt

type Receipt struct {
	ReceiptID       hash.CryptoHash `json:"receipt_id"`
	ReceiverID      types.AccountID `json:"receiver_id"`
	LightClientHead hash.CryptoHash
}

func (Receipt) Hash

func (r Receipt) Hash() hash.CryptoHash

func (Receipt) ID

func (r Receipt) ID() types.AccountID

func (Receipt) LightClientHeadHash

func (r Receipt) LightClientHeadHash() hash.CryptoHash

func (Receipt) Type

func (r Receipt) Type() string

type ReceiptView

type ReceiptView struct {
	PredecessorID types.AccountID `json:"predecessor_id"`
	ReceiverID    types.AccountID `json:"receiver_id"`
	ReceiptID     hash.CryptoHash `json:"receipt_id"`
	Receipt       json.RawMessage `json:"receipt"` // TODO: needs a type!
}

type RpcLightClientExecutionProofResponse

type RpcLightClientExecutionProofResponse struct {
	OutcomeProof     ExecutionOutcomeWithIdView `json:"outcome_proof"`
	OutcomeRootProof MerklePath                 `json:"outcome_root_proof"`
	BlockHeaderLite  LightClientBlockLiteView   `json:"block_header_lite"`
	BlockProof       MerklePath                 `json:"block_proof"`
}

type SignedTransactionView

type SignedTransactionView struct {
	SignerID   types.AccountID           `json:"signer_id"`
	PublicKey  key.Base58PublicKey       `json:"public_key"`
	Nonce      types.Nonce               `json:"nonce"`
	ReceiverID types.AccountID           `json:"receiver_id"`
	Actions    []action.Action           `json:"actions"`
	Signature  signature.Base58Signature `json:"signature"`
	Hash       hash.CryptoHash           `json:"hash"`
}

type SlashedValidator

type SlashedValidator struct {
	AccountID    types.AccountID `json:"account_id"`
	IsDoubleSign bool            `json:"is_double_sign"`
}

type StateItem

type StateItem struct {
	Key   string        `json:"key"`
	Value string        `json:"value"`
	Proof TrieProofPath `json:"proof"`
}

type StatusResponse

type StatusResponse struct {
	// Binary version
	Version NodeVersion `json:"version"`
	// Unique chain id.
	ChainID string `json:"chain_id"`
	// Currently active protocol version.
	ProtocolVersion uint32 `json:"protocol_version"`
	// Latest protocol version that this client supports.
	LatestProtocolVersion uint32 `json:"latest_protocol_version"`
	// Address for RPC server.
	RPCAddr string `json:"rpc_addr"`
	// Current epoch validators.
	Validators []ValidatorInfo `json:"validators"`
	// Sync status of the node.
	SyncInfo StatusSyncInfo `json:"sync_info"`
	// Validator id of the node
	ValidatorAccountID *types.AccountID `json:"validator_account_id"`
}

type StatusSyncInfo

type StatusSyncInfo struct {
	LatestBlockHash   hash.CryptoHash   `json:"latest_block_hash"`
	LatestBlockHeight types.BlockHeight `json:"latest_block_height"`
	LatestBlockTime   time.Time         `json:"latest_block_time"`
	Syncing           bool              `json:"syncing"`
}

type Transaction

type Transaction struct {
	TransactionHash hash.CryptoHash `json:"transaction_hash"`
	SenderID        types.AccountID `json:"sender_id"`
	LightClientHead hash.CryptoHash `json:"light_client_head"`
}

func (Transaction) Hash

func (t Transaction) Hash() hash.CryptoHash

func (Transaction) ID

func (t Transaction) ID() types.AccountID

func (Transaction) LightClientHeadHash

func (t Transaction) LightClientHeadHash() hash.CryptoHash

func (Transaction) Type

func (t Transaction) Type() string

type TransactionOpt

type TransactionOpt func(context.Context, *transactionCtx) error

func WithBlockCharacteristic

func WithBlockCharacteristic(block block.BlockCharacteristic) TransactionOpt

func WithBlockHash

func WithBlockHash(hash hash.CryptoHash) TransactionOpt

WithBlockHash sets block hash to attach this transaction to

func WithKeyNonce

func WithKeyNonce(nonce types.Nonce) TransactionOpt

WithKeyNonce sets key nonce to use with this transaction. If not set via this function, a RPC query will be done to query current nonce and (nonce+1) will be used

func WithKeyPair

func WithKeyPair(keyPair key.KeyPair) TransactionOpt

WithKeyPair sets key pair to use sign this transaction with

func WithLatestBlock

func WithLatestBlock() TransactionOpt

WithLatestBlock is alias to `WithBlockCharacteristic(block.FinalityFinal())`

type TransactionOrReceiptId

type TransactionOrReceiptId interface {
	Type() string
	ID() types.AccountID
	Hash() hash.CryptoHash
	LightClientHeadHash() hash.CryptoHash
}

type TransactionStatus

type TransactionStatus struct {
	SuccessValue     string          `json:"SuccessValue"`
	SuccessReceiptID string          `json:"SuccessReceiptId"`
	Failure          json.RawMessage `json:"Failure"` // TODO
}

type TrieProofPath

type TrieProofPath = []string

TrieProofPath is a set of serialized TrieNodes that are encoded in base64. Represent proof of inclusion of some TrieNode in the MerkleTrie.

type ValidatorInfo

type ValidatorInfo struct {
	AccountID types.AccountID `json:"account_id"`
	Slashed   bool            `json:"is_slashed"`
}

type ValidatorStakeView

type ValidatorStakeView struct {
	AccountID types.AccountID     `json:"account_id"`
	PublicKey key.Base58PublicKey `json:"public_key"`
	Stake     types.Balance       `json:"stake"`
}

ValidatorStakeView is based on ValidatorStakeV1 struct in nearcore

type ValidatorStakeWithVersion

type ValidatorStakeWithVersion struct {
	AccountID                   types.AccountID     `json:"account_id"`
	PublicKey                   key.Base58PublicKey `json:"public_key"`
	Stake                       types.Balance       `json:"stake"`
	ValidatorStakeStructVersion string              `json:"validator_stake_struct_version"`
}

type ValidatorsResponse

type ValidatorsResponse struct {
	CurrentValidators []CurrentEpochValidatorInfo `json:"current_validator"`
}

type ViewStateResult

type ViewStateResult struct {
	Values []StateItem   `json:"values"`
	Proof  TrieProofPath `json:"proof"`

	QueryResponse
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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