client

package
v0.0.0-...-cc9b5da Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressName

type AddressName string

func NewAddressName

func NewAddressName(chain xc.NativeAsset, address string) AddressName

type AssetName

type AssetName string

func NewAssetName

func NewAssetName(chain xc.NativeAsset, contractOrNativeAsset string) AssetName

type Balance

type Balance struct {
	Asset    AssetName               `json:"asset"`
	Contract xc.ContractAddress      `json:"contract"`
	Balance  xc.AmountBlockchain     `json:"balance"`
	Amount   *xc.AmountHumanReadable `json:"amount,omitempty"`
}

func NewBalance

func NewBalance(chain xc.NativeAsset, contract xc.ContractAddress, balance xc.AmountBlockchain, decimals *int) *Balance

type BalanceChange

type BalanceChange struct {
	Balance   xc.AmountBlockchain     `json:"balance"`
	Amount    *xc.AmountHumanReadable `json:"amount,omitempty"`
	XAddress  AddressName             `json:"address"`    // deprecated
	AddressId xc.Address              `json:"address_id"` // replaces address
}

func NewBalanceChange

func NewBalanceChange(chain xc.NativeAsset, addressId xc.Address, balance xc.AmountBlockchain, decimals *int) *BalanceChange

type Block

type Block struct {
	Chain xc.NativeAsset `json:"chain"`
	// required: set the blockheight of the transaction
	Height uint64 `json:"height"`
	// required: set the hash of the block of the transaction
	Hash string `json:"hash"`
	// required: set the time of the block of the transaction
	Time time.Time `json:"time"`
}

func NewBlock

func NewBlock(chain xc.NativeAsset, height uint64, hash string, time time.Time) *Block

type Client

type Client interface {
	// Fetch the basic transaction input for any new transaction
	FetchLegacyTxInput(ctx context.Context, from xc.Address, to xc.Address) (xc.TxInput, error)

	// Broadcast a signed transaction to the chain
	SubmitTx(ctx context.Context, tx xc.Tx) error

	// Fetching transaction info - legacy endpoint
	FetchLegacyTxInfo(ctx context.Context, txHash xc.TxHash) (xc.LegacyTxInfo, error)

	// Fetching transaction info
	FetchTxInfo(ctx context.Context, txHash xc.TxHash) (TxInfo, error)

	// Fetch the balance of the given asset that the client is configured with
	FetchBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)

	// Fetch the native balance for the chain on an address
	FetchNativeBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)

	// Fetch the precision (or "decimals") associated with the target asset
	FetchDecimals(ctx context.Context, contract xc.ContractAddress) (int, error)
}

Client is a client that can fetch data and submit tx to a public blockchain

type ClientV2

type ClientV2 interface {
	// Improved signature replacement of `FetchLegacyTxInput`
	FetchTransferInput(ctx context.Context, args builder.TransferArgs) (xc.TxInput, error)
}

type ClientWithDecimals

type ClientWithDecimals interface {
	FetchDecimals(ctx context.Context, contract xc.ContractAddress) (int, error)
}

type FullClient

type FullClient interface {
	Client
	ClientV2
}

type LegacyBalances

type LegacyBalances map[AssetName]xc.AmountBlockchain

type LegacyTxInfoMappingType

type LegacyTxInfoMappingType string
var Account LegacyTxInfoMappingType = "account"
var Utxo LegacyTxInfoMappingType = "utxo"

type ManualUnstakingClient

type ManualUnstakingClient interface {
	CompleteManualUnstaking(ctx context.Context, unstake *Unstake) error
}

Special 3rd-party interface for Ethereum as ethereum doesn't understand delegated staking

type Movement

type Movement struct {
	XAsset    AssetName          `json:"asset"`    // deprecated
	XContract xc.ContractAddress `json:"contract"` // deprecated
	AssetId   xc.ContractAddress `json:"asset_id"` // replaces contract

	// ContractId is set only when there is an alternative contract
	// identifier used by the chain for the native asset.  It should be blank otherwise.
	ContractId xc.ContractAddress `json:"contract_id,omitempty"`

	// required: source debits
	From []*BalanceChange `json:"from"`
	// required: destination credits
	To []*BalanceChange `json:"to"`

	Memo string `json:"memo,omitempty"`
	// contains filtered or unexported fields
}

func NewMovement

func NewMovement(chain xc.NativeAsset, contract xc.ContractAddress) *Movement

func (*Movement) AddDestination

func (tf *Movement) AddDestination(to xc.Address, balance xc.AmountBlockchain, decimals *int)

func (*Movement) AddSource

func (tf *Movement) AddSource(from xc.Address, balance xc.AmountBlockchain, decimals *int)

func (*Movement) SetMemo

func (tf *Movement) SetMemo(memo string)

type Stake

type Stake struct {
	Balance   xc.AmountBlockchain `json:"balance"`
	Validator string              `json:"validator"`
	Account   string              `json:"account"`
	Address   string              `json:"address"`
}

func (*Stake) GetValidator

func (s *Stake) GetValidator() string

type StakeEvent

type StakeEvent interface {
	GetValidator() string
}

type StakeState

type StakeState string
var Activating StakeState = "activating"
var Active StakeState = "active"
var Deactivating StakeState = "deactivating"
var Inactive StakeState = "inactive"

type StakedBalance

type StakedBalance struct {
	// the validator that the stake is delegated to
	Validator string `json:"validator"`
	// Optional; the account that the stake is associated with
	Account string `json:"account,omitempty"`
	// The states balance of the balance in the validator [+account]
	Balance StakedBalanceState `json:"balance"`
}

func NewStakedBalance

