client

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: MIT Imports: 12 Imported by: 7

Documentation

Index

Constants

This section is empty.

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
	BlockHeight uint64          `json:"block_height"`
	BlockHash   hash.CryptoHash `json:"block_hash"`
}

type AccessKeyViewInfo

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

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 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 Client

type Client struct {
	RPCClient jsonrpc.Client
}

func NewClient

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

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/develop/front-end/rpc#view-access-key-changes-all

func (*Client) AccountView

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

TODO: decode response https://docs.near.org/docs/develop/front-end/rpc#view-account

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/develop/front-end/rpc#view-account-changes

func (*Client) ChunkDetails

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

TODO: decode response https://docs.near.org/docs/develop/front-end/rpc#chunk-details

func (*Client) ContractViewCallFunction

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

TODO: decode response https://docs.near.org/docs/develop/front-end/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/develop/front-end/rpc#view-contract-code-changes

func (*Client) ContractViewState

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

TODO: decode response https://docs.near.org/docs/develop/front-end/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/develop/front-end/rpc#view-contract-state-changes

func (*Client) GasPriceView

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

TODO: decode response https://docs.near.org/docs/develop/front-end/rpc#gas-price

func (*Client) GenesisConfig

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

TODO: decode response https://docs.near.org/docs/develop/front-end/rpc#genesis-config

func (*Client) NetworkAddr

func (c *Client) NetworkAddr() string

func (*Client) NetworkInfo

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

TODO: decode response https://docs.near.org/docs/develop/front-end/rpc#network-info

func (*Client) NetworkStatusValidators

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

TODO: decode response https://docs.near.org/docs/develop/front-end/rpc#general-validator-status

func (*Client) NetworkStatusValidatorsDetailed

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

TODO: decode response https://docs.near.org/docs/develop/front-end/rpc#detailed-validator-status

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 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 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 ReceiptView

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

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 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 TransactionStatus

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

type ValidatorStakeView

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

ValidatorStakeView is based on ValidatorStakeV1 struct in nearcore

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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