client

package
v0.0.0-...-e90b4a0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 30 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Base10                      int           = 10
	DefaultGasPrice             uint64        = 10_000
	DefaultGasBudget            uint64        = 1_000_000_000
	DefaultCacheExpiration      time.Duration = 120 * time.Minute
	DefaultCacheCleanupInterval time.Duration = 240 * time.Minute
	DefaultHTTPTimeout          time.Duration = 30 * time.Second
)

Variables

View Source
var RateLimitWeights = map[string]int64{
	"MoveCall":                             1,
	"SendTransaction":                      1,
	"ReadFunction":                         1,
	"SignAndSendTransaction":               1,
	"QueryEvents":                          1,
	"QueryTransactions":                    1,
	"GetCoinsByAddress":                    1,
	"QueryCoinsByAddress":                  1,
	"EstimateGas":                          1,
	"GetTransactionStatus":                 1,
	"GetBlockById":                         1,
	"GetNormalizedModule":                  1,
	"GetSUIBalance":                        1,
	"GetValuesFromPackageOwnedObjectField": 1,
	"GetReferenceGasPrice":                 1,
	"FinishPTBAndSend":                     1,
	"BlockByDigest":                        1,

	"ReadFilterOwnedObjectIds":           0,
	"ReadOwnedObjects":                   0,
	"ReadObjectId":                       0,
	"GetLatestPackageId":                 0,
	"LoadModulePackageIds":               0,
	"GetParentObjectID":                  0,
	"GetCCIPPackageID":                   0,
	"GetTokenPoolConfigByPackageAddress": 0,
	"GetLatestEpoch":                     0,
}

Functions

func GetAddressFromPublicKey

func GetAddressFromPublicKey(pubKey []byte) (string, error)

func SerializeSuiSignature

func SerializeSuiSignature(signature, pubKey []byte) string

SerializeSuiSignature formats and serializes a signature for use with Sui transactions.

This function follows the Sui transaction signature format specification: 1. A one-byte flag indicating the signature scheme (0x00 for Ed25519) 2. The raw signature bytes 3. The public key bytes These components are concatenated and then base64 encoded to produce the final signature string that can be submitted to the Sui network.

Based on the implementation from block-vision's sui-go-sdk: https://github.com/block-vision/sui-go-sdk/blob/main/models/signature.go#L140

Parameters:

signature - The raw signature bytes from the ed25519 Sign operation
pubKey    - The public key corresponding to the private key that produced the signature

Returns:

A base64-encoded string containing the serialized signature ready for submission to Sui

Types

type EventData

type EventData struct {
	Id struct {
		TxDigest string `json:"txDigest"`
		EventSeq string `json:"eventSeq"`
	} `json:"id"`
	PackageId         string `json:"packageId"`
	TransactionModule string `json:"transactionModule"`
	Sender            string `json:"sender"`
	Type              struct {
		Address string `json:"address"`
		Module  string `json:"module"`
		Name    string `json:"name"`
	} `json:"type"`
	ParsedJson  any    `json:"parsedJson"`
	Bcs         string `json:"bcs"`
	TimestampMs string `json:"timestampMs"`
}

type EventFilterByMoveEventModule

type EventFilterByMoveEventModule struct {
	Package string `json:"package"`
	Module  string `json:"module"`
	Event   string `json:"event"`
}

type EventId

type EventId struct {
	TxDigest string `json:"txDigest"`
	EventSeq string `json:"eventSeq"`
}

type EventSelector

type EventSelector = EventFilterByMoveEventModule

EventSelector is an alias for EventFilterByMoveEventModule

type FunctionReadResponse

type FunctionReadResponse struct {
	ReturnValues []any `json:"returnValues"`
}

type MoveCallRequest

type MoveCallRequest struct {
	// the transaction signer's Sui address
	Signer string `json:"signer"`
	// the package containing the module and function
	PackageObjectId string `json:"packageObjectId"`
	// the specific module in the package containing the function
	Module string `json:"module"`
	// the function to be called
	Function string `json:"function"`
	// the type arguments to the function
	TypeArguments []any `json:"typeArguments"`
	// the arguments to the function
	Arguments []any `json:"arguments"`
	// gas object to be used in this transaction, node will pick one from the signer's possession if not provided
	Gas uint64 `json:"gas"`
	// the gas budget, the transaction will fail if the gas cost exceed the budget
	GasBudget uint64 `json:"gasBudget"`
}

type PTBClient

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

PTBClient implements SuiClient interface using the blockvision SDK

func NewPTBClient

func NewPTBClient(
	log logger.Logger,
	rpcUrl string,
	maxRetries *int,
	transactionTimeout time.Duration,
	keystoreService loop.Keystore,
	maxConcurrentRequests int64,
	defaultRequestType TransactionRequestType,
) (*PTBClient, error)

