client

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0 Imports: 17 Imported by: 9

Documentation

Index

Constants

View Source
const (
	DevNetFaucetUrl  = "https://faucet.devnet.sui.io/gas"
	TestNetFaucetUrl = "https://faucet.testnet.sui.io/gas"
)
View Source
const (
	SuiXPrefix   = "suix_"
	SuiPrefix    = "sui_"
	UnsafePrefix = "unsafe_"
)
View Source
const QUERY_MAX_RESULT_LIMIT = 1000

NOTE: This copys the query limit from our Rust JSON RPC backend, this needs to be kept in sync!

Variables

View Source
var (
	ErrNoResult = errors.New("no result in JSON-RPC response")
)

Functions

func BCS_RequestAddStake

func BCS_RequestAddStake(
	signer suiAddress,
	coins []*sui_types.ObjectRef,
	amount types.SafeSuiBigInt[uint64],
	validator suiAddress,
	gasBudget, gasPrice uint64,
) ([]byte, error)

func BCS_RequestWithdrawStake added in v2.0.1

func BCS_RequestWithdrawStake(signer suiAddress, stakedSuiRef sui_types.ObjectRef, gas []*sui_types.ObjectRef, gasBudget, gasPrice uint64) ([]byte, error)

func FaucetFundAccount

func FaucetFundAccount(address string, faucetUrl string) (string, error)

Types

type BatchElem

type BatchElem struct {
	Method string
	Args   []interface{}
	// The result is unmarshaled into this field. Result must be set to a
	// non-nil pointer value of the desired type, otherwise the response will be
	// discarded.
	Result interface{}
	// Error is set if the server returns an error for this request, or if
	// unmarshaling into Result fails. It is not set for I/O errors.
	Error error
}

BatchElem is an element in a batch request.

type Client

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

func Dial

func Dial(rpcUrl string) (client *Client, err error)

func DialWithClient

func DialWithClient(rpcUrl string, c *http.Client) (client *Client, err error)

func (*Client) BatchCall

func (c *Client) BatchCall(b []BatchElem) error

BatchCall sends all given requests as a single batch and waits for the server to return a response for all of them.

func (*Client) BatchCallContext

func (c *Client) BatchCallContext(ctx context.Context, b []BatchElem) error

BatchCallContext sends all given requests as a single batch and waits for the server to return a response for all of them. The wait duration is bounded by the context's deadline.

func (*Client) BatchGetFilteredObjectsOwnedByAddress

func (c *Client) BatchGetFilteredObjectsOwnedByAddress(
	ctx context.Context,
	address suiAddress,
	options types.SuiObjectDataOptions,
	filter func(*types.SuiObjectData) bool,
) ([]types.SuiObjectResponse, error)

func (*Client) BatchGetObjectsOwnedByAddress

func (c *Client) BatchGetObjectsOwnedByAddress(
	ctx context.Context,
	address suiAddress,
	options types.SuiObjectDataOptions,
	filterType string,
) ([]types.SuiObjectResponse, error)

BatchGetObjectsOwnedByAddress @param filterType You can specify filtering out the specified resources, this will fetch all resources if it is not empty ""

func (*Client) BatchTransaction

func (c *Client) BatchTransaction(
	ctx context.Context,
	signer suiAddress,
	txnParams []map[string]interface{},
	gas *suiObjectID,
	gasBudget uint64,
) (*types.TransactionBytes, error)

TODO: execution_mode : <SuiTransactionBlockBuilderMode>

func (*Client) Call

func (c *Client) Call(result interface{}, method Method, args ...interface{}) error

Call performs a JSON-RPC call with the given arguments and unmarshals into the result if no error occurred.

The result must be a pointer so that package json can unmarshal into it. You can also pass nil, in which case the result is ignored.

func (*Client) CallContext

func (c *Client) CallContext(ctx context.Context, result interface{}, method Method, args ...interface{}) error

CallContext performs a JSON-RPC call with the given arguments. If the context is canceled before the call has successfully returned, CallContext returns immediately.

The result must be a pointer so that package json can unmarshal into it. You can also pass nil, in which case the result is ignored.

