sui

package
v0.0.0-...-2e449e2 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0, MIT Imports: 24 Imported by: 0

README

Generated Go bindings for Sui Rust types

  • The Rust codebase for Sui has a bunch of important types (i.e. Rust enums or Rust structs). The most important one of them is TransactionData, which is used in Sui transactions. Specifically, the sui_executeTransactionBlock endpoint in a full node expects a tx_bytes parameter; this parameter is a BCS-encoded instance of the TransactionData struct, in base64.

In other words, if you want to execute a Sui transaction (from Rust), you need to:

  1. Create an instance of TransactionData in memory;
  2. Serialize that TransactionData into a vector of bytes using BCS;
  3. Encode that vector of bytes into base64;
  4. Pass that base64 string to the sui_executeTransactionBlock endpoint.

This directory contains Go types (i.e. structs and interfaces) that mirror their corresponding Rust types, and can be used to generate valid BCS data from Go. This is achieved by using https://github.com/zefchain/serde-reflection, like this:

  1. The Sui team exposes https://github.com/MystenLabs/sui/blob/main/crates/sui-core/tests/staged/sui.yaml, a YAML dump of all their Rust structs, generated with serde-reflection. We copy that file here as sui_types.yaml.
  2. We then use serde-generate (also part of https://github.com/zefchain/serde-reflection) to transform that YAML dump into auto-generated Go code that we can use to build and serialize Sui Rust types.

For posterity, these are the commands I ran to generate all files in this directory:

cp ~/code/github.com/MystenLabs/sui/crates/sui-core/tests/staged/sui.yaml sui_types.yaml

serdegen --language go --target-source-dir ./generated --module-name bcs --with-runtimes bcs -- sui_types.yaml

gofmt -w generated/bcs/lib.go

Documentation

Index

Constants

View Source
const (
	ADDRESS_LENGTH             = 64
	SIGNATURE_SCHEME_ED25519   = 0
	SIGNATURE_SCHEME_SECP256k1 = 1
)
View Source
const GAS_BUDGET_PER_COIN = uint64(20_000_000)

Variables

View Source
var (
	MaxCoinObjects int = 50
)

Functions

func AddressOrObjectOwner

func AddressOrObjectOwner(obj *types.ObjectOwner) (string, bool)

func ArgumentInput

func ArgumentInput(index uint16) *bcs.Argument__Input

func ArgumentResult

func ArgumentResult(index uint16) *bcs.Argument__Result

func Base58ToObjectDigest

func Base58ToObjectDigest(str string) (bcs.ObjectDigest, error)

func CheckError

func CheckError(err error) errors.Status

func CoinEqual

func CoinEqual(coin1 *types.Coin, coin2 *types.Coin) bool

func CoinToObject

func CoinToObject(coin *types.Coin) (*bcs.ObjectArg__ImmOrOwnedObject, error)

func DecodeHex

func DecodeHex(str string) ([]byte, error)

func HexToAddress

func HexToAddress(str string) (bcs.SuiAddress, error)

func HexToObjectID

func HexToObjectID(str string) (bcs.ObjectID, error)

func HexToPure

func HexToPure(str string) (*bcs.CallArg__Pure, error)

func NewAddressBuilder

func NewAddressBuilder(asset xc.ITask) (xc.AddressBuilder, error)

NewAddressBuilder creates a new Template AddressBuilder

func NormalizeCoinContract

func NormalizeCoinContract(contract string) string

Strip the coin::Coin<_> wrapper if present

func SortCoins

func SortCoins(coins []*types.Coin)

func U64ToPure

func U64ToPure(x uint64) *bcs.CallArg__Pure

Types

type AddressBuilder

type AddressBuilder struct {
}

func (AddressBuilder) GetAddressFromPublicKey

func (ab AddressBuilder) GetAddressFromPublicKey(publicKeyBytes []byte) (xc.Address, error)

func (AddressBuilder) GetAllPossibleAddressesFromPublicKey

func (ab AddressBuilder) GetAllPossibleAddressesFromPublicKey(publicKeyBytes []byte) ([]xc.PossibleAddress, error)

type Checkpoint

type Checkpoint struct {
	Epoch                    string `json:"epoch"`
	SequenceNumber           string `json:"sequenceNumber"`
	Digest                   string `json:"digest"`
	NetworkTotalTransactions string `json:"networkTotalTransactions"`
	PreviousDigest           string `json:"PreviousDigest"`
	TimestampMs              string `json:"timestampMs"`
}

func (*Checkpoint) GetEpoch

func (ch *Checkpoint) GetEpoch() uint64

func (*Checkpoint) GetSequenceNumber

func (ch *Checkpoint) GetSequenceNumber() uint64

type Checkpoints

type Checkpoints struct {
	Data []*Checkpoint `json:"data"`
}

type Client

type Client struct {
	Asset     xc.ITask
	SuiClient *client.Client
}

Client for Sui

func NewClient

func NewClient(cfgI xc.ITask) (*Client, error)

NewClient returns a new Sui Client

func (*Client) EstimateGas

func (c *Client) EstimateGas(ctx context.Context) (xc.AmountBlockchain, error)

func (*Client) FetchBalance

func (c *Client) FetchBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)

func (*Client) FetchBalanceFor

func (c *Client) FetchBalanceFor(ctx context.Context, address xc.Address, contract string) (xc.AmountBlockchain, error)

func (*Client) FetchCheckpoint

