common

package
v0.0.0-...-af5322b Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	OrdCreateAccount uint8 = iota
	OrdDeployContract
	OrdFunctionCall
	OrdTransfer
	OrdStake
	OrdAddKey
	OrdDeleteKey
	OrdDeleteAccount
)
View Source
const (
	TokenType_Native TokenType = "Native"
	TokenType_NFT              = "NFT"
	TokenType_FT               = "FT"
)
View Source
const (
	ContractNew = "new"

	ContractNftTransfer       = "nft_transfer_call"
	ContractNftWithdraw       = "nft_withdraw"
	ContractNftTokensForOwner = "nft_tokens_for_owner"
	ContractNftMetadata       = "nft_metadata"
	ContractNftGet            = "nft_token"

	ContractFtTransfer  = "ft_transfer_call"
	ContractFtWithdraw  = "ft_withdraw"
	ContractFtBalanceOf = "ft_balance_of"
	ContractFtMint      = "ft_mint"

	ContractStorageDeposit = "storage_deposit"

	ContractBridgeNativeDeposit  = "native_deposit"
	ContractBridgeNativeWithdraw = "native_withdraw"

	ContractFeerRegister       = "register"
	ContractFeerUnregister     = "unregister"
	ContractFeerChargeNative   = "charge_native"
	ContractFeerAddFeeToken    = "add_fee_token"
	ContractFeerUpdateFeeToken = "update_fee_token"
	ContractFeerRemoveFeeToken = "remove_fee_token"
	ContractFeerWithdraw       = "withdraw"
	ContractFeerGetFeeToken    = "get_fee_token"
	ContractFeerGetFeeTokens   = "get_fee_tokens"
)
View Source
const (
	RawKeyTypeED25519 byte = iota
	RawKeyTypeSECP256K1
)
View Source
const (
	RawSignatureTypeED25519 byte = iota
	RawSignatureTypeSECP256K1
)
View Source
const (
	SignatureTypeED25519   = SignatureType("ed25519")
	SignatureTypeSECP256K1 = SignatureType("secp256k1")
)

Variables

View Source
var (
	OrdMappings = map[string]uint8{
		"CreateAccount":  OrdCreateAccount,
		"DeployContract": OrdDeployContract,
		"FunctionCall":   OrdFunctionCall,
		"Transfer":       OrdTransfer,
		"Stake":          OrdStake,
		"AddKey":         OrdAddKey,
		"DeleteKey":      OrdDeleteKey,
		"DeleteAccount":  OrdDeleteAccount,
	}

	SimpleActions = map[string]bool{
		"CreateAccount": true,
	}
)
View Source
var (
	TenPower24 = uint128.From64(uint64(math.Pow10(12))).Mul64(uint64(math.Pow10(12)))
	ZeroNEAR   = Balance(uint128.From64(0))
	OneYocto   = Balance(uint128.From64(1))
	One        = big.NewInt(0).Exp(big.NewInt(10), big.NewInt(24), nil)
)
View Source
var (
	NftMintStorageDeposit = MustBalanceFromString("0.2")
	FtMintStorageDeposit  = MustBalanceFromString("0.00125")
)

Functions

func MustMarshalJson

func MustMarshalJson(params interface{}) []byte

func SignAndSerializeTransaction

func SignAndSerializeTransaction(keyPair KeyPair, txn Transaction) (blob string, err error)

func YoctoToNEAR

func YoctoToNEAR(yocto Balance) uint64

Types

type AccessKey

type AccessKey struct {
	Nonce 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 AccessKeyFunctionCallPermission

type AccessKeyFunctionCallPermission struct {
	Allowance   *Balance  `json:"allowance"`
	ReceiverID  AccountID `json:"receiver_id"`
	MethodNames []string  `json:"method_names"`
}

func (AccessKeyFunctionCallPermission) String

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 Base58PublicKey `json:"public_key"`
	AccessKey AccessKey       `json:"access_key"`
}

type AccountID

type AccountID = string

Account identifier. Provides access to user's state.

type AccountView

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

	QueryResponse
}

type Action

type Action struct {
	Enum borsh.Enum `borsh_enum:"true"`

	CreateAccount  ActionCreateAccount
	DeployContract ActionDeployContract
	FunctionCall   ActionFunctionCall
	Transfer       ActionTransfer
	Stake          ActionStake
	AddKey         ActionAddKey
	DeleteKey      ActionDeleteKey
	DeleteAccount  ActionDeleteAccount
}

