aptos

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: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxGasAmount = 20000
	GasPrice     = 100
	TxExpireSec  = 600

	FaucetUrlDevnet  = "https://faucet.devnet.aptoslabs.com"
	FaucetUrlTestnet = "https://faucet.testnet.aptoslabs.com"
)
View Source
const (
	GraphUrlMainnet = graphql.GraphUrlMainnet
	GraphUrlTestnet = graphql.GraphUrlTestnet
)
View Source
const (
	AptosName    = "APT"
	AptosSymbol  = "APT"
	AptosDecimal = 0
)

Variables

This section is empty.

Functions

func DecodeAddressToPublicKey

func DecodeAddressToPublicKey(address string) (string, error)

func EncodePublicKeyToAddress

func EncodePublicKeyToAddress(publicKey string) (string, error)

@param publicKey can start with 0x or not.

func FaucetFundAccount

func FaucetFundAccount(address string, amount int64, faucetUrl string) (h *base.OptionalString, err error)

*

  • This creates an account if it does not exist and mints the specified amount of
  • coins into that account
  • @param address Hex-encoded 16 bytes Aptos account address wich mints tokens
  • @param amount Amount of tokens to mint
  • @param faucetUrl default https://faucet.devnet.aptoslabs.com
  • @returns Hashes of submitted transactions, e.g. "hash1,has2,hash3,..."

func IsValidAddress

func IsValidAddress(address string) bool

@param chainnet chain name

Types

type Account

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

func AccountWithPrivateKey

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

rename for support android. Android cant support both NewAccountWithMnemonic(string) and NewAccountWithPrivateKey(string)

func AsAptosAccount

func AsAptosAccount(account base.Account) *Account

func NewAccountWithMnemonic

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

func (*Account) Address

func (a *Account) Address() string

func (*Account) DecodeAddressToPublicKey

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

@return publicKey that will start with 0x.

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) ([]byte, error)

func (*Account) SignHex

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

type Chain

type Chain struct {
	RestUrl string
	// contains filtered or unexported fields
}

func NewChainWithRestUrl

func NewChainWithRestUrl(restUrl string) *Chain

func (*Chain) BalanceOfAccount

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

func (*Chain) BalanceOfAddress

func (c *Chain) BalanceOfAddress(address string) (b *base.Balance, err 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) EstimateGasPrice

func (c *Chain) EstimateGasPrice() (*base.OptionalString, error)

func (*Chain) EstimateMaxGasAmountBCS

func (c *Chain) EstimateMaxGasAmountBCS(publicKey []byte, rawTxn *txbuilder.RawTransaction) (uint64, error)

func (*Chain) EstimatePayloadGasFeeBCS

func (c *Chain) EstimatePayloadGasFeeBCS(account base.Account, data []byte) (*base.OptionalString, error)

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) FetchTransactionDetail

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

Fetch transaction details through transaction hash

func (*Chain) FetchTransactionStatus

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

func (*Chain) GenerateTransaction

func (c *Chain) GenerateTransaction(senderPublicKey string, payload aptostypes.Payload) (txn *aptostypes.Transaction, err error)

func (*Chain) GenerateTransactionJson

func (c *Chain) GenerateTransactionJson(senderPublicKey string, payload string) (*base.OptionalString, error)

func (*Chain) GetClient

func (c *Chain) GetClient() (*aptosclient.RestClient, error)

func (*Chain) IsAllowedDirectTransferToken

func (c *Chain) IsAllowedDirectTransferToken(account string) (*base.OptionalBool, error)

func (*Chain) MainToken

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

func (*Chain) SendRawTransaction

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

Send the raw transaction on-chain @return the hex hash string

func (*Chain) SendSignedTransaction

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

func (*Chain) SignAndSendTransaction

func (c *Chain) SignAndSendTransaction(account base.Account, hexData string) (*base.OptionalString, error)

func (*Chain) SignMessage

func (c *Chain) SignMessage(account base.Account, payload *SignMessagePayload) (*SignMessageResponse, error)

func (*Chain) SignMessageJson

func (c *Chain) SignMessageJson(account base.Account, payload string) (*SignMessageResponse, error)

func (*Chain) SignTransaction

func (c *Chain) SignTransaction(account base.Account, transaction aptostypes.Transaction) (txn *aptostypes.Transaction, err error)

func (*Chain) SignTransactionJson

func (c *Chain) SignTransactionJson(account base.Account, transaction string) (*base.OptionalString, error)

func (*Chain) SubmitTransaction

func (c *Chain) SubmitTransaction(signedTxn aptostypes.Transaction) (txhash string, err error)

