aptos

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: MIT Imports: 22 Imported by: 3

Documentation

Overview

APTOS golang sdk

Aptos is a blockchain written in rust and smart contracts are written in move.

Index

Examples

Constants

View Source
const (
	PetraPath      = "m/44'/637'/0'/0'/0'"
	HmacKey        = "ed25519 seed"
	HardenedOffset = 0x80000000
)
View Source
const AddressLength = 32
View Source
const (
	Ed25519SignatureType = "ed25519_signature"
)
View Source
const SignatureLength = 64

Variables

AuxAllFakeCoins contains all the fake coins provided by aux for testing

Functions

func EncodeTransaction

func EncodeTransaction(tx *Transaction, chainId uint8) []byte

EncodeTransaction for signing See here: https://aptos.dev/guides/creating-a-signed-transaction#signing-message also see here

The process is follows - generate sha3_256 of "APTOS::RawTransaction" - bcs serialize in the following order:

  • sender
  • sequence_number
  • payload
  • max_gas_amount
  • gas_unit_price
  • expiration_timestamp_secs
  • chain_id

for entry function payload, the serialization is as follows

func GetAuxFakeCoinDecimal

func GetAuxFakeCoinDecimal(fakeCoin AuxFakeCoin) uint8

func GetDefaultEndpoint

func GetDefaultEndpoint(network Network) (restUrl string, faucetUrl string, err error)

func IsNamedAddress

func IsNamedAddress(address string) bool

Check if an address string is named address

func NewPrivateKeyFromHexString

func NewPrivateKeyFromHexString(hexString string) (*ed25519.PrivateKey, error)

NewPrivateKeyFromHexString generates a private key from hex string.

func ParseBip32Path

func ParseBip32Path(path string) ([]uint32, error)

func RequestFromFaucet

func RequestFromFaucet(ctx context.Context, faucetUrl string, address *Address, amount uint64) ([]string, error)

func StringToBCS

func StringToBCS(s string) []byte

func ULEB128Decode

func ULEB128Decode[T uint8 | uint16 | uint32 | uint64 | uint | int](data []byte) (T, int, error)

ULEB128Decode decodes byte array into an integer, returns the decoded value, the number of bytes consumed, and a possible error. If error is returned, the number of bytes returned is guaranteed to be 0.

func ULEB128Encode

func ULEB128Encode[T uint8 | uint16 | uint32 | uint64 | uint | int](input T) []byte

ULEB128Encode converts an integer into []byte

Types

type AccountResource

type AccountResource struct {
	Type *MoveTypeTag    `json:"type"`
	Data json.RawMessage `json:"data,omitempty"`
}

AccountResource includes the type and json encoding of the data.

type Address

type Address [AddressLength]byte

Address in aptos, 32 byte long.

var AptosStdAddress Address

func CalculateResourceAddress

func CalculateResourceAddress(sourceAddress Address, seed []byte) (Address, error)

CalculateResourceAddress creates a new resource address from the source address and seeds.

func GenerateAuthenticationKey

func GenerateAuthenticationKey(
	totalSignerCount int,
	requiredSignerCount int,
	signerPublicKeys ...ed25519.PublicKey,
) (Address, error)

GenerateAuthenticationKey calculates the authentication key for a scheme.

The information is based on https://aptos.dev/concepts/basics-accounts/#signature-schemes

Account in aptos is presented by SHA3-256 of - a public key of ed25519 public key (pub_key|0x00) - a series of ed25519 public keys, the number of signature required (pub_key_1 | pub_key_2 ... | pub_key_n | K | 0x01) - an address and some seed (address | seed) if on chain.

func MustStringToAddress

func MustStringToAddress(s string) Address

func ParseAddress

func ParseAddress(s string) (Address, error)

ParseAddress converts a hex encoded string to address.

func (Address) IsZero

func (address Address) IsZero() bool

Checks if the address is zero.

func (Address) MarshalJSON

func (address Address) MarshalJSON() ([]byte, error)

func (*Address) Set

func (a *Address) Set(s string) error

Set is to support cobra value

func (Address) String

func (address Address) String() string

Hex representation of the address, with 0x prefix

func (Address) ToBCS

func (a Address) ToBCS() []byte

func (Address) Type

func (a Address) Type() string

Type is to support cobra value

func (*Address) UnmarshalJSON

func (address *Address) UnmarshalJSON(input []byte) error

type AptosRequest

type AptosRequest interface {
	PathSegments() ([]string, error)
	Body() ([]byte, error)
	HttpMethod() string
}

AptosRequest

type AptosResponse

type AptosResponse[T any] struct {
	RawData []byte
	Parsed  *T
}

type AptosRestError

type AptosRestError struct {
	// HttpStatusCode returned
	HttpStatusCode int

	// Body of the response
	Body []byte

	// Message
	Message string
}

AptosRestError

func (*AptosRestError) Error

func (e *AptosRestError) Error() string

type AuxAllOrdersEvent

type AuxAllOrdersEvent struct {
	Bids [][]*AuxOpenOrderEventInfo `json:"bids"`
	Asks [][]*AuxOpenOrderEventInfo `json:"asks"`
}

type AuxAmmPool

