near

package
v0.18.14 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionFunctionCallUnstake                    = "unstake"
	ActionFunctionCallUnstakeAll                 = "unstake_all"
	ActionFunctionCallStake                      = "stake"
	ActionFunctionCallStakeAll                   = "stake_all"
	ActionFunctionCallWithdraw                   = "withdraw"
	ActionFunctionCallWithdrawAll                = "withdraw_all"
	ActionFunctionCallDepositAndStake            = "deposit_and_stake"
	ActionFunctionCallDeposit                    = "deposit"
	ActionFunctionCallDepositToStakingPool       = "deposit_to_staking_pool"
	ActionFunctionCallWithdrawFromStakingPool    = "withdraw_from_staking_pool"
	ActionFunctionCallWithdrawAllFromStakingPool = "withdraw_all_from_staking_pool"

	ActionTypeUnstake = "unstake"
	ActionTypeStake   = "stake"
)
View Source
const (
	ActionCreateAccount  = "CreateAccount"  // make a new account (for a person, company, contract, car, refrigerator, etc)
	ActionDeployContract = "DeployContract" // deploy a new contract (with its own account)
	ActionFunctionCall   = "FunctionCall"   // invoke a method on a contract (with budget for compute and storage)
	ActionTransfer       = "Transfer"       // transfer tokens from one account to another
	ActionStake          = "Stake"          // express interest in becoming a proof-of-stake validator at the next available opportunity
	ActionAddKey         = "AddKey"         // add a key to an existing account (either FullAccess or FunctionCall access)
	ActionDeleteKey      = "DeleteKey"      // delete an existing key from an account
	ActionDeleteAccount  = "DeleteAccount"  // delete an account (and transfer balance to a beneficiary account)
)

Variables

View Source
var (
	// ErrBlockMissing is returned when block has been GC'ed by the node
	ErrBlockMissing = errors.New("block is missing")

	// ErrBlockNotFound is returned when block does not exist at given height
	ErrBlockNotFound = errors.New("block not found")

	// ErrEpochUnknown is returned when epoch can't be obtained from the node
	ErrEpochUnknown = errors.New("unknown epoch")

	// ErrValidatorsUnavailable is returned when requesting validator information using invalid epoch
	ErrValidatorsUnavailable = errors.New("validator info unavailable")

	// ErrNotExist is returned when requested data is not available
	ErrNotExist = errors.New("record does not exist")
)
View Source
var (
	EmptyTxRoot = "11111111111111111111111111111111"
)

Functions

func MapConfirmActions added in v0.16.1

func MapConfirmActions(transactions []model.Transaction) (map[string][]model.TransactionsByDelegator, error)

func ParseAction added in v0.16.1

func ParseAction(trx model.Transaction, account, actionType, validator string) (amt *big.Int, err error)
	we only parse needed log message types, there is more than handled in here.
 ParseAction to get unstaked or staked amount

Types

type AccessKey added in v0.2.0

type AccessKey struct {
	Nonce      int         `json:"nonce"`
	Permission interface{} `json:"permission"`
}

type Account

type Account struct {
	Amount        string `json:"amount"`
	Locked        string `json:"locked"`
	CodeHash      string `json:"code_hash"`
	StorageUsage  int    `json:"storage_usage"`
	StoragePaidAt int    `json:"storage_paid_at"`
	BlockHeight   uint64 `json:"block_height"`
	BlockHash     string `json:"block_hash"`

	// Augumented fields not returned by RPC
	StakedAmount      *string `json:"staked_amount"`
	StakingPoolsCount *int    `json:"staking_pools_count"`
}

type AccountInfo added in v0.4.0

type AccountInfo struct {
	Account         string `json:"account_id"`
	UnstakedBalance string `json:"unstaked_balance"`
	StakedBalance   string `json:"staked_balance"`
	CanWithdraw     bool   `json:"can_withdraw"`
}

type Action

type Action struct {
	Type string      `json:"type"`
	Data interface{} `json:"data"`
}

func DecodeActions added in v0.2.0

func DecodeActions(t *Transaction) []Action

DecodeActions decodes all actions in the transactions

type ActionError added in v0.2.0

type ActionError struct {
	Index int         `json:"index"`
	Kind  interface{} `json:"kind"`
}

