near

package
v3.0.0-...-e8b7a4c Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PubKeyBytesLenCompressed is compressed pubkey byte length
	PubKeyBytesLenCompressed = 33
	// PubKeyBytesLenUncompressed is uncompressed pubkey byte length
	PubKeyBytesLenUncompressed = 65
)
View Source
const (
	ED25519 = 0

	ED25519Prefix = "ed25519:"
)

All supported key types

View Source
const (
	SWAPOUTLOG       = "SwapOut"
	SWAPOUTNATIVELOG = "SwapOutNative"
	TRANSFERLOG      = "Transfer"
	TRANSFERV4LOG    = "ft_transfer"
)

Variables

View Source
var (
	GetFtMetadata = "ft_metadata"
	GetFtBalance  = "ft_balance_of"
	EmptyArgs     = "e30="
)

Functions

func BroadcastTxCommit

func BroadcastTxCommit(url string, signedTx []byte) (string, error)

func CheckBalance

func CheckBalance(url, account, amount string) error

func CheckTokenBalance

func CheckTokenBalance(url, token, account, amount string) error

func GenerateKey

func GenerateKey() (seed, pub []byte, err error)

func GeneratePubKeyByBase58

func GeneratePubKeyByBase58(b58Key string) ([]byte, error)

func GeneratePubKeyBySeed

func GeneratePubKeyBySeed(seed []byte) ([]byte, error)

func GetAccountNonce

func GetAccountNonce(url, account, publicKey string) (uint64, error)

GetLatestBlockNumber get latest block height

func GetBlockNumberByHash

func GetBlockNumberByHash(url, hash string) (uint64, error)

func GetLatestBlockHash

func GetLatestBlockHash(url string) (string, error)

func GetLatestBlockNumber

func GetLatestBlockNumber(url string) (uint64, error)

GetLatestBlockNumber get latest block height

func GetStubChainID

func GetStubChainID(network string) *big.Int

GetStubChainID get stub chainID

func SetRPCTimeout

func SetRPCTimeout(timeout int)

SetRPCTimeout set rpc timeout

func StringToPrivateKey

func StringToPrivateKey(priv string) (*ed25519.PrivateKey, error)

func SupportsChainID

func SupportsChainID(chainID *big.Int) bool

SupportsChainID supports chainID

Types

type AccessKey

type AccessKey struct {
	Nonce      uint64
	Permission AccessKeyPermission
}

AccessKey encodes a NEAR access key.

type AccessKeyPermission

type AccessKeyPermission struct {
	Enum         borsh.Enum `borsh_enum:"true"` // treat struct as complex enum when serializing/deserializing
	FunctionCall FunctionCallPermission
	FullAccess   borsh.Enum
}

AccessKeyPermission encodes a NEAR access key permission.

type Action

type Action struct {
	Enum           borsh.Enum `borsh_enum:"true"` // treat struct as complex enum when serializing/deserializing
	CreateAccount  borsh.Enum
	DeployContract DeployContract
	FunctionCall   FunctionCall
	Transfer       Transfer
	Stake          Stake
	AddKey         AddKey
	DeleteKey      DeleteKey
	DeleteAccount  DeleteAccount
}

type AddKey

type AddKey struct {
	PublicKey PublicKey
	AccessKey AccessKey
}

The AddKey action.

type BlockDetail

type BlockDetail struct {
	Header BlockHeader `json:"header"`
}

type BlockHeader

type BlockHeader struct {
	Hash   string `json:"hash"`
	Height uint64 `json:"height"`
}

type Bridge

type Bridge struct {
	*base.NonceSetterBase
}

Bridge near bridge

func NewCrossChainBridge

func NewCrossChainBridge() *Bridge

NewCrossChainBridge new bridge

func (*Bridge) BroadcastTxCommit

func (b *Bridge) BroadcastTxCommit(signedTx []byte) (result string, err error)

BroadcastTxCommit broadcast tx

func (*Bridge) BuildRawTransaction

func (b *Bridge) BuildRawTransaction(args *tokens.BuildTxArgs) (rawTx interface{}, err error)

BuildRawTransaction build raw tx

func (*Bridge) CheckBalance

func (b *Bridge) CheckBalance(address, amount string) error

func (*Bridge) CheckTokenBalance

func (b *Bridge) CheckTokenBalance(token, amount string) error

func (*Bridge) CreateFunctionCall

func (b *Bridge) CreateFunctionCall(txHash, multichainToken, to, amount, fromChainID string, logIndex int, gas, contractVersion uint64) (string, []Action, error)

func (*Bridge) GetAccountNonce

func (b *Bridge) GetAccountNonce(account, publicKey string) (uint64, error)

func (*Bridge) GetBlockNumberByHash

func (b *Bridge) GetBlockNumberByHash(blockHash string) (uint64, error)