type AuxAmmPool struct {
	FeeBps   JsonUint64 `json:"feebps"`
	Frozen   bool       `json:"frozen"`
	XReserve Coin       `json:"x_reserve"`
	YReserve Coin       `json:"y_reserve"`

	AddLiquidityEvents    *EventHandler `json:"add_liquidity_events"`
	RemoveLiquidityEvents *EventHandler `json:"remove_liquidity_events"`
	SwapEvents            *EventHandler `json:"swap_events"`
}

AuxAmmPool is a constant product amm

type AuxClientConfig

type AuxClientConfig struct {
	Address           Address
	Deployer          Address
	DataFeedAddress   Address
	DataFeedPublicKey ed25519.PublicKey
}

func GetAuxClientConfig

func GetAuxClientConfig(chain Network) (*AuxClientConfig, error)

func GetAuxInfoFromLocalAccount

func GetAuxInfoFromLocalAccount(localAccount *LocalAccount) *AuxClientConfig

func (*AuxClientConfig) AmmPoolType

func (info *AuxClientConfig) AmmPoolType(coinX *MoveTypeTag, coinY *MoveTypeTag) (*MoveTypeTag, error)

func (*AuxClientConfig) BuildCreateMarket

func (info *AuxClientConfig) BuildCreateMarket(sender Address, baseCoin, quoteCoin *MoveTypeTag, lotSize, tickSize uint64, options ...TransactionOption) *Transaction

func (*AuxClientConfig) BuildCreatePool

func (info *AuxClientConfig) BuildCreatePool(sender Address, coinX, coinY *MoveTypeTag, feeBps uint64, options ...TransactionOption) *Transaction

func (*AuxClientConfig) BuildLoadAllOrdersIntoEvent

func (info *AuxClientConfig) BuildLoadAllOrdersIntoEvent(baseCoin, quoteCoin *MoveTypeTag, options ...TransactionOption) *Transaction

func (*AuxClientConfig) BuildLoadMarketIntoEvent

func (info *AuxClientConfig) BuildLoadMarketIntoEvent(baseCoin, quoteCoin *MoveTypeTag, options ...TransactionOption) *Transaction

func (*AuxClientConfig) BuildPlaceOrder

func (info *AuxClientConfig) BuildPlaceOrder(
	sender Address,
	isBid bool,
	baseCoin,
	quoteCoin *MoveTypeTag,
	limitPrice uint64,
	quantity uint64,
	auxToBurnPerLot uint64,
	orderType AuxClobMarketOrderType,
	ticksToSlide uint64,
	directionAggressive bool,
	timeoutTimestamp uint64,
	selfTradeType AuxClobMarketSelfTradeType,
	options ...TransactionOption,
) *Transaction

func (*AuxClientConfig) BuildUpdatePoolFee

func (info *AuxClientConfig) BuildUpdatePoolFee(sender Address, coinX, coinY *MoveTypeTag, feeBps uint64, options ...TransactionOption) *Transaction

func (*AuxClientConfig) MarketType

func (info *AuxClientConfig) MarketType(baseCoin *MoveTypeTag, quoteCoin *MoveTypeTag) (*MoveTypeTag, error)

MarketType provides the market for a pair of currencies

type AuxClobMarket

type AuxClobMarket struct {
	Asks          *AuxCritbit `json:"asks,omitempty"`
	Bids          *AuxCritbit `json:"bids,omitempty"`
	BaseDecimals  uint8       `json:"base_decimals"`
	QuoteDecimals uint8       `json:"quote_decimals"`
	LotSize       JsonUint64  `json:"lot_size"`
	TickSize      JsonUint64  `json:"tick_size"`

	FillEvents   *EventHandler `json:"fill_events"`
	PlacedEvents *EventHandler `json:"placed_events"`
	CancelEvents *EventHandler `json:"cancel_events"`
}

AuxClobMarket contains two sided book of bids and asks.

type AuxClobMarketOrderType

type AuxClobMarketOrderType uint64

AuxClobMarketOrderType, can be limit, fok, ioc, post only or passive join

const (
	AuxClobMarketOrderType_Limit        AuxClobMarketOrderType = iota + 100 // LIMIT
	AuxClobMarketOrderType_FOK                                              // FOK
	AuxClobMarketOrderType_IOC                                              // IOC
	AuxClobMarketOrderType_POST_ONLY                                        // POST_ONLY
	AuxClobMarketOrderType_PASSIVE_JOIN                                     // PASSIVE_JOIN
)

func (AuxClobMarketOrderType) String

func (i AuxClobMarketOrderType) String() string

type AuxClobMarketSelfTradeType

type AuxClobMarketSelfTradeType uint64

AuxClobMarketSelfTradeType gives instruction on how to handle self trade

const (
	AuxClobMarketSelfTradeType_CancelPassive    AuxClobMarketSelfTradeType = iota + 200 // CANCEL_PASSIVE
	AuxClobMarketSelfTradeType_CancelAggressive                                         // CANCEL_AGGRESSIVE
	AuxClobMarketSelfTradeType_CancelBoth                                               // CANCEL_BOTH
)

func (AuxClobMarketSelfTradeType) String

type AuxCritbit

type AuxCritbit struct {
	Entries  *TableWithLength `json:"entries,omitempty"`
	MaxIndex JsonUint64       `json:"max_index"`
	MinIndex JsonUint64       `json:"min_index"`
	Root     JsonUint64       `json:"root"`
	Tree     *TableWithLength `json:"tree"`
}

