Documentation ¶
Index ¶
- Variables
- type ChainManager
- type SiacoinElement
- type SingleAddressStore
- type SingleAddressWallet
- func (sw *SingleAddressWallet) Address() types.Address
- func (sw *SingleAddressWallet) Balance() (spendable, confirmed, unconfirmed types.Currency, err error)
- func (sw *SingleAddressWallet) Close() error
- func (sw *SingleAddressWallet) FundTransaction(txn *types.Transaction, amount types.Currency) ([]types.Hash256, func(), error)
- func (sw *SingleAddressWallet) ProcessConsensusChange(cc modules.ConsensusChange)
- func (sw *SingleAddressWallet) ReceiveUpdatedUnconfirmedTransactions(diff *modules.TransactionPoolDiff)
- func (sw *SingleAddressWallet) ScanHeight() uint64
- func (sw *SingleAddressWallet) SignTransaction(cs consensus.State, txn *types.Transaction, toSign []types.Hash256, ...) error
- func (sw *SingleAddressWallet) TransactionCount() (uint64, error)
- func (sw *SingleAddressWallet) Transactions(limit, offset int) ([]Transaction, error)
- func (sw *SingleAddressWallet) UnconfirmedTransactions() (txns []Transaction, _ error)
- func (sw *SingleAddressWallet) UnlockConditions() types.UnlockConditions
- type Transaction
- type TransactionPool
- type TransactionSource
- type UpdateTransaction
Constants ¶
This section is empty.
Variables ¶
var ErrDifferentSeed = errors.New("seed differs from wallet seed")
ErrDifferentSeed is returned when a different seed is provided to NewSingleAddressWallet than was used to initialize the wallet
Functions ¶
This section is empty.
Types ¶
type ChainManager ¶
type ChainManager interface { TipState() consensus.State BlockAtHeight(height uint64) (types.Block, bool) Subscribe(subscriber modules.ConsensusSetSubscriber, ccID modules.ConsensusChangeID, cancel <-chan struct{}) error }
A ChainManager manages the current state of the blockchain.
type SiacoinElement ¶
type SiacoinElement struct { types.SiacoinOutput ID types.SiacoinOutputID }
A SiacoinElement is a SiacoinOutput along with its ID.
type SingleAddressStore ¶
type SingleAddressStore interface { // LastWalletChange returns the consensus change ID and block height of // the last wallet change. LastWalletChange() (id modules.ConsensusChangeID, height uint64, err error) // UnspentSiacoinElements returns a list of all unspent siacoin outputs UnspentSiacoinElements() ([]SiacoinElement, error) // Transactions returns a paginated list of transactions ordered by // block height, descending. If no more transactions are available, // (nil, nil) should be returned. Transactions(limit, offset int) ([]Transaction, error) // TransactionCount returns the total number of transactions in the // wallet. TransactionCount() (uint64, error) UpdateWallet(ccID modules.ConsensusChangeID, height uint64, fn func(UpdateTransaction) error) error // ResetWallet resets the wallet to its initial state. This is used when a // consensus subscription error occurs. ResetWallet() error // VerifyWalletKey checks that the wallet seed matches the existing seed // hash. This detects if the user's recovery phrase has changed and the // wallet needs to rescan. VerifyWalletKey(seedHash types.Hash256) error }
A SingleAddressStore stores the state of a single-address wallet. Implementations are assumed to be thread safe.
type SingleAddressWallet ¶
type SingleAddressWallet struct {
// contains filtered or unexported fields
}
A SingleAddressWallet is a hot wallet that manages the outputs controlled by a single address.
func NewSingleAddressWallet ¶
func NewSingleAddressWallet(priv types.PrivateKey, cm ChainManager, tp TransactionPool, store SingleAddressStore, log *zap.Logger) (*SingleAddressWallet, error)
NewSingleAddressWallet returns a new SingleAddressWallet using the provided private key and store.
func (*SingleAddressWallet) Address ¶
func (sw *SingleAddressWallet) Address() types.Address
Address returns the address of the wallet.
func (*SingleAddressWallet) Balance ¶
func (sw *SingleAddressWallet) Balance() (spendable, confirmed, unconfirmed types.Currency, err error)
Balance returns the balance of the wallet.
func (*SingleAddressWallet) Close ¶
func (sw *SingleAddressWallet) Close() error
Close closes the wallet
func (*SingleAddressWallet) FundTransaction ¶
func (sw *SingleAddressWallet) FundTransaction(txn *types.Transaction, amount types.Currency) ([]types.Hash256, func(), error)
FundTransaction adds siacoin inputs worth at least amount to the provided transaction. If necessary, a change output will also be added. The inputs will not be available to future calls to FundTransaction unless ReleaseInputs is called.
func (*SingleAddressWallet) ProcessConsensusChange ¶
func (sw *SingleAddressWallet) ProcessConsensusChange(cc modules.ConsensusChange)
ProcessConsensusChange implements modules.ConsensusSetSubscriber.
func (*SingleAddressWallet) ReceiveUpdatedUnconfirmedTransactions ¶
func (sw *SingleAddressWallet) ReceiveUpdatedUnconfirmedTransactions(diff *modules.TransactionPoolDiff)
ReceiveUpdatedUnconfirmedTransactions implements modules.TransactionPoolSubscriber.
func (*SingleAddressWallet) ScanHeight ¶
func (sw *SingleAddressWallet) ScanHeight() uint64
ScanHeight returns the block height the wallet has scanned to.
func (*SingleAddressWallet) SignTransaction ¶
func (sw *SingleAddressWallet) SignTransaction(cs consensus.State, txn *types.Transaction, toSign []types.Hash256, cf types.CoveredFields) error
SignTransaction adds a signature to each of the specified inputs.
func (*SingleAddressWallet) TransactionCount ¶
func (sw *SingleAddressWallet) TransactionCount() (uint64, error)
TransactionCount returns the total number of transactions in the wallet.
func (*SingleAddressWallet) Transactions ¶
func (sw *SingleAddressWallet) Transactions(limit, offset int) ([]Transaction, error)
Transactions returns a paginated list of transactions, ordered by block height descending. If no more transactions are available, (nil, nil) is returned.
func (*SingleAddressWallet) UnconfirmedTransactions ¶
func (sw *SingleAddressWallet) UnconfirmedTransactions() (txns []Transaction, _ error)
UnconfirmedTransactions returns all unconfirmed transactions relevant to the wallet.
func (*SingleAddressWallet) UnlockConditions ¶
func (sw *SingleAddressWallet) UnlockConditions() types.UnlockConditions
UnlockConditions returns the unlock conditions of the wallet.
type Transaction ¶
type Transaction struct { ID types.TransactionID `json:"ID"` Index types.ChainIndex `json:"index"` Transaction types.Transaction `json:"transaction"` Inflow types.Currency `json:"inflow"` Outflow types.Currency `json:"outflow"` Source TransactionSource `json:"source"` Timestamp time.Time `json:"timestamp"` }
A Transaction is an on-chain transaction relevant to a particular wallet, paired with useful metadata.
func (*Transaction) DecodeFrom ¶
func (txn *Transaction) DecodeFrom(d *types.Decoder)
DecodeFrom implements types.DecoderFrom.
func (Transaction) EncodeTo ¶
func (txn Transaction) EncodeTo(e *types.Encoder)
EncodeTo implements types.EncoderTo.
type TransactionPool ¶
type TransactionPool interface {
Subscribe(subscriber modules.TransactionPoolSubscriber)
}
A TransactionPool manages unconfirmed transactions.
type TransactionSource ¶
type TransactionSource string
A TransactionSource is a string indicating the source of a transaction.
const ( TxnSourceTransaction TransactionSource = "transaction" TxnSourceMinerPayout TransactionSource = "miner" TxnSourceSiafundClaim TransactionSource = "siafundClaim" TxnSourceContract TransactionSource = "contract" TxnSourceFoundationPayout TransactionSource = "foundation" )
transaction sources indicate the source of a transaction. Transactions can either be created by sending Siacoins between unlock hashes or they can be created by consensus (e.g. a miner payout, a siafund claim, or a contract).
type UpdateTransaction ¶
type UpdateTransaction interface { AddSiacoinElement(SiacoinElement) error RemoveSiacoinElement(types.SiacoinOutputID) error AddTransaction(Transaction) error RevertBlock(types.BlockID) error AddWalletDelta(value types.Currency, timestamp time.Time) error SubWalletDelta(value types.Currency, timestamp time.Time) error }
An UpdateTransaction atomically updates the wallet store