Documentation ¶
Index ¶
- Constants
- Variables
- func SignTransaction(cs consensus.State, txn *types.Transaction, sigIndex int, key types.PrivateKey)
- func StandardTransactionSignature(id types.Hash256) types.TransactionSignature
- func UpdateChainState(tx UpdateTx, reverted []chain.RevertUpdate, applied []chain.ApplyUpdate, ...) error
- type Address
- type AddressBalance
- type AppliedState
- type Balance
- type ChainManager
- type ChainUpdate
- type Event
- type EventData
- type EventPayout
- type EventV1ContractResolution
- type EventV1Transaction
- type EventV2ContractResolution
- type EventV2Transaction
- type ID
- type IndexMode
- type Manager
- func (m *Manager) AddAddress(walletID ID, addr Address) error
- func (m *Manager) AddWallet(w Wallet) (Wallet, error)
- func (m *Manager) AddressBalance(address types.Address) (balance Balance, err error)
- func (m *Manager) AddressEvents(address types.Address, offset, limit int) (events []Event, err error)
- func (m *Manager) AddressSiacoinOutputs(address types.Address, offset, limit int) (siacoins []types.SiacoinElement, err error)
- func (m *Manager) AddressSiafundOutputs(address types.Address, offset, limit int) (siafunds []types.SiafundElement, err error)
- func (m *Manager) AddressUnconfirmedEvents(address types.Address) ([]Event, error)
- func (m *Manager) Addresses(walletID ID) ([]Address, error)
- func (m *Manager) Close() error
- func (m *Manager) DeleteWallet(walletID ID) error
- func (m *Manager) Events(eventIDs []types.Hash256) ([]Event, error)
- func (m *Manager) IndexMode() IndexMode
- func (m *Manager) RemoveAddress(walletID ID, addr types.Address) error
- func (m *Manager) Reserve(ids []types.Hash256, duration time.Duration) error
- func (m *Manager) Scan(ctx context.Context, index types.ChainIndex) error
- func (m *Manager) SiacoinElement(id types.SiacoinOutputID) (types.SiacoinElement, error)
- func (m *Manager) SiafundElement(id types.SiafundOutputID) (types.SiafundElement, error)
- func (m *Manager) Tip() (types.ChainIndex, error)
- func (m *Manager) UnconfirmedEvents() ([]Event, error)
- func (m *Manager) UnspentSiacoinOutputs(walletID ID, offset, limit int) ([]types.SiacoinElement, error)
- func (m *Manager) UnspentSiafundOutputs(walletID ID, offset, limit int) ([]types.SiafundElement, error)
- func (m *Manager) UpdateWallet(w Wallet) (Wallet, error)
- func (m *Manager) WalletBalance(walletID ID) (Balance, error)
- func (m *Manager) WalletEvents(walletID ID, offset, limit int) ([]Event, error)
- func (m *Manager) WalletUnconfirmedEvents(walletID ID) ([]Event, error)
- func (m *Manager) Wallets() ([]Wallet, error)
- type Option
- type RevertedState
- type Seed
- type SeedAddressVault
- type Store
- type TreeNodeUpdate
- type UpdateTx
- type Wallet
Constants ¶
const ( EventTypeMinerPayout = wallet.EventTypeMinerPayout EventTypeFoundationSubsidy = wallet.EventTypeFoundationSubsidy EventTypeSiafundClaim = wallet.EventTypeSiafundClaim EventTypeV1Transaction = wallet.EventTypeV1Transaction EventTypeV1ContractResolution = wallet.EventTypeV1ContractResolution EventTypeV2Transaction = wallet.EventTypeV2Transaction EventTypeV2ContractResolution = wallet.EventTypeV2ContractResolution )
event types indicate the source of an event. Events can either be created by sending Siacoins between addresses or they can be created by consensus (e.g. a miner payout, a siafund claim, or a contract).
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when a requested wallet or address is not found.
Functions ¶
func SignTransaction ¶
func SignTransaction(cs consensus.State, txn *types.Transaction, sigIndex int, key types.PrivateKey)
SignTransaction signs txn with the given key. The TransactionSignature object must already be present in txn at the given index.
func StandardTransactionSignature ¶
func StandardTransactionSignature(id types.Hash256) types.TransactionSignature
StandardTransactionSignature is the most common form of TransactionSignature. It covers the entire transaction, references a sole public key, and has no timelock.
func UpdateChainState ¶
func UpdateChainState(tx UpdateTx, reverted []chain.RevertUpdate, applied []chain.ApplyUpdate, indexMode IndexMode, log *zap.Logger) error
UpdateChainState atomically updates the state of a store with a set of updates from the chain manager.
Types ¶
type Address ¶
type Address struct { Address types.Address `json:"address"` Description string `json:"description"` SpendPolicy *types.SpendPolicy `json:"spendPolicy,omitempty"` Metadata json.RawMessage `json:"metadata"` }
A Address is an address associated with a wallet.
type AddressBalance ¶
AddressBalance pairs an address with its balance.
type AppliedState ¶
type AppliedState struct { NumLeaves uint64 Events []Event CreatedSiacoinElements []types.SiacoinElement SpentSiacoinElements []types.SiacoinElement CreatedSiafundElements []types.SiafundElement SpentSiafundElements []types.SiafundElement }
AppliedState contains all state changes made to a store after applying a chain update.
type Balance ¶
type Balance struct { Siacoins types.Currency `json:"siacoins"` ImmatureSiacoins types.Currency `json:"immatureSiacoins"` Siafunds uint64 `json:"siafunds"` }
Balance is a summary of a siacoin and siafund balance
type ChainManager ¶
type ChainManager interface { PoolTransactions() []types.Transaction V2PoolTransactions() []types.V2Transaction Tip() types.ChainIndex BestIndex(height uint64) (types.ChainIndex, bool) OnReorg(fn func(types.ChainIndex)) (cancel func()) UpdatesSince(index types.ChainIndex, max int) (rus []chain.RevertUpdate, aus []chain.ApplyUpdate, err error) }
A ChainManager manages the consensus state
type ChainUpdate ¶
type ChainUpdate interface { ForEachSiacoinElement(func(sce types.SiacoinElement, created, spent bool)) ForEachSiafundElement(func(sfe types.SiafundElement, created, spent bool)) ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool)) ForEachV2FileContractElement(func(fce types.V2FileContractElement, created bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType)) }
A ChainUpdate is a set of changes to the consensus state.
type EventPayout ¶
type EventPayout = wallet.EventPayout
An EventPayout represents a miner payout, siafund claim, or foundation subsidy.
type EventV1ContractResolution ¶
type EventV1ContractResolution = wallet.EventV1ContractResolution
An EventV1ContractResolution represents a file contract payout from a v1 contract.
type EventV1Transaction ¶
type EventV1Transaction = wallet.EventV1Transaction
An EventV1Transaction pairs a v1 transaction with its spent siacoin and siafund elements.
type EventV2ContractResolution ¶
type EventV2ContractResolution = wallet.EventV2ContractResolution
An EventV2ContractResolution represents a file contract payout from a v2 contract.
type EventV2Transaction ¶
type EventV2Transaction = wallet.EventV2Transaction
EventV2Transaction is a transaction event that includes the transaction
type ID ¶
type ID int64
An ID is a unique identifier for a wallet.
func (ID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*ID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type IndexMode ¶
type IndexMode uint8
An IndexMode determines the chain state that the wallet manager stores.
IndexMode represents the index mode of the wallet manager. The index mode determines how the wallet manager stores the consensus state.
IndexModePersonal - The wallet manager scans the blockchain starting at genesis. Only state from addresses that are registered with a wallet will be stored. If an address is added to a wallet after the scan completes, the manager will need to rescan.
IndexModeFull - The wallet manager scans the blockchain starting at genesis and stores the state of all addresses.
IndexModeNone - The wallet manager does not scan the blockchain. This is useful for multiple nodes sharing the same database. None should only be used when connecting to a database that is in "Full" mode.
func (IndexMode) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*IndexMode) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
A Manager manages wallets.
func NewManager ¶
func NewManager(cm ChainManager, store Store, opts ...Option) (*Manager, error)
NewManager creates a new wallet manager.
func (*Manager) AddAddress ¶
AddAddress adds the given address to the given wallet.
func (*Manager) AddressBalance ¶
AddressBalance returns the balance of a single address.
func (*Manager) AddressEvents ¶
func (m *Manager) AddressEvents(address types.Address, offset, limit int) (events []Event, err error)
AddressEvents returns the events of a single address.
func (*Manager) AddressSiacoinOutputs ¶
func (m *Manager) AddressSiacoinOutputs(address types.Address, offset, limit int) (siacoins []types.SiacoinElement, err error)
AddressSiacoinOutputs returns the unspent siacoin outputs for an address.
func (*Manager) AddressSiafundOutputs ¶
func (m *Manager) AddressSiafundOutputs(address types.Address, offset, limit int) (siafunds []types.SiafundElement, err error)
AddressSiafundOutputs returns the unspent siafund outputs for an address.
func (*Manager) AddressUnconfirmedEvents ¶
AddressUnconfirmedEvents returns the unconfirmed events for a single address.
func (*Manager) DeleteWallet ¶
DeleteWallet deletes the given wallet.
func (*Manager) RemoveAddress ¶
RemoveAddress removes the given address from the given wallet.
func (*Manager) Scan ¶
Scan rescans the chain starting from the given index. The scan will complete when the chain manager reaches the current tip or the context is canceled.
func (*Manager) SiacoinElement ¶
func (m *Manager) SiacoinElement(id types.SiacoinOutputID) (types.SiacoinElement, error)
SiacoinElement returns the unspent siacoin element with the given id.
func (*Manager) SiafundElement ¶
func (m *Manager) SiafundElement(id types.SiafundOutputID) (types.SiafundElement, error)
SiafundElement returns the unspent siafund element with the given id.
func (*Manager) Tip ¶
func (m *Manager) Tip() (types.ChainIndex, error)
Tip returns the last scanned chain index of the manager.
func (*Manager) UnconfirmedEvents ¶
UnconfirmedEvents returns all unconfirmed events in the transaction pool.
func (*Manager) UnspentSiacoinOutputs ¶
func (m *Manager) UnspentSiacoinOutputs(walletID ID, offset, limit int) ([]types.SiacoinElement, error)
UnspentSiacoinOutputs returns a paginated list of matured siacoin outputs relevant to the wallet
func (*Manager) UnspentSiafundOutputs ¶
func (m *Manager) UnspentSiafundOutputs(walletID ID, offset, limit int) ([]types.SiafundElement, error)
UnspentSiafundOutputs returns a paginated list of siafund outputs relevant to the wallet
func (*Manager) UpdateWallet ¶
UpdateWallet updates the given wallet.
func (*Manager) WalletBalance ¶
WalletBalance returns the balance of the given wallet.
func (*Manager) WalletEvents ¶
WalletEvents returns the events of the given wallet.
func (*Manager) WalletUnconfirmedEvents ¶
WalletUnconfirmedEvents returns the unconfirmed events of the given wallet.
type Option ¶
type Option func(*Manager)
An Option configures a wallet Manager.
func WithIndexMode ¶
WithIndexMode sets the index mode used by the manager.
func WithLogger ¶
WithLogger sets the logger used by the manager.
func WithSyncBatchSize ¶
WithSyncBatchSize sets the number of blocks to batch when scanning the blockchain. The default is 64. Increasing this value can improve performance at the cost of memory usage.
type RevertedState ¶
type RevertedState struct { NumLeaves uint64 UnspentSiacoinElements []types.SiacoinElement DeletedSiacoinElements []types.SiacoinElement UnspentSiafundElements []types.SiafundElement DeletedSiafundElements []types.SiafundElement }
RevertedState contains all state changes made to a store after reverting a chain update.
type Seed ¶
type Seed struct {
// contains filtered or unexported fields
}
A Seed is securely-generated entropy, used to derive an arbitrary number of keypairs.
func NewSeedFromEntropy ¶
NewSeedFromEntropy returns a the specified seed.
func (Seed) PrivateKey ¶
func (s Seed) PrivateKey(index uint64) types.PrivateKey
PrivateKey derives the private key for the specified index.
type SeedAddressVault ¶
type SeedAddressVault struct {
// contains filtered or unexported fields
}
A SeedAddressVault generates and stores addresses from a seed.
func NewSeedAddressVault ¶
func NewSeedAddressVault(seed Seed, initialAddrs, lookahead uint64) *SeedAddressVault
NewSeedAddressVault initializes a SeedAddressVault.
func (*SeedAddressVault) NewAddress ¶
func (sav *SeedAddressVault) NewAddress(desc string) Address
NewAddress returns a new address derived from the seed, along with descriptive metadata.
func (*SeedAddressVault) OwnsAddress ¶
func (sav *SeedAddressVault) OwnsAddress(addr types.Address) bool
OwnsAddress returns true if addr was derived from the seed.
func (*SeedAddressVault) SignTransaction ¶
func (sav *SeedAddressVault) SignTransaction(cs consensus.State, txn *types.Transaction, toSign []types.Hash256) error
SignTransaction signs the specified transaction using keys derived from the wallet seed. If toSign is nil, SignTransaction will automatically add Signatures for each input owned by the seed. If toSign is not nil, it a list of IDs of Signatures already present in txn; SignTransaction will fill in the Signature field of each.
type Store ¶
type Store interface { UpdateChainState(reverted []chain.RevertUpdate, applied []chain.ApplyUpdate) error WalletUnconfirmedEvents(id ID, index types.ChainIndex, timestamp time.Time, v1 []types.Transaction, v2 []types.V2Transaction) (annotated []Event, err error) WalletEvents(walletID ID, offset, limit int) ([]Event, error) AddWallet(Wallet) (Wallet, error) UpdateWallet(Wallet) (Wallet, error) DeleteWallet(walletID ID) error WalletBalance(walletID ID) (Balance, error) WalletSiacoinOutputs(walletID ID, index types.ChainIndex, offset, limit int) ([]types.SiacoinElement, error) WalletSiafundOutputs(walletID ID, offset, limit int) ([]types.SiafundElement, error) WalletAddresses(walletID ID) ([]Address, error) Wallets() ([]Wallet, error) AddWalletAddress(walletID ID, address Address) error RemoveWalletAddress(walletID ID, address types.Address) error AddressBalance(address types.Address) (balance Balance, err error) AddressEvents(address types.Address, offset, limit int) (events []Event, err error) AddressSiacoinOutputs(address types.Address, index types.ChainIndex, offset, limit int) (siacoins []types.SiacoinElement, err error) AddressSiafundOutputs(address types.Address, offset, limit int) (siafunds []types.SiafundElement, err error) Events(eventIDs []types.Hash256) ([]Event, error) AnnotateV1Events(index types.ChainIndex, timestamp time.Time, v1 []types.Transaction) (annotated []Event, err error) SiacoinElement(types.SiacoinOutputID) (types.SiacoinElement, error) SiafundElement(types.SiafundOutputID) (types.SiafundElement, error) SetIndexMode(IndexMode) error LastCommittedIndex() (types.ChainIndex, error) }
A Store is a persistent store of wallet data.
type TreeNodeUpdate ¶
A TreeNodeUpdate contains the hash of a Merkle tree node and its row and column indices.
type UpdateTx ¶
type UpdateTx interface { SiacoinStateElements() ([]types.StateElement, error) UpdateSiacoinStateElements([]types.StateElement) error SiafundStateElements() ([]types.StateElement, error) UpdateSiafundStateElements([]types.StateElement) error UpdateStateTree([]TreeNodeUpdate) error AddressRelevant(types.Address) (bool, error) ApplyIndex(types.ChainIndex, AppliedState) error RevertIndex(types.ChainIndex, RevertedState) error }
An UpdateTx atomically updates the state of a store.
type Wallet ¶
type Wallet struct { ID ID `json:"id"` Name string `json:"name"` Description string `json:"description"` DateCreated time.Time `json:"dateCreated"` LastUpdated time.Time `json:"lastUpdated"` Metadata json.RawMessage `json:"metadata"` }
A Wallet is a collection of addresses and metadata.