aptos

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

README

aptos-go-sdk

Aptos Go SDK

TODO List

Milestone 1 (Reading from chain)
  1. BCS Support
    • 90%? Works but more interoperability testing is always good.
  2. sequence number reading
  3. Account / object resource listing
    • Good. JSON map[string]any mode and BCS mode.
  4. Transaction waiting / reads (by hash)
    • Rough. TransactionByHash() returns map[string]any rather than struct.
Milestone 2 (Creating accounts)
  1. Faucet support
Milestone 3 (Writing to chain)
  1. ED25519 Private key support
  2. Transaction submission (no fee payer)
Milestone 4 (View functions)
Miscellaneous after
  1. Object address derivation
  2. Indexer reading support
  3. Transaction reading by version
  4. View functions

Documentation

Index

Constants

View Source
const (
	Ed25519Scheme      = uint8(0)
	MultiEd25519Scheme = uint8(1)
	SingleKeyScheme    = uint8(2)
	MultiKeyScheme     = uint8(3)
)

Seeds for deriving addresses from addresses

View Source
const (
	TransactionPayload_Script        = 0
	TransactionPayload_ModuleBundle  = 1 // Deprecated
	TransactionPayload_EntryFunction = 2
	TransactionPayload_Multisig      = 3 // TODO? defined in aptos-core/types/src/transaction/mod.rs
)
View Source
const APTOS_CLIENT_HEADER = "x-aptos-client"
View Source
const APTOS_SIGNED_BCS = "application/x.aptos.signed_transaction+bcs"

For Content-Type header when POST-ing a Transaction

View Source
const APTOS_VIEW_BCS = "application/x.aptos.view_function+bcs"
View Source
const HTTP_ERR_SUMMARY_LEN = 100

Variables

