suisdk

package
v0.0.0-...-742ae29 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SigntureFlagEd25519     = 0x0
	SigntureFlagSecp256k1   = 0x1
	AddressLength           = 64
	DerivationPathEd25519   = `m/44'/784'/0'/0'/0'`
	DerivationPathSecp256k1 = `m/54'/784'/0'/0/0`
)
View Source
const (
	Ed25519Flag   KeyPair = 0
	Secp256k1Flag KeyPair = 1
	ErrorFlag     byte    = math.MaxUint8
)
View Source
const (
	DEVNET_URL  = "https://fullnode.devnet.sui.io:443"
	TESTNET_URL = "https://fullnode.testnet.sui.io:443"
	MAINNET_URL = "https://fullnode.mainnet.sui.io:443"

	COIN_SUI   = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
	COIN_DEEP  = "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
	COIN_CETUS = "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"
	COIN_NS    = "0x5145494a5f5100e645e4b0aa950fa6b68f614e8c59e17bc5ded3495123a79178::ns::NS"
)
View Source
const (
	FirstHardenedIndex = uint32(0x80000000)
)

Variables

View Source
var (
	ErrInvalidPath        = errors.New("invalid derivation path")
	ErrNoPublicDerivation = errors.New("no public derivation for ed25519")
)
View Source
var IntentBytes = []byte{0, 0, 0}

Functions

func BCS

func BCS()

func ExampleExecuteEx1

func ExampleExecuteEx1()

func ExampleGetTransactionBlock

func ExampleGetTransactionBlock()

func Exec

func Exec()

func ParseAddress

func ParseAddress(addrStr string) transactiondata.SuiAddress

Types

type Account

type Account struct {
	PriKey  ed25519.PrivateKey
	PubKey  ed25519.PublicKey
	Address string
}

func NewAccountFromAdress

func NewAccountFromAdress(address string) *Account

func NewAccountFromMnemonic

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

func (*Account) NewMessageWithIntent

func (c *Account) NewMessageWithIntent(message []byte, scope IntentScope) []byte

func (*Account) SignMessage

func (c *Account) SignMessage(data string, scope IntentScope) (*SignedMessageSerializedSig, error)

func (*Account) Signature

func (c *Account) Signature(txBytesStr string) (*SignedTransactionSerializedSig, error)

func (*Account) ToSerializedSignature

func (c *Account) ToSerializedSignature(signature, pubKey []byte) string

type ArgObject

type ArgObject string

type ArgU64

type ArgU64 uint64

type Balance

type Balance struct {
	CoinType        string `json:"coinType"`
	CoinObjectCount int    `json:"coinObjectCount"`
	TotalBalance    string `json:"totalBalance"`
}

TODO: locked balance

type Client

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

func NewClient

func NewClient(rpcURL string) *Client

func (*Client) DryRunTransactionBlock

func (c *Client) DryRunTransactionBlock(txBytes string) (*DryRunTransactionBlockResponse, error)

func (*Client) ExecMoveCall

func (c *Client) ExecMoveCall(params MoveCallParameters) (*TransactionExecutionResult, error)

func (*Client) ExecuteTransactionBlock

func (c *Client) ExecuteTransactionBlock(txBytes string, signature string) (*TransactionExecutionResult, error)

func (*Client) GetAllBalances

func (c *Client) GetAllBalances(address string) (balances []Balance, err error)

func (*Client) GetAllCoins

func (c *Client) GetAllCoins(address string, cursor string, limit uint) (response GetAllCoinsReponse, err error)

func (*Client) GetBalance

func (c *Client) GetBalance(address string, coinType string) (balance Balance, err error)

func (*Client) GetCoinMetadata

func (c *Client) GetCoinMetadata(coinType string) (coinMetadata SuiCoinMetadata, err error)

func (*Client) GetCoins

func (c *Client) GetCoins(address string, cursor string, limit uint) (response GetAllCoinsReponse, err error)