type AddKeyAction added in v0.2.0

type AddKeyAction struct {
	PublicKey string    `json:"public_key"`
	AccessKey AccessKey `json:"access_key"`
}

type Block

type Block struct {
	Author string       `json:"author"`
	Header BlockHeader  `json:"header"`
	Chunks []BlockChunk `json:"chunks"`
}

type BlockChange added in v0.3.0

type BlockChange struct {
	Type    string `json:"type"`
	Account string `json:"account_id"`
}

type BlockChangesResponse added in v0.3.0

type BlockChangesResponse struct {
	BlockHash string        `json:"block_hash"`
	Changes   []BlockChange `json:"changes"`
}

type BlockChunk

type BlockChunk struct {
	ChunkHash            string              `json:"chunk_hash"`
	PrevBlockHash        string              `json:"prev_block_hash"`
	OutcomeRoot          string              `json:"outcome_root"`
	PrevStateRoot        string              `json:"prev_state_root"`
	EncodedMerkleRoot    string              `json:"encoded_merkle_root"`
	EncodedLength        int                 `json:"encoded_length"`
	HeightCreated        uint64              `json:"height_created"`
	HeightIncluded       uint64              `json:"height_included"`
	ShardID              int                 `json:"shard_id"`
	GasUsed              int                 `json:"gas_used"`
	GasLimit             int64               `json:"gas_limit"`
	RentPaid             string              `json:"rent_paid"`
	ValidatorReward      string              `json:"validator_reward"`
	BalanceBurnt         string              `json:"balance_burnt"`
	OutgoingReceiptsRoot string              `json:"outgoing_receipts_root"`
	TxRoot               string              `json:"tx_root"`
	ValidatorProposals   []ValidatorProposal `json:"validator_proposals"`
	Signature            string              `json:"signature"`
}

type BlockHeader

type BlockHeader struct {
	Height                uint64              `json:"height"`
	EpochID               string              `json:"epoch_id"`
	NextEpochID           string              `json:"next_epoch_id"`
	Hash                  string              `json:"hash"`
	PrevHash              string              `json:"prev_hash"`
	PrevStateRoot         string              `json:"prev_state_root"`
	ChunkReceiptsRoot     string              `json:"chunk_receipts_root"`
	ChunkHeadersRoot      string              `json:"chunk_headers_root"`
	ChunkTxRoot           string              `json:"chunk_tx_root"`
	OutcomeRoot           string              `json:"outcome_root"`
	ChunksIncluded        int                 `json:"chunks_included"`
	ChallengesRoot        string              `json:"challenges_root"`
	Timestamp             int64               `json:"timestamp"`
	TimestampNanosec      string              `json:"timestamp_nanosec"`
	RandomValue           string              `json:"random_value"`
	ValidatorProposals    []ValidatorProposal `json:"validator_proposals"`
	ChunkMask             []bool              `json:"chunk_mask"`
	GasPrice              string              `json:"gas_price"`
	RentPaid              string              `json:"rent_paid"`
	ValidatorReward       string              `json:"validator_reward"`
	TotalSupply           string              `json:"total_supply"`
	ChallengesResult      []interface{}       `json:"challenges_result"`
	LastFinalBlock        string              `json:"last_final_block"`
	LastDsFinalBlock      string              `json:"last_ds_final_block"`
	NextBpHash            string              `json:"next_bp_hash"`
	BlockMerkleRoot       string              `json:"block_merkle_root"`
	Approvals             []interface{}       `json:"approvals"`
	Signature             string              `json:"signature"`
	LatestProtocolVersion int                 `json:"latest_protocol_version"`
}

type ChunkDetails

type ChunkDetails struct {
	Header       BlockChunk    `json:"header"`
	Transactions []Transaction `json:"transactions"`
}

type Client

