polka

package
v0.0.0-...-3f3ae68 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilKey       = errors.New("no mnemonic or private key")
	ErrNilWallet    = errors.New("no mnemonic or private key or keystore")
	ErrNilKeystore  = errors.New("no keystore")
	ErrNilMetadata  = errors.New("no metadata")
	ErrNotSigned    = errors.New("transaction not signed")
	ErrNoPublicKey  = errors.New("transaction no public key")
	ErrNilExtrinsic = errors.New("nil extrinsic")
	ErrAddress      = errors.New("err address")
	ErrPublicKey    = errors.New("err publicKey")
	ErrSeedOrPhrase = errors.New("invalid seed length")

	ErrInvalidMnemonic = errors.New("invalid mnemonic")

	ErrWrongMetadata   = errors.New("wrong metadata")
	ErrNoEncrypted     = errors.New("no encrypted data to decode")
	ErrEncryptedLength = errors.New("encrypted length is less than 24")
	ErrInvalidParams   = errors.New("invalid injected scrypt params found")
	ErrSecretLength    = errors.New("secret length is not 32")
	ErrEncoded         = errors.New("encoded is nil")
	ErrPkcs8Header     = errors.New("invalid Pkcs8 header found in body")
	ErrPkcs8Divider    = errors.New("invalid Pkcs8 divider found in body")

	ErrNonPkcs8        = errors.New("unable to decode non-pkcs8 type")
	ErrNilPassword     = errors.New("password required to decode encrypted data")
	ErrNoEncryptedData = errors.New("no encrypted data available to decode")
	ErrKeystore        = errors.New("decoded public keys are not equal")

	ErrPassword = errors.New("password err")

	ErrNumber = errors.New("illegal number")
	ErrSign   = errors.New("sign panic error")
)

Functions

func ByteToHex

func ByteToHex(data []byte) string

func DecodeAddressToPublicKey

func DecodeAddressToPublicKey(address string) (string, error)

@return publicKey that will start with 0x.

func EncodePublicKeyToAddress

func EncodePublicKeyToAddress(publicKey string, network int) (string, error)

@param publicKey can start with 0x or not.

func HexToByte

func HexToByte(hex string) ([]byte, error)

func IsValidAddress

func IsValidAddress(address string) bool

@param chainnet chain name

Types

type Account

type Account struct {
	Network int
	// contains filtered or unexported fields
}

func AccountWithPrivateKey

func AccountWithPrivateKey(prikey string, network int) (*Account, error)

func AsPolkaAccount

func AsPolkaAccount(account base.Account) *Account

func NewAccountWithKeystore

func NewAccountWithKeystore(keystoreString, password string, network int) (*Account, error)

func NewAccountWithMnemonic

func NewAccountWithMnemonic(mnemonic string, network int) (*Account, error)

func (*Account) Address

func (a *Account) Address() string

@return address string

func (*Account) DecodeAddressToPublicKey

func (a *Account) DecodeAddressToPublicKey(address string) (string, error)

@return publicKey that will start with 0x.

func (*Account) DeriveAccountAt

func (a *Account) DeriveAccountAt(network int) (*Account, error)

func (*Account) EncodePublicKeyToAddress

func (a *Account) EncodePublicKeyToAddress(publicKey string) (string, error)

@param publicKey can start with 0x or not.

func (*Account) IsValidAddress

func (a *Account) IsValidAddress(address string) bool

func (*Account) PrivateKey

func (a *Account) PrivateKey() ([]byte, error)

@return privateKey data

func (*Account) PrivateKeyHex

func (a *Account) PrivateKeyHex() (string, error)

@return privateKey string that will start with 0x.

func (*Account) PublicKey

func (a *Account) PublicKey() []byte

@return publicKey data

func (*Account) PublicKeyHex

func (a *Account) PublicKeyHex() string

@return publicKey string that will start with 0x.

func (*Account) Sign

func (a *Account) Sign(message []byte, password string) (data []byte, err error)

func (*Account) SignHex

func (a *Account) SignHex(messageHex string, password string) (*base.OptionalString, error)

type Chain

type Chain struct {
	RpcUrl  string
	ScanUrl string
}

func NewChainWithRpc

func NewChainWithRpc(rpcUrl, scanUrl string) (*Chain, error)

@param rpcUrl will be used to get metadata, query balance, estimate fee, send signed tx. @param scanUrl will be used to query transaction details

func (*Chain) BalanceOfAccount

func (c *Chain) BalanceOfAccount(account base.Account) (*base.Balance, error)

func (*Chain) BalanceOfAddress

func (c *Chain) BalanceOfAddress(address string) (*base.Balance, error)

func (*Chain) BalanceOfPublicKey

func (c *Chain) BalanceOfPublicKey(publicKey string) (*base.Balance, error)

func (*Chain) BatchFetchTransactionStatus

func (c *Chain) BatchFetchTransactionStatus(hashListString string) string

func (*Chain) EstimateTransactionFee

func (c *Chain) EstimateTransactionFee(transaction base.Transaction) (fee *base.OptionalString, err error)

func (*Chain) EstimateTransactionFeeUsePublicKey

func (c *Chain) EstimateTransactionFeeUsePublicKey(transaction base.Transaction, pubkey string) (fee *base.OptionalString, err error)

func (*Chain) FetchScriptHashForMiniX

func (c *Chain) FetchScriptHashForMiniX(transferTo, amount string) (sh *MiniXScriptHash, err error)