func (*Client) GetGasCoinObj

func (c *Client) GetGasCoinObj(amount uint64) (*GasDataInfo, error)

func (*Client) GetGasCoinObjId

func (c *Client) GetGasCoinObjId(amount uint64) string

func (*Client) GetOwnedObjects

func (c *Client) GetOwnedObjects(address string, cursor string, limit uint, query ObjectResponseQuery) (response ObjectsPage, err error)

func (*Client) GetTotalSupply

func (c *Client) GetTotalSupply(coinType string) (totalSupply string, err error)

func (*Client) GetTransactionBlock

func (c *Client) GetTransactionBlock(digest string, showParams TransactionBlockResponseOptions) (response TransactionBlockResponse, err error)

func (*Client) UnsafeMoveCall

func (c *Client) UnsafeMoveCall(gasObj string, gasBudget string, packageId string, moduleName string, functionName string, arguments []interface{}) (*TransactionBlockBytes, error)

type CoinObject

type CoinObject struct {
	DataType string `json:"dataType"`
	Fields   struct {
		Balance string `json:"balance"`
		ID      struct {
			ID string `json:"id"`
		} `json:"id"`
	} `json:"fields"`
	HasPublicTransfer bool   `json:"hasPublicTransfer"`
	Type              string `json:"type"`
}

func (*CoinObject) GetBalanceUint64

func (c *CoinObject) GetBalanceUint64() uint64

type DryRunTransactionBlockResponse

type DryRunTransactionBlockResponse struct {
	Effects struct {
		MessageVersion string `json:"messageVersion"`
		Status         struct {
			Status string `json:"status"`
		} `json:"status"`
		ExecutedEpoch string `json:"executedEpoch"`
		GasUsed       struct {
			ComputationCost         string `json:"computationCost"`
			StorageCost             string `json:"storageCost"`
			StorageRebate           string `json:"storageRebate"`
			NonRefundableStorageFee string `json:"nonRefundableStorageFee"`
		} `json:"gasUsed"`
		ModifiedAtVersions []struct {
			ObjectId       string `json:"objectId"`
			SequenceNumber string `json:"sequenceNumber"`
		} `json:"modifiedAtVersions"`
		TransactionDigest string `json:"transactionDigest"`
		Mutated           []struct {
			Owner struct {
				AddressOwner string `json:"AddressOwner"`
			} `json:"owner"`
			Reference struct {
				ObjectId string `json:"objectId"`
				Version  int    `json:"version"`
				Digest   string `json:"digest"`
			} `json:"reference"`
		} `json:"mutated"`
		GasObject struct {
			Owner struct {
				AddressOwner string `json:"AddressOwner"`
			} `json:"owner"`
			Reference struct {
				ObjectId string `json:"objectId"`
				Version  int    `json:"version"`
				Digest   string `json:"digest"`
			} `json:"reference"`
		} `json:"gasObject"`
		Dependencies []string `json:"dependencies"`
	} `json:"effects"`
	Events        []interface{} `json:"events"`
	ObjectChanges []struct {
		Type   string `json:"type"`
		Sender string `json:"sender"`
		Owner  struct {
			AddressOwner string `json:"AddressOwner"`
		} `json:"owner"`
		ObjectType      string `json:"objectType"`
		ObjectId        string `json:"objectId"`
		Version         string `json:"version"`
		PreviousVersion string `json:"previousVersion"`
		Digest          string `json:"digest"`
	} `json:"objectChanges"`
	BalanceChanges []struct {
		Owner struct {
			AddressOwner string `json:"AddressOwner"`
		} `json:"owner"`
		CoinType string `json:"coinType"`
		Amount   string `json:"amount"`
	} `json:"balanceChanges"`
	Input struct {
		MessageVersion string `json:"messageVersion"`
		Transaction    struct {
			Kind         string        `json:"kind"`
			Inputs       []interface{} `json:"inputs"`
			Transactions []struct {
				MoveCall struct {
					Package  string `json:"package"`
					Module   string `json:"module"`
					Function string `json:"function"`
				} `json:"MoveCall"`
			} `json:"transactions"`
		} `json:"transaction"`
		Sender  string `json:"sender"`
		GasData struct {
			Payment []struct {
				ObjectId string `json:"objectId"`
				Version  int    `json:"version"`
				Digest   string `json:"digest"`
			} `json:"payment"`
			Owner  string `json:"owner"`
			Price  string `json:"price"`
			Budget string `json:"budget"`
		} `json:"gasData"`
	} `json:"input"`
}