AuxCritbit is a critbit tree, used to store order books. It has better tail behavior when adding/removing large number of elements, but on average performs worse than red/black tree.

type AuxFakeCoin

type AuxFakeCoin int

AuxFakeCoin contains some fake coins to use on devnet and testnet. They don't have any value and can be freely minted to anyone. Simply call mint (or register_and_mint if not signed up for it already).

const (
	AuxFakeCoin_USDC AuxFakeCoin = iota // USDC
	AuxFakeCoin_ETH                     // ETH
	AuxFakeCoin_BTC                     // BTC
	AuxFakeCoin_SOL                     // SOL
	AuxFakeCoin_AUX                     // AUX
	AuxFakeCoin_USDT                    // USDT
)

func (AuxFakeCoin) String

func (i AuxFakeCoin) String() string

type AuxLevel2Event

type AuxLevel2Event struct {
	Bids []*AuxLevel2Event_Level `json:"bids"`
	Asks []*AuxLevel2Event_Level `json:"asks"`
}

AuxLevel2Event contains the bids and asks from a `load_market_into_event` call. Since tranversing the orderbook from off-chain is difficult, we run those entry functions to emit data into event queues.

type AuxLevel2Event_Level

type AuxLevel2Event_Level struct {
	Price    JsonUint64 `json:"price"`
	Quantity JsonUint64 `json:"quantity"`
}

AuxLevel2Event_Level is price/quantity in an aux level 2 event

type AuxOpenOrderEventInfo

type AuxOpenOrderEventInfo struct {
	Id                string     `json:"id"`
	CilentOrderId     string     `json:"client_order_id"`
	Price             JsonUint64 `json:"price"`
	Quantity          JsonUint64 `json:"quantity"`
	AuxAuToBurnPerLot JsonUint64 `json:"aux_au_to_burn_per_lot"`
	IsBid             bool       `json:"is_bid"`
	OwnerId           Address    `json:"order_id"`
	TimeoutTimestamp  JsonUint64 `json:"timeout_timestsamp"`
	OrderType         JsonUint64 `json:"order_type"`
	Timestamp         JsonUint64 `json:"timestamp"`
}

type Client

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

Client for aptos

func NewClient

func NewClient(restUrl string, transactionOptions ...TransactionOption) *Client

NewClient creates a new client with an endpoint

func (*Client) FillTransactionData

func (client *Client) FillTransactionData(ctx context.Context, tx *Transaction, seqNumIsZero bool) error

FillTransactionData fills the missing data for a transaction. seqNumIsZero indicates the sequence number is 0 for the account and therefore doesn't need to check

func (*Client) GetChainId

func (client *Client) GetChainId(ctx context.Context) (uint8, error)

Get ChainId

func (*Client) RefreshData

func (client *Client) RefreshData(ctx context.Context) error

RefreshData updates gas price estimates and ledger info.

func (*Client) SubmitTransaction

func (client *Client) SubmitTransaction(ctx context.Context, request *SubmitTransactionRequest) (*AptosResponse[SubmitTransactionResponse], error)

SubmitTransaction https://fullnode.devnet.aptoslabs.com/v1/spec#/operations/submit_transaction

Example
package main

import (
	"context"
	"encoding/hex"
	"fmt"
	"os"
	"strings"
	"time"

	"github.com/davecgh/go-spew/spew"
	"github.com/fardream/go-aptos/aptos"
)

const network = aptos.Devnet

func main() {
	restUrl, faucetUrl, _ := aptos.GetDefaultEndpoint(network)

	account, _ := aptos.NewLocalAccountWithRandomKey()

	var err error

	fmt.Fprintf(os.Stderr, "private key: 0x%s\n", hex.EncodeToString(account.PrivateKey.Seed()))
	fmt.Fprintf(os.Stderr, "address: %s\n", account.Address.String())
	auxConfig, _ := aptos.GetAuxClientConfig(network)

	faucetTxes, err := aptos.RequestFromFaucet(context.Background(), faucetUrl, &account.Address, 1000000000)
	if err != nil {
		panic(err)
	}

	client := aptos.NewClient(restUrl)

	ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
	defer cancel()

	for _, faucetTx := range faucetTxes {
		txType, err := client.WaitForTransaction(ctx, faucetTx)
		if err != nil {
			spew.Dump(err)
		}
		fmt.Fprintf(os.Stderr, "fauct tx type: %s\n", txType)
	}

	tx := aptos.Transaction{
		Sender:                  account.Address,
		ExpirationTimestampSecs: aptos.JsonUint64(time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC).Unix()),
		Payload: aptos.NewEntryFunctionPayload(
			aptos.MustNewMoveFunctionTag(auxConfig.Address, "fake_coin", "mint"),
			[]*aptos.MoveTypeTag{aptos.MustNewMoveTypeTag(auxConfig.Address, "fake_coin", "USDC", nil)},
			[]aptos.EntryFunctionArg{aptos.JsonUint64(1000000000000)}),
	}

	if err := client.FillTransactionData(context.Background(), &tx, false); err != nil {
		panic(err)
	}

	encode, err := client.EncodeSubmission(context.Background(),
		&aptos.EncodeSubmissionRequest{
			Transaction: &tx,
		},
	)
	if err != nil {
		panic(err)
	}

	data, err := hex.DecodeString(strings.TrimPrefix(string(*encode.Parsed), "0x"))
	if err != nil {
		panic(err)
	}

	signature, _ := account.Sign(data)

	request := &aptos.SubmitTransactionRequest{
		Transaction: &tx,
		Signature:   *signature,
	}
	body, _ := request.Body()
	fmt.Fprintln(os.Stderr, string(body))
	resp, err := client.SubmitTransaction(context.Background(), request)
	if err != nil {
		panic(err)
	} else {
		spew.Fdump(os.Stderr, resp)
		ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
		defer cancel()
		status, err := client.WaitForTransaction(ctx, resp.Parsed.Hash)
		if err != nil {
			panic(err)
		} else {
			fmt.Println(status)
		}
	}
}
Output:

func (*Client) WaitForTransaction

func (client *Client) WaitForTransaction(ctx context.Context, txHash string, waitOptions ...TransactionWaitOption) (string, error)

WaitForTransaction by default the wait is exponentially backing off with a scale of 2 and initial wait of 1 second.

type Coin

type Coin struct {
	Value JsonUint64 `json:"value"`
}

type Config

type Config struct {
	PrivateKey string `yaml:"private_key"`
	PublicKey  string `yaml:"public_key"`
	Account    string `yaml:"account"`
	RestUrl    string `yaml:"rest_url"`
	FaucetUrl  string `yaml:"faucet_url"`
}

Config is a configuration section in aptos's yaml config file.

func (*Config) GetLocalAccount

func (config *Config) GetLocalAccount() (*LocalAccount, error)

func (*Config) SetKey

func (config *Config) SetKey(account *LocalAccount) error

type ConfigFile

type ConfigFile struct {
	Profiles map[string]*Config `yaml:"profiles"`
}

func NewConfigFile

func NewConfigFile() *ConfigFile

func ParseAptosConfigFile

func ParseAptosConfigFile(configFileContent []byte) (*ConfigFile, error)

func (*ConfigFile) ToString

func (c *ConfigFile) ToString() ([]byte, error)

type EncodeSubmissionRequest

type EncodeSubmissionRequest struct {
	*Transaction     `json:",inline" url:"-"`
	SecondarySigners []Address `json:"secondary_signers,omitempty" url:"-"`
}

EncodeSubmissionRequest

func (*EncodeSubmissionRequest) Body

func (r *EncodeSubmissionRequest) Body() ([]byte, error)

func (*EncodeSubmissionRequest) HttpMethod

func (r *EncodeSubmissionRequest) HttpMethod() string

func (*EncodeSubmissionRequest) PathSegments

func (r *EncodeSubmissionRequest) PathSegments() ([]string, error)

type EncodeSubmissionResponse

type EncodeSubmissionResponse string

type EntryFunctionArg

type EntryFunctionArg interface {
	ToBCS() []byte
}

EntryFunctionArg is argument to entry function

type EntryFunctionArgSlice

type EntryFunctionArgSlice []EntryFunctionArg

EntryFunctionArgSlice

  • for json: Parsing json or bcs payload coming back from remote is difficult without knowning the type of the payload slice. This slice will first test if the value is an u64 or bool, then try to convert the value into a string. If the converted string has 0x prefix, it will try cast that into an address. If casting fails, it will keep it as string.

  • for bcs: Instead of serialize each element in the slice, the element of entry function argument slice is prefixed with the length of the serialized bytes. For example, instead of serialize true to 01, serialize it to 0101.

func (EntryFunctionArgSlice) ToBCS

func (s EntryFunctionArgSlice) ToBCS() []byte

func (*EntryFunctionArgSlice) UnmarshalJSON

func (s *EntryFunctionArgSlice) UnmarshalJSON(data []byte) error

type EntryFunctionArgVector

type EntryFunctionArgVector[T EntryFunctionArg] []T

func (EntryFunctionArgVector[T]) ToBCS

func (v EntryFunctionArgVector[T]) ToBCS() []byte

type EntryFunctionArg_Bool

type EntryFunctionArg_Bool bool

EntryFunctionArg_Bool

func (EntryFunctionArg_Bool) MarshalJSON

func (b EntryFunctionArg_Bool) MarshalJSON() ([]byte, error)

func (EntryFunctionArg_Bool) ToBCS

func (b EntryFunctionArg_Bool) ToBCS() []byte

func (*EntryFunctionArg_Bool) UnmarshalJSON

func (b *EntryFunctionArg_Bool) UnmarshalJSON(data []byte) error

type EntryFunctionArg_String

type EntryFunctionArg_String string

func (EntryFunctionArg_String) MarshalJSON

func (s EntryFunctionArg_String) MarshalJSON() ([]byte, error)

func (EntryFunctionArg_String) ToBCS

func (s EntryFunctionArg_String) ToBCS() []byte

func (*EntryFunctionArg_String) UnmarshalJSON

func (s *EntryFunctionArg_String) UnmarshalJSON(data []byte) error

type EntryFunctionArg_Uint128

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

func NewEntryFunctionArg_Uint128

func NewEntryFunctionArg_Uint128(s string) (*EntryFunctionArg_Uint128, error)

func (EntryFunctionArg_Uint128) MarshalJSON

func (i EntryFunctionArg_Uint128) MarshalJSON() ([]byte, error)

func (EntryFunctionArg_Uint128) ToBCS

func (i EntryFunctionArg_Uint128) ToBCS() []byte

func (*EntryFunctionArg_Uint128) UnmarshalJSON

