types

package
v0.0.0-...-b700584 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PickSmaller = iota // pick smaller coins to match amount
	PickBigger         // pick bigger coins to match amount
	PickByOrder        // pick coins by coins order to match amount
)
View Source
const (
	TransactionStatusSuccess = "success"
	TransactionStatusFailure = "failure"
)
View Source
const (
	SuiCoinType   = "0x2::sui::SUI"
	DevNetRpcUrl  = "https://fullnode.devnet.sui.io"
	TestnetRpcUrl = "https://fullnode.testnet.sui.io"
)

Variables

View Source
var ErrCoinsNotMatchRequest error
View Source
var IntentBytes = []byte{0, 0, 0}

IntentBytes See: sui/crates/sui-types/src/intent.rs This is currently hardcoded with [IntentScope::TransactionData = 0, Version::V0 = 0, AppId::Sui = 0]

Functions

This section is empty.

Types

type ActiveDelegationStatus

type ActiveDelegationStatus struct {
	Active ActiveFields `json:"Active"`
}

type ActiveFields

type ActiveFields struct {
	Id struct {
		Id ObjectId `json:"id"`
	} `json:"id"`
	StakedSuiId        ObjectId `json:"staked_sui_id"`
	PrincipalSuiAmount uint64   `json:"principal_sui_amount"`
	PoolTokens         Balance  `json:"pool_tokens"`
}

type Address

type Address = HexData

func NewAddressFromHex

func NewAddressFromHex(addr string) (*Address, error)

NewAddressFromHex *

  • Creates Address from a hex string.
  • @param addr Hex string can be with a prefix or without a prefix,
  • e.g. '0x1aa' or '1aa'. Hex string will be left padded with 0s if too short.

func (Address) ShortString

func (a Address) ShortString() string

ShortString Returns the address with leading zeros trimmed, e.g. 0x2

type AuthSignInfo

type AuthSignInfo interface{}

type Balance

type Balance struct {
	Value uint64 `json:"Value"`
}

type Base64Data

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

func NewBase64Data

func NewBase64Data(str string) (*Base64Data, error)

func (Base64Data) Data

func (h Base64Data) Data() []byte

func (Base64Data) Length

func (h Base64Data) Length() int

func (Base64Data) MarshalBCS

func (h Base64Data) MarshalBCS() ([]byte, error)

func (Base64Data) MarshalJSON

func (h Base64Data) MarshalJSON() ([]byte, error)

func (Base64Data) String

func (h Base64Data) String() string

func (*Base64Data) UnmarshalJSON

func (h *Base64Data) UnmarshalJSON(data []byte) error

type Bytes

type Bytes []byte

func (Bytes) GetBase64Data

func (b Bytes) GetBase64Data() Base64Data

func (Bytes) GetHexData

func (b Bytes) GetHexData() HexData

type BytesData

type BytesData interface {
	Data() []byte
	Length() int
	String() string
}

type CertifiedTransaction

type CertifiedTransaction struct {
	TransactionDigest string        `json:"transactionDigest"`
	TxSignature       string        `json:"txSignature"`
	AuthSignInfo      *AuthSignInfo `json:"authSignInfo"`

	Data *SenderSignedData `json:"data"`
}

type ChangeEpoch

type ChangeEpoch struct {
	Epoch             interface{} `json:"epoch"`
	StorageCharge     uint64      `json:"storage_charge"`
	ComputationCharge uint64      `json:"computation_charge"`
}

type Coin

type Coin struct {
	Balance   uint64     `json:"balance"`
	Type      string     `json:"type"`
	Owner     *Address   `json:"owner"`
	Reference *ObjectRef `json:"reference"`
}

type CoinObject

type CoinObject struct {
	CoinType     string   `json:"coinType"`
	CoinObjectId ObjectId `json:"coinObjectId"`
	Version      uint64   `json:"version"`
	Digest       Digest   `json:"digest"`
	Balance      int64    `json:"balance"`
}

type CoinPage

type CoinPage struct {
	Data       []CoinObject `json:"data"`
	NextCursor *ObjectId    `json:"nextCursor"`
}