func (*Chain) SubmitTransactionJson

func (c *Chain) SubmitTransactionJson(signedTxn string) (*base.OptionalString, error)

func (*Chain) SubmitTransactionPayloadBCS

func (c *Chain) SubmitTransactionPayloadBCS(account base.Account, data []byte) (string, error)

type IChain

type IChain interface {
	base.Chain
	SubmitTransactionPayloadBCS(account base.Account, data []byte) (string, error)
	EstimatePayloadGasFeeBCS(account base.Account, data []byte) (*base.OptionalString, error)
	GetClient() (*aptosclient.RestClient, error)
}

type NFTFetcher

type NFTFetcher struct {
	Chain *Chain

	GraphUrl string
	// contains filtered or unexported fields
}

func NewNFTFetcher

func NewNFTFetcher(graphUrl string) *NFTFetcher

Default is `GraphUrlMainnet` if graphUrl is emptry.

func NewNFTFetcherWithChain deprecated

func NewNFTFetcherWithChain(chain *Chain) *NFTFetcher

Deprecated: use `NewNFTFetcher(graphUrl)`

func (*NFTFetcher) FetchNFTs

func (f *NFTFetcher) FetchNFTs(owner string) (map[string][]*base.NFT, error)

func (*NFTFetcher) FetchNFTsFilterByCreatorAddr

func (f *NFTFetcher) FetchNFTsFilterByCreatorAddr(owner, creatorAddress string) ([]*base.NFT, error)

func (*NFTFetcher) FetchNFTsJsonString

func (f *NFTFetcher) FetchNFTsJsonString(owner string) (*base.OptionalString, error)

type NFTPayloadBCSBuilder

type NFTPayloadBCSBuilder struct {
	// The contract provider for the CID module. Default is `0xc73d3c0a171c871e1858414734c7776f0b0cfa567c2af7f0070d1436aab2306b`
	CIDContract string
}

* BCS Payload builder for NFT (include Coming CID)

### Demo
example for `CIDTokenTransferPayload`
```
var payload, err = builder.CIDTokenTransferPayload(1234, receiverAddress)
var gasPrice, err = chain.EstimateGasPrice()
var gasAmount, err := chain.EstimatePayloadGasFeeBCS(account, payload)
print("estimate gas fee = %s", gasPrice * gasAmount)
var hash, err = chain.SubmitTransactionPayloadBCS(account, payload)
print("submited hash = %s", hash)
```

func NewNFTPayloadBCSBuilder

func NewNFTPayloadBCSBuilder(contractAddress string) *NFTPayloadBCSBuilder

func (*NFTPayloadBCSBuilder) CIDAllowDirectTransferPayload

func (b *NFTPayloadBCSBuilder) CIDAllowDirectTransferPayload() ([]byte, error)

func (*NFTPayloadBCSBuilder) CIDRegister

func (b *NFTPayloadBCSBuilder) CIDRegister(cid uint64) ([]byte, error)

func (*NFTPayloadBCSBuilder) CIDTokenTransferPayload

func (b *NFTPayloadBCSBuilder) CIDTokenTransferPayload(cid int64, toReceiver string) ([]byte, error)

func (*NFTPayloadBCSBuilder) CancelTokenOffer

func (b *NFTPayloadBCSBuilder) CancelTokenOffer(receiver, creator, collection, name string) ([]byte, error)

func (*NFTPayloadBCSBuilder) ClaimTokenFromHash

func (b *NFTPayloadBCSBuilder) ClaimTokenFromHash(offerHash string, chain *Chain, receiver string) (res []byte, err error)

* Build payload that claim token, the nft info will be obtaining through offer hash.

  • @param offerHash The submitted hash of the transaction that offer the token
  • @param chain The chain on which the transaction resides
  • @param receiver The token receiver will be check whether it matches the nft offer information.
  • @return The claim token payload

func (*NFTPayloadBCSBuilder) ClaimTokenTransactionParams

func (b *NFTPayloadBCSBuilder) ClaimTokenTransactionParams(sender, creator, collection, name string) ([]byte, error)

* Build payload that claim token

  • @param sender The transferred token owner
  • @param creator The token creator
  • @param collection The token's collection name
  • @param name The token's name
  • @return The claim token payload.

func (*NFTPayloadBCSBuilder) OfferTokenTransactionNFT

func (b *NFTPayloadBCSBuilder) OfferTokenTransactionNFT(receiver string, nft *base.NFT) ([]byte, error)

func (*NFTPayloadBCSBuilder) OfferTokenTransactionParams

func (b *NFTPayloadBCSBuilder) OfferTokenTransactionParams(receiver, creator, collection, name string) ([]byte, error)