type GasData

type GasData struct {
	Budget  string    `json:"budget"`
	Owner   string    `json:"owner"`
	Payment []Payment `json:"payment"`
	Price   string    `json:"price"`
}

type GasDataInfo

type GasDataInfo struct {
	ObjectId string
	Balance  string
	Digest   string
	SeqNum   int64
}

type GetAllCoinsReponse

type GetAllCoinsReponse struct {
	Data        []Item `json:"data"`
	HasNextPage bool   `json:"hasNextPage"`
	NextCursor  string `json:"nextCursor"`
}

type GetObjectShowOptions

type GetObjectShowOptions struct {
	ShowType                bool `json:"showType"`
	ShowOwner               bool `json:"showOwner"`
	ShowPreviousTransaction bool `json:"showPreviousTransaction"`
	ShowDisplay             bool `json:"showDisplay"`
	ShowContent             bool `json:"showContent"`
	ShowBcs                 bool `json:"showBcs"`
	ShowStorageRebate       bool `json:"showStorageRebate"`
}

type IntentScope

type IntentScope = uint8
const (
	TransactionDataIntentScope    IntentScope = 0
	TransactionEffectsIntentScope IntentScope = 1
	CheckpointSummaryIntentScope  IntentScope = 2
	PersonalMessageIntentScope    IntentScope = 3
)

type Item

type Item struct {
	CoinType            string `json:"coinType"`
	Version             string `json:"version"`
	Digest              string `json:"digest"`
	Balance             string `json:"balance"`
	PreviousTransaction string `json:"previousTransaction"`
}

type Key

type Key struct {
	Key       []byte
	ChainCode []byte
}

func DeriveForPath

func DeriveForPath(path string, seed []byte) (*Key, error)

func NewMasterKey

func NewMasterKey(seed []byte) (*Key, error)

NewMasterKey generates a new master key from seed.

func (*Key) Derive

func (k *Key) Derive(i uint32) (*Key, error)

type KeyPair

type KeyPair byte

type MoveCallParameters

type MoveCallParameters struct {
	PackageId    string        `json:"package_id"`
	ModuleName   string        `json:"module_name"`
	FunctionName string        `json:"function_name"`
	Arguments    []interface{} `json:"arguments"`
}

type ObjectInfo

type ObjectInfo struct {
	Data ObjectInfoData `json:"data"`
}

type ObjectInfoData

type ObjectInfoData struct {
	ObjectId            string      `json:"objectId"`
	Version             string      `json:"version"`
	Digest              string      `json:"digest"`
	Type                string      `json:"type"`
	Owner               Owner       `json:"owner"`
	PreviousTransaction string      `json:"previousTransaction"`
	StorageRebate       string      `json:"storageRebate"`
	Content             interface{} `json:"content"`
}

type ObjectRequestFilter

type ObjectRequestFilter struct {
	MatchAll []map[string]string `json:"MatchAll,omitempty"`
}

type ObjectResponseQuery

type ObjectResponseQuery struct {
	Options GetObjectShowOptions `json:"options"`
	Filter  *ObjectRequestFilter `json:"filter,omitempty"`
}

func (*ObjectResponseQuery) AddMatchStructType

