api

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServer

func NewServer(cm ChainManager, s Syncer, wm WalletManager) http.Handler

NewServer returns an HTTP handler that serves the walletd API.

Types

type ApplyUpdate

type ApplyUpdate struct {
	Update consensus.ApplyUpdate `json:"update"`
	State  consensus.State       `json:"state"`
	Block  types.Block           `json:"block"`
}

An ApplyUpdate is a consensus update that was applied to the best chain.

type BalanceResponse

type BalanceResponse wallet.Balance

BalanceResponse is the response type for /wallets/:id/balance.

type ChainManager

type ChainManager interface {
	UpdatesSince(types.ChainIndex, int) ([]chain.RevertUpdate, []chain.ApplyUpdate, error)

	BestIndex(height uint64) (types.ChainIndex, bool)
	TipState() consensus.State
	AddBlocks([]types.Block) error
	RecommendedFee() types.Currency
	PoolTransactions() []types.Transaction
	V2PoolTransactions() []types.V2Transaction
	AddPoolTransactions(txns []types.Transaction) (bool, error)
	AddV2PoolTransactions(index types.ChainIndex, txns []types.V2Transaction) (bool, error)
	UnconfirmedParents(txn types.Transaction) []types.Transaction
}

A ChainManager manages blockchain and txpool state.

type Client

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

A Client provides methods for interacting with a walletd API server.

func NewClient

func NewClient(addr, password string) *Client

NewClient returns a client that communicates with a walletd server listening on the specified address.

func (*Client) AddWallet

func (c *Client) AddWallet(uw WalletUpdateRequest) (w wallet.Wallet, err error)

AddWallet adds a wallet to the set of tracked wallets.

func (*Client) AddressBalance

func (c *Client) AddressBalance(addr types.Address) (resp BalanceResponse, err error)

AddressBalance returns the balance of a single address.

func (*Client) AddressEvents

func (c *Client) AddressEvents(addr types.Address, offset, limit int) (resp []wallet.Event, err error)

AddressEvents returns the events of a single address.

func (*Client) AddressSiacoinOutputs

func (c *Client) AddressSiacoinOutputs(addr types.Address, offset, limit int) (resp []types.SiacoinElement, err error)

AddressSiacoinOutputs returns the unspent siacoin outputs for an address.

func (*Client) AddressSiafundOutputs

func (c *Client) AddressSiafundOutputs(addr types.Address, offset, limit int) (resp []types.SiafundElement, err error)

AddressSiafundOutputs returns the unspent siafund outputs for an address.

func (*Client) AddressUnconfirmedEvents

func (c *Client) AddressUnconfirmedEvents(addr types.Address) (resp []wallet.Event, err error)

AddressUnconfirmedEvents returns the unconfirmed events for a single address.

func (*Client) ConsensusIndex

func (c *Client) ConsensusIndex(height uint64) (resp types.ChainIndex, err error)

ConsensusIndex returns the consensus index at the specified height.

func (*Client) ConsensusNetwork

func (c *Client) ConsensusNetwork() (resp *consensus.Network, err error)

ConsensusNetwork returns the node's network metadata.

func (*Client) ConsensusTip

func (c *Client) ConsensusTip() (resp types.ChainIndex, err error)

ConsensusTip returns the current tip index.

func (*Client) ConsensusTipState

func (c *Client) ConsensusTipState() (resp consensus.State, err error)

ConsensusTipState returns the current tip state.

func (*Client) ConsensusUpdates

func (c *Client) ConsensusUpdates(index types.ChainIndex, limit int) ([]chain.RevertUpdate, []chain.ApplyUpdate, error)

ConsensusUpdates returns at most n consensus updates that have occurred since the specified index

func (*Client) Event

func (c *Client) Event(id types.Hash256) (resp wallet.Event, err error)

Event returns the event with the specified ID.

func (*Client) RemoveWallet

func (c *Client) RemoveWallet(id wallet.ID) (err error)