func (i *EntryFunctionArg_Uint128) UnmarshalJSON(data []byte) error

type EntryFunctionArg_Uint64

type EntryFunctionArg_Uint64 = JsonUint64

EntryFunctionArg_Uint64 is equivalent to uint64, or u64 in move.

type EntryFunctionArg_Uint8

type EntryFunctionArg_Uint8 uint8

EntryFunctionArg_Uint8 represents u8 in move, equivalent to a byte

func (EntryFunctionArg_Uint8) MarshalJSON

func (u EntryFunctionArg_Uint8) MarshalJSON() ([]byte, error)

func (EntryFunctionArg_Uint8) ToBCS

func (u EntryFunctionArg_Uint8) ToBCS() []byte

func (*EntryFunctionArg_Uint8) UnmarshalJSON

func (u *EntryFunctionArg_Uint8) UnmarshalJSON(data []byte) error

type EntryFunctionPayload

type EntryFunctionPayload struct {
	Type          string                `json:"type"`
	Function      *MoveFunctionTag      `json:"function"`
	TypeArguments []*MoveTypeTag        `json:"type_arguments"`
	Arguments     EntryFunctionArgSlice `json:"arguments"`
}

EntryFunctionPayload

func NewEntryFunctionPayload

func NewEntryFunctionPayload(functionName *MoveFunctionTag, typeArguments []*MoveTypeTag, arguments []EntryFunctionArg) *EntryFunctionPayload

NewEntryFunctionPayload

func (EntryFunctionPayload) ToBCS

func (f EntryFunctionPayload) ToBCS() []byte

type EstimateGasPriceResponse

type EstimateGasPriceResponse struct {
	DeprioritizedGasEstimate uint `json:"deprioritized_gas_estimate"`
	GasEstimate              uint `json:"gas_estimate"`
	PrioritizedGasEstimate   uint `json:"prioritized_gas_estimate"`
}

type Event

type Event[T any] struct {
	GUID           EventGUID   `json:"guid"`
	SequenceNumber JsonUint64  `json:"sequence_number"`
	Type           MoveTypeTag `json:"type"`
	Data           *T          `json:"data"`
}

Event emitted from aptos transactions

type EventGUID

type EventGUID struct {
	CreationNumber JsonUint64 `json:"creation_num"`
	AccountAddress Address    `json:"addr"`
}

type EventHandler

type EventHandler struct {
	Counter JsonUint64 `json:"counter"`
	GUID    struct {
		Id EventGUID `json:"id"`
	} `json:"guid"`
}

type FullNodeConfig

type FullNodeConfig struct {
	Base *struct {
		DataDir  string `yaml:"data_dir"`
		Waypoint *struct {
			FromFile string         `yaml:"from_file"`
			Others   map[string]any `yaml:",inline"`
		} `yaml:"waypoint"`
		Others map[string]any `yaml:",inline"`
	} `yaml:"base"`
	Execution *struct {
		GenesisFileLocation string         `yaml:"genesis_file_location"`
		Others              map[string]any `yaml:",inline"`
	} `yaml:"execution"`
	FullNodeNetworks []*struct {
		Others map[string]any `yaml:",inline"`
	} `yaml:"full_node_networks"`

	Api *struct {
		Enabled bool           `yaml:"enabled"`
		Address string         `yaml:"address"`
		Others  map[string]any `yaml:",inline"`
	} `yaml:"api"`
	Others map[string]any `yaml:",inline"`
}

FullNodeConfig is representation of full_node_config.yml

func ParseFullNodeConfig

func ParseFullNodeConfig(data []byte) (*FullNodeConfig, error)

func (*FullNodeConfig) ToConfigFile

func (config *FullNodeConfig) ToConfigFile() ([]byte, error)

type GetAccountRequest

type GetAccountRequest struct {
	GetRequest

	Address       Address `url:"-"`
	LedgerVersion *uint64 `url:"ledger_version,omitempty"`
}

func (*GetAccountRequest) PathSegments

func (r *GetAccountRequest) PathSegments() ([]string, error)

type GetAccountResourceRequest

type GetAccountResourceRequest struct {
	GetRequest

	Address       Address `url:"-"`
	LedgerVersion *uint64 `url:"ledger_version,omitempty"`
	Type          *MoveTypeTag
}

func (*GetAccountResourceRequest) PathSegments

func (r *GetAccountResourceRequest) PathSegments() ([]string, error)

type GetAccountResourceResponse

type GetAccountResourceResponse struct {
	*AccountResource `json:",inline"`
}

type GetAccountResourcesRequest

type GetAccountResourcesRequest struct {
	GetRequest

	Address       Address `url:"-"`
	LedgerVersion *uint64 `url:"ledger_version,omitempty"`
}

func (*GetAccountResourcesRequest) PathSegments

func (r *GetAccountResourcesRequest) PathSegments() ([]string, error)

type GetAccountResourcesResponse

type GetAccountResourcesResponse []AccountResource

type GetAccountResponse

type GetAccountResponse struct {
	SequenceNumber    JsonUint64 `json:"sequence_number"`
	AuthenticationKey string     `json:"authentication_key"`
}

type GetLedgerInfoResponse

type GetLedgerInfoResponse struct {
	*LedgerInfo `json:",inline"`
}

type GetRequest

type GetRequest struct{}

GetRequest embed this struct for a get request where only path segments are necessary.