type Client interface {
	SetTimeout(time.Duration)
	SetDebug(bool)

	Call(string, interface{}, interface{}) error
	GenesisConfig() (GenesisConfig, error)
	GenesisRecords(int, int) (GenesisRecords, error)
	Status() (NodeStatus, error)
	NetworkInfo() (NetworkInfo, error)
	CurrentBlock() (Block, error)
	BlockByHeight(uint64) (Block, error)
	BlockByHash(string) (Block, error)
	Chunk(string) (ChunkDetails, error)
	Account(id string) (Account, error)
	AccountAtHeight(string, uint64) (Account, error)
	AccountInfo(string, string, uint64) (*AccountInfo, error)
	Transaction(string) (TransactionDetails, error)
	GasPrice(string) (string, error)
	CurrentValidators() (*ValidatorsResponse, error)
	ValidatorsByEpoch(string) (*ValidatorsResponse, error)
	BlockChanges(interface{}) (BlockChangesResponse, error)
	RewardFee(string) (*RewardFee, error)
	Delegations(string, uint64) ([]AccountInfo, error)
}

Client interacts with the node RPC API

func DefaultClient added in v0.3.0

func DefaultClient(endpoint string, endpoint_apikey string) Client

DefaultClient returns a new default RPc client

func NewClient

func NewClient(endpoint string, endpoint_apikey string, httpClient *http.Client) Client

NewClient returns a new RPc client with overrides

type CreateAccountAction added in v0.2.0

type CreateAccountAction struct {
}

type DeleteAccountAction added in v0.2.0

type DeleteAccountAction struct {
	BeneficiaryID string `json:"beneficiary_id"`
}

type DeleteKeyAction added in v0.2.0

type DeleteKeyAction struct {
	PublicKey string `json:"public_key"`
}

type DeployContractAction added in v0.2.0

type DeployContractAction struct {
}

type Fisher

type Fisher struct {
	AccountID string `json:"account_id"`
	PublicKey string `json:"public_key"`
	Stake     string `json:"stake"`
}

type FunctionCallAction added in v0.2.0

type FunctionCallAction struct {
	MethodName string `json:"method_name"`
	// Args       string `json:"args,omitempty"` // skipped due to large payloads
	Deposit string `json:"deposit"`
	Gas     int64  `json:"gas"`
}

type GasPriceDetails

type GasPriceDetails struct {
	GasPrice string `json:"gas_price"`
}

type GenesisConfig

type GenesisConfig struct {
	ConfigVersion         int       `json:"config_version"`
	ProtocolVersion       int       `json:"protocol_version"`
	ChainID               string    `json:"chain_id"`
	GenesisHeight         uint64    `json:"genesis_height"`
	GenesisTime           time.Time `json:"genesis_time"`
	NumBlockProducerSeats int       `json:"num_block_producer_seats"`
	EpochLength           int       `json:"epoch_length"`
	TotalSupply           string    `json:"total_supply"`
	Validators            []struct {
		AccountID string `json:"account_id"`
		PublicKey string `json:"public_key"`
		Amount    string `json:"amount"`
	} `json:"validators"`
}

type GenesisRecords

type GenesisRecords struct {
	Records    []json.RawMessage `json:"records"`
	Pagination struct {
		Offset int `json:"offset"`
		Limit  int `json:"limit"`
	} `json:"pagination"`
}

type KickoutReason added in v0.3.0

type KickoutReason struct {
	Name ReasonName
	Data map[string]interface{}
}

func (*KickoutReason) UnmarshalJSON added in v0.3.0

func (r *KickoutReason) UnmarshalJSON(data []byte) error

type NetworkInfo added in v0.2.1

type NetworkInfo struct {
	NumActivePeers int `json:"num_active_peers"`
	MaxPeersCount  int `json:"peer_max_count"`

	KnownProducers []struct {
		ID        string  `json:"id"`
		Address   string  `json:"addr"`
		AccountID *string `json:"account_id"`
	} `json:"known_producers"`

	ActivePeers []struct {
		ID        string  `json:"id"`
		Address   string  `json:"addr"`
		AccountID *string `json:"account_id"`
	} `json:"active_peers"`
}

type NodeStatus

type NodeStatus struct {
	Version  Version  `json:"version"`
	ChainID  string   `json:"chain_id"`
	RPCAddr  string   `json:"rpc_addr"`
	SyncInfo SyncInfo `json:"sync_info"`
}

type Outcome

type Outcome struct {
	GasBurnt    int64         `json:"gas_burnt"`
	TokensBurnt string        `json:"tokens_burnt"`
	ExecutorId  string        `json:"executor_id"`
	Logs        []interface{} `json:"logs"`
	ReceiptIds  []string      `json:"receipt_ids"`
	Status      Status        `json:"status"`
}

