wallet

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2015 License: MIT Imports: 12 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// AgeDelay indicates how long the wallet will wait before allowing the
	// user to double-spend a transaction under standard circumstances. The
	// rationale is that most transactions are meant to be submitted to the
	// blockchain immediately, and ones that take more than AgeDelay blocks
	// have probably failed in some way.
	AgeDelay = 80
)

Variables

View Source
var (
	ErrInvalidID = errors.New("no transaction of given id found")
)

Functions

This section is empty.

Types

type Wallet

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

A Wallet uses the state and transaction pool to track the unconfirmed balance of a user. All of the keys are stored in 'saveDir'/wallet.dat.

One feature of the wallet is preventing accidental double spends. The wallet will block an output from being spent if it has been spent in the last 'AgeDelay' blocks. This is managed by tracking a global age for the wallet and then an age for each output, set to the age of the wallet that the output was most recently spent. If the wallet is 'AgeDelay' blocks older than an output, then the output can be spent again.

A second feature of the wallet is the transaction builder, which is a series of functions that can be used to build independent transactions for use with untrusted parties. The transactions can be cobbled together piece by piece and then signed. When using the transaction builder, the wallet will always have exact outputs (by creating another transaction first if needed) and thus the transaction does not need to be spent for the transaction builder to be able to use any refunds.

func New

func New(state *consensus.State, tpool modules.TransactionPool, saveDir string) (w *Wallet, err error)

New creates a new wallet, loading any known addresses from the input file name and then using the file to save in the future.

func (*Wallet) AddArbitraryData

func (w *Wallet) AddArbitraryData(id string, arb string) (t types.Transaction, adIndex uint64, err error)

AddArbitraryData adds arbitrary data to the transaction, returning a copy of the transaction and the index of the new data within the transaction.

func (*Wallet) AddFileContract

func (w *Wallet) AddFileContract(id string, fc types.FileContract) (t types.Transaction, fcIndex uint64, err error)

AddFileContract adds a file contract to the transaction, returning a copy of the transaction and the index of the new file contract within the transaction.

func (*Wallet) AddMinerFee

func (w *Wallet) AddMinerFee(id string, fee types.Currency) (t types.Transaction, feeIndex uint64, err error)

AddMinerFee will add a miner fee to the transaction, but will not add any inputs. The transaction and the index of the new miner fee within the transaction are returned.

func (*Wallet) AddOutput

func (w *Wallet) AddOutput(id string, output types.SiacoinOutput) (t types.Transaction, outputIndex uint64, err error)

AddOutput adds an output to the transaction, but will not add any inputs. AddOutput returns the transaction and the index of the new output within the transaction.

func (*Wallet) AddSiacoinInput

func (w *Wallet) AddSiacoinInput(id string, input types.SiacoinInput) (t types.Transaction, inputIndex uint64, err error)

AddSiacoinInput will add a siacoin input to the transaction, returning the index of the input within the transaction and the transaction itself. When 'SignTransaction' is called, this input will not be signed.

func (*Wallet) AddSignature

func (w *Wallet) AddSignature(id string, sig types.TransactionSignature) (t types.Transaction, sigIndex uint64, err error)

AddSignature adds a signature to the transaction, presumably signing one of the inputs that 'SignTransaction' will not sign automatically. This can be useful for dealing with multiparty signatures, or for staged negotiations which involve sending the transaction first and the signature later.

func (*Wallet) AddStorageProof

func (w *Wallet) AddStorageProof(id string, sp types.StorageProof) (t types.Transaction, spIndex uint64, err error)

AddStorageProof adds a storage proof to the transaction, returning a copy of the transaction and the index of the new storage proof within the transaction.

func (*Wallet) Balance

func (w *Wallet) Balance(full bool) (total types.Currency)

Balance returns the number of coins available to the wallet. If `full` is set to false, only coins that can be spent immediately are counted. Otherwise, all coins that could be spent are counted (including those that have already been spent but the transactions haven't been added to the transaction pool or blockchain)

func (*Wallet) Close added in v0.3.1

func (w *Wallet) Close() error

func (*Wallet) CoinAddress

func (w *Wallet) CoinAddress() (coinAddress types.UnlockHash, unlockConditions types.UnlockConditions, err error)

CoinAddress implements the core.Wallet interface.

func (*Wallet) FundTransaction

func (w *Wallet) FundTransaction(id string, amount types.Currency) (t types.Transaction, err error)

FundTransaction adds siacoins to a transaction that the wallet knows how to spend. The exact amount of coins are always added, and this is achieved by creating two transactions. The first transaciton, the parent, spends a set of outputs that add up to at least the desired amount, and then creates a single output of the exact amount and a second refund output.

func (*Wallet) Info

func (w *Wallet) Info() modules.WalletInfo

Info fills out and returns a WalletInfo struct.

func (*Wallet) ReceiveTransactionPoolUpdate added in v0.3.1

func (w *Wallet) ReceiveTransactionPoolUpdate(revertedBlocks, appliedBlocks []types.Block, _ []types.Transaction, unconfirmedSiacoinDiffs []modules.SiacoinOutputDiff)

ReceiveTransactionPoolUpdate gets all of the changes in the confirmed and unconfirmed set and uses them to update the balance and transaction history of the wallet.

func (*Wallet) RegisterTransaction

func (w *Wallet) RegisterTransaction(t types.Transaction) (id string, err error)

RegisterTransaction starts with a transaction as input and adds that transaction to the list of open transactions, returning an id. That id can then be used to modify and sign the transaction. An empty transaction is legal input.

func (*Wallet) SignTransaction

func (w *Wallet) SignTransaction(id string, wholeTransaction bool) (txn types.Transaction, err error)

SignTransaction signs the transaction, then deletes the transaction from the wallet's internal memory, then returns the transaction.

func (*Wallet) SpendCoins

func (w *Wallet) SpendCoins(amount types.Currency, dest types.UnlockHash) (t types.Transaction, err error)

SpendCoins creates a transaction sending 'amount' to 'dest'. The transaction is submitted to the transaction pool and is also returned.

func (*Wallet) TimelockedCoinAddress

func (w *Wallet) TimelockedCoinAddress(unlockHeight types.BlockHeight) (coinAddress types.UnlockHash, unlockConditions types.UnlockConditions, err error)

TimelockedCoinAddress returns an address that can only be spent after block `unlockHeight`.

func (*Wallet) WalletNotify added in v0.3.1

func (w *Wallet) WalletNotify() <-chan struct{}

WalletNotify adds a subscriber to the wallet.

Jump to

Keyboard shortcuts

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