type Coins

type Coins []Coin

func (Coins) PickCoinNoLess

func (cs Coins) PickCoinNoLess(amount uint64) (*Coin, error)

func (Coins) PickCoins

func (cs Coins) PickCoins(amount *big.Int, pickMethod int) (Coins, error)

PickCoins pick coins, which sum >= amount, pickMethod, see PickSmaller|PickBigger|PickByOrder // if not satisfated amount, an ErrCoinsNotMatchRequest error will return

func (Coins) PickSUICoinsWithGas

func (cs Coins) PickSUICoinsWithGas(amount *big.Int, gasAmount uint64, pickMethod int) (Coins, *Coin, error)

PickSUICoinsWithGas pick coins, which sum >= amount, and pick a gas coin >= gasAmount which not in coins if not satisfated amount/gasAmount, an ErrCoinsNotMatchRequest error will return if gasAmount == 0, a nil gasCoin will return pickMethod, see PickSmaller|PickBigger|PickByOrder

func (Coins) TotalBalance

func (cs Coins) TotalBalance() *big.Int

type DelegatedStake

type DelegatedStake struct {
	StakedSui        StakedSui   `json:"staked_sui"`
	DelegationStatus interface{} `json:"delegation_status"` // "Pending" or ActiveDelegationStatus
}

func (*DelegatedStake) CalculateEarnAmount

func (d *DelegatedStake) CalculateEarnAmount(activeValidators []Validator) (earn uint64, validator *Validator)

type DevInspectResult

type DevInspectResult struct {
	Err string `json:"Err,omitempty"`
	Ok  any    `json:"Ok,omitempty"` //Result_of_Array_of_Tuple_of_uint_and_SuiExecutionResult_or_String
}

type DevInspectResults

type DevInspectResults struct {
	Effects TransactionEffects `json:"effects"`
	Results DevInspectResult   `json:"results"`
}

type Digest

type Digest = Base64Data

type Event

type Event interface{}

type EventID

type EventID struct {
	TxDigest Digest `json:"txDigest"`
	EventSeq int64  `json:"eventSeq"`
}

type EventPage

type EventPage struct {
	Data       []Event `json:"data"`
	NextCursor EventID `json:"nextCursor"`
}

type EventQuery

type EventQuery struct {
	// Return all events.
	All *string `json:"All"`
	// Return events emitted by the given transaction.
	Transaction *Digest `json:"Transaction"`
	// Return events emitted in a specified Move module
	MoveModule *MoveModule `json:"MoveModule"`
	// Return events with the given move event struct name
	MoveEvent *string `json:"MoveEvent"` // e.g. `0x2::devnet_nft::MintNFTEvent`
	// MoveEvent/Publish/CoinBalanceChange/EpochChange/Checkpoint
	// TransferObject/MutateObject/DeleteObject/NewObject
	EventType *string `json:"EventType"`
	// Query by sender address.
	Sender *Address `json:"Sender"`
	// Query by recipient address
	Recipient *ObjectOwnerInternal `json:"Recipient"`
	// Return events associated with the given object
	Object *ObjectId `json:"Object"`
	// Return events emitted in [start_time, end_time] interval
	TimeRange *TimeRange `json:"TimeRange"`
}

func (EventQuery) MarshalJSON

func (q EventQuery) MarshalJSON() ([]byte, error)

type ExecuteTransactionEffects

type ExecuteTransactionEffects struct {
	TransactionEffectsDigest string `json:"transactionEffectsDigest"`

	Effects      TransactionEffects `json:"effects"`
	AuthSignInfo *AuthSignInfo      `json:"authSignInfo"`
}

type ExecuteTransactionRequestType

type ExecuteTransactionRequestType string
const (
	TxnRequestTypeWaitForEffectsCert    ExecuteTransactionRequestType = "WaitForEffectsCert"
	TxnRequestTypeWaitForLocalExecution ExecuteTransactionRequestType = "WaitForLocalExecution"
)

type ExecuteTransactionResponse