func (*PTBClient) BlockByDigest

func (c *PTBClient) BlockByDigest(ctx context.Context, txDigest string) (*SuiTransactionBlockResponse, error)

func (*PTBClient) EstimateGas

func (c *PTBClient) EstimateGas(ctx context.Context, txBytes string) (uint64, error)

func (*PTBClient) FinishPTBAndSend

func (c *PTBClient) FinishPTBAndSend(ctx context.Context, txnSigner *signer.Signer, tx *transaction.Transaction, requestType TransactionRequestType) (SuiTransactionBlockResponse, error)

FinishPTBAndSend finishes the PTB transaction and sends it to the network. IMPORTANT: This method is only used for testing purposes.

func (*PTBClient) GetBlockById

func (c *PTBClient) GetBlockById(ctx context.Context, checkpointId string) (models.CheckpointResponse, error)

GetBlockById (i.e. get checkpoint by id) returns the checkpoint details given its ID

func (*PTBClient) GetCCIPPackageID

func (c *PTBClient) GetCCIPPackageID(ctx context.Context, offRampPackageID string, signerAddress string) (string, error)

GetCCIPPackageId gets the CCIP package ID from the offramp package ID. IMPORTANT: This function expects to call the original (un-upgraded / first version) offramp package ID.

func (*PTBClient) GetCache

func (c *PTBClient) GetCache() *cache.Cache

func (*PTBClient) GetCachedValue

func (c *PTBClient) GetCachedValue(key string) (any, bool)

func (*PTBClient) GetCachedValues

func (c *PTBClient) GetCachedValues(keys []string) (map[string]any, bool)

func (*PTBClient) GetClient

func (c *PTBClient) GetClient() sui.ISuiAPI

func (*PTBClient) GetCoinsByAddress

func (c *PTBClient) GetCoinsByAddress(ctx context.Context, address string) ([]models.CoinData, error)

func (*PTBClient) GetLatestEpoch

func (c *PTBClient) GetLatestEpoch(ctx context.Context) (string, error)

func (*PTBClient) GetLatestPackageId

func (c *PTBClient) GetLatestPackageId(ctx context.Context, packageId string, module string) (string, error)

func (*PTBClient) GetNormalizedModule

func (c *PTBClient) GetNormalizedModule(ctx context.Context, packageId string, module string) (models.GetNormalizedMoveModuleResponse, error)

func (*PTBClient) GetParentObjectID

func (c *PTBClient) GetParentObjectID(ctx context.Context, packageID string, moduleID string, pointerObjectName string) (string, error)

GetParentObjectID gets the parent object ID from a pointer object's field. With derived objects, pointers now store a reference to the parent "Object" struct (e.g., OffRampObject, CCIPObject). e.g. OffRampStatePointer contains "off_ramp_object_id" field pointing to OffRampObject.

func (*PTBClient) GetReferenceGasPrice

func (c *PTBClient) GetReferenceGasPrice(ctx context.Context) (*big.Int, error)

func (*PTBClient) GetSUIBalance

func (c *PTBClient) GetSUIBalance(ctx context.Context, address string) (*big.Int, error)

func (*PTBClient) GetTokenPoolConfigByPackageAddress

func (c *PTBClient) GetTokenPoolConfigByPackageAddress(ctx context.Context, accountAddress string, tokenPoolAddress string, ccipPackageAddress string) (module_token_admin_registry.TokenConfig, error)

A helper to abstract away having to provide the generic type of a token pool state. Requires a CCIP / StateObject package binding.

func (*PTBClient) GetTransactionPaymentCoinForAddress

func (c *PTBClient) GetTransactionPaymentCoinForAddress(ctx context.Context, payer string) (models.SuiAddressBytes, uint64, models.ObjectDigestBytes, error)

func (*PTBClient) GetTransactionStatus

func (c *PTBClient) GetTransactionStatus(ctx context.Context, digest string) (TransactionResult, error)

func (*PTBClient) GetValuesFromPackageOwnedObjectField

func (c *PTBClient) GetValuesFromPackageOwnedObjectField(ctx context.Context, packageID string, moduleID string, objectName string, fieldKeys []string) (map[string]string, error)

GetValueFromPackageOwnedObjectField gets the value of a field from a package owned object. This is used to get addresses stored within pointer objects on-chain. For example, the state object ID of a package is stored in the pointer object, so we need to get the value of the pointer object's field to get the state object ID.

func (*PTBClient) HashTxBytes

func (c *PTBClient) HashTxBytes(txBytes []byte) []byte