func (*Bridge) GetLatestBlockHash

func (b *Bridge) GetLatestBlockHash() (string, error)

func (*Bridge) GetLatestBlockNumber

func (b *Bridge) GetLatestBlockNumber() (uint64, error)

GetLatestBlockNumber gets latest block number

func (*Bridge) GetLatestBlockNumberOf

func (b *Bridge) GetLatestBlockNumberOf(apiAddress string) (uint64, error)

GetLatestBlockNumberOf gets latest block number from single api

func (*Bridge) GetPoolNonce

func (b *Bridge) GetPoolNonce(address, _height string) (uint64, error)

GetPoolNonce impl NonceSetter interface

func (*Bridge) GetSeq

func (b *Bridge) GetSeq(args *tokens.BuildTxArgs) (nonceptr *uint64, err error)

GetSeq returns account tx sequence

func (*Bridge) GetTokenDecimals

func (b *Bridge) GetTokenDecimals(tokenAddr string) (uint8, error)

GetTokenDecimals query token decimals

func (*Bridge) GetTransaction

func (b *Bridge) GetTransaction(txHash string) (tx interface{}, err error)

GetTransaction impl

func (*Bridge) GetTransactionByHash

func (b *Bridge) GetTransactionByHash(txHash string) (result *TransactionResult, err error)

GetTransactionByHash get tx response by hash

func (*Bridge) GetTransactionStatus

func (b *Bridge) GetTransactionStatus(txHash string) (status *tokens.TxStatus, err error)

GetTransactionStatus impl

func (*Bridge) GetTxBlockInfo

func (b *Bridge) GetTxBlockInfo(txHash string) (blockHeight, blockTime uint64)

GetTxBlockInfo impl NonceSetter interface

func (*Bridge) InitAfterConfig

func (b *Bridge) InitAfterConfig()

InitAfterConfig init variables (ie. extra members) after loading config

func (*Bridge) InitRouterInfo

func (b *Bridge) InitRouterInfo(routerContract, routerVersion string) (err error)

InitRouterInfo init router info

func (*Bridge) IsValidAddress

func (b *Bridge) IsValidAddress(address string) bool

IsValidAddress check address

func (*Bridge) MPCSignTransaction

func (b *Bridge) MPCSignTransaction(rawTx interface{}, args *tokens.BuildTxArgs) (signedTx interface{}, txHash string, err error)

MPCSignTransaction mpc sign raw tx

func (*Bridge) PublicKeyToAddress

func (b *Bridge) PublicKeyToAddress(pubKeyHex string) (string, error)

PublicKeyToAddress public key hex string (may be uncompressed) to address

func (*Bridge) RegisterSwap

func (b *Bridge) RegisterSwap(txHash string, args *tokens.RegisterArgs) ([]*tokens.SwapTxInfo, []error)

RegisterSwap api

func (*Bridge) SendTransaction

func (b *Bridge) SendTransaction(signedTx interface{}) (txHash string, err error)

SendTransaction send signed tx

func (*Bridge) SetTokenConfig

func (b *Bridge) SetTokenConfig(tokenAddr string, tokenCfg *tokens.TokenConfig)

SetTokenConfig set and verify token config

func (*Bridge) SignTransactionWithPrivateKey

func (b *Bridge) SignTransactionWithPrivateKey(rawTx interface{}, privKey string) (signedTx interface{}, txHash string, err error)

SignTransactionWithPrivateKey sign tx with ECDSA private key string

func (*Bridge) VerifyMsgHash

func (b *Bridge) VerifyMsgHash(rawTx interface{}, msgHashes []string) (err error)

VerifyMsgHash verify msg hash

func (*Bridge) VerifyPubKey

func (b *Bridge) VerifyPubKey(address, pubkey string) error

func (*Bridge) VerifyTokenConfig

func (b *Bridge) VerifyTokenConfig(tokenCfg *tokens.TokenConfig) error

VerifyTokenConfig verify token config

func (*Bridge) VerifyTransaction

func (b *Bridge) VerifyTransaction(txHash string, args *tokens.VerifyArgs) (*tokens.SwapTxInfo, error)

VerifyTransaction impl

type CreateAccount

type CreateAccount struct {
	NewAccountId string `json:"new_account_id"`
	NewPublicKey string `json:"new_public_key"`
}

type DeleteAccount

type DeleteAccount struct {
	BeneficiaryID string
}

The DeleteAccount action.

type DeleteKey

type DeleteKey struct {
	PublicKey PublicKey
}

The DeleteKey action.

type DeployContract

type DeployContract struct {
	Code []byte
}

The DeployContract action.

type EcdsaPublic

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

EcdsaPublic struct ripple ecdsa pubkey key

func (*EcdsaPublic) Private