type QueryResponse added in v0.3.0

type QueryResponse struct {
	BlockHash   string `json:"block_hash"`
	BlockHeight uint64 `json:"block_height"`
	Result      []byte `json:"result"`
}

type ReasonName added in v0.3.0

type ReasonName string
const (
	// Validator didn't produce enough blocks
	NotEnoughBlocks ReasonName = "NotEnoughBlocks"

	// Validator didn't produce enough chunks
	NotEnoughChunks ReasonName = "NotEnoughChunks"

	// Validator stake is now below threshold
	NotEnoughStake ReasonName = "NotEnoughStake"

	// Validator unstaked themselves
	Unstaked ReasonName = "Unstaked"

	// Enough stake but is not chosen because of seat limits.
	DidNotGetASeat ReasonName = "DidNotGetASeat"

	// Slashed validators are kicked out.
	Slashed ReasonName = "Slashed"
)

type ReceiptsOutcome

type ReceiptsOutcome struct {
	BlockHash string  `json:"block_hash"`
	ID        string  `json:"id"`
	Outcome   Outcome `json:"outcome"`
}

type RewardFee added in v0.3.0

type RewardFee struct {
	Numerator   int `json:"numerator"`
	Denominator int `json:"denominator"`
}

type StakeAction added in v0.2.0

type StakeAction struct {
	PublicKey string `json:"public_key"`
	Amount    string `json:"stake"`
}

type Status

type Status struct {
	SuccessValue     *string     `json:"SuccessValue"`
	SuccessReceiptID *string     `json:"SuccessReceiptId"`
	Failure          interface{} `json:"Failure"`
}

type SyncInfo

type SyncInfo struct {
	LatestBlockHash   string    `json:"latest_block_hash"`
	LatestBlockHeight uint64    `json:"latest_block_height"`
	LatestStateRoot   string    `json:"latest_state_root"`
	LatestBlockTime   time.Time `json:"latest_block_time"`
	Syncing           bool      `json:"syncing"`
}

type Transaction

type Transaction struct {
	Hash       string        `json:"hash"`
	Nonce      int           `json:"nonce"`
	PublicKey  string        `json:"public_key"`
	ReceiverID string        `json:"receiver_id"`
	Signature  string        `json:"signature"`
	SignerID   string        `json:"signer_id"`
	Actions    []interface{} `json:"actions"`
}

type TransactionDetails

type TransactionDetails struct {
	ReceiptsOutcome    []ReceiptsOutcome  `json:"receipts_outcome"`
	Status             interface{}        `json:"status"`
	Transaction        Transaction        `json:"transaction"`
	TransactionOutcome TransactionOutcome `json:"transaction_outcome"`
}

type TransactionOutcome

type TransactionOutcome struct {
	BlockHash string  `json:"block_hash"`
	ID        string  `json:"id"`
	Outcome   Outcome `json:"outcome"`
}

type TransferAction added in v0.2.0

type TransferAction struct {
	Deposit string `json:"deposit"`
}

type Validator

type Validator struct {
	AccountID         string `json:"account_id"`
	IsSlashed         bool   `json:"is_slashed"`
	NumExpectedBlocks int    `json:"num_expected_blocks"`
	NumProducedBlocks int    `json:"num_produced_blocks"`
	PublicKey         string `json:"public_key"`
	Shards            []int  `json:"shards"`
	Stake             string `json:"stake"`
}

type ValidatorKickout added in v0.3.0

type ValidatorKickout struct {
	Account string        `json:"account_id"`
	Reason  KickoutReason `json:"reason"`
}

type ValidatorProposal added in v0.3.0

type ValidatorProposal struct {
	AccountID string `json:"account_id"`
	PublicKey string `json:"public_key"`
	Stake     string `json:"stake"`
}

type ValidatorsResponse added in v0.3.0

type ValidatorsResponse struct {
	EpochStartHeight     uint64              `json:"epoch_start_height"`
	CurrentValidators    []Validator         `json:"current_validators"`
	CurrentProposales    []ValidatorProposal `json:"current_proposals"`
	NextValidators       []Validator         `json:"next_validators"`
	PreviousEpochKickout []ValidatorKickout  `json:"prev_epoch_kickout"`
}

type Version

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

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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