wallet

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 9, 2018 License: MIT Imports: 18 Imported by: 3

Documentation

Index

Constants

View Source
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 = 40
)

Variables

This section is empty.

Functions

This section is empty.

Types

type SeedFile

type SeedFile struct {
	UID                    UniqueID
	EncryptionVerification crypto.Ciphertext
	Seed                   crypto.Ciphertext
}

SeedFile stores an encrypted wallet seed on disk.

type SpendableKeyFile

type SpendableKeyFile struct {
	UID                    UniqueID
	EncryptionVerification crypto.Ciphertext
	SpendableKey           crypto.Ciphertext
}

SpendableKeyFile stores an encrypted spendable key on disk.

type UniqueID

type UniqueID [crypto.EntropySize]byte

UniqueID is a unique id randomly generated and put at the front of every persistence object. It is used to make sure that a different encryption key can be used for every persistence object.

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(cs modules.ConsensusSet, tpool modules.TransactionPool, persistDir string, bcInfo types.BlockchainInfo, chainCts types.ChainConstants) (*Wallet, 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. Keys and addresses are not loaded into the wallet during the call to 'new', but rather during the call to 'Unlock'.

func (*Wallet) AddressTransactions

func (w *Wallet) AddressTransactions(uh types.UnlockHash) (pts []modules.ProcessedTransaction)

AddressTransactions returns all of the wallet transactions associated with a single unlock hash.

func (*Wallet) AddressUnconfirmedTransactions

func (w *Wallet) AddressUnconfirmedTransactions(uh types.UnlockHash) (pts []modules.ProcessedTransaction)

AddressUnconfirmedHistory returns all of the unconfirmed wallet transactions related to a specific address.

func (*Wallet) AllAddresses

func (w *Wallet) AllAddresses() []types.UnlockHash

AllAddresses returns all addresses that the wallet is able to spend from. Addresses are returned sorted in byte-order.

func (*Wallet) AllSeeds

func (w *Wallet) AllSeeds() ([]modules.Seed, error)

AllSeeds returns a list of all seeds known to and used by the wallet.

func (*Wallet) BlockStakeStats added in v0.1.0

func (w *Wallet) BlockStakeStats() (BCcountLast1000 uint64, BCfeeLast1000 types.Currency, BlockCount uint64)

BlockStakeStats returns the blockstake statistical information of this wallet

func (*Wallet) Close

func (w *Wallet) Close() error

Close terminates all ongoing processes involving the wallet, enabling garbage collection.

func (*Wallet) ConfirmedBalance

func (w *Wallet) ConfirmedBalance() (coinBalance types.Currency, blockstakeBalance types.Currency)

ConfirmedBalance returns the balance of the wallet according to all of the confirmed transactions.

func (*Wallet) ConfirmedLockedBalance added in v1.0.5

func (w *Wallet) ConfirmedLockedBalance() (coinBalance types.Currency, blockstakeBalance types.Currency)

ConfirmedLockedBalance returns the locked balance of the wallet according to all of the confirmed transactions, which have locked outputs.

func (*Wallet) CreateBackup

func (w *Wallet) CreateBackup(backupFilepath string) error

CreateBackup creates a backup file at the desired filepath.

func (*Wallet) Encrypt

func (w *Wallet) Encrypt(masterKey crypto.TwofishKey, primarySeed modules.Seed) (modules.Seed, error)

Encrypt will encrypt the wallet using the input key. Upon encryption, a primary seed will be created for the wallet (no seed exists prior to this point). If the key is blank, then the hash of the seed that is generated will be used as the key. The wallet will still be locked after encryption.

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 files must be moved to a different directory or deleted.

If no primary seed is given (which is possible if a nil seed is passed as primary seed), a random one will be generated for you.

func (*Wallet) Encrypted

func (w *Wallet) Encrypted() bool

Encrypted returns whether or not the wallet has been encrypted.

func (*Wallet) GetKey added in v0.6.0

func (w *Wallet) GetKey(address types.UnlockHash) (types.SiaPublicKey, types.ByteSlice, error)

GetKey gets the pub/priv key pair, which is linked to the given unlock hash (address).

func (*Wallet) GetUnspentBlockStakeOutputs added in v0.1.0

func (w *Wallet) GetUnspentBlockStakeOutputs() (unspent []types.UnspentBlockStakeOutput)

GetUnspentBlockStakeOutputs returns the blockstake outputs where the beneficiary is an address this wallet has an unlockhash for.

func (*Wallet) LoadSeed

func (w *Wallet) LoadSeed(masterKey crypto.TwofishKey, seed modules.Seed) error

LoadSeed will track all of the addresses generated by the input seed, reclaiming any funds that were lost due to a deleted file or lost encryption key. An error will be returned if the seed has already been integrated with the wallet.

func (*Wallet) Lock

func (w *Wallet) Lock() error

Lock will erase all keys from memory and prevent the wallet from spending coins until it is unlocked.

func (*Wallet) NextAddress

func (w *Wallet) NextAddress() (types.UnlockHash, 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) PrimarySeed

func (w *Wallet) PrimarySeed() (modules.Seed, uint64, error)

PrimarySeed returns the decrypted primary seed of the wallet.

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(txns []types.Transaction, _ modules.ConsensusChange)

ReceiveUpdatedUnconfirmedTransactions updates the wallet's unconfirmed transaction set.

func (*Wallet) RegisterTransaction

func (w *Wallet) RegisterTransaction(t types.Transaction, parents []types.Transaction) modules.TransactionBuilder

RegisterTransaction takes a transaction and its parents and returns a transactionBuilder which can be used to expand the transaction. The most typical call is 'RegisterTransaction(types.Transaction{}, nil)', which registers a new transaction without parents.

func (*Wallet) SendBlockStakes

func (w *Wallet) SendBlockStakes(amount types.Currency, cond types.UnlockConditionProxy) (types.Transaction, error)

SendBlockStakes creates a transaction sending 'amount' to whoever can fulfill the condition. The transaction is submitted to the transaction pool and is also returned.

func (*Wallet) SendCoins added in v0.1.0

func (w *Wallet) SendCoins(amount types.Currency, cond types.UnlockConditionProxy, data []byte) (types.Transaction, error)

SendCoins creates a transaction sending 'amount' to whoever can fulfill the condition. If data is provided, it is added as arbitrary data to the transaction. The transaction is submitted to the transaction pool and is also returned.

func (*Wallet) SendOutputs added in v1.0.0

func (w *Wallet) SendOutputs(coinOutputs []types.CoinOutput, blockstakeOutputs []types.BlockStakeOutput, data []byte, version types.TransactionVersion) (types.Transaction, error)

SendOutputs is a tool for sending coins and block stakes from the wallet, to one or multiple addreses. The transaction is automatically given to the transaction pool, and is also returned to the caller.

func (*Wallet) StartTransaction

func (w *Wallet) StartTransaction() modules.TransactionBuilder

StartTransaction is a convenience function that calls StartTransactionWithVersion with the DefaultTransactionVersion constant.

func (*Wallet) StartTransactionWithVersion added in v1.0.5

func (w *Wallet) StartTransactionWithVersion(version types.TransactionVersion) modules.TransactionBuilder

StartTransactionWithVersion is a convenience function that calls RegisterTransaction(types.Transaction{Version: version}, nil).

func (*Wallet) Transaction

func (w *Wallet) Transaction(txid types.TransactionID) (modules.ProcessedTransaction, bool)

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 types.BlockHeight) (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() (outgoingCoins types.Currency, incomingCoins types.Currency)

UnconfirmedBalance returns the number of outgoing and incoming coins in the unconfirmed transaction set. Refund outputs are included in this reporting.

func (*Wallet) UnconfirmedTransactions

func (w *Wallet) UnconfirmedTransactions() []modules.ProcessedTransaction

UnconfirmedTransactions returns the set of unconfirmed transactions that are relevant to the wallet.

func (*Wallet) Unlock

func (w *Wallet) Unlock(masterKey crypto.TwofishKey) error

Unlock will decrypt the wallet seed and load all of the addresses into memory.

func (*Wallet) Unlocked

func (w *Wallet) Unlocked() bool

Unlocked indicates whether the wallet is locked or unlocked.

func (*Wallet) UnspentBlockStakeOutputs added in v0.1.0

func (w *Wallet) UnspentBlockStakeOutputs() map[types.BlockStakeOutputID]types.BlockStakeOutput

UnspentBlockStakeOutputs returns the blockstake outputs where the beneficiary is an address this wallet has an unlockhash for.

type WalletPersist

type WalletPersist struct {
	// EncryptionVerification is an encrypted string that, when decrypted, is
	// 32 '0' bytes. The UID is used to prevent leaking information in the
	// event that the same key gets used for multiple wallets.
	UID                    UniqueID
	EncryptionVerification crypto.Ciphertext

	// The primary seed is used to generate new addresses as they are required.
	// All addresses are tracked and spendable. Only modules.PublicKeysPerSeed
	// keys/addresses can be created per seed, after which a new seed will need
	// to be generated.
	PrimarySeedFile     SeedFile
	PrimarySeedProgress uint64

	// AuxiliarySeedFiles is a set of seeds that the wallet can spend from, but is
	// no longer using to generate addresses. The primary use case is loading
	// backups in the event of lost files or coins. All auxiliary seeds are
	// encrypted using the primary seed encryption password.
	AuxiliarySeedFiles []SeedFile

	// UnseededKeys are list of spendable keys that were not generated by a
	// random seed.
	UnseededKeys []SpendableKeyFile
}

WalletPersist contains all data that persists on disk during wallet operation.

Jump to

Keyboard shortcuts

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