Documentation ¶
Index ¶
- Constants
- Variables
- type Wallet
- func (w *Wallet) AddArbitraryData(id string, arb string) (t consensus.Transaction, adIndex uint64, err error)
- func (w *Wallet) AddFileContract(id string, fc consensus.FileContract) (t consensus.Transaction, fcIndex uint64, err error)
- func (w *Wallet) AddMinerFee(id string, fee consensus.Currency) (t consensus.Transaction, feeIndex uint64, err error)
- func (w *Wallet) AddOutput(id string, output consensus.SiacoinOutput) (t consensus.Transaction, outputIndex uint64, err error)
- func (w *Wallet) AddSiacoinInput(id string, input consensus.SiacoinInput) (t consensus.Transaction, inputIndex uint64, err error)
- func (w *Wallet) AddSignature(id string, sig consensus.TransactionSignature) (t consensus.Transaction, sigIndex uint64, err error)
- func (w *Wallet) AddStorageProof(id string, sp consensus.StorageProof) (t consensus.Transaction, spIndex uint64, err error)
- func (w *Wallet) Balance(full bool) (total consensus.Currency)
- func (w *Wallet) CoinAddress() (coinAddress consensus.UnlockHash, unlockConditions consensus.UnlockConditions, ...)
- func (w *Wallet) FundTransaction(id string, amount consensus.Currency) (t consensus.Transaction, err error)
- func (w *Wallet) Info() modules.WalletInfo
- func (w *Wallet) RegisterTransaction(t consensus.Transaction) (id string, err error)
- func (w *Wallet) SignTransaction(id string, wholeTransaction bool) (txn consensus.Transaction, err error)
- func (w *Wallet) SpendCoins(amount consensus.Currency, dest consensus.UnlockHash) (t consensus.Transaction, err error)
- func (w *Wallet) TimelockedCoinAddress(unlockHeight consensus.BlockHeight) (coinAddress consensus.UnlockHash, unlockConditions consensus.UnlockConditions, ...)
Constants ¶
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 ¶
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 consensus.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 consensus.FileContract) (t consensus.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 consensus.Currency) (t consensus.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 consensus.SiacoinOutput) (t consensus.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 consensus.SiacoinInput) (t consensus.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 consensus.TransactionSignature) (t consensus.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 consensus.StorageProof) (t consensus.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 ¶
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) CoinAddress ¶
func (w *Wallet) CoinAddress() (coinAddress consensus.UnlockHash, unlockConditions consensus.UnlockConditions, err error)
CoinAddress implements the core.Wallet interface.
func (*Wallet) FundTransaction ¶
func (w *Wallet) FundTransaction(id string, amount consensus.Currency) (t consensus.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) RegisterTransaction ¶
func (w *Wallet) RegisterTransaction(t consensus.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 consensus.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 consensus.Currency, dest consensus.UnlockHash) (t consensus.Transaction, err error)
SpendCoins creates a transaction sending 'amount' to 'dest'. The transaction is submitted to the miner pool, but is also returned.
TODO: Since the style of FundTransaction has changed to work with untrusted parties, SpendCoins has actually become inefficient, creating 2 transactions and extra outputs where something slimmer would do the same job just as well.
func (*Wallet) TimelockedCoinAddress ¶
func (w *Wallet) TimelockedCoinAddress(unlockHeight consensus.BlockHeight) (coinAddress consensus.UnlockHash, unlockConditions consensus.UnlockConditions, err error)
TimelockedCoinAddress returns an address that can only be spent after block `unlockHeight`.