walrus

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2019 License: MIT Imports: 18 Imported by: 3

README

walrus

GoDoc Go Report Card

walrus is a Sia wallet server that can be used as a traditional hot wallet or as part of a cold wallet/watch-only wallet setup. It presents a low-level, performant API that is suitable for both user-facing apps and exchanges. In particular, walrus strives to integrate smoothly with Sia-compatible hardware wallets such as the Ledger Nano S.

If you are an end-user who simply wants to store your siacoins, you probably want walrus-cli, a CLI frontend for walrus.

API docs for the server are available here.

Usage

To start the server in hot wallet mode, first you'll need to generate a seed with walrus seed. (Don't be alarmed: walrus seeds are only 15 words long.) Then start the server with walrus start and enter your seed at the prompt. You can bypass the prompt by storing your seed in the WALRUS_SEED environment variable. You may then use the hot wallet API routes.

To start the server in watch-only mode, run walrus start --watch-only. You may then use the watch-only API routes.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSeedServer

func NewSeedServer(w *wallet.SeedWallet, tp TransactionPool) http.Handler

NewSeedServer returns an HTTP handler that serves the seed wallet API.

func NewWatchSeedServer

func NewWatchSeedServer(w *wallet.WatchOnlyWallet, tp TransactionPool) http.Handler

NewWatchSeedServer returns an HTTP handler that serves the watch-only seed-based wallet API.

Types

type RequestSign

type RequestSign struct {
	Transaction types.Transaction `json:"transaction"`
	ToSign      []int             `json:"toSign"`
}

RequestSign is the request type for the /sign endpoint.

type RequestTransactions

type RequestTransactions struct {
	Max     *int              // optional
	Address *types.UnlockHash // optional
}

RequestTransactions is the request type for the /transactions endpoint.

type ResponseConsensus

type ResponseConsensus struct {
	Height types.BlockHeight `json:"height"`
	CCID   crypto.Hash       `json:"ccid"`
}

ResponseConsensus is the response type for the /consensus endpoint.

type ResponseTransactionsID

type ResponseTransactionsID struct {
	Transaction types.Transaction `json:"transaction"`
	Inflow      types.Currency    `json:"inflow"`
	Outflow     types.Currency    `json:"outflow"`
	FeePerByte  types.Currency    `json:"feePerByte"`
}

ResponseTransactionsID is the response type for the /transactions/:id endpoint.

func (ResponseTransactionsID) MarshalJSON