type ExecuteTransactionResponse struct {
	ImmediateReturn *struct {
		TransactionDigest string `json:"tx_digest"`
	} `json:"ImmediateReturn,omitempty"`

	TxCert *struct {
		Certificate CertifiedTransaction `json:"certificate"`
	} `json:"TxCert,omitempty"`

	EffectsCert *struct {
		Certificate CertifiedTransaction      `json:"certificate"`
		Effects     ExecuteTransactionEffects `json:"effects"`

		ConfirmedLocalExecution bool `json:"confirmed_local_execution"`
	} `json:"EffectsCert,omitempty"`
}

func (*ExecuteTransactionResponse) TransactionDigest

func (r *ExecuteTransactionResponse) TransactionDigest() string

type GasCostSummary

type GasCostSummary struct {
	ComputationCost uint64 `json:"computationCost"`
	StorageCost     uint64 `json:"storageCost"`
	StorageRebate   uint64 `json:"storageRebate"`
}

type HexData

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

func NewHexData

func NewHexData(str string) (*HexData, error)

func (HexData) Data

func (a HexData) Data() []byte

func (HexData) Length

func (a HexData) Length() int

func (HexData) MarshalBCS

func (a HexData) MarshalBCS() ([]byte, error)

func (HexData) MarshalJSON

func (a HexData) MarshalJSON() ([]byte, error)

func (HexData) String

func (a HexData) String() string

func (*HexData) UnmarshalJSON

func (a *HexData) UnmarshalJSON(data []byte) error

type InputObjectKind

type InputObjectKind map[string]interface{}

type ModulePublish

type ModulePublish struct {
	Modules [][]byte `json:"modules"`
}

type MoveCall

type MoveCall struct {
	Package  ObjectRef     `json:"package"`
	Module   string        `json:"module"`
	Function string        `json:"function"`
	TypeArgs []interface{} `json:"typeArguments"`
	Args     []interface{} `json:"arguments"`
}

type MoveFunction

type MoveFunction struct {
	Package  ObjectId `json:"package"`
	Module   string   `json:"module,omitempty"`
	Function string   `json:"function,omitempty"`
}

type MoveModule

type MoveModule struct {
	Package ObjectId `json:"package"`
	Module  string   `json:"module"`
}

type ObjectId

type ObjectId = HexData

type ObjectInfo

type ObjectInfo struct {
	ObjectId *ObjectId    `json:"objectId"`
	Version  int          `json:"version"`
	Digest   string       `json:"digest"`
	Type     string       `json:"type"`
	Owner    *ObjectOwner `json:"owner"`

	PreviousTransaction string `json:"previousTransaction"`
}

type ObjectOwner

type ObjectOwner struct {
	*ObjectOwnerInternal
	// contains filtered or unexported fields
}

func (ObjectOwner) MarshalJSON

func (o ObjectOwner) MarshalJSON() ([]byte, error)

func (*ObjectOwner) UnmarshalJSON

func (o *ObjectOwner) UnmarshalJSON(data []byte) error

type ObjectOwnerInternal

type ObjectOwnerInternal struct {
	AddressOwner *Address `json:"AddressOwner,omitempty"`
	ObjectOwner  *Address `json:"ObjectOwner,omitempty"`
	SingleOwner  *Address `json:"SingleOwner,omitempty"`
	Shared       *struct {
		InitialSharedVersion uint64 `json:"initial_shared_version"`
	} `json:"Shared,omitempty"`
}

type ObjectRead

type ObjectRead struct {
	Details *ObjectReadDetail `json:"details"`
	Status  ObjectStatus      `json:"status"`
}

type ObjectReadDetail

type ObjectReadDetail struct {
	Data  map[string]interface{} `json:"data"`
	Owner *ObjectOwner           `json:"owner"`

	PreviousTransaction string     `json:"previousTransaction"`
	StorageRebate       int        `json:"storageRebate"`
	Reference           *ObjectRef `json:"reference"`
}

type ObjectRef

type ObjectRef struct {
	ObjectId ObjectId `json:"objectId"`
	Version  uint64   `json:"version"`
	Digest   Digest   `json:"digest"`
}