func NewAddKey

func NewAddKey(publicKey PublicKey, nonce Nonce, permission AccessKeyPermission) Action

func NewCreateAccount

func NewCreateAccount() Action

NewCreateAccount Create an (sub)account using a transaction `receiver_id` as an ID for a new account

func NewDeleteAccount

func NewDeleteAccount(beneficiaryID AccountID) Action

func NewDeleteKey

func NewDeleteKey(publicKey PublicKey) Action

func NewDeployContract

func NewDeployContract(code []byte) Action

func NewFeeChargeNativeCall

func NewFeeChargeNativeCall(params FeerDepositArgs, amount Balance, gas Gas) Action

func NewFeeTokenAddCall

func NewFeeTokenAddCall(params FeeManageOperationArgs, gas Gas) Action

func NewFeeTokenRemoveCall

func NewFeeTokenRemoveCall(params FeeManageOperationArgs, gas Gas) Action

func NewFeeTokenUpdateCall

func NewFeeTokenUpdateCall(params FeeManageOperationArgs, gas Gas) Action

func NewFeeTokenWithdrawCall

func NewFeeTokenWithdrawCall(params FeeManageOperationArgs, receiver AccountID, amount Balance, gas Gas) Action

func NewFtTransferCall

func NewFtTransferCall(params FtTransferArgs, gas Gas) Action

func NewFtWithdrawCall

func NewFtWithdrawCall(params FtWithdrawArgs, gas Gas, deposit Balance) Action

func NewFunctionCall

func NewFunctionCall(methodName string, args []byte, gas Gas, deposit Balance) Action

func NewNativeDepositCall

func NewNativeDepositCall(params NativeDepositArgs, gas Gas, deposit Balance) Action

func NewNativeWithdrawCall

func NewNativeWithdrawCall(params NativeWithdrawArgs, gas Gas, deposit Balance) Action

func NewNftTransferCall

func NewNftTransferCall(params NftTransferArgs, gas Gas) Action

func NewNftWithdrawCall

func NewNftWithdrawCall(params NftWithdrawArgs, gas Gas, deposit Balance) Action

func NewStake

func NewStake(stake Balance, publicKey PublicKey) Action

func NewTransfer

func NewTransfer(deposit Balance) Action

func (*Action) DepositBalance

func (a *Action) DepositBalance() Balance

func (*Action) PrepaidGas

func (a *Action) PrepaidGas() Gas

func (Action) String

func (a Action) String() string

func (*Action) UnderlyingValue

func (a *Action) UnderlyingValue() interface{}

func (*Action) UnmarshalJSON

func (a *Action) UnmarshalJSON(b []byte) (err error)

type ActionAccessKeyPermission

type ActionAccessKeyPermission struct {
	Enum borsh.Enum `borsh_enum:"true"`

	FunctionCallPermission AccessKeyFunctionCallPermission
	FullAccessPermission   struct{}
}

func NewFullAccessPermission

func NewFullAccessPermission() ActionAccessKeyPermission

func NewFunctionCallPermission

func NewFunctionCallPermission(allowance Balance, receiverID AccountID, methodNames []string) ActionAccessKeyPermission

func NewFunctionCallUnlimitedAllowancePermission

func NewFunctionCallUnlimitedAllowancePermission(receiverID AccountID, methodNames []string) ActionAccessKeyPermission

func (*ActionAccessKeyPermission) IsFullAccess

func (a *ActionAccessKeyPermission) IsFullAccess() bool

func (*ActionAccessKeyPermission) IsFunctionCall

func (a *ActionAccessKeyPermission) IsFunctionCall() bool

func (ActionAccessKeyPermission) MarshalJSON

func (a ActionAccessKeyPermission) MarshalJSON() ([]byte, error)

func (ActionAccessKeyPermission) String

func (a ActionAccessKeyPermission) String() string

func (*ActionAccessKeyPermission) UnmarshalJSON

func (a *ActionAccessKeyPermission) UnmarshalJSON(b []byte) error

type ActionAddKey

type ActionAddKey struct {
	PublicKey PublicKey             `json:"public_key"`
	AccessKey ActionAddKeyAccessKey `json:"access_key"`
}

func (ActionAddKey) MarshalJSON

func (a ActionAddKey) MarshalJSON() (b []byte, err error)

func (*ActionAddKey) UnmarshalJSON