func (*Client) DevInspectTransactionBlock

func (c *Client) DevInspectTransactionBlock(
	ctx context.Context,
	senderAddress suiAddress,
	txByte suiBase64Data,
	gasPrice *types.SafeSuiBigInt[uint64],
	epoch *uint64,
) (*types.DevInspectResults, error)

func (*Client) DryRunTransaction

func (c *Client) DryRunTransaction(
	ctx context.Context,
	txBytes suiBase64Data,
) (*types.DryRunTransactionBlockResponse, error)

func (*Client) ExecuteTransactionBlock

func (c *Client) ExecuteTransactionBlock(
	ctx context.Context, txBytes suiBase64Data, signatures []any,
	options *types.SuiTransactionBlockResponseOptions, requestType types.ExecuteTransactionRequestType,
) (*types.SuiTransactionBlockResponse, error)

func (*Client) GetAllBalances

func (c *Client) GetAllBalances(ctx context.Context, owner suiAddress) ([]types.Balance, error)

func (*Client) GetAllCoins

func (c *Client) GetAllCoins(
	ctx context.Context,
	owner suiAddress,
	cursor *suiObjectID,
	limit uint,
) (*types.CoinPage, error)

GetAllCoins start with the first object when cursor is nil

func (*Client) GetBalance

func (c *Client) GetBalance(ctx context.Context, owner suiAddress, coinType string) (*types.Balance, error)

GetBalance to use default sui coin(0x2::sui::SUI) when coinType is empty

func (*Client) GetCoinMetadata

func (c *Client) GetCoinMetadata(ctx context.Context, coinType string) (*types.SuiCoinMetadata, error)

func (*Client) GetCoins

func (c *Client) GetCoins(
	ctx context.Context,
	owner suiAddress,
	coinType *string,
	cursor *suiObjectID,
	limit uint,
) (*types.CoinPage, error)

GetCoins to use default sui coin(0x2::sui::SUI) when coinType is nil start with the first object when cursor is nil

func (*Client) GetDynamicFieldObject

func (c *Client) GetDynamicFieldObject(
	ctx context.Context, parentObjectId suiObjectID,
	name sui_types.DynamicFieldName,
) (*types.SuiObjectResponse, error)

func (*Client) GetDynamicFields

func (c *Client) GetDynamicFields(
	ctx context.Context, parentObjectId suiObjectID, cursor *suiObjectID,
	limit *uint,
) (*types.DynamicFieldPage, error)

func (*Client) GetEvents

func (c *Client) GetEvents(ctx context.Context, digest suiDigest) ([]types.SuiEvent, error)

func (*Client) GetLatestCheckpointSequenceNumber

func (c *Client) GetLatestCheckpointSequenceNumber(ctx context.Context) (string, error)

func (*Client) GetLatestSuiSystemState

func (c *Client) GetLatestSuiSystemState(ctx context.Context) (*types.SuiSystemStateSummary, error)

func (*Client) GetNFTsOwnedByAddress

func (c *Client) GetNFTsOwnedByAddress(ctx context.Context, address suiAddress) ([]types.SuiObjectResponse, error)

func (*Client) GetObject

func (c *Client) GetObject(
	ctx context.Context,
	objID suiObjectID,
	options *types.SuiObjectDataOptions,
) (*types.SuiObjectResponse, error)

func (*Client) GetOwnedObjects

func (c *Client) GetOwnedObjects(
	ctx context.Context,
	address suiAddress,
	query *types.SuiObjectResponseQuery,
	cursor *types.CheckpointedObjectId,
	limit *uint,
) (*types.ObjectsPage, error)

address : <SuiAddress> - the owner's Sui address query : <ObjectResponseQuery> - the objects query criteria. cursor : <CheckpointedObjectID> - An optional paging cursor. If provided, the query will start from the next item after the specified cursor. Default to start from the first item if not specified. limit : <uint> - Max number of items returned per page, default to [QUERY_MAX_RESULT_LIMIT_OBJECTS] if is 0

func (*Client) GetReferenceGasPrice

func (c *Client) GetReferenceGasPrice(ctx context.Context) (*types.SafeSuiBigInt[uint64], error)