RemoveWallet deletes a wallet. If the wallet is currently subscribed, it will be unsubscribed.

func (*Client) Rescan

func (c *Client) Rescan(height uint64) (err error)

Rescan rescans the blockchain starting from the specified height.

func (*Client) ScanStatus

func (c *Client) ScanStatus() (resp RescanResponse, err error)

ScanStatus returns the current state of wallet scanning.

func (*Client) State

func (c *Client) State() (resp StateResponse, err error)

State returns information about the current state of the walletd daemon.

func (*Client) SyncerBroadcastBlock

func (c *Client) SyncerBroadcastBlock(b types.Block) (err error)

SyncerBroadcastBlock broadcasts a block to all peers.

func (*Client) SyncerConnect

func (c *Client) SyncerConnect(addr string) (err error)

SyncerConnect adds the address as a peer of the syncer.

func (*Client) SyncerPeers

func (c *Client) SyncerPeers() (resp []GatewayPeer, err error)

SyncerPeers returns the current peers of the syncer.

func (*Client) TxpoolBroadcast

func (c *Client) TxpoolBroadcast(txns []types.Transaction, v2txns []types.V2Transaction) (err error)

TxpoolBroadcast broadcasts a set of transaction to the network.

func (*Client) TxpoolFee

func (c *Client) TxpoolFee() (resp types.Currency, err error)

TxpoolFee returns the recommended fee (per weight unit) to ensure a high probability of inclusion in the next block.

func (*Client) TxpoolParents

func (c *Client) TxpoolParents(txn types.Transaction) (resp []types.Transaction, err error)

TxpoolParents returns the parents of a transaction that are currently in the transaction pool.

func (*Client) TxpoolTransactions

func (c *Client) TxpoolTransactions() (txns []types.Transaction, v2txns []types.V2Transaction, err error)

TxpoolTransactions returns all transactions in the transaction pool.

func (*Client) UpdateWallet

func (c *Client) UpdateWallet(id wallet.ID, uw WalletUpdateRequest) (w wallet.Wallet, err error)

UpdateWallet updates a wallet.

func (*Client) Wallet

func (c *Client) Wallet(id wallet.ID) *WalletClient

Wallet returns a client for interacting with the specified wallet.

func (*Client) Wallets

func (c *Client) Wallets() (ws []wallet.Wallet, err error)

Wallets returns the set of tracked wallets.

type ConsensusUpdatesResponse

type ConsensusUpdatesResponse struct {
	Applied  []ApplyUpdate  `json:"applied"`
	Reverted []RevertUpdate `json:"reverted"`
}

ConsensusUpdatesResponse is the response type for /consensus/updates/:index.

type GatewayPeer

type GatewayPeer struct {
	Addr    string `json:"addr"`
	Inbound bool   `json:"inbound"`
	Version string `json:"version"`

	FirstSeen      time.Time     `json:"firstSeen,omitempty"`
	ConnectedSince time.Time     `json:"connectedSince,omitempty"`
	SyncedBlocks   uint64        `json:"syncedBlocks,omitempty"`
	SyncDuration   time.Duration `json:"syncDuration,omitempty"`
}

A GatewayPeer is a currently-connected peer.

type RescanResponse

type RescanResponse struct {
	StartIndex types.ChainIndex `json:"startIndex"`
	Index      types.ChainIndex `json:"index"`
	StartTime  time.Time        `json:"startTime"`
	Error      *string          `json:"error,omitempty"`
}

RescanResponse contains information about the state of a chain rescan.

type RevertUpdate

type RevertUpdate struct {
	Update consensus.RevertUpdate `json:"update"`
	State  consensus.State        `json:"state"`
	Block  types.Block            `json:"block"`
}

A RevertUpdate is a consensus update that was reverted from the best chain.

type SeedSignRequest

type SeedSignRequest struct {
	Transaction types.Transaction `json:"transaction"`
	Keys        []uint64          `json:"keys"`
}