func (a *ActionAddKey) UnmarshalJSON(b []byte) (err error)

type ActionAddKeyAccessKey

type ActionAddKeyAccessKey struct {
	Nonce      Nonce               `json:"nonce"`
	Permission AccessKeyPermission `json:"permission"`
}

type ActionCreateAccount

type ActionCreateAccount struct {
}

type ActionDeleteAccount

type ActionDeleteAccount struct {
	BeneficiaryID AccountID `json:"beneficiary_id"`
}

type ActionDeleteKey

type ActionDeleteKey struct {
	PublicKey PublicKey `json:"public_key"`
}

func (ActionDeleteKey) MarshalJSON

func (a ActionDeleteKey) MarshalJSON() (b []byte, err error)

func (*ActionDeleteKey) UnmarshalJSON

func (a *ActionDeleteKey) UnmarshalJSON(b []byte) (err error)

type ActionDeployContract

type ActionDeployContract struct {
	Code []byte `json:"code"`
}

type ActionFunctionCall

type ActionFunctionCall struct {
	MethodName string  `json:"method_name"`
	Args       []byte  `json:"args"`
	Gas        Gas     `json:"gas"`
	Deposit    Balance `json:"deposit"`
}

func (ActionFunctionCall) String

func (f ActionFunctionCall) String() string

type ActionStake

type ActionStake struct {
	// Amount of tokens to stake.
	Stake Balance `json:"stake"`
	// Validator key which will be used to sign transactions on behalf of singer_id
	PublicKey PublicKey `json:"public_key"`
}

type ActionTransfer

type ActionTransfer struct {
	Deposit Balance `json:"deposit"`
}

func (ActionTransfer) String

func (t ActionTransfer) String() string

type Balance

type Balance uint128.Uint128

Balance holds amount of yoctoNEAR

func BalanceFromString

func BalanceFromString(s string) (bal Balance, err error)

func MustBalanceFromString

func MustBalanceFromString(s string) Balance

func NEARToYocto

func NEARToYocto(near uint64) Balance

func (Balance) Big

func (bal Balance) Big() *big.Int

func (Balance) Div64

func (bal Balance) Div64(div uint64) Balance

func (Balance) Empty

func (bal Balance) Empty() bool

func (Balance) Equals

func (bal Balance) Equals(other Balance) bool

func (Balance) MarshalJSON

func (bal Balance) MarshalJSON() ([]byte, error)

func (Balance) String

func (bal Balance) String() string

func (Balance) Uint64

func (bal Balance) Uint64() uint64

func (*Balance) UnmarshalJSON

func (bal *Balance) UnmarshalJSON(b []byte) error

type Base58PublicKey

type Base58PublicKey struct {
	Type  PublicKeyType
	Value string

	Key PublicKey
}

func NewBase58PublicKey

func NewBase58PublicKey(raw string) (pk Base58PublicKey, err error)

func (Base58PublicKey) MarshalJSON

func (pk Base58PublicKey) MarshalJSON() ([]byte, error)

func (Base58PublicKey) String

func (pk Base58PublicKey) String() string

func (*Base58PublicKey) ToPublicKey

func (pk *Base58PublicKey) ToPublicKey() PublicKey

Copies Base58PublicKey to PublicKey

func (*Base58PublicKey) UnmarshalJSON

func (pk *Base58PublicKey) UnmarshalJSON(b []byte) (err error)

type Base58Signature

type Base58Signature struct {
	Type  SignatureType
	Value string
}

func NewBase58Signature

func NewBase58Signature(raw string) (pk Base58Signature, err error)

func (Base58Signature) MarshalJSON

func (sig Base58Signature) MarshalJSON() ([]byte, error)

func (Base58Signature) String

func (sig Base58Signature) String() string

func (*Base58Signature) UnmarshalJSON

func (sig *Base58Signature) UnmarshalJSON(b []byte) (err error)

type BlockHeaderView

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

type BlockHeight

type BlockHeight = uint64

BlockHeight is used for height of the block

type BlockView

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

type BridgeBaseEventData

type BridgeBaseEventData struct {
	Sender    AccountID  `json:"sender"`
	Receiver  string     `json:"receiver"`
	Token     *AccountID `json:"token,omitempty"`
	TokenID   *string    `json:"token_id,omitempty"`
	Amount    *string    `json:"amount,omitempty"`
	IsWrapped *bool      `json:"is_wrapped,omitempty"`
}