func (*Client) GetStakes

func (c *Client) GetStakes(ctx context.Context, owner suiAddress) ([]types.DelegatedStake, error)

func (*Client) GetStakesByIds

func (c *Client) GetStakesByIds(ctx context.Context, stakedSuiIds []suiObjectID) ([]types.DelegatedStake, error)

func (*Client) GetSuiCoinsOwnedByAddress

func (c *Client) GetSuiCoinsOwnedByAddress(ctx context.Context, address suiAddress) (types.Coins, error)

GetSuiCoinsOwnedByAddress This function will retrieve a maximum of 200 coins.

func (*Client) GetTotalSupply

func (c *Client) GetTotalSupply(ctx context.Context, coinType string) (*types.Supply, error)

func (*Client) GetTotalTransactionBlocks

func (c *Client) GetTotalTransactionBlocks(ctx context.Context) (string, error)

func (*Client) GetTransactionBlock

func (c *Client) GetTransactionBlock(
	ctx context.Context,
	digest suiDigest,
	options types.SuiTransactionBlockResponseOptions,
) (*types.SuiTransactionBlockResponse, error)

func (*Client) GetValidatorsApy

func (c *Client) GetValidatorsApy(ctx context.Context) (*types.ValidatorsApy, error)

func (*Client) MergeCoins

func (c *Client) MergeCoins(
	ctx context.Context,
	signer suiAddress,
	primaryCoin, coinToMerge suiObjectID,
	gas *suiObjectID,
	gasBudget types.SafeSuiBigInt[uint64],
) (*types.TransactionBytes, error)

MergeCoins Create an unsigned transaction to merge multiple coins into one coin.

func (*Client) MintNFT

func (c *Client) MintNFT(
	ctx context.Context,
	signer suiAddress,
	nftName, nftDescription, nftUri string,
	gas *suiObjectID,
	gasBudget uint64,
) (*types.TransactionBytes, error)

MintNFT Create an unsigned transaction to mint a nft at devnet

func (*Client) MoveCall

func (c *Client) MoveCall(
	ctx context.Context,
	signer suiAddress,
	packageId suiObjectID,
	module, function string,
	typeArgs []string,
	arguments []any,
	gas *suiObjectID,
	gasBudget types.SafeSuiBigInt[uint64],
) (*types.TransactionBytes, error)

MoveCall Create an unsigned transaction to execute a Move call on the network, by calling the specified function in the module of a given package. TODO: not support param `typeArguments` yet. So now only methods with `typeArguments` are supported TODO: execution_mode : <SuiTransactionBlockBuilderMode>

func (*Client) MultiGetObjects

func (c *Client) MultiGetObjects(
	ctx context.Context,
	objIDs []suiObjectID,
	options *types.SuiObjectDataOptions,
) ([]types.SuiObjectResponse, error)

func (*Client) Pay

func (c *Client) Pay(
	ctx context.Context,
	signer suiAddress,
	inputCoins []suiObjectID,
	recipients []suiAddress,
	amount []types.SafeSuiBigInt[uint64],
	gas *suiObjectID,
	gasBudget types.SafeSuiBigInt[uint64],
) (*types.TransactionBytes, error)

func (*Client) PayAllSui

func (c *Client) PayAllSui(
	ctx context.Context,
	signer, recipient suiAddress,
	inputCoins []suiObjectID,
	gasBudget types.SafeSuiBigInt[uint64],
) (*types.TransactionBytes, error)

PayAllSui Create an unsigned transaction to send all SUI coins to one recipient.

func (*Client) PaySui

func (c *Client) PaySui(
	ctx context.Context,
	signer suiAddress,
	inputCoins []suiObjectID,
	recipients []suiAddress,
	amount []types.SafeSuiBigInt[uint64],
	gasBudget types.SafeSuiBigInt[uint64],
) (*types.TransactionBytes, error)

func (*Client) Publish

func (c *Client) Publish(
	ctx context.Context,
	sender suiAddress,
	compiledModules []*suiBase64Data,
	dependencies []suiObjectID,
	gas suiObjectID,
	gasBudget uint,
) (*types.TransactionBytes, error)