* Build payload that offer token

  • @param receiver The token receiver
  • @param creator The token creator
  • @param collection The token's collection name
  • @param name The token's name
  • @return The offer token payload.

func (*NFTPayloadBCSBuilder) TokenTransferPayload

func (b *NFTPayloadBCSBuilder) TokenTransferPayload(receiver, creator, collectionName, tokenName string, tokenVersion, amount int64) ([]byte, error)

Note: The `tokenVersion`, `amount` should be uint64, but it is not supported by the SDK generated by gomobile.

type RestReachability

type RestReachability struct {
}

func NewRestReachability

func NewRestReachability() *RestReachability

func (*RestReachability) LatencyOf

func (r *RestReachability) LatencyOf(rpc string, timeout int64) (l *base.RpcLatency, err error)

@return latency (ms) of rpc query blockNumber. -1 means the connection failed.

type SignMessagePayload

type SignMessagePayload struct {
	// Should we include the address of the account in the message
	Address bool `json:"address,omitempty"`
	// Should we include the domain of the dApp
	Application bool `json:"application,omitempty"`
	// Should we include the current chain id the wallet is connected to
	ChainId bool `json:"chainId,omitempty"`
	// The message to be signed and displayed to the user
	Message string `json:"message"`
	// A nonce the dApp should generate
	Nonce int64 `json:"nonce"`
}

func (*SignMessagePayload) JsonString

func (j *SignMessagePayload) JsonString() string

type SignMessageResponse

type SignMessageResponse struct {
	Address     string `json:"address,omitempty"`
	Application string `json:"application,omitempty"`
	ChainId     int64  `json:"chainId,omitempty"`
	Message     string `json:"message"` // The message passed in by the user
	Nonce       int64  `json:"nonce"`
	Prefix      string `json:"prefix"`           // Should always be APTOS
	FullMessage string `json:"fullMessage"`      // The message that was generated to sign
	Signature   string `json:"signature"`        // The signed full message
	Bitmap      []byte `json:"bitmap,omitempty"` // a 4-byte (32 bits) bit-vector of length N
}

func (*SignMessageResponse) JsonString

func (j *SignMessageResponse) JsonString() string

type SignedTransaction

type SignedTransaction struct {
	RawTxn *txbuilder.RawTransaction

	SignedBytes []byte
}

func AsSignedTransaction

func AsSignedTransaction(txn base.SignedTransaction) *SignedTransaction

func (*SignedTransaction) HexString

func (txn *SignedTransaction) HexString() (res *base.OptionalString, err error)

type Token

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

func NewMainToken

func NewMainToken(chain *Chain) *Token

func NewToken

func NewToken(chain *Chain, tag string) (*Token, error)

@param tag format `address::module_name::name`, e.g. "0x1::aptos_coin::AptosCoin"

func (*Token) BalanceOfAccount

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

func (*Token) BalanceOfAddress

func (t *Token) BalanceOfAddress(address string) (b *base.Balance, err 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) BuildTransferTx deprecated

func (t *Token) BuildTransferTx(privateKey, receiverAddress, amount string) (*base.OptionalString, error)

Deprecated: use `BuildTransfer()`

func (*Token) BuildTransferTxWithAccount deprecated

func (t *Token) BuildTransferTxWithAccount(account *Account, receiverAddress, amount string) (*base.OptionalString, error)

Deprecated: use `BuildTransfer()`

func (*Token) CanTransferAll

func (t *Token) CanTransferAll() bool

func (*Token) Chain

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

func (*Token) EnsureOwnerRegistedToken

func (t *Token) EnsureOwnerRegistedToken(owner *Account) (*base.OptionalString, error)

func (*Token) EstimateFees deprecated

func (t *Token) EstimateFees(account *Account, receiverAddress, amount string) (f *base.OptionalString, err error)

Deprecated: use `BuildTransfer() & chain.EstimateTransactionFeeUsePublicKey()`

func (*Token) HasRegisted

func (t *Token) HasRegisted(ownerAddress string) (b *base.OptionalBool, err error)

func (*Token) RegisterTokenForOwner

func (t *Token) RegisterTokenForOwner(owner *Account) (s *base.OptionalString, err error)

@return transaction hash if register token succeed.

func (*Token) TokenInfo

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

type Transaction

type Transaction struct {
	RawTxn txbuilder.RawTransaction
}

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 Util

type Util struct {
}

func NewUtil

func NewUtil() (*Util, error)

func (*Util) DecodeAddressToPublicKey

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

Warning: Aptos cannot support decode address to public key

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