func (k *EcdsaPublic) Private(sequence *uint32) []byte

Private not used

func (*EcdsaPublic) Public

func (k *EcdsaPublic) Public(sequence *uint32) []byte

Public returns pubkey bytes

type FtSwapIn

type FtSwapIn struct {
	TxHash      string `json:"tx_hash"`
	ReceiverId  string `json:"receiver_id"`
	Amount      string `json:"amount"`
	FromChainId string `json:"from_chain_id"`
}

type FtTransfer

type FtTransfer struct {
	ReceiverId string `json:"receiver_id"`
	Amount     string `json:"amount"`
	Memo       string `json:"memo"`
}

type FunctionCall

type FunctionCall struct {
	MethodName string
	Args       []byte
	Gas        uint64
	Deposit    big.Int // u128
}

The FunctionCall action.

type FunctionCallPermission

type FunctionCallPermission struct {
	Allowance   *big.Int
	ReceiverID  string
	MethodNames []string
}

FunctionCallPermission encodes a NEAR function call permission (an access key permission).

type FunctionCallResult

type FunctionCallResult struct {
	BlockHash   string   `json:"block_hash"`
	BlockHeight uint64   `json:"block_height"`
	Logs        []string `json:"logs"`
	Result      []byte   `json:"result"`
	Error       string   `json:"error,omitempty"`
}

type FungibleTokenMetadata

type FungibleTokenMetadata struct {
	Spec          string `json:"spec"`
	Name          string `json:"name"`
	Symbol        string `json:"symbol"`
	Icon          string `json:"icon"`
	Reference     string `json:"reference"`
	ReferenceHash string `json:"reference_hash"`
	Decimals      uint8  `json:"decimals"`
}

type Nep141V4TransferEvent

type Nep141V4TransferEvent struct {
	Standard string                 `json:"standard"`
	Version  string                 `json:"version"`
	Event    string                 `json:"event"`
	Data     []Nep141V4TransferMemo `json:"data"`
}

type Nep141V4TransferMemo

type Nep141V4TransferMemo struct {
	OldOwnerId string `json:"old_owner_id"`
	NewOwnerId string `json:"new_owner_id"`
	Amount     string `json:"amount"`
	Memo       string `json:"memo"`
}

type Outcome

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

type Proof

type Proof struct {
	Direction string `json:"direction"`
	Hash      string `json:"hash"`
}

type PublicKey

type PublicKey struct {
	KeyType uint8
	Data    [32]byte
}

PublicKey encoding for NEAR.

func PublicKeyFromBytes

func PublicKeyFromBytes(pubKeyBytes []byte) (*PublicKey, error)

func PublicKeyFromEd25519

func PublicKeyFromEd25519(pk ed25519.PublicKey) *PublicKey

PublicKeyFromEd25519 derives a public key in NEAR encoding from pk.

func PublicKeyFromHexString

func PublicKeyFromHexString(pubKeyHex string) (*PublicKey, error)

func PublicKeyFromString

func PublicKeyFromString(pub string) (*PublicKey, error)

func (*PublicKey) Address

func (pk *PublicKey) Address() string

func (*PublicKey) Bytes

func (pk *PublicKey) Bytes() []byte

func (*PublicKey) String

func (pk *PublicKey) String() string

type RawTransaction

type RawTransaction struct {
	SignerID   string
	PublicKey  PublicKey
	Nonce      uint64
	ReceiverID string
	BlockHash  [32]byte
	Actions    []Action
}

A Transaction encodes a NEAR transaction.

func CreateTransaction

func CreateTransaction(
	signerID string,
	publicKey *PublicKey,
	receiverID string,
	nonce uint64,
	blockHash []byte,
	actions []Action,
) *RawTransaction

type ReceiptsOutcome

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

type Signature

type Signature struct {
	KeyType uint8
	Data    [64]byte
}

A Signature used for signing transaction.

type SignedTransaction

type SignedTransaction struct {
	Transaction RawTransaction
	Signature   Signature
}

type Stake

type Stake struct {
	Stake     big.Int // u128
	PublicKey PublicKey
}

The Stake action.

type Status

type Status struct {
	SuccessValue     interface{} `json:"SuccessValue,omitempty"`
	SuccessReceiptID interface{} `json:"SuccessReceiptId,omitempty"`
	Failure          interface{} `json:"Failure,omitempty"`
	Unknown          interface{} `json:"Unknown,omitempty"`
}

type Transaction

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

type TransactionOutcome

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

type TransactionResult

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

func GetTransactionByHash

func GetTransactionByHash(url, txHash, senderID string) (*TransactionResult, error)

GetTransactionByHash get tx by hash

type Transfer

type Transfer struct {
	Deposit big.Int
}

Directories

Path Synopsis
tools

Jump to

Keyboard shortcuts

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