func (*Client) QueryEvents

func (c *Client) QueryEvents(
	ctx context.Context, query types.EventFilter, cursor *types.EventId, limit *uint,
	descendingOrder bool,
) (*types.EventPage, error)

func (*Client) QueryTransactionBlocks

func (c *Client) QueryTransactionBlocks(
	ctx context.Context, query types.SuiTransactionBlockResponseQuery,
	cursor *suiDigest, limit *uint, descendingOrder bool,
) (*types.TransactionBlocksPage, error)

func (*Client) RequestAddStake

func (c *Client) RequestAddStake(
	ctx context.Context,
	signer suiAddress,
	coins []suiObjectID,
	amount types.SuiBigInt,
	validator suiAddress,
	gas *suiObjectID,
	gasBudget types.SuiBigInt,
) (*types.TransactionBytes, error)

func (*Client) RequestWithdrawStake

func (c *Client) RequestWithdrawStake(
	ctx context.Context,
	signer suiAddress,
	stakedSuiId suiObjectID,
	gas *suiObjectID,
	gasBudget types.SuiBigInt,
) (*types.TransactionBytes, error)

func (*Client) ResolveNameServiceAddress added in v2.0.1

func (c *Client) ResolveNameServiceAddress(ctx context.Context, suiName string) (*suiAddress, error)

func (*Client) ResolveNameServiceNames added in v2.0.1

func (c *Client) ResolveNameServiceNames(ctx context.Context,
	owner suiAddress, cursor *suiObjectID, limit *uint) (*types.SuiNamePage, error)

func (*Client) SplitCoin

func (c *Client) SplitCoin(
	ctx context.Context,
	signer suiAddress,
	Coin suiObjectID,
	splitAmounts []types.SafeSuiBigInt[uint64],
	gas *suiObjectID,
	gasBudget types.SafeSuiBigInt[uint64],
) (*types.TransactionBytes, error)

SplitCoin Create an unsigned transaction to split a coin object into multiple coins.

func (*Client) SplitCoinEqual

func (c *Client) SplitCoinEqual(
	ctx context.Context,
	signer suiAddress,
	Coin suiObjectID,
	splitCount types.SafeSuiBigInt[uint64],
	gas *suiObjectID,
	gasBudget types.SafeSuiBigInt[uint64],
) (*types.TransactionBytes, error)

SplitCoinEqual Create an unsigned transaction to split a coin object into multiple equal-size coins.

func (*Client) TransferObject

func (c *Client) TransferObject(
	ctx context.Context,
	signer, recipient suiAddress,
	objID suiObjectID,
	gas *suiObjectID,
	gasBudget types.SafeSuiBigInt[uint64],
) (*types.TransactionBytes, error)

TransferObject Create an unsigned transaction to transfer an object from one address to another. The object's type must allow public transfers

func (*Client) TransferSui

func (c *Client) TransferSui(
	ctx context.Context, signer, recipient suiAddress, suiObjID suiObjectID, amount,
	gasBudget types.SafeSuiBigInt[uint64],
) (*types.TransactionBytes, error)

TransferSui Create an unsigned transaction to send SUI coin object to a Sui address. The SUI object is also used as the gas object.

func (*Client) TryGetPastObject

func (c *Client) TryGetPastObject(
	ctx context.Context,
	objectId suiObjectID,
	version uint64,
	options *types.SuiObjectDataOptions,
) (*types.SuiPastObjectResponse, error)

type HTTPError

type HTTPError struct {
	StatusCode int
	Status     string
	Body       []byte
}

func (HTTPError) Error

func (err HTTPError) Error() string

type Method

type Method interface {
	String() string
}

type SuiMethod

type SuiMethod string

func (SuiMethod) String

func (s SuiMethod) String() string

type SuiXMethod

type SuiXMethod string

func (SuiXMethod) String

func (s SuiXMethod) String() string

type UnsafeMethod

type UnsafeMethod string

func (UnsafeMethod) String

func (u UnsafeMethod) String() string

Jump to

Keyboard shortcuts

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