HashTxBytes is a helper method to hash (Blake2) the transaction bytes before signing

func (*PTBClient) LoadModulePackageIds

func (c *PTBClient) LoadModulePackageIds(ctx context.Context, packageId string, module string) ([]string, error)

LoadModulePackages returns the set of package IDs for a given module using its original package ID This method assumes that module names are unique across all packages

func (*PTBClient) MoveCall

func (c *PTBClient) MoveCall(ctx context.Context, req MoveCallRequest) (TxnMetaData, error)

func (*PTBClient) PayAllSui

func (c *PTBClient) PayAllSui(ctx context.Context, toAddress string, coinObjectRefs []string, signer string) error

func (*PTBClient) QueryCoinsByAddress

func (c *PTBClient) QueryCoinsByAddress(ctx context.Context, address string, coinType string) ([]models.CoinData, error)

func (*PTBClient) QueryEvents

func (c *PTBClient) QueryEvents(ctx context.Context, filter EventFilterByMoveEventModule, limit *uint, cursor *EventId, sortOptions *QuerySortOptions) (*models.PaginatedEventsResponse, error)

func (*PTBClient) QueryTransactions

func (c *PTBClient) QueryTransactions(ctx context.Context, fromAddress string, cursor *string, limit *uint64) (models.SuiXQueryTransactionBlocksResponse, error)

func (*PTBClient) ReadFilterOwnedObjectIds

func (c *PTBClient) ReadFilterOwnedObjectIds(ctx context.Context, ownerAddress string, structType string, cursor string) ([]models.SuiObjectData, error)

func (*PTBClient) ReadFunction

func (c *PTBClient) ReadFunction(ctx context.Context, signerAddress string, packageId string, module string, function string, args []any, argTypes []string, typeArgs []string) ([]any, error)

func (*PTBClient) ReadObjectId

func (c *PTBClient) ReadObjectId(ctx context.Context, objectId string) (models.SuiObjectData, error)

func (*PTBClient) ReadOwnedObjects

func (c *PTBClient) ReadOwnedObjects(ctx context.Context, ownerAddress string, cursor *models.ObjectId) ([]models.SuiObjectResponse, error)

func (*PTBClient) SendTransaction

func (*PTBClient) SetCachedValue

func (c *PTBClient) SetCachedValue(key string, value any)

func (*PTBClient) SetCachedValues

func (c *PTBClient) SetCachedValues(keyValues map[string]any)

func (*PTBClient) SignAndSendTransaction

func (c *PTBClient) SignAndSendTransaction(ctx context.Context, txBytesRaw string, signerPublicKey []byte, executionRequestType TransactionRequestType) (SuiTransactionBlockResponse, error)

func (*PTBClient) TransformTransactionArg

func (c *PTBClient) TransformTransactionArg(
	ctx context.Context,
	tx *transaction.Transaction,
	arg any,
	argType string,
	mutable bool,
) (*transaction.Argument, error)

func (*PTBClient) WithRateLimit

func (c *PTBClient) WithRateLimit(ctx context.Context, methodName string, f func(ctx context.Context) error) error

type PaginatedEventsResponse

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

type QuerySortOptions

type QuerySortOptions struct {
	Descending bool `json:"descending"`
}

type SigFlag

type SigFlag byte
const (
	SigFlagEd25519 SigFlag = 0x00
)

type SuiExecutionStatus

type SuiExecutionStatus struct {
	Status string `json:"status"`
	Error  string `json:"error,omitempty"`
}

type SuiPTBClient