func (c *Client) FetchCheckpoint(ctx context.Context, checkpoint uint64) (*Checkpoint, error)

func (*Client) FetchDecimals

func (client *Client) FetchDecimals(ctx context.Context, contract xc.ContractAddress) (int, error)

func (*Client) FetchLatestCheckpoint

func (c *Client) FetchLatestCheckpoint(ctx context.Context) (*Checkpoint, error)

func (*Client) FetchLegacyTxInfo

func (c *Client) FetchLegacyTxInfo(ctx context.Context, txHash xc.TxHash) (xc.LegacyTxInfo, error)

func (*Client) FetchLegacyTxInput

func (c *Client) FetchLegacyTxInput(ctx context.Context, from xc.Address, to xc.Address) (xc.TxInput, error)

func (*Client) FetchNativeBalance

func (c *Client) FetchNativeBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)

func (*Client) FetchTransferInput

func (c *Client) FetchTransferInput(ctx context.Context, args xcbuilder.TransferArgs) (xc.TxInput, error)

func (*Client) FetchTxInfo

func (client *Client) FetchTxInfo(ctx context.Context, txHashStr xc.TxHash) (xclient.TxInfo, error)

func (*Client) GetAllCoinsFor

func (c *Client) GetAllCoinsFor(ctx context.Context, address xc.Address, contract string) ([]*types.Coin, error)

func (*Client) SubmitTx

func (c *Client) SubmitTx(ctx context.Context, tx xc.Tx) error

SubmitTx submits a Sui tx

type ObjectRef

type ObjectRef struct {
	Field0 bcs.ObjectID
	Field1 bcs.SequenceNumber
	Field2 bcs.ObjectDigest
}

type SuiMethod

type SuiMethod string

func (SuiMethod) String

func (m SuiMethod) String() string

type Tx

type Tx struct {
	Tx bcs.TransactionData__V1
	// contains filtered or unexported fields
}

func (*Tx) AddSignatures

func (tx *Tx) AddSignatures(signatures ...xc.TxSignature) error

func (Tx) GetSignatures

func (tx Tx) GetSignatures() []xc.TxSignature

func (Tx) Hash

func (tx Tx) Hash() xc.TxHash

Hash returns the tx hash or id

func (Tx) Serialize

func (tx Tx) Serialize() ([]byte, error)

func (Tx) Sighashes

func (tx Tx) Sighashes() ([]xc.TxDataToSign, error)

type TxBuilder

type TxBuilder struct {
	Asset xc.ITask
}

func NewTxBuilder

func NewTxBuilder(asset xc.ITask) (*TxBuilder, error)

NewTxBuilder creates a new Template TxBuilder

func (TxBuilder) NewNativeTransfer

func (txBuilder TxBuilder) NewNativeTransfer(from xc.Address, to xc.Address, amount xc.AmountBlockchain, input xc.TxInput) (xc.Tx, error)

func (TxBuilder) NewTokenTransfer

func (txBuilder TxBuilder) NewTokenTransfer(from xc.Address, to xc.Address, amount xc.AmountBlockchain, input xc.TxInput) (xc.Tx, error)

func (TxBuilder) NewTransfer

func (txBuilder TxBuilder) NewTransfer(from xc.Address, to xc.Address, amount xc.AmountBlockchain, input xc.TxInput) (xc.Tx, error)

Old transfer interface

func (TxBuilder) Transfer

func (txBuilder TxBuilder) Transfer(args xcbuilder.TransferArgs, input xc.TxInput) (xc.Tx, error)

NewTransfer creates a new transfer for an Asset, either native or token

type TxInput

type TxInput struct {
	xc.TxInputEnvelope
	GasBudget uint64 `json:"gas_budget,omitempty"`
	GasPrice  uint64 `json:"gas_price,omitempty"`
	Pubkey    []byte `json:"pubkey,omitempty"`
	// Native Sui object that we can use to pay gas with
	GasCoin types.Coin `json:"gas_coin,omitempty"`
	// All objects (native or token)
	Coins []*types.Coin `json:"coins,omitempty"`
	// current epoch
	CurrentEpoch uint64 `json:"current_epoch,omitempty"`
}

Tx for Template

func NewTxInput

func NewTxInput() *TxInput

func (*TxInput) ExcludeGasCoin

func (input *TxInput) ExcludeGasCoin()

func (*TxInput) GetDriver

func (input *TxInput) GetDriver() xc.Driver

func (*TxInput) IndependentOf

func (input *TxInput) IndependentOf(other xc.TxInput) (independent bool)

func (*TxInput) IsNativeTransfer

func (input *TxInput) IsNativeTransfer() bool

func (*TxInput) SafeFromDoubleSend

func (input *TxInput) SafeFromDoubleSend(others ...xc.TxInput) (safe bool)

func (*TxInput) SetGasFeePriority

func (input *TxInput) SetGasFeePriority(other xc.GasFeePriority) error

func (*TxInput) SetPublicKey

func (input *TxInput) SetPublicKey(pubkey []byte) error

func (*TxInput) SetPublicKeyFromStr

func (input *TxInput) SetPublicKeyFromStr(pubkeyStr string) error

func (*TxInput) SortCoins

func (input *TxInput) SortCoins()

Sort coins in place from highest to lowest

func (*TxInput) TotalBalance

func (input *TxInput) TotalBalance() xc.AmountBlockchain

Directories

Path Synopsis
generated
bcs

Jump to

Keyboard shortcuts

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