type BridgeDepositedEvent

type BridgeDepositedEvent struct {
	BridgeEvent
	Data []BridgeDepositedEventData `json:"data"`
}

type BridgeDepositedEventData

type BridgeDepositedEventData struct {
	BridgeBaseEventData
	ChainTo    string  `json:"chain_to"`
	BundleData *string `json:"bundle_data,omitempty"`
	BundleSalt *string `json:"bundle_salt,omitempty"`
}

type BridgeEvent

type BridgeEvent struct {
	Standard string `json:"standard"`
	Version  string `json:"version"`
	Event    string `json:"event"`
}

type BridgeEventType

type BridgeEventType string
const (
	EventTypeFTDeposited     BridgeEventType = "ft_deposited"
	EventTypeFTWithdrawn     BridgeEventType = "ft_withdrawn"
	EventTypeNFTDeposited    BridgeEventType = "nft_deposited"
	EventTypeNFTWithdrawn    BridgeEventType = "nft_withdrawn"
	EventTypeNativeDeposited BridgeEventType = "native_deposited"
	EventTypeNativeWithdrawn BridgeEventType = "native_withdrawn"
)

type BridgeWithdrawnEvent

type BridgeWithdrawnEvent struct {
	BridgeEvent
	Data []BridgeWithdrawnEventData `json:"data"`
}

type BridgeWithdrawnEventData

type BridgeWithdrawnEventData struct {
	BridgeBaseEventData
	Origin     string   `json:"origin"`
	Signature  string   `json:"signature"`
	Path       []string `json:"path"`
	RecoveryID uint8    `json:"recovery_id"`
}

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                 `json:"chunk_hash"`
	PrevBlockHash        Hash                 `json:"prev_block_hash"`
	OutcomeRoot          Hash                 `json:"outcome_root"`
	PrevStateRoot        json.RawMessage      `json:"prev_state_root"` // TODO: needs a type!
	EncodedMerkleRoot    Hash                 `json:"encoded_merkle_root"`
	EncodedLength        uint64               `json:"encoded_length"`
	HeightCreated        BlockHeight          `json:"height_created"`
	HeightIncluded       BlockHeight          `json:"height_included"`
	ShardID              ShardID              `json:"shard_id"`
	GasUsed              Gas                  `json:"gas_used"`
	GasLimit             Gas                  `json:"gas_limit"`
	RentPaid             Balance              `json:"rent_paid"`        // TODO: deprecated
	ValidatorReward      Balance              `json:"validator_reward"` // TODO: deprecated
	BalanceBurnt         Balance              `json:"balance_burnt"`
	OutgoingReceiptsRoot Hash                 `json:"outgoing_receipts_root"`
	TxRoot               Hash                 `json:"tx_root"`
	ValidatorProposals   []ValidatorStakeView `json:"validator_proposals"`
	Signature            Base58Signature      `json:"signature"`
}

type ChunkView

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

type CurrentEpochValidatorInfo

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

type EdgeInfo

