api

package
v0.1.1-alpha Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 14 Imported by: 0

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 ChainManager

type ChainManager interface {
	TipState() consensus.State

	RecommendedFee() types.Currency
	PoolTransactions() []types.Transaction
	AddPoolTransactions(txns []types.Transaction) 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(name string, info json.RawMessage) (err error)

AddWallet adds a wallet to the set of tracked wallets.

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) RemoveWallet

func (c *Client) RemoveWallet(name string) (err error)

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

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) (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) TxpoolTransactions

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

TxpoolTransactions returns all transactions in the transaction pool.

func (*Client) Wallet

func (c *Client) Wallet(name string) *WalletClient

Wallet returns a client for interacting with the specified wallet.

func (*Client) Wallets

func (c *Client) Wallets() (ws map[string]json.RawMessage, err error)

Wallets returns the set of tracked wallets.

type GatewayPeer

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

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

A GatewayPeer is a currently-connected peer.

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 Syncer

type Syncer interface {
	Addr() string
	Peers() []*gateway.Peer
	PeerInfo(peer string) (syncer.PeerInfo, bool)
	Connect(addr string) (*gateway.Peer, error)
	BroadcastTransactionSet(txns []types.Transaction)
}

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

type WalletBalanceResponse

type WalletBalanceResponse struct {
	Siacoins types.Currency `json:"siacoins"`
	Siafunds uint64         `json:"siafunds"`
}

WalletBalanceResponse is the response type for /wallets/:name/balance.

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(addr types.Address, info json.RawMessage) (err error)

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

func (*WalletClient) Addresses

func (c *WalletClient) Addresses() (resp map[types.Address]json.RawMessage, err error)

Addresses the addresses controlled by the wallet.

func (*WalletClient) Balance

func (c *WalletClient) Balance() (resp WalletBalanceResponse, 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) Outputs

func (c *WalletClient) Outputs() (sc []wallet.SiacoinElement, sf []wallet.SiafundElement, err error)

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

func (*WalletClient) PoolTransactions

func (c *WalletClient) PoolTransactions() (resp []wallet.PoolTransaction, err error)

PoolTransactions returns all txpool transactions relevant to the wallet.

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) Subscribe

func (c *WalletClient) Subscribe(height uint64) (err error)

Subscribe subscribes the wallet to consensus updates, starting at the specified height. This can only be done once.

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/:name/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/:name/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/:name/fundsf.

type WalletManager

type WalletManager interface {
	AddWallet(name string, info json.RawMessage) error
	DeleteWallet(name string) error
	Wallets() map[string]json.RawMessage
	SubscribeWallet(name string, startHeight uint64) error

	AddAddress(name string, addr types.Address, info json.RawMessage) error
	RemoveAddress(name string, addr types.Address) error
	Addresses(name string) (map[types.Address]json.RawMessage, error)
	Events(name string, offset, limit int) ([]wallet.Event, error)
	UnspentOutputs(name string) ([]wallet.SiacoinElement, []wallet.SiafundElement, error)
	Annotate(name string, pool []types.Transaction) ([]wallet.PoolTransaction, error)
}

A WalletManager manages wallets, keyed by name.

type WalletOutputsResponse

type WalletOutputsResponse struct {
	SiacoinOutputs []wallet.SiacoinElement `json:"siacoinOutputs"`
	SiafundOutputs []wallet.SiafundElement `json:"siafundOutputs"`
}

WalletOutputsResponse is the response type for /wallets/:name/outputs.

type WalletReleaseRequest

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

WalletReleaseRequest is the request type for /wallets/:name/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/:name/reserve.

Jump to

Keyboard shortcuts

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