func NewStakedBalance(balance xc.AmountBlockchain, state StakeState, validator, account string) *StakedBalance

func NewStakedBalances

func NewStakedBalances(balances StakedBalanceState, validator, account string) *StakedBalance

type StakedBalanceArgs

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

func NewStakeBalanceArgs

func NewStakeBalanceArgs(from xc.Address, options ...StakedBalanceOption) (StakedBalanceArgs, error)

func (*StakedBalanceArgs) GetAccount

func (opts *StakedBalanceArgs) GetAccount() (string, bool)

func (*StakedBalanceArgs) GetFrom

func (opts *StakedBalanceArgs) GetFrom() xc.Address

func (*StakedBalanceArgs) GetValidator

func (opts *StakedBalanceArgs) GetValidator() (string, bool)

type StakedBalanceOption

type StakedBalanceOption func(opts *StakedBalanceArgs) error

func StakeBalanceOptionAccount

func StakeBalanceOptionAccount(account string) StakedBalanceOption

func StakeBalanceOptionValidator

func StakeBalanceOptionValidator(validator string) StakedBalanceOption

type StakedBalanceState

type StakedBalanceState struct {
	Active       xc.AmountBlockchain `json:"active,omitempty"`
	Activating   xc.AmountBlockchain `json:"activating,omitempty"`
	Deactivating xc.AmountBlockchain `json:"deactivating,omitempty"`
	Inactive     xc.AmountBlockchain `json:"inactive,omitempty"`
}

type StakingClient

type StakingClient interface {
	// Fetch staked balances accross different possible states
	FetchStakeBalance(ctx context.Context, args StakedBalanceArgs) ([]*StakedBalance, error)

	// Fetch inputs required for a staking transaction
	FetchStakingInput(ctx context.Context, args builder.StakeArgs) (xc.StakeTxInput, error)

	// Fetch inputs required for a unstaking transaction
	FetchUnstakingInput(ctx context.Context, args builder.StakeArgs) (xc.UnstakeTxInput, error)

	// Fetch input for a withdraw transaction -- not all chains use this as they combine it with unstake
	FetchWithdrawInput(ctx context.Context, args builder.StakeArgs) (xc.WithdrawTxInput, error)
}

type State

type State string
const Failed State = "failed"
const Mining State = "mining"
const Succeeded State = "succeeded"

type TransactionName

type TransactionName string

func NewTransactionName

func NewTransactionName(chain xc.NativeAsset, txHash string) TransactionName

func (TransactionName) Chain

func (name TransactionName) Chain() string

type TransferSource

type TransferSource struct {
	From   AddressName         `json:"from"`
	Asset  AssetName           `json:"asset"`
	Amount xc.AmountBlockchain `json:"amount"`
}

type TxInfo

type TxInfo struct {
	Name TransactionName `json:"name"`
	// required: set the transaction hash/id
	Hash string `json:"hash"`
	// required: set the chain
	XChain xc.NativeAsset `json:"chain"` //deprecated

	State State `json:"state"`
	Final bool  `json:"final"`

	// required: set the block info
	Block *Block `json:"block"`

	// required: set any movements
	Movements []*Movement `json:"movements"`

	// output-only: calculate via .CalcuateFees() method
	Fees []*Balance `json:"fees"`

	// Native staking events
	Stakes   []*Stake   `json:"stakes,omitempty"`
	Unstakes []*Unstake `json:"unstakes,omitempty"`

	// required: set the confirmations at time of querying the info
	Confirmations uint64 `json:"confirmations"`
	// optional: set the error of the transaction if there was an error
	Error *string `json:"error,omitempty"`
}

This should roughly match stoplight

func NewTxInfo

func NewTxInfo(block *Block, chainCfg *xc.ChainConfig, hash string, confirmations uint64, err *string) *TxInfo

func TxInfoFromLegacy

func TxInfoFromLegacy(chainCfg *xc.ChainConfig, legacyTx xc.LegacyTxInfo, mappingType LegacyTxInfoMappingType) TxInfo

func (*TxInfo) AddFee

func (info *TxInfo) AddFee(from xc.Address, contract xc.ContractAddress, balance xc.AmountBlockchain, decimals *int)

func (*TxInfo) AddMovement

func (info *TxInfo) AddMovement(transfer *Movement)

func (*TxInfo) AddSimpleTransfer

func (info *TxInfo) AddSimpleTransfer(from xc.Address, to xc.Address, contract xc.ContractAddress, balance xc.AmountBlockchain, decimals *int, memo string)

func (*TxInfo) CalculateFees

func (info *TxInfo) CalculateFees() []*Balance

func (*TxInfo) Coalesece

func (info *TxInfo) Coalesece()

Merge together movements that have the same asset. This may not always be the right thing to do, depends on the chain.

  • UXTO chains, where there's not always a distinct from/to, should be coalesced.
  • Account based chains, where there's always distinct from/to, should NOT be coalesced, as this would make it more confusing who is sending to who.

Generally if it's very clear who is sending to who, we don't coalesce. If it's not clear who is sending to who, we should coalesce to simplify.

func (*TxInfo) SetContractIdForNativeAsset

func (tx *TxInfo) SetContractIdForNativeAsset(contractId xc.ContractAddress)

func (*TxInfo) SyncDeprecatedFields

func (tx *TxInfo) SyncDeprecatedFields()

type Unstake

type Unstake struct {
	Balance   xc.AmountBlockchain `json:"balance"`
	Validator string              `json:"validator"`
	Account   string              `json:"account"`
	Address   string              `json:"address"`
}

func (*Unstake) GetValidator

func (s *Unstake) GetValidator() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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