func (*GetRequest) Body

func (*GetRequest) Body() ([]byte, error)

func (*GetRequest) HttpMethod

func (*GetRequest) HttpMethod() string

type GetTransactionByHashRequest

type GetTransactionByHashRequest struct {
	GetRequest
	Hash string `url:"-"`
}

func (*GetTransactionByHashRequest) PathSegments

func (r *GetTransactionByHashRequest) PathSegments() ([]string, error)

type GetTransactionByHashResponse

type GetTransactionByHashResponse struct {
	*Transaction     `json:",inline"`
	Type             string `json:"type"`
	*TransactionInfo `json:",inline"`
}

type JsonUint64

type JsonUint64 uint64

JsonUint64 is an uint64, but serialized into a string, and can be deserialized from either a string or a number from json. This is because aptos fullnode uses string for uint64, whereas golang's json encoding only support number.

func (JsonUint64) MarshalJSON

func (i JsonUint64) MarshalJSON() ([]byte, error)

func (JsonUint64) ToBCS

func (i JsonUint64) ToBCS() []byte

func (*JsonUint64) UnmarshalJSON

func (i *JsonUint64) UnmarshalJSON(data []byte) error

type LedgerInfo

type LedgerInfo struct {
	ChainId             int32      `json:"chain_id"`
	Epoch               JsonUint64 `json:"epoch"`
	LedgerVersion       JsonUint64 `json:"ledger_version"`
	OldestLedgerVersion JsonUint64 `json:"oldest_ledger_version"`
	LedgerTimestamp     JsonUint64 `json:"ledger_timestamp"`
	NodeRole            string     `json:"node_role"`
	OldestBlockHeight   JsonUint64 `json:"oldest_block_height"`
	BlockHeight         JsonUint64 `json:"block_height"`
	GitHash             string     `json:"git_hash"`
}

LedgerInfo contains basic information about the chain.

type LocalAccount

type LocalAccount struct {
	PrivateKey ed25519.PrivateKey
	PublicKey  ed25519.PublicKey
	Address    Address
}

LocalAccount contains the private key, public key, and the address.

func NewLocalAccountFromPrivateKey

func NewLocalAccountFromPrivateKey(privateKey *ed25519.PrivateKey) (*LocalAccount, error)

NewLocalAccountFromPrivateKey creates a local account based on the private key. the authentication key will be the one calculated from public key.

func NewLocalAccountWithMnemonic

func NewLocalAccountWithMnemonic() (*LocalAccount, string, error)

func NewLocalAccountWithRandomKey

func NewLocalAccountWithRandomKey() (*LocalAccount, error)

NewLocalAccountWithRandomKey creates a new account with random key.

func (*LocalAccount) IsOriginalAuthenticationKey

func (account *LocalAccount) IsOriginalAuthenticationKey() bool

IsOriginalAuthenticationKey checks if the authentication key is the authentication key generated from the single public key.

func (*LocalAccount) Sign

func (account *LocalAccount) Sign(message []byte) (*SingleSignature, error)

func (*LocalAccount) SignForSimulation

func (account *LocalAccount) SignForSimulation(message []byte) (*SingleSignature, error)

type MoveFunctionTag

type MoveFunctionTag struct {
	MoveModuleTag

	Name string
}

MoveFunctionTag identifies a function on chain. Note the function's generic parameters or parameters are not part of the tag.

func MustNewMoveFunctionTag

func MustNewMoveFunctionTag(address Address, module, name string) *MoveFunctionTag

func NewMoveFunctionTag

func NewMoveFunctionTag(address Address, module, name string) (*MoveFunctionTag, error)

func ParseModuleFunctionTag

func ParseModuleFunctionTag(str string) (*MoveFunctionTag, error)

func (MoveFunctionTag) MarshalJSON

func (f MoveFunctionTag) MarshalJSON() ([]byte, error)

func (MoveFunctionTag) String

func (f MoveFunctionTag) String() string

func (MoveFunctionTag) ToBCS

func (f MoveFunctionTag) ToBCS() []byte

func (*MoveFunctionTag) UnmarshalJSON

func (f *MoveFunctionTag) UnmarshalJSON(data []byte) error

type MoveModuleTag

type MoveModuleTag struct {
	// Address of module
	Address Address
	// Module name
	Module string
}

MoveModuleTag identifies a move module on the chain

func MustNewMoveModuleTag

func MustNewMoveModuleTag(address Address, module string) *MoveModuleTag

func NewMoveModuleTag

func NewMoveModuleTag(address Address, module string) (*MoveModuleTag, error)

NewMoveModuleTag creates a new module module tag

func ParseMoveModuleTag

func ParseMoveModuleTag(str string) (*MoveModuleTag, error)

func (MoveModuleTag) MarshalJSON

func (m MoveModuleTag) MarshalJSON() ([]byte, error)

func (*MoveModuleTag) Set

func (m *MoveModuleTag) Set(str string) error

func (MoveModuleTag) String

func (m MoveModuleTag) String() string

func (MoveModuleTag) ToBCS

func (m MoveModuleTag) ToBCS() []byte

func (MoveModuleTag) Type

func (m MoveModuleTag) Type() string

func (*MoveModuleTag) UnmarshalJSON

func (m *MoveModuleTag) UnmarshalJSON(data []byte) error

type MoveType

type MoveType uint8