type EdgeInfo struct {
	Nonce     Nonce     `json:"nonce"`
	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 EndpointSetup

type EndpointSetup struct {
	JsonRpc string `json:"jsonrpc"`
	ID      string `json:"id"`
	Method  string `json:"method"`
}

type ExecutionOutcomeView

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

type ExecutionOutcomeWithIdView

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

type ExecutionOutcomeWithReceipt

type ExecutionOutcomeWithReceipt struct {
	ExecutionOutcome ExecutionOutcomeWithIdView `json:"execution_outcome"`
	Receipt          *ReceiptView               `json:"receipt"`
}

type FeeManageOperation

type FeeManageOperation struct {
	SignArgs
	Token FeeToken `json:"token,required"`
}

type FeeManageOperationArgs

type FeeManageOperationArgs struct {
	Operation FeeManageOperation `json:"op,required"`
}

type FeeManageOperationArgsWithBorsh

type FeeManageOperationArgsWithBorsh struct {
	Operation FeeManageOperationWithBorsh `json:"op,required"`
}

type FeeManageOperationType

type FeeManageOperationType int
const (
	FeeAddFeeToken FeeManageOperationType = iota + 1
	FeeRemoveFeeToken
	FeeUpdateFeeToken
	FeeWithdraw
)

type FeeManageOperationWithBorsh

type FeeManageOperationWithBorsh struct {
	SignArgs
	Token FeeTokenWithBorsh `json:"token,required"`
}

type FeeToken

type FeeToken struct {
	TokenAddr *AccountID `json:"token_addr"`
	TokenType TokenType  `json:"token_type"`
	Fee       Balance    `json:"fee"`
}

type FeeTokenWithBorsh

type FeeTokenWithBorsh struct {
	TokenAddr *AccountID `json:"token_addr"`
	TokenType string     `json:"token_type"`
	Fee       Balance    `json:"fee"`
}

type FeerDepositArgs

type FeerDepositArgs struct {
	FeeTokenAddr *AccountID       `json:"fee_token_addr"`
	TokenAddr    *AccountID       `json:"token_addr,omitempty"`
	TokenType    TokenType        `json:"token_type,omitempty"`
	TransferType FeerTransferType `json:"transfer_type"`
	Receiver     string           `json:"receiver"`
	ChainTo      string           `json:"chain_to"`
	IsWrapped    bool             `json:"is_wrapped"`
	BundleData   *string          `json:"bundle_data,omitempty"`
	BundleSalt   *string          `json:"bundle_salt,omitempty"`
}

func (FeerDepositArgs) String

func (f FeerDepositArgs) String() (string, error)

func (FeerDepositArgs) WithTransferType

func (f FeerDepositArgs) WithTransferType(transferType FeerTransferType) FeerDepositArgs

type FeerTransferType

type FeerTransferType string
const (
	FeerTransferType_Fee     FeerTransferType = "Fee"
	FeerTransferType_Deposit FeerTransferType = "Deposit"
)

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 FtTransferArgs

type FtTransferArgs struct {
	ReceiverId AccountID `json:"receiver_id"`
	Amount     Balance   `json:"amount"`
	Msg        string    `json:"msg"` // TransferArgs | FeeDepositArgs
}

type FtWithdrawArgs

type FtWithdrawArgs struct {
	WithdrawArgs
	Token     AccountID `json:"token"`
	Amount    Balance   `json:"amount"`
	IsWrapped bool      `json:"is_wrapped"`
}

type FullAccessPermissionWrapper

type FullAccessPermissionWrapper struct {
	FunctionCall AccessKeyFunctionCallPermission `json:"FunctionCall"`
}

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 *Balance `json:"allowance"`
	// ReceiverID holds the contract the key is allowed to call methods on
	ReceiverID 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 Gas

type Gas = uint64

Gas is a type for storing amounts of gas.

var (
	// 30 TGas
	DefaultFunctionCallGas Gas = 30 * 1000000000000
)

type GasPrice

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

type GenesisID

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

type Hash

type Hash [sha256.Size]byte

Hash is a wrapper for SHA-256 digest byte array. Note that nearcore also defines MerkleHash as an alias, but it's omitted from this project.

func MustCryptoHashFromBase58

func MustCryptoHashFromBase58(blob string) Hash

func NewCryptoHash

func NewCryptoHash(data []byte) Hash

func NewCryptoHashFromBase58

func NewCryptoHashFromBase58(blob string) (ch Hash, err error)

func (Hash) MarshalJSON

func (c Hash) MarshalJSON() ([]byte, error)

func (Hash) String

func (c Hash) String() string

func (*Hash) UnmarshalJSON

func (c *Hash) UnmarshalJSON(b []byte) (err error)

type JsonActionAddKey

type JsonActionAddKey struct {
	PublicKey Base58PublicKey       `json:"public_key"`
	AccessKey ActionAddKeyAccessKey `json:"access_key"`
}

type JsonActionDeleteKey

type JsonActionDeleteKey struct {
	PublicKey Base58PublicKey `json:"public_key"`
}

type JsonRpcError

type JsonRpcError struct {
	Name  string            `json:"name"`
	Cause JsonRpcErrorCause `json:"cause"`

	// Legacy - do not rely on them
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data"`
}

func (*JsonRpcError) Error

func (err *JsonRpcError) Error() string

type JsonRpcErrorCause

type JsonRpcErrorCause struct {
	Name string          `json:"name"`
	Info json.RawMessage `json:"info"`
	// contains filtered or unexported fields
}

func (JsonRpcErrorCause) String

func (cause JsonRpcErrorCause) String() string

func (*JsonRpcErrorCause) UnmarshalJSON

func (cause *JsonRpcErrorCause) UnmarshalJSON(b []byte) (err error)

type JsonRpcErrorCauseMessage

type JsonRpcErrorCauseMessage struct {
	ErrorMessage string `json:"error_message"`
}

type KeyPair

type KeyPair struct {
	Type PublicKeyType

	PublicKey  Base58PublicKey
	PrivateKey ed25519.PrivateKey
}

func GenerateKeyPair

func GenerateKeyPair(keyType PublicKeyType, rand io.Reader) (kp KeyPair, err error)

func NewBase58KeyPair

func NewBase58KeyPair(raw string) (kp KeyPair, err error)

func NewKeyPair

func NewKeyPair(keyType PublicKeyType, pub Base58PublicKey, priv ed25519.PrivateKey) KeyPair

func (*KeyPair) PrivateEncoded

func (kp *KeyPair) PrivateEncoded() string

func (*KeyPair) Sign

func (kp *KeyPair) Sign(data []byte) (sig Signature)

func (*KeyPair) UnmarshalJSON

func (kp *KeyPair) UnmarshalJSON(b []byte) (err error)

type KnownProducer

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

KnownProducer is basically PeerInfo, but AccountID is known

type LogEvent

type LogEvent struct {
	Standard string                  `json:"standard,required"`
	Version  string                  `json:"version,required"`
	Event    LogEventType            `json:"event,required"`
	Data     []LogEventDepositedData `json:"data,required"`
}

type LogEventDepositedData

type LogEventDepositedData struct {
	Token *AccountID `json:"token,required"`
	// Empty if fungible token
	TokenID *string `json:"token_id,omitempty"`
	// Empty if non fungible token
	Amount    *Balance `json:"amount,omitempty"`
	Chain     string   `json:"chain,required"`
	IsWrapped bool     `json:"is_wrapped,required"`
}

type LogEventType

type LogEventType = string
const (
	LogEventTypeNftDeposited    LogEventType = "nft_deposited"
	LogEventTypeFtDeposited     LogEventType = "ft_deposited"
	LogEventTypeNativeDeposited LogEventType = "native_deposited"
)

type MerklePath

type MerklePath = []MerklePathItem

type MerklePathItem

type MerklePathItem struct {
	Hash      Hash   `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 NativeDepositArgs

type NativeDepositArgs struct {
	ReceiverId AccountID `json:"receiver_id"`
	Chain      string    `json:"chain"`
}

type NativeWithdrawArgs

type NativeWithdrawArgs struct {
	WithdrawArgs
	Amount Balance `json:"amount"`
}

type NetworkID

type NetworkID = string
const (
	NetworkMainnet NetworkID = "mainnet"
	NetworkTestnet NetworkID = "testnet"
	NetworkBetanet NetworkID = "betanet"
)

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 NftContractMetadataView

type NftContractMetadataView struct {
	// required, essentially a version like "nft-1.0.0"
	Spec string `json:"spec"`
	// required, ex. "Mosaics"
	Name string `json:"name"`
	// required, ex. "MOSIAC"
	Symbol string `json:"symbol"`
	// Data URL
	Icon *string `json:"icon"`
	// Centralized gateway known to have reliable access to decentralized storage assets referenced by `reference` or `media` URLs
	BaseURI *string `json:"base_uri,omitempty"`
	// URL to an off-chain JSON file with more info.
	Reference *string `json:"reference,omitempty"`
	// Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
	ReferenceHash []byte `json:"reference_hash,omitempty"`
}

type NftMetadataView

type NftMetadataView struct {
	// ex. "Arch Nemesis: Mail Carrier" or "Parcel #5055"
	Title string `json:"title,omitempty"`
	// free-form description
	Description string `json:"description,omitempty"`
	// URL to associated media, preferably to decentralized, content-addressed storage
	Media string `json:"media,omitempty"`
	// Base64-encoded sha256 hash of content referenced by the `media` field. Required if `media` is included.
	MediaHash []byte `json:"media_hash,omitempty"`
	// number of copies of this set of metadata in existence when token was minted.
	Copies uint64 `json:"copies,omitempty"`
	// ISO 8601 datetime when token was issued or minted
	IssuedAt time.Time `json:"issued_at,omitempty"`
	// ISO 8601 datetime when token expires
	ExpiresAt time.Time `json:"expires_at,omitempty"`
	// ISO 8601 datetime when token starts being valid
	StartsAt time.Time `json:"starts_at,omitempty"`
	// ISO 8601 datetime when token was last updated
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// anything extra the NFT wants to store on-chain. Can be stringified JSON.
	Extra string `json:"extra,omitempty"`
	// URL to an off-chain JSON file with more info.
	Reference string `json:"reference,omitempty"`
	// Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
	ReferenceHash []byte `json:"reference_hash,omitempty"`
}

type NftTransferArgs

type NftTransferArgs struct {
	ReceiverId AccountID `json:"receiver_id"`
	TokenID    string    `json:"token_id"`
	Msg        string    `json:"msg"` // // TransferArgs | FeeDepositArgs
}

type NftView

type NftView struct {
	TokenID            string               `json:"token_id"`
	OwnerID            string               `json:"owner_id"`
	Metadata           *NftMetadataView     `json:"metadata"`
	ApprovedAccountIds *map[AccountID]int64 `json:"approved_account_ids"`
}

type NftWithdrawArgs

type NftWithdrawArgs struct {
	WithdrawArgs
	Token         AccountID        `json:"token"`
	TokenID       string           `json:"token_id"`
	TokenMetadata *NftMetadataView `json:"token_metadata,omitempty"`
	IsWrapped     bool             `json:"is_wrapped"`
}

type NodeVersion

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

type Nonce

type Nonce = uint64

Nonce for transactions.

type NumBlocks

type NumBlocks = uint64

NumBlocks holds number of blocks in current group.

type PeerChainInfo

type PeerChainInfo struct {
	// ChainTo Id and hash of genesis block.
	GenesisID GenesisID `json:"genesis_id"`
	// Last known chain height of the peer.
	Height BlockHeight `json:"height"`
	// Shards that the peer is tracking.
	TrackedShards []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 PeerID

type PeerID = Base58PublicKey

PeerID is the public key

type PeerInfo

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

PeerInfo holds peer information

type PublicKey

type PublicKey [33]byte

TODO: SECP256K1

func PublicKeyFromBytes

func PublicKeyFromBytes(b []byte) (pk PublicKey, err error)

func WrapED25519

func WrapED25519(key ed25519.PublicKey) PublicKey

func WrapRawKey

func WrapRawKey(keyType PublicKeyType, key []byte) (pk PublicKey, err error)

func (PublicKey) Hash

func (p PublicKey) Hash() string

func (PublicKey) MarshalJSON

func (p PublicKey) MarshalJSON() ([]byte, error)

func (PublicKey) String

func (p PublicKey) String() string

func (*PublicKey) ToBase58PublicKey

func (p *PublicKey) ToBase58PublicKey() Base58PublicKey

func (PublicKey) TypeByte

func (p PublicKey) TypeByte() byte

func (*PublicKey) UnmarshalJSON

func (p *PublicKey) UnmarshalJSON(b []byte) error

func (PublicKey) Value

func (p PublicKey) Value() []byte

func (*PublicKey) Verify

func (p *PublicKey) Verify(data []byte, signature Signature) (ok bool, err error)

type PublicKeyType

type PublicKeyType string
const (
	KeyTypeED25519   PublicKeyType = "ed25519"
	KeyTypeSECP256K1 PublicKeyType = "secp256k1"
)

type QueryResponse

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

type ReceiptView

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

type Request

type Request struct {
	EndpointSetup
	Params interface{} `json:"params,omitempty"`
}

type Response

type Response struct {
	EndpointSetup
	Error  *JsonRpcError   `json:"error"`
	Result json.RawMessage `json:"result"`
}

type ShardChunkTransactionView

type ShardChunkTransactionView struct {
	Outcome     ExecutionOutcomeWithReceipt `json:"outcome"`
	Transaction SignedTransactionView       `json:"transaction"`
}

type ShardChunkView

type ShardChunkView struct {
	Author       AccountID                   `json:"author"`
	Header       ChunkHeaderView             `json:"header"`
	Receipts     []ReceiptView               `json:"receipts"`
	Transactions []ShardChunkTransactionView `json:"transactions"`
}

type ShardID

type ShardID = uint64

ShardID is used for a shard index, from 0 to NUM_SHARDS - 1.

type ShardStateChangeCauseView

type ShardStateChangeCauseView struct {
	Type   string `json:"type"`
	TxHash Hash   `json:"tx_hash"`
}

type ShardStateChangeChangeView

type ShardStateChangeChangeView struct {
	AccountID     AccountID        `json:"account_id"`
	AccessKey     *AccessKeyView   `json:"access_key,omitempty"`
	PublicKey     *Base58PublicKey `json:"public_key,omitempty"`
	Amount        *Balance         `json:"amount,omitempty"`
	Locked        *Balance         `json:"locked,omitempty"`
	CodeHash      *Hash            `json:"code_hash,omitempty"`
	StorageUsage  *StorageUsage    `json:"storage_usage,omitempty"`
	StoragePaidAt *BlockHeight     `json:"storage_paid_at,omitempty"`
}

type ShardStateChangeView

type ShardStateChangeView struct {
	Type   string                     `json:"type"`
	Cause  ShardStateChangeCauseView  `json:"cause"`
	Change ShardStateChangeChangeView `json:"change"`
}

type ShardView

type ShardView struct {
	ShardID                  ShardID                       `json:"shard_id"`
	Chunk                    *ShardChunkView               `json:"chunk"`
	ReceiptExecutionOutcomes []ExecutionOutcomeWithReceipt `json:"receipt_execution_outcomes"`
	StateChanges             []ShardStateChangeView        `json:"state_changes"`
}

type SignArgs

type SignArgs struct {
	Origin     string     `json:"origin"`
	Path       [][32]byte `json:"path"`
	Signature  string     `json:"signature"`
	RecoveryID byte       `json:"recovery_id"`
}

type Signature

type Signature [1 + ed25519.SignatureSize]byte

TODO: SECP256K1 support

func NewSignatureED25519

func NewSignatureED25519(data []byte) Signature

func (Signature) Type

func (s Signature) Type() byte

func (Signature) Value

func (s Signature) Value() []byte

type SignatureType

type SignatureType string

type SignedTransaction

type SignedTransaction struct {
	Transaction Transaction
	Signature   Signature

	SerializedTransaction []byte `borsh_skip:"true"`
	// contains filtered or unexported fields
}

func NewSignedTransaction

func NewSignedTransaction(keyPair KeyPair, transaction Transaction) (stxn SignedTransaction, err error)

func (*SignedTransaction) Hash

func (st *SignedTransaction) Hash() Hash

func (SignedTransaction) Serialize

func (st SignedTransaction) Serialize() (serialized string, err error)

func (*SignedTransaction) Size

func (st *SignedTransaction) Size() int

func (*SignedTransaction) Verify

func (st *SignedTransaction) Verify(pubKey PublicKey) (ok bool, err error)

type SignedTransactionView

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

type SlashedValidator

type SlashedValidator struct {
	AccountID    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 *AccountID `json:"validator_account_id"`
}

type StatusSyncInfo

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

type StorageUsage

type StorageUsage = uint64

StorageUsage is used to count the amount of storage used by a contract.

type TimeNanos

type TimeNanos = Balance

Time nanoseconds fit into uint128. Using existing Balance type which implements JSON marshal/unmarshal

type TokenType

type TokenType = string

type Transaction

type Transaction struct {
	SignerID   AccountID
	PublicKey  PublicKey
	Nonce      Nonce
	ReceiverID AccountID
	BlockHash  Hash
	Actions    []Action
}

func (Transaction) Hash

func (t Transaction) Hash() (txnHash Hash, serialized []byte, err error)

func (Transaction) HashAndSign

func (t Transaction) HashAndSign(keyPair KeyPair) (txnHash Hash, serialized []byte, sig Signature, err error)

type TransactionStatus

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

type TransferArgs

type TransferArgs struct {
	Token      AccountID `json:"token"`
	Sender     AccountID `json:"sender"`
	Receiver   AccountID `json:"receiver"`
	ChainTo    string    `json:"chain_to"`
	IsWrapped  bool      `json:"is_wrapped"`
	BundleData string    `json:"bundle_data,omitempty"`
	BundleSalt string    `json:"bundle_salt,omitempty"`
}

func NewTransferArgs

func NewTransferArgs(token string, sender, receiver AccountID, chainTo string, isWrapped bool) *TransferArgs

func (*TransferArgs) String

func (t *TransferArgs) String() (string, error)

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 AccountID `json:"account_id"`
	Slashed   bool      `json:"is_slashed"`
}

type ValidatorStakeView

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

ValidatorStakeView is based on ValidatorStakeV1 struct in nearcore

type ValidatorsResponse

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

type ViewStateResult

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

	QueryResponse
}

type WithdrawArgs

type WithdrawArgs struct {
	SignArgs
	ReceiverID AccountID `json:"receiver_id"`
}

Jump to

Keyboard shortcuts

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