ObjectRef for BCS, need to keep this order

type ObjectStatus

type ObjectStatus string
const (
	// ObjectStatusExists ObjectStatusNotExists ObjectStatusDeleted
	// status for sui_getObject
	ObjectStatusExists    ObjectStatus = "Exists"
	ObjectStatusNotExists ObjectStatus = "NotExists"
	ObjectStatusDeleted   ObjectStatus = "Deleted"
	// ObjectDeleted VersionFound VersionTooHigh VersionNotFound
	//status for sui_tryGetPastObject
	ObjectDeleted   ObjectStatus = "ObjectDeleted"
	VersionFound    ObjectStatus = "VersionFound"
	VersionTooHigh  ObjectStatus = "VersionTooHigh"
	VersionNotFound ObjectStatus = "VersionNotFound"
)

type OwnedObjectRef

type OwnedObjectRef struct {
	Owner     *ObjectOwner `json:"owner"`
	Reference *ObjectRef   `json:"reference"`
}

type ParsedTransactionResponse

type ParsedTransactionResponse interface{}

type Pay

type Pay struct {
	Coins      []ObjectRef `json:"coins"`
	Recipients []Address   `json:"recipients"`
	Amounts    []uint64    `json:"amounts"`
}

type PayAllSui

type PayAllSui struct {
	Coins     []ObjectRef `json:"coins"`
	Recipient Address     `json:"recipient"`
}

type PaySui

type PaySui struct {
	Coins      []ObjectRef `json:"coins"`
	Recipients []Address   `json:"recipients"`
	Amounts    []uint64    `json:"amounts"`
}

type ResourceType

type ResourceType struct {
	Address    *Address
	ModuleName string
	FuncName   string

	SubType *ResourceType
}

func NewResourceType

func NewResourceType(str string) (*ResourceType, error)

func (*ResourceType) ShortString

func (t *ResourceType) ShortString() string

func (*ResourceType) String

func (t *ResourceType) String() string

type SenderSignedData

type SenderSignedData struct {
	Transactions []SingleTransactionKind `json:"transactions,omitempty"`

	Sender     *Address   `json:"sender"`
	GasPayment *ObjectRef `json:"gasPayment"`
	GasBudget  uint64     `json:"gasBudget"`
}

type SignatureScheme

type SignatureScheme string
const (
	SignatureSchemeEd25519   SignatureScheme = "ED25519"
	SignatureSchemeSecp256k1 SignatureScheme = "Secp256k1"
)

type SignatureSchemeSerialized

type SignatureSchemeSerialized byte
const (
	SignatureSchemeSerializedEd25519   SignatureSchemeSerialized = 0
	SignatureSchemeSerializedSecp256k1 SignatureSchemeSerialized = 1
)

type SignedTransaction

type SignedTransaction struct {
	// transaction data bytes
	TxBytes *Base64Data `json:"tx_bytes"`

	// Flag of the signature scheme that is used.
	SigScheme SignatureScheme `json:"sig_scheme"`

	// transaction signature
	Signature *Base64Data `json:"signature"`

	// signer's public key
	PublicKey *Base64Data `json:"pub_key"`
}

SignedTransaction Deprecated: replace with SignedTransactionSerializedSig

type SignedTransactionSerializedSig

type SignedTransactionSerializedSig struct {
	// transaction data bytes
	TxBytes *Base64Data `json:"tx_bytes"`

	// transaction signature
	Signature *Base64Data `json:"signature"`
}

type SingleTransactionKind

type SingleTransactionKind struct {
	TransferObject *TransferObject `json:"TransferObject,omitempty"`
	Publish        *ModulePublish  `json:"Publish,omitempty"`
	Call           *MoveCall       `json:"Call,omitempty"`
	TransferSui    *TransferSui    `json:"TransferSui,omitempty"`
	ChangeEpoch    *ChangeEpoch    `json:"ChangeEpoch,omitempty"`
	PaySui         *PaySui         `json:"PaySui,omitempty"`
	Pay            *Pay            `json:"Pay,omitempty"`
	PayAllSui      *PayAllSui      `json:"PayAllSui,omitempty"`
}

