Documentation ¶
Index ¶
- Constants
- Variables
- func ComputeValuedTransactions(pts []modules.ProcessedTransaction, blockHeight uint64) ([]modules.ValuedTransaction, error)
- func SignTransaction(txn *types.Transaction, seed modules.Seed, toSign []types.Hash256, ...) error
- type Wallet
- func (w *Wallet) AddUnlockConditions(uc types.UnlockConditions) error
- func (w *Wallet) AddWatchAddresses(addrs []types.Address, unused bool) error
- func (w *Wallet) AddressTransactions(uh types.Address) (pts []modules.ProcessedTransaction, err error)
- func (w *Wallet) AddressUnconfirmedTransactions(uh types.Address) (pts []modules.ProcessedTransaction, err error)
- func (w *Wallet) Alerts() (crit, err, warn, info []modules.Alert)
- func (w *Wallet) AllAddresses() ([]types.Address, error)
- func (w *Wallet) AllSeeds() ([]modules.Seed, error)
- func (w *Wallet) ChangeKey(masterKey modules.WalletKey, newKey modules.WalletKey) error
- func (w *Wallet) ChangeKeyWithSeed(seed modules.Seed, newKey modules.WalletKey) error
- func (w *Wallet) Close() error
- func (w *Wallet) ConfirmedBalance() (siacoinBalance types.Currency, siafundBalance uint64, ...)
- func (w *Wallet) DropTransactions(txnSet []types.Transaction)
- func (w *Wallet) DustThreshold() (types.Currency, error)
- func (w *Wallet) Encrypt(masterKey modules.WalletKey) (modules.Seed, error)
- func (w *Wallet) Encrypted() (bool, error)
- func (w *Wallet) FundTransaction(txn *types.Transaction, amount types.Currency) (parentTxn types.Transaction, toSign []types.Hash256, err error)
- func (w *Wallet) Height() (uint64, error)
- func (w *Wallet) InitFromSeed(masterKey modules.WalletKey, seed modules.Seed) error
- func (w *Wallet) IsMasterKey(masterKey modules.WalletKey) (bool, error)
- func (w *Wallet) LastAddresses(n uint64) ([]types.Address, error)
- func (w *Wallet) LoadSeed(masterKey modules.WalletKey, seed modules.Seed) error
- func (w *Wallet) Lock() error
- func (w *Wallet) MarkAddressUnused(addrs ...types.UnlockConditions) error
- func (w *Wallet) MarkWalletInputs(txn types.Transaction) (toSign []types.Hash256)
- func (w *Wallet) NextAddress() (types.UnlockConditions, error)
- func (w *Wallet) NextAddresses(n uint64) ([]types.UnlockConditions, error)
- func (w *Wallet) PrimarySeed() (modules.Seed, uint64, error)
- func (w *Wallet) ProcessConsensusChange(cc modules.ConsensusChange)
- func (w *Wallet) ReceiveUpdatedUnconfirmedTransactions(diff *modules.TransactionPoolDiff)
- func (w *Wallet) ReleaseInputs(txnSet []types.Transaction)
- func (w *Wallet) RemoveWatchAddresses(addrs []types.Address, unused bool) error
- func (w *Wallet) Rescanning() (bool, error)
- func (w *Wallet) Reset() error
- func (w *Wallet) SendSiacoins(amount types.Currency, dest types.Address) ([]types.Transaction, error)
- func (w *Wallet) SendSiacoinsFeeIncluded(amount types.Currency, dest types.Address) ([]types.Transaction, error)
- func (w *Wallet) SendSiacoinsMulti(outputs []types.SiacoinOutput) (txns []types.Transaction, err error)
- func (w *Wallet) SetSettings(s modules.WalletSettings) error
- func (w *Wallet) Settings() (modules.WalletSettings, error)
- func (w *Wallet) Sign(txn *types.Transaction, toSign []types.Hash256, cf types.CoveredFields) error
- func (w *Wallet) SignTransaction(txn *types.Transaction, toSign []types.Hash256, cf types.CoveredFields) error
- func (w *Wallet) SweepSeed(seed modules.Seed) (coins types.Currency, funds uint64, err error)
- func (w *Wallet) SweepTransaction(txn types.Transaction, output types.SiacoinOutput) (types.Transaction, []types.Transaction)
- func (w *Wallet) Transaction(txid types.TransactionID) (pt modules.ProcessedTransaction, found bool, err error)
- func (w *Wallet) Transactions(startHeight, endHeight uint64) (pts []modules.ProcessedTransaction, err error)
- func (w *Wallet) UnconfirmedBalance() (outgoingSiacoins types.Currency, incomingSiacoins types.Currency, err error)
- func (w *Wallet) UnconfirmedTransactions() ([]modules.ProcessedTransaction, error)
- func (w *Wallet) Unlock(masterKey modules.WalletKey) error
- func (w *Wallet) UnlockAsync(masterKey modules.WalletKey) <-chan error
- func (w *Wallet) UnlockConditions(addr types.Address) (uc types.UnlockConditions, err error)
- func (w *Wallet) Unlocked() (bool, error)
- func (w *Wallet) UnspentOutputs() ([]modules.UnspentOutput, error)
- func (w *Wallet) WatchAddresses() ([]types.Address, error)
Constants ¶
const ( // RespendTimeout records the number of blocks that the wallet will wait // before spending an output that has been spent in the past. If the // transaction spending the output has not made it to the transaction pool // after the limit, the assumption is that it never will. RespendTimeout = 100 )
Variables ¶
var ( // ErrInconsistentKeys is the error when keys provided are for different addresses. ErrInconsistentKeys = errors.New("keyfiles provided that are for different addresses") // ErrInsufficientKeys is the error when there's not enough keys provided to spend // the Siafunds. ErrInsufficientKeys = errors.New("not enough keys provided to spend the siafunds") )
Functions ¶
func ComputeValuedTransactions ¶
func ComputeValuedTransactions(pts []modules.ProcessedTransaction, blockHeight uint64) ([]modules.ValuedTransaction, error)
ComputeValuedTransactions creates ValuedTransaction from a set of ProcessedTransactions.
func SignTransaction ¶
func SignTransaction(txn *types.Transaction, seed modules.Seed, toSign []types.Hash256, height uint64) error
SignTransaction signs txn using secret keys derived from seed. The transaction should be complete with the exception of the Signature fields of each TransactionSignature referenced by toSign, which must not be empty.
SignTransaction must derive all of the keys from scratch, so it is appreciably slower than calling the Wallet.SignTransaction method. Only the first 1 million keys are derived.
Types ¶
type Wallet ¶
type Wallet struct {
// contains filtered or unexported fields
}
Wallet is an object that tracks balances, creates keys and addresses, manages building and sending transactions.
func New ¶
func New(db *sql.DB, cs modules.ConsensusSet, tpool modules.TransactionPool, dir string) (*Wallet, error)
New creates a new wallet. Keys and addresses are not loaded into the wallet during the call to 'New', but rather during the call to 'Unlock'.
func (*Wallet) AddUnlockConditions ¶
func (w *Wallet) AddUnlockConditions(uc types.UnlockConditions) error
AddUnlockConditions adds a set of UnlockConditions to the wallet database.
func (*Wallet) AddWatchAddresses ¶
AddWatchAddresses instructs the wallet to begin tracking a set of addresses, in addition to the addresses it was previously tracking. If none of the addresses have appeared in the blockchain, the unused flag may be set to true. Otherwise, the wallet must rescan the blockchain to search for transactions containing the addresses.
func (*Wallet) AddressTransactions ¶
func (w *Wallet) AddressTransactions(uh types.Address) (pts []modules.ProcessedTransaction, err error)
AddressTransactions returns all of the wallet transactions associated with a single unlock hash.
func (*Wallet) AddressUnconfirmedTransactions ¶
func (w *Wallet) AddressUnconfirmedTransactions(uh types.Address) (pts []modules.ProcessedTransaction, err error)
AddressUnconfirmedTransactions returns all of the unconfirmed wallet transactions related to a specific address.
func (*Wallet) AllAddresses ¶
AllAddresses returns all addresses that the wallet is able to spend from, including unseeded addresses. Addresses are returned sorted in byte-order.
func (*Wallet) ChangeKeyWithSeed ¶
ChangeKeyWithSeed is the same as ChangeKey but uses the primary seed instead of the current masterKey.
func (*Wallet) Close ¶
Close terminates all ongoing processes involving the wallet, enabling garbage collection.
func (*Wallet) ConfirmedBalance ¶
func (w *Wallet) ConfirmedBalance() (siacoinBalance types.Currency, siafundBalance uint64, siafundClaimBalance types.Currency, err error)
ConfirmedBalance returns the balance of the wallet according to all of the confirmed transactions.
func (*Wallet) DropTransactions ¶
func (w *Wallet) DropTransactions(txnSet []types.Transaction)
DropTransactions is a helper function that releases the inputs of a transaction set. It should only be called on transactions that are invalid or will never be broadcast.
func (*Wallet) DustThreshold ¶
DustThreshold returns the quantity per byte below which a Currency is considered to be Dust.
func (*Wallet) Encrypt ¶
Encrypt will create a primary seed for the wallet and encrypt it using masterKey. If masterKey is blank, then the hash of the primary seed will be used instead. The wallet will still be locked after Encrypt is called.
Encrypt can only be called once throughout the life of the wallet, and will return an error on subsequent calls (even after restarting the wallet). To reset the wallet, the wallet must be deleted.
func (*Wallet) FundTransaction ¶
func (w *Wallet) FundTransaction(txn *types.Transaction, amount types.Currency) (parentTxn types.Transaction, toSign []types.Hash256, err error)
FundTransaction adds Siacoin inputs worth at least the requested amount to the provided transaction. A change output is also added, if necessary. The inputs will not be available to future calls to FundTransaction unless ReleaseInputs is called.
func (*Wallet) InitFromSeed ¶
InitFromSeed functions like Init, but using a specified seed. Unlike Init, the blockchain will be scanned to determine the seed's progress. For this reason, InitFromSeed should not be called until the blockchain is fully synced.
func (*Wallet) IsMasterKey ¶
IsMasterKey verifies that the masterKey is the key used to encrypt the wallet.
func (*Wallet) LastAddresses ¶
LastAddresses returns the last n addresses starting at the last seedProgress for which an address was generated. If n is greater than the current progress, fewer than n keys will be returned. That means all addresses can be retrieved in reverse order by simply supplying math.MaxUint64 for n.
func (*Wallet) LoadSeed ¶
LoadSeed will track all of the addresses generated by the input seed, reclaiming any funds that were lost due to a deleted seed or lost encryption key. An error will be returned if the seed has already been integrated with the wallet.
func (*Wallet) Lock ¶
Lock will erase all keys from memory and prevent the wallet from spending coins until it is unlocked.
func (*Wallet) MarkAddressUnused ¶
func (w *Wallet) MarkAddressUnused(addrs ...types.UnlockConditions) error
MarkAddressUnused marks the provided address as unused which causes it to be handed out by a subsequent call to `NextAddresses` again.
func (*Wallet) MarkWalletInputs ¶
func (w *Wallet) MarkWalletInputs(txn types.Transaction) (toSign []types.Hash256)
MarkWalletInputs scans a transaction and infers which inputs belong to this wallet. This allows those inputs to be signed.
func (*Wallet) NextAddress ¶
func (w *Wallet) NextAddress() (types.UnlockConditions, error)
NextAddress returns an unlock hash that is ready to receive Siacoins or Siafunds. The address is generated using the primary address seed.
func (*Wallet) NextAddresses ¶
func (w *Wallet) NextAddresses(n uint64) ([]types.UnlockConditions, error)
NextAddresses returns n unlock hashes that are ready to receive Siacoins or Siafunds. The addresses are generated using the primary address seed.
Warning: If this function is used to generate large numbers of addresses, those addresses should be used. Otherwise the lookahead might not be able to keep up and multiple wallets with the same seed might desync.
func (*Wallet) PrimarySeed ¶
PrimarySeed returns the decrypted primary seed of the wallet, as well as the number of addresses that the seed can be safely used to generate.
func (*Wallet) ProcessConsensusChange ¶
func (w *Wallet) ProcessConsensusChange(cc modules.ConsensusChange)
ProcessConsensusChange parses a consensus change to update the set of confirmed outputs known to the wallet.
func (*Wallet) ReceiveUpdatedUnconfirmedTransactions ¶
func (w *Wallet) ReceiveUpdatedUnconfirmedTransactions(diff *modules.TransactionPoolDiff)
ReceiveUpdatedUnconfirmedTransactions updates the wallet's unconfirmed transaction set.
func (*Wallet) ReleaseInputs ¶
func (w *Wallet) ReleaseInputs(txnSet []types.Transaction)
ReleaseInputs is a helper function that releases the inputs of txn for use in other transactions. It should only be called on transactions that are invalid or will never be broadcast.
func (*Wallet) RemoveWatchAddresses ¶
RemoveWatchAddresses instructs the wallet to stop tracking a set of addresses and delete their associated transactions. If none of the addresses have appeared in the blockchain, the unused flag may be set to true. Otherwise, the wallet must rescan the blockchain to rebuild its transaction history.
func (*Wallet) Rescanning ¶
Rescanning reports whether the wallet is currently rescanning the blockchain.
func (*Wallet) Reset ¶
Reset will reset the wallet, clearing the database and returning it to the unencrypted state.
func (*Wallet) SendSiacoins ¶
func (w *Wallet) SendSiacoins(amount types.Currency, dest types.Address) ([]types.Transaction, error)
SendSiacoins creates a transaction sending 'amount' to 'dest'. The transaction is submitted to the transaction pool and is also returned. Fees are added to the amount sent.
func (*Wallet) SendSiacoinsFeeIncluded ¶
func (w *Wallet) SendSiacoinsFeeIncluded(amount types.Currency, dest types.Address) ([]types.Transaction, error)
SendSiacoinsFeeIncluded creates a transaction sending 'amount' to 'dest'. The transaction is submitted to the transaction pool and is also returned. Fees are subtracted from the amount sent.
func (*Wallet) SendSiacoinsMulti ¶
func (w *Wallet) SendSiacoinsMulti(outputs []types.SiacoinOutput) (txns []types.Transaction, err error)
SendSiacoinsMulti creates a transaction that includes the specified outputs. The transaction is submitted to the transaction pool and is also returned.
func (*Wallet) SetSettings ¶
func (w *Wallet) SetSettings(s modules.WalletSettings) error
SetSettings will update the settings for the wallet.
func (*Wallet) Settings ¶
func (w *Wallet) Settings() (modules.WalletSettings, error)
Settings returns the wallet's current settings.
func (*Wallet) Sign ¶
func (w *Wallet) Sign(txn *types.Transaction, toSign []types.Hash256, cf types.CoveredFields) error
Sign will sign any inputs added by FundTransaction.
func (*Wallet) SignTransaction ¶
func (w *Wallet) SignTransaction(txn *types.Transaction, toSign []types.Hash256, cf types.CoveredFields) error
SignTransaction signs txn using secret keys known to the wallet. The transaction should be complete with the exception of the Signature fields of each TransactionSignature referenced by toSign. For convenience, if toSign is empty, SignTransaction signs everything that it can.
func (*Wallet) SweepSeed ¶
SweepSeed scans the blockchain for outputs generated from seed and creates a transaction that transfers them to the wallet. Note that this incurs a transaction fee. It returns the total value of the outputs, minus the fee. If only Siafunds were found, the fee is deducted from the wallet.
func (*Wallet) SweepTransaction ¶
func (w *Wallet) SweepTransaction(txn types.Transaction, output types.SiacoinOutput) (types.Transaction, []types.Transaction)
SweepTransaction creates a funded txn that sends the inputs of the transaction to the specified output if submitted to the blockchain.
func (*Wallet) Transaction ¶
func (w *Wallet) Transaction(txid types.TransactionID) (pt modules.ProcessedTransaction, found bool, err error)
Transaction returns the transaction with the given id. 'False' is returned if the transaction does not exist.
func (*Wallet) Transactions ¶
func (w *Wallet) Transactions(startHeight, endHeight uint64) (pts []modules.ProcessedTransaction, err error)
Transactions returns all transactions relevant to the wallet that were confirmed in the range [startHeight, endHeight].
func (*Wallet) UnconfirmedBalance ¶
func (w *Wallet) UnconfirmedBalance() (outgoingSiacoins types.Currency, incomingSiacoins types.Currency, err error)
UnconfirmedBalance returns the number of outgoing and incoming Siacoins in the unconfirmed transaction set. Refund outputs are included in this reporting.
func (*Wallet) UnconfirmedTransactions ¶
func (w *Wallet) UnconfirmedTransactions() ([]modules.ProcessedTransaction, error)
UnconfirmedTransactions returns the set of unconfirmed transactions that are relevant to the wallet.
func (*Wallet) Unlock ¶
Unlock will decrypt the wallet seed and load all of the addresses into memory.
func (*Wallet) UnlockAsync ¶
UnlockAsync will decrypt the wallet seed and load all of the addresses into memory.
func (*Wallet) UnlockConditions ¶
UnlockConditions returns the UnlockConditions for the specified address, if they are known to the wallet.
func (*Wallet) UnspentOutputs ¶
func (w *Wallet) UnspentOutputs() ([]modules.UnspentOutput, error)
UnspentOutputs returns the unspent outputs tracked by the wallet.