func (c *ObjectResponseQuery) AddMatchStructType(structType string)

type ObjectsPage

type ObjectsPage struct {
	Data        []ObjectInfo `json:"data"`
	HasNextPage bool         `json:"hasNextPage"`
	NextCursor  string       `json:"nextCursor"`
}

type Owner

type Owner struct {
	AddressOwner string `json:"AddressOwner"`
}

type Payment

type Payment struct {
	ObjectId string `json:"objectId"`
	Version  int    `json:"version"`
	Digest   string `json:"digest"`
}

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type RPCRequest

type RPCRequest struct {
	JSONRPC string        `json:"jsonrpc"`
	ID      int           `json:"id"`
	Method  string        `json:"method"`
	Params  []interface{} `json:"params"`
}

type RPCResponse

type RPCResponse struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      int             `json:"id"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *RPCError       `json:"error,omitempty"`
}

type SigFlag

type SigFlag byte
const (
	SigFlagEd25519   SigFlag = 0x00
	SigFlagSecp256k1 SigFlag = 0x01
)

type SignedMessageSerializedSig

type SignedMessageSerializedSig struct {
	Message   string `json:"message"`
	Signature string `json:"signature"`
}

type SignedTransactionSerializedSig

type SignedTransactionSerializedSig struct {
	TxBytes   string `json:"txBytes"`
	Signature string `json:"signature"`
}

type SuiCoinMetadata

type SuiCoinMetadata struct {
	Decimals    int    `json:"decimals"`
	Description string `json:"description"`
	IconUrl     string `json:"iconUrl"`
	Id          string `json:"id"`
	Name        string `json:"name"`
	Symbol      string `json:"symbol"`
}

type TransactionBlock

type TransactionBlock struct {
	Data         TransactionBlockData `json:"data"`
	TxSignatures []string             `json:"txSignatures"`
}

type TransactionBlockBytes

type TransactionBlockBytes struct {
	Gas string `json:"gas"`
	// InputObjects []InputObject `json:"inputObjects"`
	TxBytes string `json:"txBytes"`
}

type TransactionBlockData

type TransactionBlockData struct {
	GasData        GasData              `json:"gasData"`
	MessageVersion string               `json:"messageVersion"`
	Sender         string               `json:"sender"`
	Transaction    TransactionBlockKind `json:"transaction"`
}

type TransactionBlockKind

type TransactionBlockKind struct {
	Computation_charge       string `json:"computation_charge"`
	Epoch                    string `json:"epoch"`
	Epoch_start_timestamp_ms string `json:"epoch_start_timestamp_ms"`
	Kind                     string `json:"kind"`
	Storage_charge           string `json:"storage_charge"`
	Storage_rebate           string `json:"storage_rebate"`
}

type TransactionBlockResponse

type TransactionBlockResponse struct {
	Digest         string           `json:"digest"`
	TimestampMs    string           `json:"timestampMs"`
	CheckPoint     string           `json:"checkpoint"`
	Transaction    TransactionBlock `json:"transaction"`
	RawTransaction string           `json:"rawTransaction"`
}

type TransactionBlockResponseOptions

type TransactionBlockResponseOptions struct {
	ShowInput          bool `json:"showInput"`
	ShowRawInput       bool `json:"showRawInput"`
	ShowEffects        bool `json:"showEffects"`
	ShowEvents         bool `json:"showEvents"`
	ShowObjectChanges  bool `json:"showObjectChanges"`
	ShowBalanceChanges bool `json:"showBalanceChanges"`
	ShowRawEffects     bool `json:"showRawEffects"`
}

type TransactionBuilder

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

func NewTransactionBuilder

func NewTransactionBuilder(client *Client) *TransactionBuilder

func (*TransactionBuilder) AddCommand

func (c *TransactionBuilder) AddCommand(cmd *TransactionBuilderMoveCall)

func (*TransactionBuilder) Build

func (c *TransactionBuilder) Build() (string, error)

type TransactionBuilderMoveCall

type TransactionBuilderMoveCall struct {
	PackageId    string
	ModuleName   string
	FunctionName string
	Arguments    []interface{}
}

func NewTransactionBuilderMoveCall

func NewTransactionBuilderMoveCall() *TransactionBuilderMoveCall

func (*TransactionBuilderMoveCall) Build

type TransactionExecutionResult

type TransactionExecutionResult struct {
	Digest      string `json:"digest"`
	Transaction struct {
		Data struct {
			MessageVersion string `json:"messageVersion"`
			Transaction    struct {
				Kind         string        `json:"kind"`
				Inputs       []interface{} `json:"inputs"`
				Transactions []struct {
					MoveCall struct {
						Package  string `json:"package"`
						Module   string `json:"module"`
						Function string `json:"function"`
					} `json:"MoveCall"`
				} `json:"transactions"`
			} `json:"transaction"`
			Sender  string `json:"sender"`
			GasData struct {
				Payment []struct {
					ObjectId string `json:"objectId"`
					Version  int    `json:"version"`
					Digest   string `json:"digest"`
				} `json:"payment"`
				Owner  string `json:"owner"`
				Price  string `json:"price"`
				Budget string `json:"budget"`
			} `json:"gasData"`
		} `json:"data"`
		TxSignatures []string `json:"txSignatures"`
	} `json:"transaction"`
	RawTransaction string `json:"rawTransaction"`
	Effects        struct {
		MessageVersion string `json:"messageVersion"`
		Status         struct {
			Status string `json:"status"`
		} `json:"status"`
		ExecutedEpoch string `json:"executedEpoch"`
		GasUsed       struct {
			ComputationCost         string `json:"computationCost"`
			StorageCost             string `json:"storageCost"`
			StorageRebate           string `json:"storageRebate"`
			NonRefundableStorageFee string `json:"nonRefundableStorageFee"`
		} `json:"gasUsed"`
		ModifiedAtVersions []struct {
			ObjectId       string `json:"objectId"`
			SequenceNumber string `json:"sequenceNumber"`
		} `json:"modifiedAtVersions"`
		TransactionDigest string `json:"transactionDigest"`
		Mutated           []struct {
			Owner struct {
				AddressOwner string `json:"AddressOwner"`
			} `json:"owner"`
			Reference struct {
				ObjectId string `json:"objectId"`
				Version  int    `json:"version"`
				Digest   string `json:"digest"`
			} `json:"reference"`
		} `json:"mutated"`
		GasObject struct {
			Owner struct {
				AddressOwner string `json:"AddressOwner"`
			} `json:"owner"`
			Reference struct {
				ObjectId string `json:"objectId"`
				Version  int    `json:"version"`
				Digest   string `json:"digest"`
			} `json:"reference"`
		} `json:"gasObject"`
		Dependencies []string `json:"dependencies"`
	} `json:"effects"`
	Events        []interface{} `json:"events"`
	ObjectChanges []struct {
		Type   string `json:"type"`
		Sender string `json:"sender"`
		Owner  struct {
			AddressOwner string `json:"AddressOwner"`
		} `json:"owner"`
		ObjectType      string `json:"objectType"`
		ObjectId        string `json:"objectId"`
		Version         string `json:"version"`
		PreviousVersion string `json:"previousVersion"`
		Digest          string `json:"digest"`
	} `json:"objectChanges"`
	BalanceChanges []struct {
		Owner struct {
			AddressOwner string `json:"AddressOwner"`
		} `json:"owner"`
		CoinType string `json:"coinType"`
		Amount   string `json:"amount"`
	} `json:"balanceChanges"`
	ConfirmedLocalExecution bool   `json:"confirmedLocalExecution"`
	RawEffects              []byte `json:"rawEffects"`
}

Jump to

Keyboard shortcuts

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