View Source
var AccountFour = AccountAddress{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4}
View Source
var AccountOne = AccountAddress{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
View Source
var AccountThree = AccountAddress{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3}
View Source
var AccountTwo = AccountAddress{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
View Source
var AccountZero = AccountAddress{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
View Source
var AptosClientHeaderValue = "aptos-go-sdk/unk"
View Source
var DevnetConfig = NetworkConfig{
	Name:       "devnet",
	NodeUrl:    "https://api.devnet.aptoslabs.com/v1",
	IndexerUrl: "",
	FaucetUrl:  "https://faucet.devnet.aptoslabs.com/",
}
View Source
var ErrAddressTooLong = errors.New("AccountAddress too long")
View Source
var ErrAddressTooShort = errors.New("AccountAddress too short")
View Source
var ErrUnknownNetworkName = errors.New("Unknown network name")
View Source
var LocalnetConfig = NetworkConfig{
	Name:       "localnet",
	ChainId:    4,
	NodeUrl:    "http://localhost:8080/v1",
	IndexerUrl: "",
	FaucetUrl:  "http://localhost:8081/v1",
}
View Source
var MainnetConfig = NetworkConfig{
	Name:       "mainnet",
	ChainId:    1,
	NodeUrl:    "https://api.mainnet.aptoslabs.com/v1",
	IndexerUrl: "",
	FaucetUrl:  "",
}
View Source
var NamedNetworks map[string]NetworkConfig

Map from network name to NetworkConfig

View Source
var TestnetConfig = NetworkConfig{
	Name:       "testnet",
	ChainId:    2,
	NodeUrl:    "https://api.testnet.aptoslabs.com/v1",
	IndexerUrl: "",
	FaucetUrl:  "https://faucet.testnet.aptoslabs.com/",
}

Functions

func BcsDeserialize

func BcsDeserialize(dest BCSStruct, bcsBlob []byte) error

func BcsSerialize

func BcsSerialize(value BCSStruct) (bcsBlob []byte, err error)

func DeserializeMapToSlices

func DeserializeMapToSlices[K, V any](bcs *Deserializer) (keys []K, values []V)

DeserializeMapToSlices returns two slices []K and []V of equal length that are equivalent to map[K]V but may represent types that are not valid Go map keys.

func DeserializeSequence

func DeserializeSequence[T any](bcs *Deserializer) []T

func GenerateEd5519Keys

func GenerateEd5519Keys() (privkey Ed25519PrivateKey, pubkey Ed25519PublicKey, err error)

func ParseHex

func ParseHex(hexStr string) ([]byte, error)

ParseHex Convenience function to deal with 0x at the beginning of hex strings

func RawTransactionPrehash

func RawTransactionPrehash() []byte

Return the sha3-256 prehash for RawTransaction Do not write to the []byte returned

func SHA3_256Hash

func SHA3_256Hash(bytes [][]byte) (output []byte)

func SerializeSequence

func SerializeSequence[AT []T, T any](x AT, bcs *Serializer)

func ToU128OrU256

func ToU128OrU256(val string) (num *big.Int, err error)

TODO: move somewhere more useful

func ToU64

func ToU64(val string) (uint64, error)

TODO: Move somewhere more useful

Types

type Account

type Account struct {
	Address AccountAddress
	Signer  Signer
}

Account represents an onchain account, with an associated signer, which may be a PrivateKey

func NewEd25519Account

func NewEd25519Account() (*Account, error)

NewEd25519Account creates an account with a new random Ed25519 private key

func (*Account) Sign

func (account *Account) Sign(message []byte) (authenticator Authenticator, err error)

Sign signs a message, returning an appropriate authenticator for the signer

type AccountAddress

type AccountAddress [32]byte

AccountAddress a 32-byte representation of an onchain address

func (*AccountAddress) DerivedAddress

func (aa *AccountAddress) DerivedAddress(seed []byte, typeByte uint8) (accountAddress AccountAddress)

DerivedAddress addresses are derived by the address, the seed, then the type byte

func (*AccountAddress) FromPublicKey

func (aa *AccountAddress) FromPublicKey(pubkey PublicKey)

FromPublicKey Generates an account address from a public key using the appropriate account address scheme

func (*AccountAddress) IsSpecial

func (aa *AccountAddress) IsSpecial() bool

IsSpecial Returns whether the address is a "special" address. Addresses are considered special if the first 63 characters of the hex string are zero. In other words, an address is special if the first 31 bytes are zero and the last byte is smaller than `0b10000` (16). In other words, special is defined as an address that matches the following regex: `^0x0{63}[0-9a-f]$`. In short form this means the addresses in the range from `0x0` to `0xf` (inclusive) are special. For more details see the v1 address standard defined as part of AIP-40: https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md

func (AccountAddress) MarshalBCS

func (aa AccountAddress) MarshalBCS(bcs *Serializer)

MarshalBCS Converts the AccountAddress to BCS encoded bytes

func (*AccountAddress) NamedObjectAddress

func (aa *AccountAddress) NamedObjectAddress(seed []byte) (accountAddress AccountAddress)

NamedObjectAddress derives a named object address based on the input address as the creator

func (*AccountAddress) ObjectAddressFromObject

func (aa *AccountAddress) ObjectAddressFromObject(objectAddress *AccountAddress) (accountAddress AccountAddress)

ObjectAddressFromObject derives a object address based on the input address as the creator object

func (*AccountAddress) ParseStringRelaxed

func (aa *AccountAddress) ParseStringRelaxed(x string) error

ParseStringRelaxed parses a string into an AccountAddress TODO: add strict mode checking

func (*AccountAddress) Random

func (aa *AccountAddress) Random()

Random generates a random account address, mainly for testing

func (*AccountAddress) ResourceAccount

func (aa *AccountAddress) ResourceAccount(seed []byte) (accountAddress AccountAddress)

ResourceAccount derives a object address based on the input address as the creator

func (*AccountAddress) String

func (aa *AccountAddress) String() string

String Returns the canonical string representation of the AccountAddress

func (*AccountAddress) UnmarshalBCS

func (aa *AccountAddress) UnmarshalBCS(bcs *Deserializer)

UnmarshalBCS Converts the AccountAddress from BCS encoded bytes

type AccountAddressTag

type AccountAddressTag struct {
	Value AccountAddress
}

func (*AccountAddressTag) GetType

func (xt *AccountAddressTag) GetType() TypeTagType

func (*AccountAddressTag) MarshalBCS

func (xt *AccountAddressTag) MarshalBCS(bcs *Serializer)

func (*AccountAddressTag) UnmarshalBCS

func (xt *AccountAddressTag) UnmarshalBCS(bcs *Deserializer)

type AccountInfo

type AccountInfo struct {
	SequenceNumberStr    string `json:"sequence_number"`
	AuthenticationKeyHex string `json:"authentication_key"`
}

AccountInfo is returned from calls to #Account()

func (AccountInfo) AuthenticationKey

func (ai AccountInfo) AuthenticationKey() ([]byte, error)

AuthenticationKey Hex decode of AuthenticationKeyHex

func (AccountInfo) SequenceNumber

func (ai AccountInfo) SequenceNumber() (uint64, error)

SequenceNumber ParseUint of SequenceNumberStr

type AccountResourceInfo

type AccountResourceInfo struct {
	// e.g. "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>"
	Type string `json:"type"`

	// Decoded from Move contract data, could really be anything
	Data map[string]any `json:"data"`
}

AccountResourceInfo is returned by #AccountResource() and #AccountResources()

type AccountResourceRecord

type AccountResourceRecord struct {
	// Account::Module::Name
	Tag StructTag

	// BCS data as stored by Move contract
	Data []byte
}

AccountResourceRecord DeserializeSequence[AccountResourceRecord](bcs) approximates the Rust side BTreeMap<StructTag,Vec<u8>> They should BCS the same with a prefix Uleb128 length followed by (StructTag,[]byte) pairs.

func (*AccountResourceRecord) MarshalBCS

func (aar *AccountResourceRecord) MarshalBCS(bcs *Serializer)

func (*AccountResourceRecord) UnmarshalBCS

func (aar *AccountResourceRecord) UnmarshalBCS(bcs *Deserializer)

type Authenticator

type Authenticator struct {
	Kind AuthenticatorType
	Auth AuthenticatorImpl
}

func (*Authenticator) MarshalBCS

func (ea *Authenticator) MarshalBCS(bcs *Serializer)

func (*Authenticator) UnmarshalBCS

func (ea *Authenticator) UnmarshalBCS(bcs *Deserializer)

func (*Authenticator) Verify

func (ea *Authenticator) Verify(data []byte) bool

type AuthenticatorImpl

type AuthenticatorImpl interface {
	BCSStruct

	// Verify Return true if this Authenticator approves
	Verify(data []byte) bool
}

type AuthenticatorType

type AuthenticatorType uint8

AuthenticatorType single byte representing the spot in the enum from the Rust implementation

const (
	AuthenticatorEd25519      AuthenticatorType = 0
	AuthenticatorMultiEd25519 AuthenticatorType = 1
	AuthenticatorMultiAgent   AuthenticatorType = 2
	AuthenticatorFeePayer     AuthenticatorType = 3
	AuthenticatorSingleSender AuthenticatorType = 4
)

type BCSStruct

type BCSStruct interface {
	MarshalBCS(*Serializer)
	UnmarshalBCS(*Deserializer)
}

type BoolTag

type BoolTag struct {
	Value bool
}

func (*BoolTag) GetType

func (xt *BoolTag) GetType() TypeTagType

func (*BoolTag) MarshalBCS

func (xt *BoolTag) MarshalBCS(bcs *Serializer)

func (*BoolTag) String

func (xt *BoolTag) String() string

func (*BoolTag) UnmarshalBCS

func (xt *BoolTag) UnmarshalBCS(bcs *Deserializer)

type ChainIdOption

type ChainIdOption uint8

ChainIdOption is an option to APTTransferTransaction

type Client

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

Client is a facade over the multiple types of underlying clients, as the user doesn't actually care where the data comes from. It will be then handled underneath

func NewClient

func NewClient(config NetworkConfig) (client *Client, err error)

NewClient Creates a new client with a specific network config that can be extended in the future

func NewClientFromNetworkName

func NewClientFromNetworkName(networkName string) (client *Client, err error)

NewClientFromNetworkName Creates a new client for a specific network name

func (*Client) Account

func (client *Client) Account(address AccountAddress, ledgerVersion ...int) (info AccountInfo, err error)

Account Retrieves information about the account such as SequenceNumber and AuthenticationKey

func (*Client) AccountResource

func (client *Client) AccountResource(address AccountAddress, resourceType string, ledgerVersion ...int) (data map[string]any, err error)

AccountResource Retrieves a single resource given its struct name. Can also fetch at a specific ledger version

func (*Client) AccountResources

func (client *Client) AccountResources(address AccountAddress, ledgerVersion ...int) (resources []AccountResourceInfo, err error)

AccountResources fetches resources for an account into a JSON-like map[string]any in AccountResourceInfo.Data For fetching raw Move structs as BCS, See #AccountResourcesBCS

func (*Client) AccountResourcesBCS

func (client *Client) AccountResourcesBCS(address AccountAddress, ledgerVersion ...int) (resources []AccountResourceRecord, err error)

AccountResourcesBCS fetches account resources as raw Move struct BCS blobs in AccountResourceRecord.Data []byte

func (*Client) BuildSignAndSubmitTransaction

func (client *Client) BuildSignAndSubmitTransaction(sender *Account, payload TransactionPayload, options ...any) (hash string, err error)

BuildSignAndSubmitTransaction Convenience function to do all three in one for more configuration, please use them separately

func (*Client) BuildTransaction

func (client *Client) BuildTransaction(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransaction, err error)

BuildTransaction Builds a raw transaction from the payload and fetches any necessary information from onchain

func (*Client) Fund

func (client *Client) Fund(address AccountAddress, amount uint64) error

Fund Uses the faucet to fund an address, only applies to non-production networks

func (*Client) GetChainId

func (client *Client) GetChainId() (chainId uint8, err error)

GetChainId Retrieves the ChainId of the network Note this will be cached forever, or taken directly from the config

func (*Client) Info

func (client *Client) Info() (info NodeInfo, err error)

Info Retrieves the node info about the network and it's current state

func (*Client) PollForTransactions

func (client *Client) PollForTransactions(txnHashes []string, options ...any) error

PollForTransactions Waits up to 10 seconds for transactions to be done, polling at 10Hz Accepts options PollPeriod and PollTimeout which should wrap time.Duration values.

func (*Client) SetTimeout

func (client *Client) SetTimeout(timeout time.Duration)

SetTimeout adjusts the HTTP client timeout

func (*Client) SubmitTransaction

func (client *Client) SubmitTransaction(signedTransaction *SignedTransaction) (data map[string]any, err error)

SubmitTransaction Submits an already signed transaction to the blockchain

func (*Client) TransactionByHash

func (client *Client) TransactionByHash(txnHash string) (data map[string]any, err error)

TransactionByHash gets info on a transaction The transaction may be pending or recently committed.

data, err := c.TransactionByHash("0xabcd")
if err != nil {
	if httpErr, ok := err.(aptos.HttpError) {
		if httpErr.StatusCode == 404 {
			// if we're sure this has been submitted, assume it is still pending elsewhere in the mempool
		}
	}
} else {
	if data["type"] == "pending_transaction" {
		// known to local mempool, but not committed yet
	}
}

func (*Client) TransactionByVersion

func (client *Client) TransactionByVersion(version uint64) (data map[string]any, err error)

TransactionByVersion gets info on a transaction from its LedgerVersion. It must have been committed to have a ledger version

func (*Client) Transactions

func (client *Client) Transactions(start *uint64, limit *uint64) (data []map[string]any, err error)

Transactions Get recent transactions. Start is a version number. Nil for most recent transactions. Limit is a number of transactions to return. 'about a hundred' by default.

func (*Client) View

func (client *Client) View(payload *ViewPayload) (vals []any, err error)

View Runs a view function on chain returning a list of return values. TODO: support ledger version

func (*Client) WaitForTransaction

func (client *Client) WaitForTransaction(txnHash string) (data map[string]any, err error)

Do a long-GET for one transaction and wait for it to complete

type Deserializer

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

func NewDeserializer

func NewDeserializer(bcsBlob []byte) *Deserializer

func (*Deserializer) Bool

func (d *Deserializer) Bool() bool

func (*Deserializer) Error

func (d *Deserializer) Error() error

If there has been any error, return it

func (*Deserializer) ReadBytes

func (d *Deserializer) ReadBytes() []byte

func (*Deserializer) ReadFixedBytes

func (d *Deserializer) ReadFixedBytes(blen int) []byte

func (*Deserializer) ReadFixedBytesInto

func (d *Deserializer) ReadFixedBytesInto(dest []byte)

func (*Deserializer) ReadString

func (d *Deserializer) ReadString() string

func (*Deserializer) Remaining

func (d *Deserializer) Remaining() int

func (*Deserializer) SetError

func (d *Deserializer) SetError(err error)

If the data is well formed but nonsense, UnmarshalBCS() code can set error

func (*Deserializer) Struct

func (d *Deserializer) Struct(x BCSStruct)

func (*Deserializer) U128

func (d *Deserializer) U128() big.Int

func (*Deserializer) U16

func (d *Deserializer) U16() uint16

func (*Deserializer) U256

func (d *Deserializer) U256() big.Int

func (*Deserializer) U32

func (d *Deserializer) U32() uint32

func (*Deserializer) U64

func (d *Deserializer) U64() uint64

func (*Deserializer) U8

func (d *Deserializer) U8() uint8

func (*Deserializer) Uleb128

func (d *Deserializer) Uleb128() uint32

type Ed25519Authenticator

type Ed25519Authenticator struct {
	PublicKey [ed25519.PublicKeySize]byte
	Signature [ed25519.SignatureSize]byte
}

func (*Ed25519Authenticator) MarshalBCS

func (ea *Ed25519Authenticator) MarshalBCS(bcs *Serializer)

func (*Ed25519Authenticator) UnmarshalBCS

func (ea *Ed25519Authenticator) UnmarshalBCS(bcs *Deserializer)

func (*Ed25519Authenticator) Verify

func (ea *Ed25519Authenticator) Verify(data []byte) bool

Verify Return true if the data was well signed

type Ed25519PrivateKey

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

func (*Ed25519PrivateKey) Bytes

func (key *Ed25519PrivateKey) Bytes() []byte

func (*Ed25519PrivateKey) FromHex

func (key *Ed25519PrivateKey) FromHex(hexStr string) (err error)

func (*Ed25519PrivateKey) PubKey

func (key *Ed25519PrivateKey) PubKey() PublicKey

func (*Ed25519PrivateKey) Sign

func (key *Ed25519PrivateKey) Sign(msg []byte) (authenticator Authenticator, err error)

func (*Ed25519PrivateKey) ToHex

func (key *Ed25519PrivateKey) ToHex() string

type Ed25519PublicKey

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

func (*Ed25519PublicKey) Bytes

func (key *Ed25519PublicKey) Bytes() []byte

func (*Ed25519PublicKey) FromHex

func (key *Ed25519PublicKey) FromHex(hexStr string) (err error)

func (*Ed25519PublicKey) Scheme

func (key *Ed25519PublicKey) Scheme() uint8

func (*Ed25519PublicKey) ToHex

func (key *Ed25519PublicKey) ToHex() string

type EntryFunction

type EntryFunction struct {
	Module   ModuleId
	Function string
	ArgTypes []TypeTag
	Args     [][]byte
}

Call an existing published function

func (*EntryFunction) MarshalBCS

func (sf *EntryFunction) MarshalBCS(bcs *Serializer)

func (*EntryFunction) UnmarshalBCS

func (sf *EntryFunction) UnmarshalBCS(bcs *Deserializer)

type ExpirationSeconds

type ExpirationSeconds int64

ExpirationSeconds is an option to APTTransferTransaction

type FaucetClient

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

func (*FaucetClient) Fund

func (faucetClient *FaucetClient) Fund(address AccountAddress, amount uint64) error

Fund account with the given amount of AptosCoin

type FromHex

type FromHex interface {
	// FromHex loads the key from the hex string
	FromHex(string) error
}

type FungibleAssetClient

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

FungibleAssetClient This is an example client around a single fungible asset

func NewFungibleAssetClient

func NewFungibleAssetClient(client *Client, metadataAddress AccountAddress) (faClient *FungibleAssetClient, err error)

NewFungibleAssetClient verifies the address exists when creating the client TODO: Add lookup of other metadata information such as symbol, supply, etc

func (*FungibleAssetClient) Balance

func (client *FungibleAssetClient) Balance(storeAddress AccountAddress) (balance uint64, err error)

func (*FungibleAssetClient) Decimals

func (client *FungibleAssetClient) Decimals() (decimals uint8, err error)

func (*FungibleAssetClient) IsFrozen

func (client *FungibleAssetClient) IsFrozen(storeAddress AccountAddress) (isFrozen bool, err error)

func (*FungibleAssetClient) Maximum

func (client *FungibleAssetClient) Maximum() (maximum *big.Int, err error)

func (*FungibleAssetClient) Name

func (client *FungibleAssetClient) Name() (name string, err error)

func (*FungibleAssetClient) PrimaryBalance

func (client *FungibleAssetClient) PrimaryBalance(owner AccountAddress) (balance uint64, err error)

func (*FungibleAssetClient) PrimaryIsFrozen

func (client *FungibleAssetClient) PrimaryIsFrozen(owner AccountAddress) (isFrozen bool, err error)

func (*FungibleAssetClient) PrimaryStoreAddress

func (client *FungibleAssetClient) PrimaryStoreAddress(owner AccountAddress) (address AccountAddress, err error)

func (*FungibleAssetClient) PrimaryStoreExists

func (client *FungibleAssetClient) PrimaryStoreExists(owner AccountAddress) (exists bool, err error)

func (*FungibleAssetClient) StoreExists

func (client *FungibleAssetClient) StoreExists(storeAddress AccountAddress) (exists bool, err error)

func (*FungibleAssetClient) StoreMetadata

func (client *FungibleAssetClient) StoreMetadata(storeAddress AccountAddress) (metadataAddress AccountAddress, err error)

func (*FungibleAssetClient) Supply

func (client *FungibleAssetClient) Supply() (supply *big.Int, err error)

func (*FungibleAssetClient) Symbol

func (client *FungibleAssetClient) Symbol() (symbol string, err error)

func (*FungibleAssetClient) Transfer

func (client *FungibleAssetClient) Transfer(sender *Account, senderStore AccountAddress, receiverStore AccountAddress, amount uint64) (stxn *SignedTransaction, err error)

func (*FungibleAssetClient) TransferPrimaryStore

func (client *FungibleAssetClient) TransferPrimaryStore(sender *Account, receiverAddress AccountAddress, amount uint64) (stxn *SignedTransaction, err error)

type GasUnitPrice

type GasUnitPrice uint64

GasUnitPrice is an option to APTTransferTransaction

type HttpError

type HttpError struct {
	Status     string // e.g. "200 OK"
	StatusCode int    // e.g. 200
	Header     http.Header
	Method     string
	RequestUrl url.URL
	Body       []byte
}

func NewHttpError

func NewHttpError(response *http.Response) *HttpError

func (*HttpError) Error

func (he *HttpError) Error() string

implement error interface

type MaxGasAmount

type MaxGasAmount uint64

MaxGasAmount is an option to APTTransferTransaction

type ModuleBundle

type ModuleBundle struct {
}

ModuleBundle is long deprecated and no longer used, but exist as an enum position in TransactionPayload

func (*ModuleBundle) MarshalBCS

func (txn *ModuleBundle) MarshalBCS(bcs *Serializer)

func (*ModuleBundle) UnmarshalBCS

func (txn *ModuleBundle) UnmarshalBCS(bcs *Deserializer)

type ModuleId

type ModuleId struct {
	Address AccountAddress
	Name    string
}

func (*ModuleId) MarshalBCS

func (mod *ModuleId) MarshalBCS(bcs *Serializer)

func (*ModuleId) UnmarshalBCS

func (mod *ModuleId) UnmarshalBCS(bcs *Deserializer)

type MoveResource

type MoveResource struct {
	Tag   MoveStructTag
	Value map[string]any // MoveStructValue // TODO: api/types/src/move_types.rs probably actually has more to say about what a MoveStructValue is, but at first read it effectively says map[string]any; there's probably convention elesewhere about what goes into those 'any' parts
}

func (*MoveResource) MarshalBCS

func (mr *MoveResource) MarshalBCS(bcs *Serializer)

func (*MoveResource) UnmarshalBCS

func (mr *MoveResource) UnmarshalBCS(bcs *Deserializer)

type MoveStructTag

type MoveStructTag struct {
	Address           AccountAddress
	Module            string
	Name              string
	GenericTypeParams []MoveType
}

func (*MoveStructTag) MarshalBCS

func (mst *MoveStructTag) MarshalBCS(bcs *Serializer)

func (*MoveStructTag) UnmarshalBCS

func (mst *MoveStructTag) UnmarshalBCS(bcs *Deserializer)

type MoveType

type MoveType uint8

enum

const (
	MoveType_Bool             MoveType = 0
	MoveType_U8               MoveType = 1
	MoveType_U16              MoveType = 2
	MoveType_U32              MoveType = 3
	MoveType_U64              MoveType = 4
	MoveType_U128             MoveType = 5
	MoveType_U256             MoveType = 6
	MoveType_Address          MoveType = 7
	MoveType_Signer           MoveType = 8
	MoveType_Vector           MoveType = 9  // contains MoveType of items of vector
	MoveType_MoveStructTag    MoveType = 10 // contains a MoveStructTag
	MoveType_GeneritTypeParam MoveType = 11 // contains a uint16
	MoveType_Reference        MoveType = 12 // {mutable bool, to MoveType}
	MoveType_Unparsable       MoveType = 13 // contains a string
)

func (*MoveType) MarshalBCS

func (mt *MoveType) MarshalBCS(bcs *Serializer)

func (*MoveType) UnmarshalBCS

func (mt *MoveType) UnmarshalBCS(bcs *Deserializer)

type NetworkConfig

type NetworkConfig struct {
	Name       string
	ChainId    uint8
	NodeUrl    string
	IndexerUrl string
	FaucetUrl  string
}

NetworkConfig a configuration for the Client and which network to use. Use one of the preconfigured LocalnetConfig, DevnetConfig, TestnetConfig, or MainnetConfig unless you have your own full node

type NilBody

type NilBody struct {
}

empty io.ReadCloser

func (*NilBody) Close

func (nb *NilBody) Close() error

func (*NilBody) Read

func (nb *NilBody) Read(p []byte) (n int, err error)

type NodeClient

type NodeClient struct {
	ChainId uint8
	// contains filtered or unexported fields
}

func (*NodeClient) Account

func (rc *NodeClient) Account(address AccountAddress, ledger_version ...int) (info AccountInfo, err error)

func (*NodeClient) AccountResource

func (rc *NodeClient) AccountResource(address AccountAddress, resourceType string, ledger_version ...int) (data map[string]any, err error)

func (*NodeClient) AccountResources

func (rc *NodeClient) AccountResources(address AccountAddress, ledger_version ...int) (resources []AccountResourceInfo, err error)

AccountResources fetches resources for an account into a JSON-like map[string]any in AccountResourceInfo.Data For fetching raw Move structs as BCS, See #AccountResourcesBCS

func (*NodeClient) AccountResourcesBCS

func (rc *NodeClient) AccountResourcesBCS(address AccountAddress, ledger_version ...int) (resources []AccountResourceRecord, err error)

AccountResourcesBCS fetches account resources as raw Move struct BCS blobs in AccountResourceRecord.Data []byte

func (*NodeClient) BuildSignAndSubmitTransaction

func (rc *NodeClient) BuildSignAndSubmitTransaction(sender *Account, payload TransactionPayload, options ...any) (hash string, err error)

BuildSignAndSubmitTransaction right now, this is "easy mode", all in one, no configuration. More configuration comes from splitting into multiple calls

func (*NodeClient) BuildTransaction

func (rc *NodeClient) BuildTransaction(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransaction, err error)

BuildTransaction builds a raw transaction for signing Accepts options: MaxGasAmount, GasUnitPrice, ExpirationSeconds, SequenceNumber, ChainIdOption

func (*NodeClient) Get

func (rc *NodeClient) Get(getUrl string) (*http.Response, error)

func (*NodeClient) GetBCS

func (rc *NodeClient) GetBCS(getUrl string) (*http.Response, error)

func (*NodeClient) GetChainId

func (rc *NodeClient) GetChainId() (chainId uint8, err error)

func (*NodeClient) Info

func (rc *NodeClient) Info() (info NodeInfo, err error)

func (*NodeClient) PollForTransactions

func (rc *NodeClient) PollForTransactions(txnHashes []string, options ...any) error

PollForTransactions waits up to 10 seconds for transactions to be done, polling at 10Hz Accepts options PollPeriod and PollTimeout which should wrap time.Duration values.

func (*NodeClient) Post

func (rc *NodeClient) Post(postUrl string, contentType string, body io.Reader) (resp *http.Response, err error)

func (*NodeClient) SubmitTransaction

func (rc *NodeClient) SubmitTransaction(stxn *SignedTransaction) (data map[string]any, err error)

func (*NodeClient) TransactionByHash

func (rc *NodeClient) TransactionByHash(txnHash string) (data map[string]any, err error)

TransactionByHash gets info on a transaction The transaction may be pending or recently committed.

data, err := c.TransactionByHash("0xabcd")
if err != nil {
	if httpErr, ok := err.(aptos.HttpError) {
		if httpErr.StatusCode == 404 {
			// if we're sure this has been submitted, assume it is still pending elsewhere in the mempool
		}
	}
} else {
	if data["type"] == "pending_transaction" {
		// known to local mempool, but not committed yet
	}
}

func (*NodeClient) TransactionByVersion

func (rc *NodeClient) TransactionByVersion(version uint64) (data map[string]any, err error)

func (*NodeClient) Transactions

func (rc *NodeClient) Transactions(start *uint64, limit *uint64) (data []map[string]any, err error)

Get recent transactions. Start is a version number. Nil for most recent transactions. Limit is a number of transactions to return. 'about a hundred' by default.

func (*NodeClient) View

func (rc *NodeClient) View(payload *ViewPayload) (data []any, err error)

func (*NodeClient) WaitForTransaction

func (rc *NodeClient) WaitForTransaction(txnHash string, options ...any) (data map[string]any, err error)

WaitForTransaction does a long-GET for one transaction and wait for it to complete. Initially poll at 10 Hz for up to 1 second if node replies with 404 (wait for txn to propagate). Accept option arguments PollPeriod and PollTimeout like PollForTransactions.

type NodeInfo

type NodeInfo struct {
	ChainId                uint8  `json:"chain_id"`
	EpochStr               string `json:"epoch"`
	LedgerVersionStr       string `json:"ledger_version"`
	OldestLedgerVersionStr string `json:"oldest_ledger_version"`
	NodeRole               string `json:"node_role"`
	BlockHeightStr         string `json:"block_height"`
	OldestBlockHeightStr   string `json:"oldest_block_height"`
	GitHash                string `json:"git_hash"`
}

func (NodeInfo) BlockHeight

func (info NodeInfo) BlockHeight() uint64

func (NodeInfo) Epoch

func (info NodeInfo) Epoch() uint64

func (NodeInfo) LedgerVersion

func (info NodeInfo) LedgerVersion() uint64

func (NodeInfo) OldestBlockHeight

func (info NodeInfo) OldestBlockHeight() uint64

func (NodeInfo) OldestLedgerVersion

func (info NodeInfo) OldestLedgerVersion() uint64

type PollPeriod

type PollPeriod time.Duration

PollPeriod is an option to PollForTransactions

type PollTimeout

type PollTimeout time.Duration

PollTimeout is an option to PollForTransactions

type PrivateKey

type PrivateKey interface {
	Signer
	FromHex

	/// PubKey Retrieve the public key for signature verification
	PubKey() PublicKey

	Bytes() []byte
}

PrivateKey a generic interface for a signing private key

type PublicKey

type PublicKey interface {
	ToHex
	FromHex

	// Bytes the raw bytes for an authenticator
	Bytes() []byte

	// Scheme The scheme used for address derivation
	Scheme() uint8
}

PublicKey a generic interface for a public key associated with the private key

type RawTransaction

type RawTransaction struct {
	Sender         AccountAddress
	SequenceNumber uint64
	Payload        TransactionPayload
	MaxGasAmount   uint64
	GasUnitPrice   uint64

	// ExpirationTimetampSeconds is seconds since Unix epoch
	ExpirationTimetampSeconds uint64

	ChainId uint8
}

func (*RawTransaction) MarshalBCS

func (txn *RawTransaction) MarshalBCS(bcs *Serializer)

func (*RawTransaction) Sign

func (txn *RawTransaction) Sign(sender *Account) (stxn *SignedTransaction, err error)

func (*RawTransaction) SignableBytes

func (txn *RawTransaction) SignableBytes() (signableBytes []byte, err error)

func (*RawTransaction) UnmarshalBCS

func (txn *RawTransaction) UnmarshalBCS(bcs *Deserializer)

type Script

type Script struct {
	Code     []byte
	ArgTypes []TypeTag
	Args     []ScriptArgument
}

Execute a Script literal immediately as a transaction

func (*Script) MarshalBCS

func (sc *Script) MarshalBCS(bcs *Serializer)

func (*Script) UnmarshalBCS

func (sc *Script) UnmarshalBCS(bcs *Deserializer)

type ScriptArgument

type ScriptArgument struct {
	Variant ScriptArgumentVariant
	Value   any
}

func (*ScriptArgument) MarshalBCS

func (sa *ScriptArgument) MarshalBCS(bcs *Serializer)

func (*ScriptArgument) SetU128

func (sa *ScriptArgument) SetU128(v big.Int)

TODO: more like these Set*() accessors?

func (*ScriptArgument) SetU8

func (sa *ScriptArgument) SetU8(v uint8)

TODO: more like these Set*() accessors?

func (*ScriptArgument) UnmarshalBCS

func (sa *ScriptArgument) UnmarshalBCS(bcs *Deserializer)

type ScriptArgumentVariant

type ScriptArgumentVariant uint8
const (
	ScriptArgument_U8       ScriptArgumentVariant = 0
	ScriptArgument_U64      ScriptArgumentVariant = 1
	ScriptArgument_U128     ScriptArgumentVariant = 2
	ScriptArgument_Address  ScriptArgumentVariant = 3
	ScriptArgument_U8Vector ScriptArgumentVariant = 4
	ScriptArgument_Bool     ScriptArgumentVariant = 5
	ScriptArgument_U16      ScriptArgumentVariant = 6
	ScriptArgument_U32      ScriptArgumentVariant = 7
	ScriptArgument_U256     ScriptArgumentVariant = 8
)

type SequenceNumber

type SequenceNumber uint64

SequenceNumber is an option to APTTransferTransaction

type Serializer

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

func (*Serializer) Bool

func (bcs *Serializer) Bool(v bool)

func (*Serializer) Error

func (bcs *Serializer) Error() error

func (*Serializer) FixedBytes

func (bcs *Serializer) FixedBytes(v []byte)

Something somewhere already knows how long this byte string will be

func (*Serializer) SetError

func (bcs *Serializer) SetError(err error)

If the data is well formed but nonsense, MarshalBCS() code can set error

func (*Serializer) Struct

func (bcs *Serializer) Struct(x BCSStruct)

func (*Serializer) ToBytes

func (bcs *Serializer) ToBytes() []byte

func (*Serializer) U128

func (bcs *Serializer) U128(v big.Int)

func (*Serializer) U16

func (bcs *Serializer) U16(v uint16)

func (*Serializer) U256

func (bcs *Serializer) U256(v big.Int)

func (*Serializer) U32

func (bcs *Serializer) U32(v uint32)

func (*Serializer) U64

func (bcs *Serializer) U64(v uint64)

func (*Serializer) U8

func (bcs *Serializer) U8(v uint8)

func (*Serializer) Uleb128

func (bcs *Serializer) Uleb128(v uint32)

func (*Serializer) WriteBytes

func (bcs *Serializer) WriteBytes(v []byte)

func (*Serializer) WriteString

func (bcs *Serializer) WriteString(v string)

type SignedTransaction

type SignedTransaction struct {
	Transaction   RawTransaction
	Authenticator Authenticator
}

func APTTransferTransaction

func APTTransferTransaction(client *Client, sender *Account, dest AccountAddress, amount uint64, options ...any) (signedTxn *SignedTransaction, err error)

Move some APT from sender to dest Amount in Octas (10^-8 APT)

options may be: MaxGasAmount, GasUnitPrice, ExpirationSeconds, ValidUntil, SequenceNumber, ChainIdOption

func (*SignedTransaction) MarshalBCS

func (txn *SignedTransaction) MarshalBCS(bcs *Serializer)

func (*SignedTransaction) UnmarshalBCS

func (txn *SignedTransaction) UnmarshalBCS(bcs *Deserializer)

func (*SignedTransaction) Verify

func (txn *SignedTransaction) Verify() error

type Signer

type Signer interface {
	// ToHex if a private key, it's bytes, if it's not a private key
	// then a placeholder
	ToHex

	Sign(msg []byte) (authenticator Authenticator, err error)
}

Signer a generic interface for any kind of signing

type StructTag

type StructTag struct {
	Address    AccountAddress
	Module     string
	Name       string
	TypeParams []TypeTag
}

func (*StructTag) GetType

func (st *StructTag) GetType() TypeTagType

func (*StructTag) MarshalBCS

func (st *StructTag) MarshalBCS(bcs *Serializer)

func (*StructTag) String

func (st *StructTag) String() string

func (*StructTag) UnmarshalBCS

func (st *StructTag) UnmarshalBCS(bcs *Deserializer)

type ToHex

type ToHex interface {
	ToHex() string
}

type TransactionPayload

type TransactionPayload struct {
	Payload BCSStruct
}

func (*TransactionPayload) MarshalBCS

func (txn *TransactionPayload) MarshalBCS(bcs *Serializer)

func (*TransactionPayload) UnmarshalBCS

func (txn *TransactionPayload) UnmarshalBCS(bcs *Deserializer)

type TypeTag

type TypeTag struct {
	Value TypeTagImpl
}

func NewTypeTag

func NewTypeTag(v any) *TypeTag

func (*TypeTag) MarshalBCS

func (tt *TypeTag) MarshalBCS(bcs *Serializer)

func (*TypeTag) String

func (tt *TypeTag) String() string

func (*TypeTag) UnmarshalBCS

func (tt *TypeTag) UnmarshalBCS(bcs *Deserializer)

type TypeTagImpl

type TypeTagImpl interface {
	BCSStruct
	GetType() TypeTagType
	String() string
}

type TypeTagType

type TypeTagType uint64
const (
	TypeTag_Bool           TypeTagType = 0
	TypeTag_U8             TypeTagType = 1
	TypeTag_U64            TypeTagType = 2
	TypeTag_U128           TypeTagType = 3
	TypeTag_AccountAddress TypeTagType = 4
	TypeTag_Signer         TypeTagType = 5
	TypeTag_Vector         TypeTagType = 6
	TypeTag_Struct         TypeTagType = 7
	TypeTag_U16            TypeTagType = 8
	TypeTag_U32            TypeTagType = 9
	TypeTag_U256           TypeTagType = 10
)

type U16Tag

type U16Tag struct {
	Value uint16
}

func (*U16Tag) GetType

func (xt *U16Tag) GetType() TypeTagType

func (*U16Tag) MarshalBCS

func (xt *U16Tag) MarshalBCS(bcs *Serializer)

func (*U16Tag) String

func (xt *U16Tag) String() string

func (*U16Tag) UnmarshalBCS

func (xt *U16Tag) UnmarshalBCS(bcs *Deserializer)

type U32Tag

type U32Tag struct {
	Value uint32
}

func (*U32Tag) GetType

func (xt *U32Tag) GetType() TypeTagType

func (*U32Tag) MarshalBCS

func (xt *U32Tag) MarshalBCS(bcs *Serializer)

func (*U32Tag) String

func (xt *U32Tag) String() string

func (*U32Tag) UnmarshalBCS

func (xt *U32Tag) UnmarshalBCS(bcs *Deserializer)

type U64Tag

type U64Tag struct {
	Value uint64
}

func (*U64Tag) GetType

func (xt *U64Tag) GetType() TypeTagType

func (*U64Tag) MarshalBCS

func (xt *U64Tag) MarshalBCS(bcs *Serializer)

func (*U64Tag) String

func (xt *U64Tag) String() string

func (*U64Tag) UnmarshalBCS

func (xt *U64Tag) UnmarshalBCS(bcs *Deserializer)

type U8Tag

type U8Tag struct {
	Value uint8
}

func (*U8Tag) GetType

func (xt *U8Tag) GetType() TypeTagType

func (*U8Tag) MarshalBCS

func (xt *U8Tag) MarshalBCS(bcs *Serializer)

func (*U8Tag) String

func (xt *U8Tag) String() string

func (*U8Tag) UnmarshalBCS

func (xt *U8Tag) UnmarshalBCS(bcs *Deserializer)

type ViewPayload

type ViewPayload struct {
	Module   ModuleId
	Function string
	ArgTypes []TypeTag
	Args     [][]byte
}

func (*ViewPayload) MarshalBCS

func (vp *ViewPayload) MarshalBCS(bcs *Serializer)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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