func (r ResponseTransactionsID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

type SeedClient

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

A SeedClient is a client for a SeedServer.

func NewSeedClient

func NewSeedClient(addr string) *SeedClient

NewSeedClient returns a SeedClient communicating with a SeedServer listening on the specified address.

func (*SeedClient) AddToLimbo added in v0.4.0

func (c *SeedClient) AddToLimbo(txn types.Transaction) (err error)

AddToLimbo places a transaction in Limbo. The output will no longer be returned by Outputs or contribute to the wallet's balance.

Manually adding transactions to Limbo is typically unnecessary. Calling Broadcast will move all transactions in the set to Limbo automatically.

func (*SeedClient) AddressInfo

func (c *SeedClient) AddressInfo(addr types.UnlockHash) (info wallet.SeedAddressInfo, err error)

AddressInfo returns information about a specific address, including its unlock conditions and the index it was derived from.

func (*SeedClient) Addresses

func (c *SeedClient) Addresses() (addrs []types.UnlockHash, err error)

Addresses returns all addresses known to the wallet.

func (*SeedClient) Balance

func (c *SeedClient) Balance(limbo bool) (bal types.Currency, err error)

Balance returns the current wallet balance. If the limbo flag is true, the balance will reflect any transactions currently in Limbo.

func (*SeedClient) BlockRewards added in v0.3.0

func (c *SeedClient) BlockRewards(max int) (rewards []wallet.BlockReward, err error)

BlockRewards returns the block rewards tracked by the wallet. If max < 0, all rewards are returned; otherwise, at most max rewards are returned. The rewards are ordered newest-to-oldest.

func (*SeedClient) Broadcast

func (c *SeedClient) Broadcast(txnSet []types.Transaction) error

Broadcast broadcasts the supplied transaction set to all connected peers.

func (*SeedClient) ConsensusInfo

func (c *SeedClient) ConsensusInfo() (info ResponseConsensus, err error)

ConsensusInfo returns the current blockchain height and consensus change ID. The latter is a unique ID that changes whenever blocks are added to the blockchain.

func (*SeedClient) FileContractHistory added in v0.3.0

func (c *SeedClient) FileContractHistory(id types.FileContractID) (history []wallet.FileContract, err error)

FileContractHistory returns the revision history of the specified file contract, which must be a contract tracked by the wallet.

func (*SeedClient) FileContracts added in v0.3.0

func (c *SeedClient) FileContracts(max int) (contracts []wallet.FileContract, err error)

FileContracts returns the file contracts tracked by the wallet. If max < 0, all contracts are returned; otherwise, at most max contracts are returned. The contracts are ordered newest-to-oldest.

func (*SeedClient) LimboTransactions added in v0.4.0

func (c *SeedClient) LimboTransactions() (txns []wallet.LimboTransaction, err error)

LimboTransactions returns transactions that are in Limbo.

func (*SeedClient) Memo

func (c *SeedClient) Memo(txid types.TransactionID) (memo []byte, err error)

Memo retrieves the memo for a transaction.

func (*SeedClient) NextAddress

func (c *SeedClient) NextAddress() (addr types.UnlockHash, err error)

NextAddress generates a new address from the wallet's seed.

func (*SeedClient) RecommendedFee

func (c *SeedClient) RecommendedFee() (fee types.Currency, err error)

RecommendedFee returns the current recommended transaction fee in hastings per byte of the Sia-encoded transaction.

func (*SeedClient) RemoveFromLimbo

func (c *SeedClient) RemoveFromLimbo(txid types.TransactionID) (err error)

RemoveFromLimbo removes a transaction from Limbo.

Manually removing transactions from Limbo is typically unnecessary. When a transaction appears in a valid block, it will be removed from Limbo automatically.

func (*SeedClient) SeedIndex

func (c *SeedClient) SeedIndex() (index uint64, err error)

SeedIndex returns the wallet's current seed index. This index will be used to derive the next address.

func (*SeedClient) SetMemo

func (c *SeedClient) SetMemo(txid types.TransactionID, memo []byte) (err error)

SetMemo adds a memo for a transaction, overwriting the previous memo if it exists.

Memos are not stored on the blockchain. They exist only in the local wallet.

func (*SeedClient) SignTransaction

func (c *SeedClient) SignTransaction(txn *types.Transaction, toSign []int) (err error)

SignTransaction signs the specified transaction using keys owned by the wallet. If toSign is nil, SignTransaction will automatically add TransactionSignatures for each input owned by the SeedManager. If toSign is not nil, it a list of indices of TransactionSignatures already present in txn; SignTransaction will fill in the Signature field of each.

func (*SeedClient) Transaction

func (c *SeedClient) Transaction(txid types.TransactionID) (txn ResponseTransactionsID, err error)

Transaction returns the transaction with the specified ID, as well as inflow, outflow, and fee information. The transaction must be relevant to the wallet.

func (*SeedClient) Transactions

func (c *SeedClient) Transactions(max int) (txids []types.TransactionID, err error)

Transactions lists the IDs of transactions relevant to the wallet. If max < 0, all such IDs are returned; otherwise, at most max IDs are returned. The IDs are ordered newest-to-oldest.

func (*SeedClient) TransactionsByAddress

func (c *SeedClient) TransactionsByAddress(addr types.UnlockHash, max int) (txids []types.TransactionID, err error)

Transactions lists the IDs of transactions relevant to the specified address, which must be owned by the wallet. If max < 0, all such IDs are returned; otherwise, at most max IDs are returned. The IDs are ordered newest-to-oldest.

func (*SeedClient) UnconfirmedParents added in v0.4.0

func (c *SeedClient) UnconfirmedParents(txn types.Transaction) (parents []wallet.LimboTransaction, err error)

UnconfirmedParents returns any parents of txn that are in Limbo. These transactions will need to be included in the transaction set passed to Broadcast.

func (*SeedClient) UnspentOutputs

func (c *SeedClient) UnspentOutputs(limbo bool) (utxos []UTXO, err error)

UnspentOutputs returns the outputs that the wallet can spend. If the limbo flag is true, the outputs will reflect any transactions currently in Limbo.

type TransactionPool added in v0.4.0

type TransactionPool interface {
	AcceptTransactionSet([]types.Transaction) error
	FeeEstimation() (min types.Currency, max types.Currency)
}

A TransactionPool can broadcast transactions and estimate transaction fees.

type UTXO

type UTXO struct {
	ID               types.SiacoinOutputID  `json:"ID"`
	Value            types.Currency         `json:"value"`
	UnlockConditions types.UnlockConditions `json:"unlockConditions"`
	UnlockHash       types.UnlockHash       `json:"unlockHash"`
	KeyIndex         uint64                 `json:"keyIndex"`
}

A UTXO is an unspent transaction output owned by a seed-derived address.

func (UTXO) MarshalJSON added in v0.3.0

func (u UTXO) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

type WatchSeedClient

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

WatchSeedClient is a client for a WatchSeedServer.

func NewWatchSeedClient

func NewWatchSeedClient(addr string) *WatchSeedClient

NewWatchSeedClient returns a WatchSeedClient communicating with a WatchSeedServer listening on the specified address.

func (*WatchSeedClient) AddToLimbo added in v0.4.0

func (c *WatchSeedClient) AddToLimbo(txn types.Transaction) (err error)

AddToLimbo places a transaction in Limbo. The output will no longer be returned by Outputs or contribute to the wallet's balance.

Manually adding transactions to Limbo is typically unnecessary. Calling Broadcast will move all transactions in the set to Limbo automatically.

func (*WatchSeedClient) AddressInfo

func (c *WatchSeedClient) AddressInfo(addr types.UnlockHash) (info wallet.SeedAddressInfo, err error)

AddressInfo returns information about a specific address, including its unlock conditions and the index it was derived from.

func (*WatchSeedClient) Addresses

func (c *WatchSeedClient) Addresses() (addrs []types.UnlockHash, err error)

Addresses returns all addresses known to the wallet.

func (*WatchSeedClient) Balance

func (c *WatchSeedClient) Balance(limbo bool) (bal types.Currency, err error)

Balance returns the current wallet balance. If the limbo flag is true, the balance will reflect any transactions currently in Limbo.

func (*WatchSeedClient) BlockRewards added in v0.3.0

func (c *WatchSeedClient) BlockRewards(max int) (rewards []wallet.BlockReward, err error)

BlockRewards returns the block rewards tracked by the wallet. If max < 0, all rewards are returned; otherwise, at most max rewards are returned. The rewards are ordered newest-to-oldest.

func (*WatchSeedClient) Broadcast

func (c *WatchSeedClient) Broadcast(txnSet []types.Transaction) error

Broadcast broadcasts the supplied transaction set to all connected peers.

func (*WatchSeedClient) ConsensusInfo

func (c *WatchSeedClient) ConsensusInfo() (info ResponseConsensus, err error)

ConsensusInfo returns the current blockchain height and consensus change ID. The latter is a unique ID that changes whenever blocks are added to the blockchain.

func (*WatchSeedClient) FileContractHistory added in v0.3.0

func (c *WatchSeedClient) FileContractHistory(id types.FileContractID) (history []wallet.FileContract, err error)

FileContractHistory returns the revision history of the specified file contract, which must be a contract tracked by the wallet.

func (*WatchSeedClient) FileContracts added in v0.3.0

func (c *WatchSeedClient) FileContracts(max int) (contracts []wallet.FileContract, err error)

FileContracts returns the file contracts tracked by the wallet. If max < 0, all contracts are returned; otherwise, at most max contracts are returned. The contracts are ordered newest-to-oldest.

func (*WatchSeedClient) LimboTransactions added in v0.4.0

func (c *WatchSeedClient) LimboTransactions() (txns []wallet.LimboTransaction, err error)

LimboTransactions returns transactions that are in Limbo.

func (*WatchSeedClient) Memo

func (c *WatchSeedClient) Memo(txid types.TransactionID) (memo []byte, err error)

Memo retrieves the memo for a transaction.

func (*WatchSeedClient) RecommendedFee

func (c *WatchSeedClient) RecommendedFee() (fee types.Currency, err error)

RecommendedFee returns the current recommended transaction fee in hastings per byte of the Sia-encoded transaction.

func (*WatchSeedClient) RemoveFromLimbo

func (c *WatchSeedClient) RemoveFromLimbo(txid types.TransactionID) (err error)

RemoveFromLimbo removes a transaction from Limbo.

Manually removing transactions from Limbo is typically unnecessary. When a transaction appears in a valid block, it will be removed from Limbo automatically.

func (*WatchSeedClient) SetMemo

func (c *WatchSeedClient) SetMemo(txid types.TransactionID, memo []byte) (err error)

SetMemo adds a memo for a transaction, overwriting the previous memo if it exists.

Memos are not stored on the blockchain. They exist only in the local wallet.

func (*WatchSeedClient) Transaction

func (c *WatchSeedClient) Transaction(txid types.TransactionID) (txn ResponseTransactionsID, err error)

Transaction returns the transaction with the specified ID, as well as inflow, outflow, and fee information. The transaction must be relevant to the wallet.

func (*WatchSeedClient) Transactions

func (c *WatchSeedClient) Transactions(max int) (txids []types.TransactionID, err error)

Transactions lists the IDs of transactions relevant to the wallet. If max < 0, all such IDs are returned; otherwise, at most max IDs are returned. The IDs are ordered newest-to-oldest.

func (*WatchSeedClient) TransactionsByAddress

func (c *WatchSeedClient) TransactionsByAddress(addr types.UnlockHash, max int) (txids []types.TransactionID, err error)

Transactions lists the IDs of transactions relevant to the specified address, which must be owned by the wallet. If max < 0, all such IDs are returned; otherwise, at most max IDs are returned. The IDs are ordered newest-to-oldest.

func (*WatchSeedClient) UnconfirmedParents added in v0.4.0

func (c *WatchSeedClient) UnconfirmedParents(txn types.Transaction) (parents []wallet.LimboTransaction, err error)

UnconfirmedParents returns any parents of txn that are in Limbo. These transactions will need to be included in the transaction set passed to Broadcast.

func (*WatchSeedClient) UnspentOutputs

func (c *WatchSeedClient) UnspentOutputs(limbo bool) (utxos []UTXO, err error)

UnspentOutputs returns the outputs that the wallet can spend. If the limbo flag is true, the outputs will reflect any transactions currently in Limbo.

func (*WatchSeedClient) UnwatchAddress

func (c *WatchSeedClient) UnwatchAddress(addr types.UnlockHash) error

UnwatchAddress removes an address from the wallet. Future transactions and outputs relevant to this address will not be considered relevant to the wallet.

Removing an address does NOT remove transactions and outputs relevant to that address that are already recorded in the wallet.

func (*WatchSeedClient) WatchAddress

func (c *WatchSeedClient) WatchAddress(info wallet.SeedAddressInfo) error

WatchAddress adds a set of address metadata to the wallet. Future transactions and outputs relevant to this address will be considered relevant to the wallet.

Importing an address does NOT import transactions and outputs relevant to that address that are already in the blockchain.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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