wallet

package
v0.8.97 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: AGPL-3.0, AGPL-3.0-or-later, Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PayTimeout = 4 * time.Minute

	NativeCoin = "TRX"
)

Variables

View Source
var (
	ErrUnavailable = errors.New("wallet: payment engine unavailable")
	ErrNoAnswer    = errors.New("wallet: the payment engine never answered")
	ErrReverted    = errors.New("wallet: the payment reverted")
	ErrAlreadyPaid = errors.New("wallet: the order is already paid")
)

Functions

func DeriveSeed

func DeriveSeed(owner domain.Owner, identityKey ed25519.PrivateKey, network string) (string, error)

func IsAddress added in v0.8.83

func IsAddress(address string) bool

Types

type Account

type Account struct {
	TokenBalance string
	TRX          string
	Staked       string
	Unstaking    []Unstaking
	Activated    bool
	CreatedAt    int64
}

func (Account) IsLockedEnough added in v0.8.83

func (a Account) IsLockedEnough(minTRX uint64) bool

func (Account) IsStakeEnough added in v0.8.83

func (a Account) IsStakeEnough(minTRX uint64) bool

type Client

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

func New

func New(cfg Config) *Client

func (*Client) Address

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

func (*Client) Balance

func (c *Client) Balance(ctx context.Context, address string) (Account, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) Decimals

func (c *Client) Decimals() uint8

func (*Client) Export

func (c *Client) Export(ctx context.Context, seed string) (address, privateKey string, err error)

func (*Client) History

func (c *Client) History(ctx context.Context, address, asset string, limit int) ([]Transfer, error)

func (*Client) IsAvailable

func (c *Client) IsAvailable(ctx context.Context) bool

func (*Client) IsPaid

func (c *Client) IsPaid(ctx context.Context, txId string, s Sponsorship) (Receipt, error)

func (*Client) MaxFeePercent

func (c *Client) MaxFeePercent() uint64

func (*Client) Network

func (c *Client) Network() string

func (*Client) Pay

func (c *Client) Pay(ctx context.Context, seed string, s Sponsorship) (Payment, error)

Pay settles sponsored content and nothing else. It sends the money through one of the project's splitter contracts, which adds the fee on top of the amount, routes that fee to a project wallet and emits the Paid event that verification later reads to prove this transaction paid for this order.

Paying a person rather than a sponsorship is Transfer: it moves the whole amount to the recipient, takes no fee and leaves no receipt to check. Do not reach for Pay to send someone money.

func (*Client) Payment added in v0.8.83

func (c *Client) Payment(ctx context.Context, s Sponsorship, since time.Time) (PaymentState, error)

Payment asks the splitter whether the buyer's order is paid and which of the buyer's transactions from since onwards paid it, so a payment whose answer was lost is found rather than sent again.

func (*Client) Quote

func (c *Client) Quote(ctx context.Context, seed string, s Sponsorship) (Quote, error)

Quote asks what Pay would cost the wallet of seed for s, without signing anything: the token amounts exactly and the TRX the network would burn.

func (*Client) Splitter

func (c *Client) Splitter() string

func (*Client) Splitters added in v0.8.83

func (c *Client) Splitters() []string

Splitters are every splitter this node accepts payments to: the one it pays through first, then the retired ones.

func (*Client) Stake added in v0.8.83

func (c *Client) Stake(ctx context.Context, seed, amount string) (string, error)

func (*Client) Token

func (c *Client) Token() string

func (*Client) Transfer

func (c *Client) Transfer(ctx context.Context, seed, asset, to, amount string) (string, error)

func (*Client) Unstake added in v0.8.83

func (c *Client) Unstake(ctx context.Context, seed, amount string) (string, error)

func (*Client) Withdraw added in v0.8.83

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

type Config

type Config struct {
	BinaryPath    string
	Network       string
	Endpoint      string
	Token         string
	TokenContract string
	Decimals      uint8
	RPS           float64
	Splitter      string
	// Retired are splitters this node no longer pays through but still accepts
	// payments to, so a buyer on an older node is not left with a payment no
	// author will confirm.
	Retired       []string
	MaxFeePercent uint64
}

func DefaultConfig

func DefaultConfig(network, binaryPath, endpoint string) Config

type Payment

type Payment struct {
	Payer      string
	Token      string
	FeePercent uint64
	Fee        string
	Total      string
	ResetTx    string
	ApproveTx  string
	PayTx      string
}

type PaymentState added in v0.8.83

type PaymentState struct {
	Paid bool   `json:"paid"`
	Tx   string `json:"tx"`
}

PaymentState is what the splitter records of an order: whether it is paid, and which transaction paid it once the indexer lists it.

type Quote

type Quote struct {
	Token          string      `json:"token"`
	FeePercent     uint64      `json:"fee_percent"`
	Fee            string      `json:"fee"`
	Total          string      `json:"total"`
	Balance        string      `json:"balance"`
	TRX            string      `json:"trx"`
	EnergyPrice    int64       `json:"energy_price"`
	BandwidthPrice int64       `json:"bandwidth_price"`
	NetworkFee     string      `json:"network_fee"`
	Steps          []QuoteStep `json:"steps"`
}

type QuoteStep

type QuoteStep struct {
	Kind        string `json:"kind"`
	Energy      int64  `json:"energy"`
	Bandwidth   int64  `json:"bandwidth"`
	Burn        string `json:"burn"`
	Approximate bool   `json:"approximate"`
}

type Receipt added in v0.8.83

type Receipt struct {
	Confirmed bool
	BlockTime time.Time
}

Receipt is what verification says of a payment: whether it is confirmed, and when the block that holds it was produced.

type Sponsorship

type Sponsorship struct {
	Splitter      string
	OrderId       string
	Author        string
	Buyer         string
	Amount        string
	MaxFeePercent uint64
	MaxTotal      string
}

type Transfer

type Transfer struct {
	Tx        string
	Asset     string
	From      string
	To        string
	Value     string
	Timestamp int64
	Incoming  bool
}

type Unstaking added in v0.8.83

type Unstaking struct {
	Amount      string `json:"amount"`
	AvailableAt int64  `json:"available_at"`
}

Jump to

Keyboard shortcuts

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