Documentation ¶
Index ¶
- Constants
- Variables
- func BcsDeserialize(dest BCSStruct, bcsBlob []byte) error
- func BcsSerialize(value BCSStruct) (bcsBlob []byte, err error)
- func DeserializeMapToSlices[K, V any](bcs *Deserializer) (keys []K, values []V)
- func DeserializeSequence[T any](bcs *Deserializer) []T
- func GenerateEd5519Keys() (privkey Ed25519PrivateKey, pubkey Ed25519PublicKey, err error)
- func ParseHex(hexStr string) ([]byte, error)
- func RawTransactionPrehash() []byte
- func SHA3_256Hash(bytes [][]byte) (output []byte)
- func SerializeSequence[AT []T, T any](x AT, bcs *Serializer)
- func ToU128OrU256(val string) (num *big.Int, err error)
- func ToU64(val string) (uint64, error)
- type Account
- type AccountAddress
- func (aa *AccountAddress) DerivedAddress(seed []byte, typeByte uint8) (accountAddress AccountAddress)
- func (aa *AccountAddress) FromPublicKey(pubkey PublicKey)
- func (aa *AccountAddress) IsSpecial() bool
- func (aa AccountAddress) MarshalBCS(bcs *Serializer)
- func (aa *AccountAddress) NamedObjectAddress(seed []byte) (accountAddress AccountAddress)
- func (aa *AccountAddress) ObjectAddressFromObject(objectAddress *AccountAddress) (accountAddress AccountAddress)
- func (aa *AccountAddress) ParseStringRelaxed(x string) error
- func (aa *AccountAddress) Random()
- func (aa *AccountAddress) ResourceAccount(seed []byte) (accountAddress AccountAddress)
- func (aa *AccountAddress) String() string
- func (aa *AccountAddress) UnmarshalBCS(bcs *Deserializer)
- type AccountAddressTag
- type AccountInfo
- type AccountResourceInfo
- type AccountResourceRecord
- type Authenticator
- type AuthenticatorImpl
- type AuthenticatorType
- type BCSStruct
- type BoolTag
- type ChainIdOption
- type Client
- func (client *Client) Account(address AccountAddress, ledgerVersion ...int) (info AccountInfo, err error)
- func (client *Client) AccountResource(address AccountAddress, resourceType string, ledgerVersion ...int) (data map[string]any, err error)
- func (client *Client) AccountResources(address AccountAddress, ledgerVersion ...int) (resources []AccountResourceInfo, err error)
- func (client *Client) AccountResourcesBCS(address AccountAddress, ledgerVersion ...int) (resources []AccountResourceRecord, err error)
- func (client *Client) BuildSignAndSubmitTransaction(sender *Account, payload TransactionPayload, options ...any) (hash string, err error)
- func (client *Client) BuildTransaction(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransaction, err error)
- func (client *Client) Fund(address AccountAddress, amount uint64) error
- func (client *Client) GetChainId() (chainId uint8, err error)
- func (client *Client) Info() (info NodeInfo, err error)
- func (client *Client) PollForTransactions(txnHashes []string, options ...any) error
- func (client *Client) SetTimeout(timeout time.Duration)
- func (client *Client) SubmitTransaction(signedTransaction *SignedTransaction) (data map[string]any, err error)
- func (client *Client) TransactionByHash(txnHash string) (data map[string]any, err error)
- func (client *Client) TransactionByVersion(version uint64) (data map[string]any, err error)
- func (client *Client) Transactions(start *uint64, limit *uint64) (data []map[string]any, err error)
- func (client *Client) View(payload *ViewPayload) (vals []any, err error)
- func (client *Client) WaitForTransaction(txnHash string) (data map[string]any, err error)
- type Deserializer
- func (d *Deserializer) Bool() bool
- func (d *Deserializer) Error() error
- func (d *Deserializer) ReadBytes() []byte
- func (d *Deserializer) ReadFixedBytes(blen int) []byte
- func (d *Deserializer) ReadFixedBytesInto(dest []byte)
- func (d *Deserializer) ReadString() string
- func (d *Deserializer) Remaining() int
- func (d *Deserializer) SetError(err error)
- func (d *Deserializer) Struct(x BCSStruct)
- func (d *Deserializer) U128() big.Int
- func (d *Deserializer) U16() uint16
- func (d *Deserializer) U256() big.Int
- func (d *Deserializer) U32() uint32
- func (d *Deserializer) U64() uint64
- func (d *Deserializer) U8() uint8
- func (d *Deserializer) Uleb128() uint32
- type Ed25519Authenticator
- type Ed25519PrivateKey
- type Ed25519PublicKey
- type EntryFunction
- type ExpirationSeconds
- type FaucetClient
- type FromHex
- type FungibleAssetClient
- func (client *FungibleAssetClient) Balance(storeAddress AccountAddress) (balance uint64, err error)
- func (client *FungibleAssetClient) Decimals() (decimals uint8, err error)
- func (client *FungibleAssetClient) IsFrozen(storeAddress AccountAddress) (isFrozen bool, err error)
- func (client *FungibleAssetClient) Maximum() (maximum *big.Int, err error)
- func (client *FungibleAssetClient) Name() (name string, err error)
- func (client *FungibleAssetClient) PrimaryBalance(owner AccountAddress) (balance uint64, err error)
- func (client *FungibleAssetClient) PrimaryIsFrozen(owner AccountAddress) (isFrozen bool, err error)
- func (client *FungibleAssetClient) PrimaryStoreAddress(owner AccountAddress) (address AccountAddress, err error)
- func (client *FungibleAssetClient) PrimaryStoreExists(owner AccountAddress) (exists bool, err error)
- func (client *FungibleAssetClient) StoreExists(storeAddress AccountAddress) (exists bool, err error)
- func (client *FungibleAssetClient) StoreMetadata(storeAddress AccountAddress) (metadataAddress AccountAddress, err error)
- func (client *FungibleAssetClient) Supply() (supply *big.Int, err error)
- func (client *FungibleAssetClient) Symbol() (symbol string, err error)
- func (client *FungibleAssetClient) Transfer(sender *Account, senderStore AccountAddress, receiverStore AccountAddress, ...) (stxn *SignedTransaction, err error)
- func (client *FungibleAssetClient) TransferPrimaryStore(sender *Account, receiverAddress AccountAddress, amount uint64) (stxn *SignedTransaction, err error)
- type GasUnitPrice
- type HttpError
- type MaxGasAmount
- type ModuleBundle
- type ModuleId
- type MoveResource
- type MoveStructTag
- type MoveType
- type NetworkConfig
- type NilBody
- type NodeClient
- func (rc *NodeClient) Account(address AccountAddress, ledger_version ...int) (info AccountInfo, err error)
- func (rc *NodeClient) AccountResource(address AccountAddress, resourceType string, ledger_version ...int) (data map[string]any, err error)
- func (rc *NodeClient) AccountResources(address AccountAddress, ledger_version ...int) (resources []AccountResourceInfo, err error)
- func (rc *NodeClient) AccountResourcesBCS(address AccountAddress, ledger_version ...int) (resources []AccountResourceRecord, err error)
- func (rc *NodeClient) BuildSignAndSubmitTransaction(sender *Account, payload TransactionPayload, options ...any) (hash string, err error)
- func (rc *NodeClient) BuildTransaction(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransaction, err error)
- func (rc *NodeClient) Get(getUrl string) (*http.Response, error)
- func (rc *NodeClient) GetBCS(getUrl string) (*http.Response, error)
- func (rc *NodeClient) GetChainId() (chainId uint8, err error)
- func (rc *NodeClient) Info() (info NodeInfo, err error)
- func (rc *NodeClient) PollForTransactions(txnHashes []string, options ...any) error
- func (rc *NodeClient) Post(postUrl string, contentType string, body io.Reader) (resp *http.Response, err error)
- func (rc *NodeClient) SubmitTransaction(stxn *SignedTransaction) (data map[string]any, err error)
- func (rc *NodeClient) TransactionByHash(txnHash string) (data map[string]any, err error)
- func (rc *NodeClient) TransactionByVersion(version uint64) (data map[string]any, err error)
- func (rc *NodeClient) Transactions(start *uint64, limit *uint64) (data []map[string]any, err error)
- func (rc *NodeClient) View(payload *ViewPayload) (data []any, err error)
- func (rc *NodeClient) WaitForTransaction(txnHash string, options ...any) (data map[string]any, err error)
- type NodeInfo
- type PollPeriod
- type PollTimeout
- type PrivateKey
- type PublicKey
- type RawTransaction
- type Script
- type ScriptArgument
- type ScriptArgumentVariant
- type SequenceNumber
- type Serializer
- func (bcs *Serializer) Bool(v bool)
- func (bcs *Serializer) Error() error
- func (bcs *Serializer) FixedBytes(v []byte)
- func (bcs *Serializer) SetError(err error)
- func (bcs *Serializer) Struct(x BCSStruct)
- func (bcs *Serializer) ToBytes() []byte
- func (bcs *Serializer) U128(v big.Int)
- func (bcs *Serializer) U16(v uint16)
- func (bcs *Serializer) U256(v big.Int)
- func (bcs *Serializer) U32(v uint32)
- func (bcs *Serializer) U64(v uint64)
- func (bcs *Serializer) U8(v uint8)
- func (bcs *Serializer) Uleb128(v uint32)
- func (bcs *Serializer) WriteBytes(v []byte)
- func (bcs *Serializer) WriteString(v string)
- type SignedTransaction
- type Signer
- type StructTag
- type ToHex
- type TransactionPayload
- type TypeTag
- type TypeTagImpl
- type TypeTagType
- type U16Tag
- type U32Tag
- type U64Tag
- type U8Tag
- type ViewPayload
Constants ¶
const ( Ed25519Scheme = uint8(0) MultiEd25519Scheme = uint8(1) SingleKeyScheme = uint8(2) MultiKeyScheme = uint8(3) )
Seeds for deriving addresses from addresses
const ( TransactionPayload_Script = 0 TransactionPayload_ModuleBundle = 1 // Deprecated TransactionPayload_EntryFunction = 2 TransactionPayload_Multisig = 3 // TODO? defined in aptos-core/types/src/transaction/mod.rs )
const APTOS_CLIENT_HEADER = "x-aptos-client"
const APTOS_SIGNED_BCS = "application/x.aptos.signed_transaction+bcs"
For Content-Type header when POST-ing a Transaction
const APTOS_VIEW_BCS = "application/x.aptos.view_function+bcs"
const HTTP_ERR_SUMMARY_LEN = 100
Variables ¶
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}
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}
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}
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}
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}
var AptosClientHeaderValue = "aptos-go-sdk/unk"
var DevnetConfig = NetworkConfig{
Name: "devnet",
NodeUrl: "https://api.devnet.aptoslabs.com/v1",
IndexerUrl: "",
FaucetUrl: "https://faucet.devnet.aptoslabs.com/",
}
var ErrAddressTooLong = errors.New("AccountAddress too long")
var ErrAddressTooShort = errors.New("AccountAddress too short")
var ErrUnknownNetworkName = errors.New("Unknown network name")
var LocalnetConfig = NetworkConfig{
Name: "localnet",
ChainId: 4,
NodeUrl: "http://localhost:8080/v1",
IndexerUrl: "",
FaucetUrl: "http://localhost:8081/v1",
}
var MainnetConfig = NetworkConfig{
Name: "mainnet",
ChainId: 1,
NodeUrl: "https://api.mainnet.aptoslabs.com/v1",
IndexerUrl: "",
FaucetUrl: "",
}
var NamedNetworks map[string]NetworkConfig
Map from network name to NetworkConfig
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 BcsSerialize ¶
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 RawTransactionPrehash ¶
func RawTransactionPrehash() []byte
Return the sha3-256 prehash for RawTransaction Do not write to the []byte returned
func SHA3_256Hash ¶
func SerializeSequence ¶
func SerializeSequence[AT []T, T any](x AT, bcs *Serializer)
func ToU128OrU256 ¶
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 ¶
NewEd25519Account creates an account with a new random Ed25519 private key
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 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) UnmarshalBCS ¶
func (xt *BoolTag) UnmarshalBCS(bcs *Deserializer)
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 ¶
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 ¶
GetChainId Retrieves the ChainId of the network Note this will be cached forever, or taken directly from the config
func (*Client) PollForTransactions ¶
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 ¶
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 ¶
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 ¶
TransactionByVersion gets info on a transaction from its LedgerVersion. It must have been committed to have a ledger version
func (*Client) Transactions ¶
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.
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 ¶
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 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 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 ¶
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 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) 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) 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 ¶
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 (NodeInfo) LedgerVersion ¶
func (NodeInfo) OldestBlockHeight ¶
func (NodeInfo) OldestLedgerVersion ¶
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) UnmarshalBCS ¶
func (st *StructTag) UnmarshalBCS(bcs *Deserializer)
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 (*TypeTag) MarshalBCS ¶
func (tt *TypeTag) MarshalBCS(bcs *Serializer)
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) 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) 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) 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) UnmarshalBCS ¶
func (xt *U8Tag) UnmarshalBCS(bcs *Deserializer)
type ViewPayload ¶
func (*ViewPayload) MarshalBCS ¶
func (vp *ViewPayload) MarshalBCS(bcs *Serializer)