sqlite

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

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

func OpenDatabase(fp string, log *zap.Logger) (*Store, error)

OpenDatabase creates a new SQLite store and initializes the database. If the database does not exist, it is created.

func (*Store) AccountBalance

func (s *Store) AccountBalance(accountID rhp3.Account) (balance types.Currency, err error)

AccountBalance returns the balance of the account with the given ID.

func (*Store) AccountFunding added in v0.2.0

func (s *Store) AccountFunding(account rhp3.Account) (srcs []accounts.FundingSource, err error)

AccountFunding returns all contracts that were used to fund the account.

func (*Store) Accounts added in v0.2.0

func (s *Store) Accounts(limit, offset int) (acc []accounts.Account, err error)

Accounts returns all accounts in the database paginated.

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

func (s *Store) AddVolume(localPath string, readOnly bool) (volumeID int64, err error)

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) Close

func (s *Store) Close() error

Close closes the underlying database.

func (*Store) Contract

func (s *Store) Contract(id types.FileContractID) (contract contracts.Contract, err error)

Contract returns the contract with the given ID.

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) CreditAccountWithContract added in v0.2.0

func (s *Store) CreditAccountWithContract(fund accounts.FundAccountWithContract) (balance types.Currency, err error)

CreditAccountWithContract adds the specified amount to the account with the given ID.

func (*Store) DebitAccount

func (s *Store) DebitAccount(accountID rhp3.Account, usage accounts.Usage) (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

func (s *Store) ExpireContractSectors(height uint64) error

ExpireContractSectors expires all sectors that are no longer covered by an active contract.

func (*Store) ExpireTempSectors

func (s *Store) ExpireTempSectors(height uint64) error

ExpireTempSectors deletes the roots of sectors that are no longer temporarily stored on the host.

func (*Store) GetRegistryValue

func (s *Store) GetRegistryValue(key rhp3.RegistryKey) (entry rhp3.RegistryValue, _ error)

GetRegistryValue returns the registry value for the given key. If the key is not found should return ErrEntryNotFound.

func (*Store) GrowVolume

func (s *Store) GrowVolume(id int64, maxSectors uint64) error

GrowVolume grows a storage volume's metadata by n sectors.

func (*Store) HasSector added in v1.0.0

func (s *Store) HasSector(root types.Hash256) (bool, error)

HasSector returns true if the sector is stored on the host.

func (*Store) HostKey

func (s *Store) HostKey() (pk types.PrivateKey)

HostKey returns the host's private key.

func (*Store) IncrementRHPDataUsage added in v1.0.0

func (s *Store) IncrementRHPDataUsage(ingress, egress uint64) error

IncrementRHPDataUsage increments the RHP3 ingress and egress metrics.

func (*Store) IncrementRegistryAccess

func (s *Store) IncrementRegistryAccess(read, write uint64) error

IncrementRegistryAccess increments the registry read and write metrics.

func (*Store) IncrementSectorStats

func (s *Store) IncrementSectorStats(reads, writes, cacheHit, cacheMiss uint64) error

IncrementSectorStats increments the sector read, write and cache metrics.

func (*Store) LastAnnouncement added in v0.2.2

func (s *Store) LastAnnouncement() (ann settings.Announcement, err error)

LastAnnouncement returns the last announcement.

func (*Store) LastContractChange

func (s *Store) LastContractChange() (id modules.ConsensusChangeID, err error)

LastContractChange gets the last consensus change processed by the contractor.

func (*Store) LastSettingsConsensusChange added in v0.2.2

func (s *Store) LastSettingsConsensusChange() (cc modules.ConsensusChangeID, height uint64, err error)

LastSettingsConsensusChange returns the last processed consensus change ID of the settings manager

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) Metrics

func (s *Store) Metrics(timestamp time.Time) (m metrics.Metrics, err error)

Metrics returns aggregate metrics for the host as of the timestamp.

func (*Store) MigrateSectors

func (s *Store) MigrateSectors(ctx context.Context, volumeID int64, startIndex uint64, migrateFn storage.MigrateFunc) (migrated, failed int, err error)

MigrateSectors migrates each occupied sector of a volume starting at startIndex. migrateFn will be called for each sector that needs to be migrated. The sector data should be copied to the new location and synced to disk immediately. If migrateFn returns an error, that sector will be considered failed and the migration will continue. If the context is canceled, the migration will stop and the error will be returned. The number of sectors migrated and failed will always be returned, even if an error occurs.

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) PinnedSettings added in v1.0.4