MoveType aptos right now supports the following types - bool - u8 - u64 - u128 - address - signer - vector - struct

const (
	MoveType_Bool    MoveType = iota // move_type_bool
	MoveType_Uint8                   // mvoe_type_u8
	MoveType_Uint64                  // move_type_u64
	MoveType_Uint128                 // move_type_u128
	MoveType_Address                 // move_type_address
	MoveType_Signer                  // move_type_signer
	MoveType_Vector                  // move_type_vector
	MoveType_Struct                  // move_type_struct
)

func (MoveType) String

func (i MoveType) String() string

type MoveTypeTag

type MoveTypeTag struct {
	MoveModuleTag
	// Name of the type
	Name string

	GenericTypeParameters []*MoveTypeTag
}

A type in move is in the format of address::module_name::TypeName off-chain, the address is a 0x prefixed hex encoded string, but during move development there can be named addresses.

func GetAuxFakeCoinCoinType

func GetAuxFakeCoinCoinType(moduleAddress Address, fakeCoin AuxFakeCoin) (*MoveTypeTag, error)

GetAuxFakeCoinCoinType returns the fake coin coin type - this is a coin as defined by the aptos framework.

func GetAuxFakeCoinType

func GetAuxFakeCoinType(moduleAddress Address, fakeCoin AuxFakeCoin) (*MoveTypeTag, error)

GetAuxFakeCoinType returns the fake coin type. Note, this is actually not a type of coin. Use GetAuxFakeCoinCoinType to get the coin type.

func MustNewMoveTypeTag

func MustNewMoveTypeTag(address Address, module, name string, genericTypeParameters []*MoveTypeTag) *MoveTypeTag

func NewMoveTypeTag

func NewMoveTypeTag(address Address, module string, name string, genericTypeParameters []*MoveTypeTag) (*MoveTypeTag, error)

func ParseMoveTypeTag

func ParseMoveTypeTag(fullName string) (*MoveTypeTag, error)

ParseMoveTypeTag takes the full name of the move type tag

func (*MoveTypeTag) MarshalJSON

func (t *MoveTypeTag) MarshalJSON() ([]byte, error)

func (*MoveTypeTag) Set

func (t *MoveTypeTag) Set(data string) error

Set is to support cobra value

func (*MoveTypeTag) String

func (t *MoveTypeTag) String() string

func (*MoveTypeTag) ToBCS

func (t *MoveTypeTag) ToBCS() []byte

ToBCS for MoveTypeTag. Note move supports 8 types (see MoveType), therefore the first byte is 7, which is `MoveType_Struct`

func (*MoveTypeTag) Type

func (t *MoveTypeTag) Type() string

Type is to support cobra value

func (*MoveTypeTag) UnmarshalJSON

func (t *MoveTypeTag) UnmarshalJSON(data []byte) error

type Network

type Network string
const (
	Devnet    Network = "devnet"
	Testnet   Network = "testnet"
	Localnet  Network = "localnet"
	Mainnet   Network = "mainnet"
	Customnet Network = "customnet"
)

func (*Network) Set

func (network *Network) Set(s string) error

func (Network) String

func (network Network) String() string

func (*Network) Type

func (network *Network) Type() string

type RawEvent

type RawEvent = Event[json.RawMessage]

type SimulateTransactionRequest

type SimulateTransactionRequest struct {
	*Transaction `json:",inline" url:"-"`
	Signature    *SingleSignature `json:"signature" url:"-"`
}

func (*SimulateTransactionRequest) Body

func (request *SimulateTransactionRequest) Body() ([]byte, error)

func (*SimulateTransactionRequest) HttpMethod

func (request *SimulateTransactionRequest) HttpMethod() string

func (*SimulateTransactionRequest) PathSegments

func (request *SimulateTransactionRequest) PathSegments() ([]string, error)

type SimulateTransactionResponse

type SimulateTransactionResponse []struct {
	*Transaction     `json:",inline" url:"-"`
	*TransactionInfo `json:",inline" url:"-"`
}

type SingleSignature

type SingleSignature struct {
	Type      string `json:"type"`
	PublicKey string `json:"public_key"`
	Signature string `json:"signature"`
}

SingleSignature

func NewSingleSignature

func NewSingleSignature(publicKey *ed25519.PublicKey, signature []byte) *SingleSignature

func NewSingleSignatureForSimulation

func NewSingleSignatureForSimulation(publicKey *ed25519.PublicKey) *SingleSignature

type SubmitTransactionRequest

type SubmitTransactionRequest struct {
	*Transaction `json:",inline" url:"-"`
	Signature    SingleSignature `json:"signature" url:"-"`
}

func (*SubmitTransactionRequest) Body

func (r *SubmitTransactionRequest) Body() ([]byte, error)

func (*SubmitTransactionRequest) HttpMethod

func (r *SubmitTransactionRequest) HttpMethod() string

func (*SubmitTransactionRequest) PathSegments

func (r *SubmitTransactionRequest) PathSegments() ([]string, error)

type SubmitTransactionResponse

type SubmitTransactionResponse struct {
	*Transaction     `json:",inline"`
	*TransactionInfo `json:",inline"`
}

type Table

type Table struct {
	Handle Address `json:"handle"`
}

type TableWithLength

type TableWithLength struct {
	Inner  *Table     `json:"inner"`
	Length JsonUint64 `json:"length"`
}