SeedSignRequest requests that a transaction be signed using the keys derived from the given indices.

type StateResponse

type StateResponse struct {
	Version   string           `json:"version"`
	Commit    string           `json:"commit"`
	OS        string           `json:"os"`
	BuildTime time.Time        `json:"buildTime"`
	StartTime time.Time        `json:"startTime"`
	IndexMode wallet.IndexMode `json:"indexMode"`
}

A StateResponse returns information about the current state of the walletd daemon.

type Syncer

type Syncer interface {
	Addr() string
	Peers() []*syncer.Peer
	PeerInfo(addr string) (syncer.PeerInfo, error)
	Connect(ctx context.Context, addr string) (*syncer.Peer, error)
	BroadcastHeader(bh gateway.BlockHeader)
	BroadcastTransactionSet(txns []types.Transaction)
	BroadcastV2TransactionSet(index types.ChainIndex, txns []types.V2Transaction)
	BroadcastV2BlockOutline(bo gateway.V2BlockOutline)
}

A Syncer can connect to other peers and synchronize the blockchain.

type TxpoolBroadcastRequest

type TxpoolBroadcastRequest struct {
	Transactions   []types.Transaction   `json:"transactions"`
	V2Transactions []types.V2Transaction `json:"v2transactions"`
}

TxpoolBroadcastRequest is the request type for /txpool/broadcast.

type TxpoolTransactionsResponse

type TxpoolTransactionsResponse struct {
	Transactions   []types.Transaction   `json:"transactions"`
	V2Transactions []types.V2Transaction `json:"v2transactions"`
}

TxpoolTransactionsResponse is the response type for /txpool/transactions.

type WalletClient

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

A WalletClient provides methods for interacting with a particular wallet on a walletd API server.

func (*WalletClient) AddAddress

func (c *WalletClient) AddAddress(a wallet.Address) (err error)

AddAddress adds the specified address and associated metadata to the wallet.

func (*WalletClient) Addresses

func (c *WalletClient) Addresses() (resp []wallet.Address, err error)

Addresses the addresses controlled by the wallet.

func (*WalletClient) Balance

func (c *WalletClient) Balance() (resp BalanceResponse, err error)

Balance returns the current wallet balance.

func (*WalletClient) Events

func (c *WalletClient) Events(offset, limit int) (resp []wallet.Event, err error)

Events returns all events relevant to the wallet.

func (*WalletClient) Fund

func (c *WalletClient) Fund(txn types.Transaction, amount types.Currency, changeAddr types.Address) (resp WalletFundResponse, err error)

Fund funds a siacoin transaction.

func (*WalletClient) FundSF

func (c *WalletClient) FundSF(txn types.Transaction, amount uint64, changeAddr, claimAddr types.Address) (resp WalletFundResponse, err error)

FundSF funds a siafund transaction.

func (*WalletClient) Release

func (c *WalletClient) Release(sc []types.SiacoinOutputID, sf []types.SiafundOutputID) (err error)

Release releases a set of previously-reserved outputs.

func (*WalletClient) RemoveAddress

func (c *WalletClient) RemoveAddress(addr types.Address) (err error)

RemoveAddress removes the specified address from the wallet.

func (*WalletClient) Reserve

func (c *WalletClient) Reserve(sc []types.SiacoinOutputID, sf []types.SiafundOutputID, duration time.Duration) (err error)

Reserve reserves a set outputs for use in a transaction.

func (*WalletClient) SiacoinOutputs

func (c *WalletClient) SiacoinOutputs(offset, limit int) (sc []types.SiacoinElement, err error)

SiacoinOutputs returns the set of unspent outputs controlled by the wallet.

func (*WalletClient) SiafundOutputs

func (c *WalletClient) SiafundOutputs(offset, limit int) (sf []types.SiafundElement, err error)

SiafundOutputs returns the set of unspent outputs controlled by the wallet.

func (*WalletClient) UnconfirmedEvents