type StakedSui

type StakedSui struct {
	Id struct {
		Id ObjectId `json:"id"`
	} `json:"id"`
	ValidatorAddress       Address `json:"validator_address"`
	PoolStartingEpoch      uint64  `json:"pool_starting_epoch"`
	DelegationRequestEpoch uint64  `json:"delegation_request_epoch"`
	Principal              Balance `json:"principal"`
	SuiTokenLock           int     `json:"sui_token_lock,omitempty"`
}

type StakingPool

type StakingPool struct {
	ValidatorAddress      Address     `json:"validator_address"`
	StartingEpoch         uint64      `json:"starting_epoch"`
	SuiBalance            uint64      `json:"sui_balance"`
	RewardsPool           Balance     `json:"rewards_pool"`
	DelegationTokenSupply Supply      `json:"delegation_token_supply"`
	PendingDelegations    interface{} `json:"pending_delegations"` //: LinkedTable<ObjectID>,
	PendingWithdraws      interface{} `json:"pending_withdraws"`   //: TableVec,
}

type SuiCoinBalance

type SuiCoinBalance struct {
	CoinType        string `json:"coinType"`
	CoinObjectCount int64  `json:"coinObjectCount"`
	TotalBalance    int64  `json:"totalBalance"`
}

type SuiCoinMetadata

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

type SuiSystemState

type SuiSystemState struct {
	Info                   interface{}  `json:"info"` //: UID
	Epoch                  uint64       `json:"epoch"`
	Validators             ValidatorSet `json:"validators"`
	Treasury_cap           Supply       `json:"treasury_cap"`
	StorageFund            Balance      `json:"storage_fund"`
	Parameters             interface{}  `json:"parameters"` //: SystemParameters,
	ReferenceGasPrice      uint64       `json:"reference_gas_price"`
	ValidatorReportRecords interface{}  `json:"validator_report_records"` //: VecMap<SuiAddress, VecSet<SuiAddress>>,
	StakeSubsidy           interface{}  `json:"stake_subsidy"`            //: StakeSubsidy,
	SafeMode               bool         `json:"safe_mode"`
	EpochStartTimestampMs  uint64       `json:"epoch_start_timestamp_ms"`
}

type Supply

type Supply struct {
	Value uint64 `json:"value"`
}

type TimeRange

type TimeRange struct {
	StartTime uint64 `json:"startTime"` // left endpoint of time interval, milliseconds since epoch, inclusive
	EndTime   uint64 `json:"endTime"`   // right endpoint of time interval, milliseconds since epoch, exclusive
}

type TransactionBytes

type TransactionBytes struct {
	// the gas object to be used
	Gas ObjectRef `json:"gas"`

	// objects to be used in this transaction
	InputObjects []InputObjectKind `json:"inputObjects"`

	// transaction data bytes
	TxBytes Base64Data `json:"txBytes"`
}

func (*TransactionBytes) SignSerializedSigWith

func (txn *TransactionBytes) SignSerializedSigWith(privateKey ed25519.PrivateKey) *SignedTransactionSerializedSig

func (*TransactionBytes) SignWith

func (txn *TransactionBytes) SignWith(privateKey ed25519.PrivateKey) *SignedTransaction

SignWith Deprecated: replace with SignSerializedSigWith

type TransactionEffects

type TransactionEffects struct {
	Status TransactionStatus `json:"status"`

	TransactionDigest string          `json:"transactionDigest"`
	GasUsed           *GasCostSummary `json:"gasUsed"`
	GasObject         *OwnedObjectRef `json:"gasObject"`
	Events            []Event         `json:"events,omitempty"`
	Dependencies      []string        `json:"dependencies,omitempty"`

	// SharedObjects []ObjectRef      `json:"sharedObjects"`
	Created   []OwnedObjectRef `json:"created,omitempty"`
	Mutated   []OwnedObjectRef `json:"mutated,omitempty"`
	Unwrapped []OwnedObjectRef `json:"unwrapped,omitempty"`
	Deleted   []ObjectRef      `json:"deleted,omitempty"`
	Wrapped   []ObjectRef      `json:"wrapped,omitempty"`
}