type Transaction

type Transaction struct {
	// Sender.
	// Note if the signer is the first parameter, it doesn't need to be included in the payload parameter list.
	Sender Address `json:"sender"`
	// SequenceNumber of the transaction for the sender.
	// transactions with sequence number less than the curernt on chain sequence number for address will be rejected.
	SequenceNumber JsonUint64 `json:"sequence_number"`
	// MaxGasAmount
	MaxGasAmount JsonUint64 `json:"max_gas_amount"`
	// UnitGasPrice
	GasUnitPrice JsonUint64 `json:"gas_unit_price"`
	// ExpirationTimestampSecs
	ExpirationTimestampSecs JsonUint64            `json:"expiration_timestamp_secs"`
	Payload                 *EntryFunctionPayload `json:"payload"`
}

Transaction doesn't have signatures attached to them.

func ApplyTransactionOptions

func ApplyTransactionOptions(tx *Transaction, options ...TransactionOption) *Transaction

ApplyTransactionOptions apply multiple options in order

type TransactionInfo

type TransactionInfo struct {
	// Hash of the transaction.
	Hash string `json:"hash"`

	StateChangeHash     string `json:"state_change_hash"`
	EventRootHash       string `json:"event_root_hash"`
	StateCheckPointHash string `json:"state_checkpoint_hash"`

	GasUsed JsonUint64 `json:"gas_used"`

	// If the transaction is successful or not.
	Success bool `json:"success"`

	// VmStatus is useful for debug if the transaction failed.
	VmStatus            string `json:"vm_status"`
	AccumulatorRootHash string `json:"accumulator_root_hash"`

	Changes []json.RawMessage `json:"changes"`
	Events  []*RawEvent       `json:"events"`

	Timestamp JsonUint64 `json:"timestamp"`
}

TransactionInfo contains the information about the transaction that has been submitted to the blockchain.

type TransactionOption

type TransactionOption interface {
	SetTransactionOption(*Transaction) *Transaction
}

TransactionOption for transaction

type TransactionOption_ExpireAfter

type TransactionOption_ExpireAfter time.Duration

TransactionOption_ExpireAfter specifies a duration after which the transaction will expire. The expiry will be computed when SetTransactionOption is called, instead of right now.

func (TransactionOption_ExpireAfter) SetTransactionOption

func (duration TransactionOption_ExpireAfter) SetTransactionOption(tx *Transaction) *Transaction

type TransactionOption_ExpireAt

type TransactionOption_ExpireAt time.Time

TransactionOption_ExpireAt specifies a time point that the transaction will expire at.

func (TransactionOption_ExpireAt) SetTransactionOption

func (expiry TransactionOption_ExpireAt) SetTransactionOption(tx *Transaction) *Transaction

type TransactionOption_GasUnitPrice

type TransactionOption_GasUnitPrice uint64

TransactionOption_GasUnitPrice sets the gas unit price of the transaction

func (TransactionOption_GasUnitPrice) SetTransactionOption

func (gasUnitPrice TransactionOption_GasUnitPrice) SetTransactionOption(tx *Transaction) *Transaction

type TransactionOption_MaxGasAmount

type TransactionOption_MaxGasAmount uint64

Max Gas Amount Option

func (TransactionOption_MaxGasAmount) SetTransactionOption

func (maxGasAmount TransactionOption_MaxGasAmount) SetTransactionOption(tx *Transaction) *Transaction

type TransactionOption_Sender

type TransactionOption_Sender Address

TransactionOption_Sender sets the sender of the transaction.

func (TransactionOption_Sender) SetTransactionOption

func (sender TransactionOption_Sender) SetTransactionOption(tx *Transaction) *Transaction

type TransactionOption_SequenceNumber

type TransactionOption_SequenceNumber uint64

TransactionOption_SequenceNumber sets the sequence number of transaction.

func (TransactionOption_SequenceNumber) SetTransactionOption

func (seqnum TransactionOption_SequenceNumber) SetTransactionOption(tx *Transaction) *Transaction

type TransactionOptions

TransactionOptions contains all possible transactions

func (*TransactionOptions) FillIfDefault

func (options *TransactionOptions) FillIfDefault(tx *Transaction)

FillIfDefault only overwrite the transaction option if it is set to the default value.

func (*TransactionOptions) SetOption

func (options *TransactionOptions) SetOption(opt TransactionOption)

SetOption sets the specific option on the options. If there is already an option for that specifc option, it will be overwritten.

type TransactionWaitOption

type TransactionWaitOption struct {
	Scale       float64
	InitialWait time.Duration
	// contains filtered or unexported fields
}

func NewTransactionWaitOption

func NewTransactionWaitOption(scale float64, initialWait time.Duration) TransactionWaitOption

func (*TransactionWaitOption) Wait

func (w *TransactionWaitOption) Wait() <-chan time.Time

type TypedAccountResource

type TypedAccountResource[T any] struct {
	AccountResource
	ParsedData *T
}

TypedAccountResource

Directories

Path Synopsis
cmd
contains commands that are supported by the aptos-aux cli.
contains commands that are supported by the aptos-aux cli.
aptos-aux
aptos-aux is a cli for aptos and aux.exchange
aptos-aux is a cli for aptos and aux.exchange
Known coins, pools, markets included with the binary.
Known coins, pools, markets included with the binary.

Jump to

Keyboard shortcuts

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