Documentation ¶
Index ¶
- type Store
- func (s *Store) AccountBalance(accountID rhpv3.Account) (balance types.Currency, err error)
- func (s *Store) AddContract(revision contracts.SignedRevision, formationSet []types.Transaction, ...) error
- func (s *Store) AddTemporarySectors(sectors []storage.TempSector) error
- func (s *Store) AddVolume(localPath string, readOnly bool) (volumeID int, err error)
- func (s *Store) Close() error
- func (s *Store) Contract(id types.FileContractID) (contracts.Contract, error)
- func (s *Store) ContractAction(height uint64, contractFn func(types.FileContractID, uint64, string)) error
- func (s *Store) ContractFormationSet(id types.FileContractID) ([]types.Transaction, error)
- func (s *Store) Contracts(filter contracts.ContractFilter) (contracts []contracts.Contract, count int, err error)
- func (s *Store) CreditAccount(accountID rhpv3.Account, amount types.Currency, expiration time.Time) (balance types.Currency, err error)
- func (s *Store) DebitAccount(accountID rhpv3.Account, amount types.Currency) (balance types.Currency, err error)
- func (s *Store) ExpireContract(id types.FileContractID, status contracts.ContractStatus) error
- func (s *Store) ExpireContractSectors(height uint64) error
- func (s *Store) ExpireTempSectors(height uint64) error
- func (s *Store) GetRegistryValue(key rhpv3.RegistryKey) (entry rhpv3.RegistryValue, _ error)
- func (s *Store) GrowVolume(id int, maxSectors uint64) error
- func (s *Store) HostKey() (pk types.PrivateKey)
- func (s *Store) IncrementRHP2DataUsage(ingress, egress uint64) error
- func (s *Store) IncrementRHP3DataUsage(ingress, egress uint64) error
- func (s *Store) IncrementRegistryAccess(read, write uint64) error
- func (s *Store) IncrementSectorStats(reads, writes, cacheHit, cacheMiss uint64) error
- func (s *Store) LastContractChange() (id modules.ConsensusChangeID, err error)
- func (s *Store) LastWalletChange() (id modules.ConsensusChangeID, height uint64, err error)
- func (s *Store) Metrics(timestamp time.Time) (m metrics.Metrics, err error)
- func (s *Store) MigrateSectors(volumeID int, startIndex uint64, ...) error
- func (s *Store) PeriodMetrics(start time.Time, n int, interval metrics.Interval) ([]metrics.Metrics, error)
- func (s *Store) PruneAccounts(height uint64) error
- func (s *Store) PruneSectors() (int, error)
- func (s *Store) RegistryEntries() (count, max uint64, err error)
- func (s *Store) RemoveSector(root types.Hash256) (err error)
- func (s *Store) RemoveVolume(id int, force bool) error
- func (s *Store) RenewContract(renewal contracts.SignedRevision, clearing contracts.SignedRevision, ...) error
- func (s *Store) ResetWallet(seedHash types.Hash256) error
- func (s *Store) ReviseContract(revision contracts.SignedRevision, usage contracts.Usage, oldSectors uint64, ...) error
- func (s *Store) SectorLocation(root types.Hash256) (storage.SectorLocation, func() error, error)
- func (s *Store) SectorRoots(contractID types.FileContractID) (roots []types.Hash256, err error)
- func (s *Store) SetAvailable(volumeID int, available bool) error
- func (s *Store) SetReadOnly(volumeID int, readOnly bool) error
- func (s *Store) SetRegistryValue(entry rhpv3.RegistryEntry, expiration uint64) error
- func (s *Store) Settings() (config settings.Settings, err error)
- func (s *Store) ShrinkVolume(id int, maxSectors uint64) error
- func (s *Store) StorageUsage() (usedSectors, totalSectors uint64, err error)
- func (s *Store) StoreSector(root types.Hash256, fn func(loc storage.SectorLocation, exists bool) error) (func() error, error)
- func (s *Store) TransactionCount() (count uint64, err error)
- func (s *Store) Transactions(limit, offset int) (txns []wallet.Transaction, err error)
- func (s *Store) UnspentSiacoinElements() (utxos []wallet.SiacoinElement, err error)
- func (s *Store) UpdateContractState(ccID modules.ConsensusChangeID, height uint64, ...) error
- func (s *Store) UpdateSettings(settings settings.Settings) error
- func (s *Store) UpdateWallet(ccID modules.ConsensusChangeID, height uint64, ...) error
- func (s *Store) VerifyWalletKey(seedHash types.Hash256) error
- func (s *Store) Volume(id int) (storage.Volume, error)
- func (s *Store) Volumes() ([]storage.Volume, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
A Store is a persistent store that uses a SQL database as its backend.
func OpenDatabase ¶
OpenDatabase creates a new SQLite store and initializes the database. If the database does not exist, it is created.
func (*Store) AccountBalance ¶
AccountBalance returns the balance of the account with the given ID.
func (*Store) AddContract ¶
func (s *Store) AddContract(revision contracts.SignedRevision, formationSet []types.Transaction, lockedCollateral types.Currency, initialUsage contracts.Usage, negotationHeight uint64) error
AddContract adds a new contract to the database.
func (*Store) AddTemporarySectors ¶
func (s *Store) AddTemporarySectors(sectors []storage.TempSector) error
AddTemporarySectors adds the roots of sectors that are temporarily stored on the host. The sectors will be deleted after the expiration height.
func (*Store) AddVolume ¶
AddVolume initializes a new storage volume and adds it to the volume store. GrowVolume must be called afterwards to initialize the volume to its desired size.
func (*Store) ContractAction ¶
func (s *Store) ContractAction(height uint64, contractFn func(types.FileContractID, uint64, string)) error
ContractAction calls contractFn on every contract in the store that needs a lifecycle action performed.
func (*Store) ContractFormationSet ¶
func (s *Store) ContractFormationSet(id types.FileContractID) ([]types.Transaction, error)
ContractFormationSet returns the set of transactions that were created during contract formation.
func (*Store) Contracts ¶
func (s *Store) Contracts(filter contracts.ContractFilter) (contracts []contracts.Contract, count int, err error)
Contracts returns a paginated list of contracts.
func (*Store) CreditAccount ¶
func (s *Store) CreditAccount(accountID rhpv3.Account, amount types.Currency, expiration time.Time) (balance types.Currency, err error)
CreditAccount adds the specified amount to the account with the given ID.
func (*Store) DebitAccount ¶
func (s *Store) DebitAccount(accountID rhpv3.Account, amount types.Currency) (balance types.Currency, err error)
DebitAccount subtracts the specified amount from the account with the given ID. Returns the remaining balance of the account.
func (*Store) ExpireContract ¶ added in v0.1.1
func (s *Store) ExpireContract(id types.FileContractID, status contracts.ContractStatus) error
ExpireContract expires a contract and updates its status. Should only be used if the contract is active or pending.
func (*Store) ExpireContractSectors ¶
ExpireContractSectors expires all sectors that are no longer covered by an active contract.
func (*Store) ExpireTempSectors ¶
ExpireTempSectors deletes the roots of sectors that are no longer temporarily stored on the host.
func (*Store) GetRegistryValue ¶
func (s *Store) GetRegistryValue(key rhpv3.RegistryKey) (entry rhpv3.RegistryValue, _ error)
GetRegistryValue returns the registry value for the given key. If the key is not found should return ErrEntryNotFound.
func (*Store) GrowVolume ¶
GrowVolume grows a storage volume's metadata by n sectors.
func (*Store) HostKey ¶
func (s *Store) HostKey() (pk types.PrivateKey)
HostKey returns the host's private key.
func (*Store) IncrementRHP2DataUsage ¶
IncrementRHP2DataUsage increments the RHP2 ingress and egress metrics.
func (*Store) IncrementRHP3DataUsage ¶
IncrementRHP3DataUsage increments the RHP3 ingress and egress metrics.
func (*Store) IncrementRegistryAccess ¶
IncrementRegistryAccess increments the registry read and write metrics.
func (*Store) IncrementSectorStats ¶
IncrementSectorStats increments the sector read, write and cache metrics.
func (*Store) LastContractChange ¶
func (s *Store) LastContractChange() (id modules.ConsensusChangeID, err error)
LastContractChange gets the last consensus change processed by the contractor.
func (*Store) LastWalletChange ¶
func (s *Store) LastWalletChange() (id modules.ConsensusChangeID, height uint64, err error)
LastWalletChange gets the last consensus change processed by the wallet.
func (*Store) MigrateSectors ¶
func (s *Store) MigrateSectors(volumeID int, startIndex uint64, migrateFn func(locations []storage.SectorLocation) error) error
MigrateSectors migrates each occupied sector of a volume starting at startIndex. The sector data should be copied to the new location and synced to disk during migrateFn. Sectors are migrated in batches of 256.
func (*Store) PeriodMetrics ¶
func (s *Store) PeriodMetrics(start time.Time, n int, interval metrics.Interval) ([]metrics.Metrics, error)
PeriodMetrics returns aggregate metrics for n periods starting at start
func (*Store) PruneAccounts ¶
PruneAccounts removes all accounts that have expired
func (*Store) PruneSectors ¶
PruneSectors removes the metadata of any sectors that are not locked or referenced by a contract.
func (*Store) RegistryEntries ¶
RegistryEntries returns the current number of entries as well as the maximum number of entries the registry can hold.
func (*Store) RemoveSector ¶
RemoveSector removes the metadata of a sector and returns its location in the volume.
func (*Store) RemoveVolume ¶
RemoveVolume removes a storage volume from the volume store. If there are used sectors in the volume, ErrVolumeNotEmpty is returned. If force is true, the volume is removed regardless of whether it is empty.
func (*Store) RenewContract ¶
func (s *Store) RenewContract(renewal contracts.SignedRevision, clearing contracts.SignedRevision, renewalTxnSet []types.Transaction, lockedCollateral types.Currency, clearingUsage, renewalUsage contracts.Usage, negotationHeight uint64) error
RenewContract adds a new contract to the database and sets the old contract's renewed_from field. The old contract's sector roots are copied to the new contract.
func (*Store) ResetWallet ¶
ResetWallet resets the wallet to its initial state. This is used when a consensus subscription error occurs.
func (*Store) ReviseContract ¶
func (s *Store) ReviseContract(revision contracts.SignedRevision, usage contracts.Usage, oldSectors uint64, sectorChanges []contracts.SectorChange) error
ReviseContract atomically updates a contract's revision and sectors
func (*Store) SectorLocation ¶
SectorLocation returns the location of a sector or an error if the sector is not found. The location is locked until release is called.
func (*Store) SectorRoots ¶
SectorRoots returns the sector roots for a contract. If limit is 0, all roots are returned.
func (*Store) SetAvailable ¶
SetAvailable sets the available flag on a volume.
func (*Store) SetReadOnly ¶
SetReadOnly sets the read-only flag on a volume.
func (*Store) SetRegistryValue ¶
func (s *Store) SetRegistryValue(entry rhpv3.RegistryEntry, expiration uint64) error
SetRegistryValue sets the registry value for the given key.
func (*Store) ShrinkVolume ¶
ShrinkVolume shrinks a storage volume's metadata to maxSectors. If there are used sectors outside of the new maximum, ErrVolumeNotEmpty is returned.
func (*Store) StorageUsage ¶
StorageUsage returns the number of sectors stored and the total number of sectors available in the storage pool.
func (*Store) StoreSector ¶
func (s *Store) StoreSector(root types.Hash256, fn func(loc storage.SectorLocation, exists bool) error) (func() error, error)
StoreSector calls fn with an empty location in a writable volume. If the sector root already exists, fn is called with the existing location and exists is true. Unless exists is true, The sector must be written to disk within fn. If fn returns an error, the metadata is rolled back. If no space is available, ErrNotEnoughStorage is returned. The location is locked until release is called.
The sector should be referenced by either a contract or temp store before release is called to prevent Prune() from removing it.
func (*Store) TransactionCount ¶
TransactionCount returns the total number of transactions in the wallet.
func (*Store) Transactions ¶
func (s *Store) Transactions(limit, offset int) (txns []wallet.Transaction, err error)
Transactions returns a paginated list of transactions ordered by block height descending. If no transactions are found, (nil, nil) is returned.
func (*Store) UnspentSiacoinElements ¶
func (s *Store) UnspentSiacoinElements() (utxos []wallet.SiacoinElement, err error)
UnspentSiacoinElements returns the spendable siacoin outputs in the wallet.
func (*Store) UpdateContractState ¶
func (s *Store) UpdateContractState(ccID modules.ConsensusChangeID, height uint64, fn func(contracts.UpdateStateTransaction) error) error
UpdateContractState atomically updates the contractor's state.
func (*Store) UpdateSettings ¶
UpdateSettings updates the host's stored settings.
func (*Store) UpdateWallet ¶
func (s *Store) UpdateWallet(ccID modules.ConsensusChangeID, height uint64, fn func(wallet.UpdateTransaction) error) error
UpdateWallet begins an update transaction on the wallet store.
func (*Store) VerifyWalletKey ¶
VerifyWalletKey checks that the wallet seed matches the seed hash. This detects if the user's recovery phrase has changed and the wallet needs to rescan.