获取 mini 多签转账时需要的 scriptHash @param transferTo 转账目标地址 @param amount 要转出的金额

func (*Chain) FetchTransactionDetail

func (c *Chain) FetchTransactionDetail(hashString string) (*base.TransactionDetail, error)

func (*Chain) FetchTransactionStatus

func (c *Chain) FetchTransactionStatus(hashString string) base.TransactionStatus

func (*Chain) GetMetadataString

func (c *Chain) GetMetadataString() (string, error)

Get the metadata string of the chain (if not, it will be downloaded automatically)

func (*Chain) GetSignData

func (c *Chain) GetSignData(t *Transaction, walletAddress string) (data []byte, err error)

功能和 GetSignData 相同,不需要提供 nonce, version 等参数,但需要提供 chain 对象和地址

func (*Chain) GetTx

func (c *Chain) GetTx() (*Tx, error)

func (*Chain) LoadCachedMetadataString

func (c *Chain) LoadCachedMetadataString(metadataString string) error

Load cached metadata string. This will save a lot of network traffic to download metadata from rpcUrl.

func (*Chain) MainToken

func (c *Chain) MainToken() base.Token

func (*Chain) ReloadMetadata

func (c *Chain) ReloadMetadata() (string, error)

Reload the latest metadata of this chain. @return the latest metadata string

func (*Chain) RpcCall

func (c *Chain) RpcCall(result interface{}, method string, params ...any) error

func (*Chain) SendRawTransaction

func (c *Chain) SendRawTransaction(signedTx string) (s string, err error)

func (*Chain) SendSignedTransaction

func (c *Chain) SendSignedTransaction(signedTxn base.SignedTransaction) (hash *base.OptionalString, err error)

type MiniXScriptHash

type MiniXScriptHash struct {
	ScriptHash  string
	BlockNumber int32
}

type Token

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

func NewToken

func NewToken(chain *Chain) *Token

func (*Token) BalanceOfAccount

func (t *Token) BalanceOfAccount(account base.Account) (*base.Balance, error)

func (*Token) BalanceOfAddress

func (t *Token) BalanceOfAddress(address string) (*base.Balance, error)

func (*Token) BalanceOfPublicKey

func (t *Token) BalanceOfPublicKey(publicKey string) (*base.Balance, error)

func (*Token) BuildTransfer

func (t *Token) BuildTransfer(sender, receiver, amount string) (txn base.Transaction, err error)

func (*Token) BuildTransferAll

func (t *Token) BuildTransferAll(sender, receiver string) (txn base.Transaction, err error)

func (*Token) CanTransferAll

func (t *Token) CanTransferAll() bool

func (*Token) Chain

func (t *Token) Chain() base.Chain

func (*Token) TokenInfo

func (t *Token) TokenInfo() (*base.TokenInfo, error)

Warning: polka chain is not currently supported

type Transaction

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

func (*Transaction) GetSignData

func (t *Transaction) GetSignData(genesisHashString string, nonce int64, specVersion, transVersion int32) ([]byte, error)

func (*Transaction) GetTx

func (t *Transaction) GetTx(signerPublicKey []byte, signatureData []byte) (string, error)

func (*Transaction) GetTxFromHex

func (t *Transaction) GetTxFromHex(signerPublicKeyHex string, signatureDataHex string) (string, error)

func (*Transaction) GetUnSignTx

func (t *Transaction) GetUnSignTx() (string, error)

func (*Transaction) SignWithAccount

func (t *Transaction) SignWithAccount(account base.Account) (signedTx *base.OptionalString, err error)

func (*Transaction) SignedTransactionWithAccount

func (t *Transaction) SignedTransactionWithAccount(account base.Account) (signedTx base.SignedTransaction, err error)

type Tx

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

func NewTx

func NewTx(metadataString string) (*Tx, error)

func (*Tx) NewBalanceTransferTx

func (t *Tx) NewBalanceTransferTx(dest, amount string) (*Transaction, error)

func (*Tx) NewComingNftTransferTx

func (t *Tx) NewComingNftTransferTx(dest string, cid int64) (*Transaction, error)

func (*Tx) NewExtrinsics

func (t *Tx) NewExtrinsics(call string, args ...interface{}) (*Transaction, error)

func (*Tx) NewThreshold

func (t *Tx) NewThreshold(thresholdPublicKey, destAddress, aggSignature, aggPublicKey, controlBlock, message, scriptHash, transferAmount string, blockNumber int32) (*Transaction, error)

func (*Tx) NewTransactionFromHex

func (t *Tx) NewTransactionFromHex(txHex string) (*Transaction, error)

func (*Tx) NewXAssetsTransferTx

func (t *Tx) NewXAssetsTransferTx(dest, amount string) (*Transaction, error)

func (*Tx) NewXGatewayBitcoinCreateTaprootWithdrawTx

func (t *Tx) NewXGatewayBitcoinCreateTaprootWithdrawTx(ids, transactionHex string) (*Transaction, error)

type Util

type Util struct {
	Network int
}

func NewUtilWithNetwork

func NewUtilWithNetwork(network int) *Util

func (*Util) DecodeAddressToPublicKey

func (u *Util) DecodeAddressToPublicKey(address string) (string, error)

@return publicKey that will start with 0x.

func (*Util) EncodePublicKeyToAddress

func (u *Util) EncodePublicKeyToAddress(publicKey string) (string, error)

@param publicKey can start with 0x or not.

func (*Util) IsValidAddress

func (u *Util) IsValidAddress(address string) bool

Jump to

Keyboard shortcuts

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