func (c *WalletClient) UnconfirmedEvents() (resp []wallet.Event, err error)

UnconfirmedEvents returns all unconfirmed events relevant to the wallet.

type WalletFundRequest

type WalletFundRequest struct {
	Transaction   types.Transaction `json:"transaction"`
	Amount        types.Currency    `json:"amount"`
	ChangeAddress types.Address     `json:"changeAddress"`
}

WalletFundRequest is the request type for /wallets/:id/fund.

type WalletFundResponse

type WalletFundResponse struct {
	Transaction types.Transaction   `json:"transaction"`
	ToSign      []types.Hash256     `json:"toSign"`
	DependsOn   []types.Transaction `json:"dependsOn"`
}

WalletFundResponse is the response type for /wallets/:id/fund.

type WalletFundSFRequest

type WalletFundSFRequest struct {
	Transaction   types.Transaction `json:"transaction"`
	Amount        uint64            `json:"amount"`
	ChangeAddress types.Address     `json:"changeAddress"`
	ClaimAddress  types.Address     `json:"claimAddress"`
}

WalletFundSFRequest is the request type for /wallets/:id/fundsf.

type WalletManager

type WalletManager interface {
	IndexMode() wallet.IndexMode
	Tip() (types.ChainIndex, error)
	Scan(_ context.Context, index types.ChainIndex) error

	AddWallet(wallet.Wallet) (wallet.Wallet, error)
	UpdateWallet(wallet.Wallet) (wallet.Wallet, error)
	DeleteWallet(wallet.ID) error
	Wallets() ([]wallet.Wallet, error)

	AddAddress(id wallet.ID, addr wallet.Address) error
	RemoveAddress(id wallet.ID, addr types.Address) error
	Addresses(id wallet.ID) ([]wallet.Address, error)
	WalletEvents(id wallet.ID, offset, limit int) ([]wallet.Event, error)
	WalletUnconfirmedEvents(id wallet.ID) ([]wallet.Event, error)
	UnspentSiacoinOutputs(id wallet.ID, offset, limit int) ([]types.SiacoinElement, error)
	UnspentSiafundOutputs(id wallet.ID, offset, limit int) ([]types.SiafundElement, error)
	WalletBalance(id wallet.ID) (wallet.Balance, error)

	AddressBalance(address types.Address) (wallet.Balance, error)
	AddressEvents(address types.Address, offset, limit int) ([]wallet.Event, error)
	AddressUnconfirmedEvents(address types.Address) ([]wallet.Event, error)
	AddressSiacoinOutputs(address types.Address, offset, limit int) ([]types.SiacoinElement, error)
	AddressSiafundOutputs(address types.Address, offset, limit int) ([]types.SiafundElement, error)

	Events(eventIDs []types.Hash256) ([]wallet.Event, error)

	SiacoinElement(types.SiacoinOutputID) (types.SiacoinElement, error)
	SiafundElement(types.SiafundOutputID) (types.SiafundElement, error)

	Reserve(ids []types.Hash256, duration time.Duration) error
}

A WalletManager manages wallets, keyed by name.

type WalletReleaseRequest

type WalletReleaseRequest struct {
	SiacoinOutputs []types.SiacoinOutputID `json:"siacoinOutputs"`
	SiafundOutputs []types.SiafundOutputID `json:"siafundOutputs"`
}

WalletReleaseRequest is the request type for /wallets/:id/release.

type WalletReserveRequest

type WalletReserveRequest struct {
	SiacoinOutputs []types.SiacoinOutputID `json:"siacoinOutputs"`
	SiafundOutputs []types.SiafundOutputID `json:"siafundOutputs"`
	Duration       time.Duration           `json:"duration"`
}

WalletReserveRequest is the request type for /wallets/:id/reserve.

type WalletUpdateRequest

type WalletUpdateRequest struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Metadata    json.RawMessage `json:"metadata"`
}

A WalletUpdateRequest is a request to update a wallet

Jump to

Keyboard shortcuts

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