func (*TransactionEffects) GasFee

func (te *TransactionEffects) GasFee() uint64

type TransactionQuery

type TransactionQuery struct {
	All *string `json:"All"`
	/// Query by move function.
	MoveFunction *MoveFunction `json:"MoveFunction"`
	/// Query by input object.
	InputObject *ObjectId `json:"InputObject"`
	/// Query by mutated object.
	MutatedObject *ObjectId `json:"MutatedObject"`
	/// Query by sender address.
	FromAddress *Address `json:"FromAddress"`
	/// Query by recipient address.
	ToAddress *Address `json:"ToAddress"`
}

func (TransactionQuery) MarshalJSON

func (t TransactionQuery) MarshalJSON() ([]byte, error)

type TransactionResponse

type TransactionResponse struct {
	Certificate *CertifiedTransaction     `json:"certificate"`
	Effects     *TransactionEffects       `json:"effects"`
	ParsedData  ParsedTransactionResponse `json:"parsed_data,omitempty"`
	TimestampMs uint64                    `json:"timestamp_ms,omitempty"`
}

type TransactionStatus

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

type TransactionsPage

type TransactionsPage struct {
	Data       []string `json:"data"`
	NextCursor string   `json:"nextCursor"`
}

type TransferObject

type TransferObject struct {
	Recipient Address   `json:"recipient"`
	ObjectRef ObjectRef `json:"object_ref"`
}

type TransferSui

type TransferSui struct {
	Recipient Address `json:"recipient"`
	Amount    uint64  `json:"amount"`
}

type Validator

type Validator struct {
	Metadata              ValidatorMetadata `json:"metadata"`
	VotingPower           uint64            `json:"voting_power"`
	StakeAmount           uint64            `json:"stake_amount"`
	PendingStake          uint64            `json:"pending_stake"`
	PendingWithdraw       uint64            `json:"pending_withdraw"`
	GasPrice              uint64            `json:"gas_price"`
	DelegationStakingPool StakingPool       `json:"delegation_staking_pool"`
	CommissionRate        uint64            `json:"commission_rate"`
}

func (*Validator) CalculateAPY

func (v *Validator) CalculateAPY(epoch uint64) float64

type ValidatorMetadata

type ValidatorMetadata struct {
	SuiAddress              Address `json:"sui_address"`
	PubkeyBytes             []byte  `json:"pubkey_bytes"`
	NetworkPubkeyBytes      []byte  `json:"network_pubkey_bytes"`
	WorkerPubkeyBytes       []byte  `json:"worker_pubkey_bytes"`
	ProofOfPossessionBytes  []byte  `json:"proof_of_possession_bytes"`
	Name                    []byte  `json:"name"`
	Description             []byte  `json:"description"`
	ImageUrl                []byte  `json:"image_url"`
	ProjectUrl              []byte  `json:"project_url"`
	NetAddress              []byte  `json:"net_address"`
	ConsensusAddress        []byte  `json:"consensus_address"`
	WorkerAddress           []byte  `json:"worker_address"`
	NextEpochStake          uint64  `json:"next_epoch_stake"`
	NextEpochDelegation     uint64  `json:"next_epoch_delegation"`
	NextEpochGasPrice       uint64  `json:"next_epoch_gas_price"`
	NextEpochCommissionRate uint64  `json:"next_epoch_commission_rate"`
}

type ValidatorSet

type ValidatorSet struct {
	ValidatorStake            uint64              `json:"validator_stake"`
	DelegationStake           uint64              `json:"delegation_stake"`
	ActiveValidators          []Validator         `json:"active_validators"`
	PendingValidators         []Validator         `json:"pending_validators"`
	PendingRemovals           []uint64            `json:"pending_removals"`
	NextEpochValidators       []ValidatorMetadata `json:"next_epoch_validators"`
	PendingDelegationSwitches interface{}         `json:"pending_delegation_switches"` //: VecMap<ValidatorPair, TableVec>,
}

Jump to

Keyboard shortcuts

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