type SuiPTBClient interface {
	MoveCall(ctx context.Context, req MoveCallRequest) (TxnMetaData, error)
	SendTransaction(ctx context.Context, payload TransactionBlockRequest) (SuiTransactionBlockResponse, error)
	ReadOwnedObjects(ctx context.Context, ownerAddress string, cursor *models.ObjectId) ([]models.SuiObjectResponse, error)
	ReadFilterOwnedObjectIds(ctx context.Context, ownerAddress string, structType string, cursor string) ([]models.SuiObjectData, error)
	ReadObjectId(ctx context.Context, objectId string) (models.SuiObjectData, error)
	ReadFunction(ctx context.Context, signerAddress string, packageId string, module string, function string, args []any, argTypes []string, typeArgs []string) ([]any, error)
	SignAndSendTransaction(ctx context.Context, txBytesRaw string, signerPublicKey []byte, executionRequestType TransactionRequestType) (SuiTransactionBlockResponse, error)
	QueryEvents(ctx context.Context, filter EventFilterByMoveEventModule, limit *uint, cursor *EventId, sortOptions *QuerySortOptions) (*models.PaginatedEventsResponse, error)
	QueryTransactions(ctx context.Context, fromAddress string, cursor *string, limit *uint64) (models.SuiXQueryTransactionBlocksResponse, error)
	GetTransactionStatus(ctx context.Context, digest string) (TransactionResult, error)
	GetCoinsByAddress(ctx context.Context, address string) ([]models.CoinData, error)
	QueryCoinsByAddress(ctx context.Context, address string, coinType string) ([]models.CoinData, error)
	EstimateGas(ctx context.Context, txBytes string) (uint64, error)
	GetReferenceGasPrice(ctx context.Context) (*big.Int, error)
	FinishPTBAndSend(ctx context.Context, txnSigner *signer.Signer, tx *transaction.Transaction, requestType TransactionRequestType) (SuiTransactionBlockResponse, error)
	BlockByDigest(ctx context.Context, txDigest string) (*SuiTransactionBlockResponse, error)
	GetBlockById(ctx context.Context, checkpointId string) (models.CheckpointResponse, error)
	GetLatestEpoch(ctx context.Context) (string, error)
	GetNormalizedModule(ctx context.Context, packageId string, moduleId string) (models.GetNormalizedMoveModuleResponse, error)
	GetSUIBalance(ctx context.Context, address string) (*big.Int, error)
	LoadModulePackageIds(ctx context.Context, packageId string, module string) ([]string, error)
	GetLatestPackageId(ctx context.Context, packageId string, module string) (string, error)
	GetClient() sui.ISuiAPI
	GetCache() *cache.Cache
	GetCachedValue(key string) (any, bool)
	SetCachedValue(key string, value any)
	GetCachedValues(keys []string) (map[string]any, bool)
	SetCachedValues(keyValues map[string]any)
	HashTxBytes(txBytes []byte) []byte
	GetCCIPPackageID(ctx context.Context, offRampPackageID string, signerAddress string) (string, error)
	GetValuesFromPackageOwnedObjectField(ctx context.Context, packageID string, moduleID string, objectName string, fieldKeys []string) (map[string]string, error)
	GetParentObjectID(ctx context.Context, packageID string, moduleID string, pointerObjectName string) (string, error)
	GetTokenPoolConfigByPackageAddress(ctx context.Context, accountAddress string, tokenPoolAddress string, ccipPackageAddress string) (module_token_admin_registry.TokenConfig, error)
}

type SuiTransactionBlockResponse

type SuiTransactionBlockResponse struct {
	TxDigest      string                    `json:"txDigest"`
	Status        SuiExecutionStatus        `json:"status"`
	Effects       models.SuiEffects         `json:"effects"`
	Events        []models.SuiEventResponse `json:"events,omitempty"`
	Timestamp     uint64                    `json:"timestamp"`
	Height        uint64                    `json:"height"`
	ObjectChanges []models.ObjectChange     `json:"objectChanges,omitempty"`
}

type TransactionBlockOptions

type TransactionBlockOptions struct {
	ShowInput          bool `json:"showInput,omitempty"`
	ShowRawInput       bool `json:"showRawInput,omitempty"`
	ShowEffects        bool `json:"showEffects,omitempty"`
	ShowEvents         bool `json:"showEvents,omitempty"`
	ShowObjectChanges  bool `json:"showObjectChanges,omitempty"`
	ShowBalanceChanges bool `json:"showBalanceChanges,omitempty"`
}

type TransactionBlockRequest

type TransactionBlockRequest struct {
	// BCS serialized transaction data bytes without its type tag, as base-64 encoded string.
	TxBytes string `json:"txBytes"`
	// A list of signatures (`flag || signature || pubkey` bytes, as base-64 encoded string).
	// Signature is committed to the intent message of the transaction data, as base-64 encoded string.
	Signatures []string `json:"signature"`
	// Options for specifying the content to be returned
	Options TransactionBlockOptions `json:"options"`
	// The request type, derived from `SuiTransactionBlockResponseOptions` if None.
	// The optional enumeration values are: `WaitForEffectsCert`, or `WaitForLocalExecution`
	RequestType string `json:"requestType"`
}

TransactionBlockRequest represents the request the SuiExecuteTransactionBlock endpoint. https://docs.sui.io/sui-api-ref#sui_executetransactionblock

type TransactionRequestType

type TransactionRequestType string

TransactionRequestType defines the possible request types for transaction execution

const (
	WaitForEffectsCert    TransactionRequestType = "WaitForEffectsCert"
	WaitForLocalExecution TransactionRequestType = "WaitForLocalExecution"
)

type TransactionResult

type TransactionResult struct {
	Status string `json:"status"`
	Error  string `json:"error"`
}

type TxnMetaData

type TxnMetaData struct {
	TxBytes string `json:"txBytes"`
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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