func (s *Store) PinnedSettings(context.Context) (pinned pin.PinnedSettings, err error)

PinnedSettings returns the host's pinned settings.

func (*Store) PruneAccounts

func (s *Store) PruneAccounts(height uint64) error

PruneAccounts removes all accounts that have expired

func (*Store) RegisterWebHook added in v1.0.0

func (s *Store) RegisterWebHook(url, secret string, scopes []string) (id int64, err error)

RegisterWebHook registers a new webhook.

func (*Store) RegistryEntries

func (s *Store) RegistryEntries() (count, max uint64, err error)

RegistryEntries returns the current number of entries as well as the maximum number of entries the registry can hold.

func (*Store) RemoveSector

func (s *Store) RemoveSector(root types.Hash256) (err error)

RemoveSector removes the metadata of a sector and returns its location in the volume.

func (*Store) RemoveVolume

func (s *Store) RemoveVolume(id int64, force bool) error

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) RemoveWebHook added in v1.0.0

func (s *Store) RemoveWebHook(id int64) error

RemoveWebHook removes a webhook.

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

func (s *Store) ResetWallet(seedHash types.Hash256) error

ResetWallet resets the wallet to its initial state. This is used when a consensus subscription error occurs.

func (*Store) RevertLastAnnouncement added in v0.2.2

func (s *Store) RevertLastAnnouncement() error

RevertLastAnnouncement reverts the last announcement.

func (*Store) ReviseContract

func (s *Store) ReviseContract(revision contracts.SignedRevision, roots []types.Hash256, usage contracts.Usage, sectorChanges []contracts.SectorChange) error

ReviseContract atomically updates a contract's revision and sectors

func (*Store) SectorLocation

func (s *Store) SectorLocation(root types.Hash256) (storage.SectorLocation, func() error, error)

SectorLocation returns the location of a sector or an error if the sector is not found. The sector is locked until release is called.

func (*Store) SectorReferences added in v1.0.0

func (s *Store) SectorReferences(root types.Hash256) (refs storage.SectorReference, err error)

SectorReferences returns the references, if any of a sector root

func (*Store) SectorRoots

func (s *Store) SectorRoots(contractID types.FileContractID) (roots []types.Hash256, err error)

SectorRoots returns the sector roots for a contract. The contract must be locked before calling.

func (*Store) SetAvailable

func (s *Store) SetAvailable(volumeID int64, available bool) error

SetAvailable sets the available flag on a volume.

func (*Store) SetReadOnly

func (s *Store) SetReadOnly(volumeID int64, readOnly bool) error

SetReadOnly sets the read-only flag on a volume.

func (*Store) SetRegistryValue

func (s *Store) SetRegistryValue(entry rhp3.RegistryEntry, expiration uint64) error

SetRegistryValue sets the registry value for the given key.

func (*Store) Settings

func (s *Store) Settings() (config settings.Settings, err error)

Settings returns the current host settings.

func (*Store) ShrinkVolume

func (s *Store) ShrinkVolume(id int64, maxSectors uint64) error

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

func (s *Store) StorageUsage() (usedSectors, totalSectors uint64, err error)

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 it from being pruned

func (*Store) TransactionCount

func (s *Store) TransactionCount() (count uint64, err error)

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) UpdateLastAnnouncement added in v0.2.2

func (s *Store) UpdateLastAnnouncement(ann settings.Announcement) error

UpdateLastAnnouncement updates the last announcement.

func (*Store) UpdatePinnedSettings added in v1.0.4

func (s *Store) UpdatePinnedSettings(_ context.Context, p pin.PinnedSettings) error

UpdatePinnedSettings updates the host's pinned settings.

func (*Store) UpdateSettings

func (s *Store) UpdateSettings(settings settings.Settings) error

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) UpdateWebHook added in v1.0.0

func (s *Store) UpdateWebHook(id int64, url string, scopes []string) error

UpdateWebHook updates a webhook.

func (*Store) VerifyWalletKey

func (s *Store) VerifyWalletKey(seedHash types.Hash256) error

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.

func (*Store) Volume

func (s *Store) Volume(id int64) (storage.Volume, error)

Volume returns a volume by its ID.

func (*Store) Volumes

func (s *Store) Volumes() ([]storage.Volume, error)

Volumes returns a list of all volumes.

func (*Store) WebHooks added in v1.0.0

func (s *Store) WebHooks() ([]webhooks.WebHook, error)

WebHooks returns all webhooks.

Jump to

Keyboard shortcuts

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