sqlite

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 25 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPeerStore

func NewPeerStore(s *Store) (syncer.PeerStore, error)

NewPeerStore creates a new peer store using the given store.

Types

type PeerStore

type PeerStore struct {
	// contains filtered or unexported fields
}

A PeerStore stores information about peers.

func (*PeerStore) AddPeer

func (ps *PeerStore) AddPeer(peer string) error

AddPeer adds the given peer to the store.

func (*PeerStore) Ban

func (ps *PeerStore) Ban(peer string, duration time.Duration, reason string) error

Ban temporarily bans the given peer.

func (*PeerStore) Banned

func (ps *PeerStore) Banned(peer string) (bool, error)

Banned returns true if the peer is banned.

func (*PeerStore) PeerInfo

func (ps *PeerStore) PeerInfo(peer string) (syncer.PeerInfo, error)

PeerInfo returns the information for the given peer.

func (*PeerStore) Peers

func (ps *PeerStore) Peers() ([]syncer.PeerInfo, error)

Peers returns the addresses of all known peers.

func (*PeerStore) UpdatePeerInfo

func (ps *PeerStore) UpdatePeerInfo(peer string, fn func(*syncer.PeerInfo)) error

UpdatePeerInfo updates the information for the given peer.

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

func (s *Store) AddPeer(peer string) error

AddPeer adds the given peer to the store.

func (*Store) AddWallet

func (s *Store) AddWallet(w wallet.Wallet) (wallet.Wallet, error)

AddWallet adds a wallet to the database.

func (*Store) AddWalletAddress

func (s *Store) AddWalletAddress(id wallet.ID, addr wallet.Address) error

AddWalletAddress adds an address to a wallet.

func (*Store) AddressBalance

func (s *Store) AddressBalance(address types.Address) (balance wallet.Balance, err error)

AddressBalance returns the balance of a single address.

func (*Store) AddressEvents

func (s *Store) AddressEvents(address types.Address, offset, limit int) (events []wallet.Event, err error)

AddressEvents returns the events of a single address.

func (*Store) AddressSiacoinOutputs

func (s *Store) AddressSiacoinOutputs(address types.Address, index types.ChainIndex, offset, limit int) (siacoins []types.SiacoinElement, err error)

AddressSiacoinOutputs returns the unspent siacoin outputs for an address.

func (*Store) AddressSiafundOutputs

func (s *Store) AddressSiafundOutputs(address types.Address, offset, limit int) (siafunds []types.SiafundElement, err error)

AddressSiafundOutputs returns the unspent siafund outputs for an address.

func (*Store) AnnotateV1Events

func (s *Store) AnnotateV1Events(index types.ChainIndex, timestamp time.Time, v1 []types.Transaction) (annotated []wallet.Event, err error)

AnnotateV1Events annotates a list of unconfirmed transactions with relevant addresses and siacoin/siafund elements.

func (*Store) Ban

func (s *Store) Ban(peer string, duration time.Duration, reason string) error

Ban temporarily bans one or more IPs. The addr should either be a single IP with port (e.g. 1.2.3.4:5678) or a CIDR subnet (e.g. 1.2.3.4/16).

func (*Store) Banned

func (s *Store) Banned(peer string) (banned bool, _ error)

Banned returns true if the peer is banned.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database.

func (*Store) DeleteWallet

func (s *Store) DeleteWallet(id wallet.ID) error

DeleteWallet deletes a wallet from the database. This does not stop tracking addresses that were previously associated with the wallet.

func (*Store) Events

func (s *Store) Events(eventIDs []types.Hash256) (events []wallet.Event, err error)

Events returns the events with the given event IDs. If an event is not found, it is skipped.

func (*Store) IndexMode

func (s *Store) IndexMode() (wallet.IndexMode, error)

IndexMode returns the current index mode.

func (*Store) LastCommittedIndex

func (s *Store) LastCommittedIndex() (index types.ChainIndex, err error)

LastCommittedIndex returns the last chain index that was committed.

func (*Store) Peers

func (s *Store) Peers() (peers []syncer.PeerInfo, _ error)

Peers returns the addresses of all known peers.

func (*Store) RemoveWalletAddress

func (s *Store) RemoveWalletAddress(id wallet.ID, address types.Address) error

RemoveWalletAddress removes an address from a wallet. This does not stop tracking the address.

func (*Store) ResetLastIndex

func (s *Store) ResetLastIndex() error

ResetLastIndex resets the last indexed tip to trigger a full rescan.

func (*Store) SetIndexMode

func (s *Store) SetIndexMode(mode wallet.IndexMode) error

SetIndexMode sets the index mode. If the index mode is already set, this function will return an error.

func (*Store) SiacoinElement

func (s *Store) SiacoinElement(id types.SiacoinOutputID) (ele types.SiacoinElement, err error)

SiacoinElement returns an unspent Siacoin UTXO by its ID.

func (*Store) SiafundElement

func (s *Store) SiafundElement(id types.SiafundOutputID) (ele types.SiafundElement, err error)

SiafundElement returns an unspent Siafund UTXO by its ID.

func (*Store) UpdateChainState

func (s *Store) UpdateChainState(reverted []chain.RevertUpdate, applied []chain.ApplyUpdate) error

UpdateChainState implements chain.Subscriber

func (*Store) UpdateWallet

func (s *Store) UpdateWallet(w wallet.Wallet) (wallet.Wallet, error)

UpdateWallet updates a wallet in the database.

func (*Store) WalletAddresses

func (s *Store) WalletAddresses(id wallet.ID) (addresses []wallet.Address, err error)

WalletAddresses returns a slice of addresses registered to the wallet.

func (*Store) WalletBalance

func (s *Store) WalletBalance(id wallet.ID) (balance wallet.Balance, err error)

WalletBalance returns the total balance of a wallet.

func (*Store) WalletEvents

func (s *Store) WalletEvents(id wallet.ID, offset, limit int) (events []wallet.Event, err error)

WalletEvents returns the events relevant to a wallet, sorted by height descending.

func (*Store) WalletSiacoinOutputs

func (s *Store) WalletSiacoinOutputs(id wallet.ID, index types.ChainIndex, offset, limit int) (siacoins []types.SiacoinElement, err error)

WalletSiacoinOutputs returns the unspent siacoin outputs for a wallet.

func (*Store) WalletSiafundOutputs

func (s *Store) WalletSiafundOutputs(id wallet.ID, offset, limit int) (siafunds []types.SiafundElement, err error)

WalletSiafundOutputs returns the unspent siafund outputs for a wallet.

func (*Store) WalletUnconfirmedEvents

func (s *Store) WalletUnconfirmedEvents(id wallet.ID, index types.ChainIndex, timestamp time.Time, v1 []types.Transaction, v2 []types.V2Transaction) (annotated []wallet.Event, err error)

WalletUnconfirmedEvents annotates a list of unconfirmed transactions with relevant addresses and siacoin/siafund elements.

func (*Store) Wallets

func (s *Store) Wallets() (wallets []wallet.Wallet, err error)

Wallets returns a map of wallet names to wallet extra data.

Jump to

Keyboard shortcuts

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