tapdb

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 65 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultNumTxRetries is the default number of times we'll retry a
	// transaction if it fails with an error that permits transaction
	// repetition.
	DefaultNumTxRetries = 10

	// DefaultInitialRetryDelay is the default initial delay between
	// retries. This will be used to generate a random delay between -50%
	// and +50% of this value, so 20 to 60 milliseconds. The retry will be
	// doubled after each attempt until we reach DefaultMaxRetryDelay. We
	// start with a random value to avoid multiple goroutines that are
	// created at the same time to effectively retry at the same time.
	DefaultInitialRetryDelay = time.Millisecond * 40

	// DefaultMaxRetryDelay is the default maximum delay between retries.
	DefaultMaxRetryDelay = time.Second * 3
)
View Source
const (
	PostgresTag = "15"
)
View Source
const StatsCacheDuration = time.Minute * 30

StatsCacheDuration is the duration for which the stats cache is valid.

View Source
const Subsystem = "TADB"

Subsystem defines the logging code for this subsystem.

Variables

View Source
var (
	// DefaultPostgresFixtureLifetime is the default maximum time a Postgres
	// test fixture is being kept alive. After that time the docker
	// container will be terminated forcefully, even if the tests aren't
	// fully executed yet. So this time needs to be chosen correctly to be
	// longer than the longest expected individual test run time.
	DefaultPostgresFixtureLifetime = 60 * time.Minute
)
View Source
var (
	// DefaultStoreTimeout is the default timeout used for any interaction
	// with the storage/database.
	DefaultStoreTimeout = time.Second * 10
)
View Source
var ErrAssetMetaNotFound = fmt.Errorf("asset meta not found")

ErrAssetMetaNotFound is returned when an asset meta is not found in the database.

View Source
var (
	// ErrRetriesExceeded is returned when a transaction is retried more
	// than the max allowed valued without a success.
	ErrRetriesExceeded = errors.New("db tx retries exceeded")
)
View Source
var (
	// MaxValidSQLTime is the maximum valid time that can be rendered as a
	// time string and can be used for comparisons in SQL.
	MaxValidSQLTime = time.Date(9999, 12, 31, 23, 59, 59, 999999, time.UTC)
)

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func IsSerializationError added in v0.2.1

func IsSerializationError(err error) bool

IsSerializationError returns true if the given error is a serialization error.

func MapSQLError

func MapSQLError(err error) error

MapSQLError attempts to interpret a given error as a database agnostic SQL error.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type ActiveAssetsStore

type ActiveAssetsStore interface {
	// UpsertAssetStore houses the methods related to inserting/updating
	// assets.
	UpsertAssetStore

	// QueryAssets fetches the set of fully confirmed assets.
	QueryAssets(context.Context, QueryAssetFilters) ([]ConfirmedAsset,
		error)

	// QueryAssetBalancesByAsset queries the balances for assets or
	// alternatively for a selected one that matches the passed asset ID
	// filter.
	QueryAssetBalancesByAsset(context.Context, []byte) ([]RawAssetBalance,
		error)

	// QueryAssetBalancesByGroup queries the asset balances for asset
	// groups or alternatively for a selected one that matches the passed
	// filter.
	QueryAssetBalancesByGroup(context.Context,
		[]byte) ([]RawAssetGroupBalance, error)

	// FetchGroupedAssets fetches all assets with non-nil group keys.
	FetchGroupedAssets(context.Context) ([]RawGroupedAsset, error)

	// FetchAssetProofs fetches all the asset proofs we have stored on
	// disk.
	FetchAssetProofs(ctx context.Context) ([]AssetProof, error)

	// FetchAssetProof fetches the asset proof for a given asset identified
	// by its script key.
	FetchAssetProof(ctx context.Context,
		arg FetchAssetProof) ([]AssetProofI, error)

	// HasAssetProof returns true if we have proof for a given asset
	// identified by its script key.
	HasAssetProof(ctx context.Context, scriptKey []byte) (bool, error)

	// FetchAssetProofsByAssetID fetches all asset proofs for a given asset
	// ID.
	FetchAssetProofsByAssetID(ctx context.Context,
		assetID []byte) ([]AssetProofByIDRow, error)

	// UpsertChainTx inserts a new or updates an existing chain tx into the
	// DB.
	UpsertChainTx(ctx context.Context, arg ChainTxParams) (int64, error)

	// FetchChainTx fetches a chain tx from the DB.
	FetchChainTx(ctx context.Context, txid []byte) (ChainTx, error)

	// UpsertManagedUTXO inserts a new or updates an existing managed UTXO
	// to disk and returns the primary key.
	UpsertManagedUTXO(ctx context.Context, arg RawManagedUTXO) (int64,
		error)

	// UpsertAssetProof inserts a new or updates an existing asset proof on
	// disk.
	UpsertAssetProof(ctx context.Context, arg ProofUpdate) error

	// UpsertAssetProofByID inserts a new or updates an existing asset
	// proof on disk.
	UpsertAssetProofByID(ctx context.Context, arg ProofUpdateByID) error

	// UpsertAssetWitness upserts a new prev input for an asset into the
	// database.
	UpsertAssetWitness(context.Context, PrevInput) error

	// FetchAssetWitnesses attempts to fetch either all the asset witnesses
	// on disk (NULL param), or the witness for a given asset ID.
	FetchAssetWitnesses(context.Context, sql.NullInt64) ([]AssetWitness,
		error)

	// FetchManagedUTXO fetches a managed UTXO based on either the outpoint
	// or the transaction that anchors it.
	FetchManagedUTXO(context.Context, UtxoQuery) (AnchorPoint, error)

	// FetchManagedUTXOs fetches all managed UTXOs.
	FetchManagedUTXOs(context.Context) ([]ManagedUTXORow, error)

	// ApplyPendingOutput applies a transfer output (new amount and script
	// key) based on the existing script key of an asset.
	ApplyPendingOutput(ctx context.Context, arg ApplyPendingOutput) (int64,
		error)

	// DeleteManagedUTXO deletes the managed utxo identified by the passed
	// serialized outpoint.
	DeleteManagedUTXO(ctx context.Context, outpoint []byte) error

	// UpdateUTXOLease leases a managed UTXO identified by the passed
	// serialized outpoint.
	UpdateUTXOLease(ctx context.Context, arg UpdateUTXOLease) error

	// DeleteUTXOLease deletes the lease on a managed UTXO identified by
	// the passed serialized outpoint.
	DeleteUTXOLease(ctx context.Context, outpoint []byte) error

	// DeleteExpiredUTXOLeases deletes all expired UTXO leases.
	DeleteExpiredUTXOLeases(ctx context.Context, now sql.NullTime) error

	// ConfirmChainAnchorTx marks a new anchor transaction that was
	// previously unconfirmed as confirmed.
	ConfirmChainAnchorTx(ctx context.Context, arg AnchorTxConf) error

	// InsertAssetTransfer inserts a new asset transfer into the DB.
	InsertAssetTransfer(ctx context.Context,
		arg NewAssetTransfer) (int64, error)

	// InsertAssetTransferInput inserts a new asset transfer input into the
	// DB.
	InsertAssetTransferInput(ctx context.Context,
		arg NewTransferInput) error

	// InsertAssetTransferOutput inserts a new asset transfer output into
	// the DB.
	InsertAssetTransferOutput(ctx context.Context,
		arg NewTransferOutput) error

	// FetchTransferInputs fetches the inputs to a given asset transfer.
	FetchTransferInputs(ctx context.Context,
		transferID int64) ([]TransferInputRow, error)

	// FetchTransferOutputs fetches the outputs to a given asset transfer.
	FetchTransferOutputs(ctx context.Context,
		transferID int64) ([]TransferOutputRow, error)

	// QueryAssetTransfers queries for a set of asset transfers in the db.
	QueryAssetTransfers(ctx context.Context,
		query sqlc.QueryAssetTransfersParams) ([]AssetTransferRow,
		error)

	// DeleteAssetWitnesses deletes the witnesses on disk associated with a
	// given asset ID.
	DeleteAssetWitnesses(ctx context.Context, assetID int64) error

	// LogProofTransferAttempt logs a new proof transfer attempt.
	LogProofTransferAttempt(ctx context.Context,
		arg LogProofTransAttemptParams) error

	// QueryProofTransferAttempts returns timestamps from the proof transfer
	// attempts log.
	QueryProofTransferAttempts(ctx context.Context,
		arg QueryProofTransAttemptsParams) ([]time.Time, error)

	// InsertPassiveAsset inserts a new row which includes the data
	// necessary to re-anchor a passive asset.
	InsertPassiveAsset(ctx context.Context, arg NewPassiveAsset) error

	// QueryPassiveAssets returns the data required to re-anchor
	// pending passive assets that are anchored at the given outpoint.
	QueryPassiveAssets(ctx context.Context,
		transferID int64) ([]PassiveAsset, error)

	// ReAnchorPassiveAssets re-anchors the passive assets identified by
	// the passed params.
	ReAnchorPassiveAssets(ctx context.Context, arg ReAnchorParams) error

	// FetchAssetMetaByHash fetches the asset meta for a given meta hash.
	//
	// TODO(roasbeef): split into MetaStore?
	FetchAssetMetaByHash(ctx context.Context,
		metaDataHash []byte) (sqlc.FetchAssetMetaByHashRow, error)

	// FetchAssetMetaForAsset fetches the asset meta for a given asset.
	FetchAssetMetaForAsset(ctx context.Context,
		assetID []byte) (sqlc.FetchAssetMetaForAssetRow, error)
}

ActiveAssetsStore is a sub-set of the main sqlc.Querier interface that contains methods related to querying the set of confirmed assets.

type AddrBook

type AddrBook interface {
	// UpsertAssetStore houses the methods related to inserting/updating
	// assets.
	UpsertAssetStore

	// GroupStore houses the methods related to fetching genesis assets and
	// asset groups related to them.
	GroupStore

	// FetchAddrs returns all the addresses based on the constraints of the
	// passed AddrQuery.
	FetchAddrs(ctx context.Context, arg AddrQuery) ([]Addresses, error)

	// FetchAddrByTaprootOutputKey returns a single address based on its
	// Taproot output key or a sql.ErrNoRows error if no such address
	// exists.
	FetchAddrByTaprootOutputKey(ctx context.Context,
		arg []byte) (AddrByTaprootOutput, error)

	// InsertAddr inserts a new address into the database.
	InsertAddr(ctx context.Context, arg NewAddr) (int64, error)

	// UpsertInternalKey inserts a new or updates an existing internal key
	// into the database and returns the primary key.
	UpsertInternalKey(ctx context.Context, arg InternalKey) (int64, error)

	// UpsertScriptKey inserts a new script key on disk into the DB.
	UpsertScriptKey(context.Context, NewScriptKey) (int64, error)

	// SetAddrManaged sets an address as being managed by the internal
	// wallet.
	SetAddrManaged(ctx context.Context, arg AddrManaged) error

	// UpsertManagedUTXO inserts a new or updates an existing managed UTXO
	// to disk and returns the primary key.
	UpsertManagedUTXO(ctx context.Context, arg RawManagedUTXO) (int64,
		error)

	// UpsertChainTx inserts a new or updates an existing chain tx into the
	// DB.
	UpsertChainTx(ctx context.Context, arg ChainTxParams) (int64, error)

	// UpsertAddrEvent inserts a new or updates an existing address event
	// and returns the primary key.
	UpsertAddrEvent(ctx context.Context, arg UpsertAddrEvent) (int64, error)

	// FetchAddrEvent returns a single address event based on its primary
	// key.
	FetchAddrEvent(ctx context.Context, id int64) (AddrEvent, error)

	// QueryEventIDs returns a list of event IDs and their corresponding
	// address IDs that match the given query parameters.
	QueryEventIDs(ctx context.Context, query AddrEventQuery) ([]AddrEventID,
		error)

	// FetchAssetProof fetches the asset proof for a given asset identified
	// by its script key.
	FetchAssetProof(ctx context.Context,
		arg FetchAssetProof) ([]AssetProofI, error)

	// FetchGenesisByAssetID attempts to fetch asset genesis information
	// for a given asset ID.
	FetchGenesisByAssetID(ctx context.Context,
		assetID []byte) (sqlc.GenesisInfoView, error)

	// FetchScriptKeyByTweakedKey attempts to fetch the script key and
	// corresponding internal key from the database.
	FetchScriptKeyByTweakedKey(ctx context.Context,
		tweakedScriptKey []byte) (ScriptKey, error)
}

AddrBook is an interface that represents the storage backed needed to create the TapAddressBook book. We need to be able to insert/fetch addresses, and also make internal keys since each address has an internal key and a script key (tho they can be the same).

type AddrBookTxOptions

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

AddrBookTxOptions defines the set of db txn options the AddrBook understands.

func (*AddrBookTxOptions) ReadOnly

func (a *AddrBookTxOptions) ReadOnly() bool

ReadOnly returns true if the transaction should be read only.

NOTE: This implements the TxOptions

type AddrByTaprootOutput

type AddrByTaprootOutput = sqlc.FetchAddrByTaprootOutputKeyRow

AddrByTaprootOutput is a type alias for returning an address by its Taproot output key.

type AddrEvent

type AddrEvent = sqlc.FetchAddrEventRow

AddrEvent is a type alias for fetching an address event row.

type AddrEventID

type AddrEventID = sqlc.QueryEventIDsRow

AddrEventID is a type alias for fetching the ID of an address event and its corresponding address.

type AddrEventQuery

type AddrEventQuery = sqlc.QueryEventIDsParams

AddrEventQuery is a type alias for a query into the set of known address events.

type AddrManaged

type AddrManaged = sqlc.SetAddrManagedParams

AddrManaged is a type alias for setting an address as managed.

type AddrQuery

type AddrQuery = sqlc.FetchAddrsParams

AddrQuery as a type alias for a query into the set of known addresses.

type Addresses

type Addresses = sqlc.FetchAddrsRow

Addresses is a type alias for the full address row with key locator information.

type AggregateStats

type AggregateStats = sqlc.QueryUniverseStatsRow

AggregateStats is used to return the aggregate stats for the entire Universe.

type AnchorPoint

type AnchorPoint = sqlc.FetchManagedUTXORow

AnchorPoint wraps a managed UTXO along with all the auxiliary information it references.

type AnchorTxConf

type AnchorTxConf = sqlc.ConfirmChainAnchorTxParams

AnchorTxConf identifies an unconfirmed anchor tx to confirm.

type ApplyPendingOutput

type ApplyPendingOutput = sqlc.ApplyPendingOutputParams

ApplyPendingOutput is used to update the script key and amount of an existing asset.

type AssetAnchor

type AssetAnchor = sqlc.AnchorPendingAssetsParams

AssetAnchor is used to bind assets on disk with the transaction that will create them on-chain.

type AssetBalance

type AssetBalance struct {
	ID           asset.ID
	Version      int32
	Balance      uint64
	Tag          string
	MetaHash     [asset.MetaHashLen]byte
	Type         asset.Type
	GenesisPoint wire.OutPoint
	OutputIndex  uint32
}

AssetBalance holds a balance query result for a particular asset or all assets tracked by this daemon.

type AssetGroupBalance

type AssetGroupBalance struct {
	GroupKey *btcec.PublicKey
	Balance  uint64
}

AssetGroupBalance holds abalance query result for a particular asset group or all asset groups tracked by this daemon.

type AssetGroupKey

type AssetGroupKey = sqlc.UpsertAssetGroupKeyParams

AssetGroupKey is used to insert a new asset key group into the DB.

type AssetGroupWitness added in v0.3.0

type AssetGroupWitness = sqlc.UpsertAssetGroupWitnessParams

AssetGroupWitness is used to insert the group key witness for a given asset on disk.

type AssetHumanReadable

type AssetHumanReadable struct {
	// ID is the unique identifier for the asset.
	ID asset.ID

	// Version is the version of the asset.
	Version asset.Version

	// Amount is the number of units represented by the asset.
	Amount uint64

	// LockTime, if non-zero, restricts an asset from being moved prior to
	// the represented block height in the chain.
	LockTime uint64

	// RelativeLockTime, if non-zero, restricts an asset from being moved
	// until a number of blocks after the confirmation height of the latest
	// transaction for the asset is reached.
	RelativeLockTime uint64

	// Tag is the human-readable identifier for the asset.
	Tag string

	// MetaHash is the hash of the meta data for this asset.
	MetaHash [asset.MetaHashLen]byte

	// Type uniquely identifies the type of Taproot asset.
	Type asset.Type

	// GroupKey is the tweaked public key that is used to associate assets
	// together across distinct asset IDs.
	GroupKey *btcec.PublicKey
}

AssetHumanReadable is a subset of the base asset struct that only includes human-readable asset fields.

type AssetMintingStore

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

AssetMintingStore is an implementation of the tapgarden.PlantingLog interface backed by a persistent database. The abstracted BatchedPendingAssetStore permits re-use of the main storage related business logic for any backend that can implement the specified interface.

func NewAssetMintingStore

func NewAssetMintingStore(db BatchedPendingAssetStore) *AssetMintingStore

NewAssetMintingStore creates a new AssetMintingStore from the specified BatchedPendingAssetStore interface.

func (*AssetMintingStore) AddSeedlingsToBatch

func (a *AssetMintingStore) AddSeedlingsToBatch(ctx context.Context,
	batchKey *btcec.PublicKey, seedlings ...*tapgarden.Seedling) error

AddSeedlingsToBatch adds a new set of seedlings to an existing batch.

func (*AssetMintingStore) AddSproutsToBatch

func (a *AssetMintingStore) AddSproutsToBatch(ctx context.Context,
	batchKey *btcec.PublicKey, genesisPacket *tapgarden.FundedPsbt,
	assetRoot *commitment.TapCommitment) error

AddSproutsToBatch updates a batch with the passed batch transaction and also binds the genesis transaction (which will create the set of assets in the batch) to the batch itself.

func (*AssetMintingStore) CommitMintingBatch

func (a *AssetMintingStore) CommitMintingBatch(ctx context.Context,
	newBatch *tapgarden.MintingBatch) error

CommitMintingBatch commits a new minting batch to disk along with any seedlings specified as part of the batch. A new internal key is also created, with the batch referencing that internal key. This internal key will be used as the internal key which will mint all the assets in the batch.

func (*AssetMintingStore) CommitSignedGenesisTx

func (a *AssetMintingStore) CommitSignedGenesisTx(ctx context.Context,
	batchKey *btcec.PublicKey, genesisPkt *tapgarden.FundedPsbt,
	anchorOutputIndex uint32, merkleRoot []byte) error

CommitSignedGenesisTx binds a fully signed genesis transaction to a pending batch on disk. The anchor output index and script root are also stored to ensure we can reconstruct the private key needed to sign for the batch. The genesis transaction itself is inserted as a new chain transaction, which all other components then reference.

TODO(roasbeef): or could just re-read assets from disk and set the script root manually?

func (*AssetMintingStore) FetchAllBatches

func (a *AssetMintingStore) FetchAllBatches(
	ctx context.Context) ([]*tapgarden.MintingBatch, error)

FetchAllBatches fetches all batches on disk.

func (*AssetMintingStore) FetchGroupByGenesis

func (a *AssetMintingStore) FetchGroupByGenesis(ctx context.Context,
	genesisID int64) (*asset.AssetGroup, error)

FetchGroupByGenesis fetches the asset group created by the genesis referenced by the given ID.

func (*AssetMintingStore) FetchGroupByGroupKey

func (a *AssetMintingStore) FetchGroupByGroupKey(ctx context.Context,
	groupKey *btcec.PublicKey) (*asset.AssetGroup, error)

FetchGroupByGroupKey fetches the asset group with a matching tweaked key, including the genesis information used to create the group.

func (*AssetMintingStore) FetchMintingBatch

func (a *AssetMintingStore) FetchMintingBatch(ctx context.Context,
	batchKey *btcec.PublicKey) (*tapgarden.MintingBatch, error)

FetchMintingBatch fetches the single batch with the given batch key.

func (*AssetMintingStore) FetchNonFinalBatches

func (a *AssetMintingStore) FetchNonFinalBatches(
	ctx context.Context) ([]*tapgarden.MintingBatch, error)

FetchNonFinalBatches fetches all the batches that aren't fully finalized on disk.

func (*AssetMintingStore) MarkBatchConfirmed

func (a *AssetMintingStore) MarkBatchConfirmed(ctx context.Context,
	batchKey *btcec.PublicKey, blockHash *chainhash.Hash,
	blockHeight uint32, txIndex uint32,
	mintingProofs proof.AssetBlobs) error

MarkBatchConfirmed stores final confirmation information for a batch on disk.

func (*AssetMintingStore) UpdateBatchState

func (a *AssetMintingStore) UpdateBatchState(ctx context.Context,
	batchKey *btcec.PublicKey, newState tapgarden.BatchState) error

UpdateBatchState updates the state of a batch based on the batch key.

type AssetProof

type AssetProof = sqlc.FetchAssetProofsRow

AssetProof is the asset proof for a given asset, identified by its script key.

type AssetProofByIDRow added in v0.3.0

type AssetProofByIDRow = sqlc.FetchAssetProofsByAssetIDRow

AssetProofByIDRow is the asset proof for a given asset, identified by its asset ID.

type AssetProofI

type AssetProofI = sqlc.FetchAssetProofRow

AssetProofI is identical to AssetProof but is used for the case where the proofs for a specific asset are fetched.

type AssetQueryFilters

type AssetQueryFilters struct {
	tapfreighter.CommitmentConstraints

	// MinAnchorHeight is the minimum block height the asset's anchor tx
	// must have been confirmed at.
	MinAnchorHeight int32
}

AssetQueryFilters is a wrapper struct over the CommitmentConstraints struct which lets us filter the results of the set of assets returned.

type AssetSeedling

type AssetSeedling = sqlc.AssetSeedling

AssetSeedling is an asset seedling.

type AssetSeedlingItem

type AssetSeedlingItem = sqlc.InsertAssetSeedlingIntoBatchParams

AssetSeedlingItem is used to insert a seedling into an asset based on the batch key of the batch.

type AssetSeedlingShell

type AssetSeedlingShell = sqlc.InsertAssetSeedlingParams

AssetSeedlingShell holds the components of a seedling asset.

type AssetSeedlingTuple

type AssetSeedlingTuple = sqlc.FetchSeedlingIDParams

AssetSeedlingTuple is used to look up the ID of a seedling.

type AssetSprout

type AssetSprout = sqlc.FetchAssetsForBatchRow

AssetSprout is used to fetch the set of assets from disk.

type AssetStatsPerDay added in v0.2.3

type AssetStatsPerDay = sqlc.QueryAssetStatsPerDaySqliteRow

AssetStatsPerDay is the assets stats record for a given day.

type AssetStatsPerDayPg added in v0.2.3

type AssetStatsPerDayPg = sqlc.QueryAssetStatsPerDayPostgresRow

AssetStatsPerDayPg is the assets stats record for a given day (for Postgres).

type AssetStatsPerDayQuery added in v0.2.3

type AssetStatsPerDayQuery = sqlc.QueryAssetStatsPerDaySqliteParams

AssetStatsPerDayQuery is the query used to fetch the asset stats for a given day.

type AssetStatsPerDayQueryPg added in v0.2.3

type AssetStatsPerDayQueryPg = sqlc.QueryAssetStatsPerDayPostgresParams

AssetStatsPerDayQueryPg is the query used to fetch the asset stats for a given day (for Postgres).

type AssetStore

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

AssetStore is used to query for the set of pending and confirmed assets.

func NewAssetStore

func NewAssetStore(db BatchedAssetStore, clock clock.Clock) *AssetStore

NewAssetStore creates a new AssetStore from the specified BatchedAssetStore interface.

func (*AssetStore) ConfirmParcelDelivery

func (a *AssetStore) ConfirmParcelDelivery(ctx context.Context,
	conf *tapfreighter.AssetConfirmEvent) error

ConfirmParcelDelivery marks a spend event on disk as confirmed. This updates the on-chain reference information on disk to point to this new spend.

func (*AssetStore) DeleteExpiredLeases added in v0.3.0

func (a *AssetStore) DeleteExpiredLeases(ctx context.Context) error

DeleteExpiredLeases deletes all expired leases from the database.

func (*AssetStore) FetchAllAssets

func (a *AssetStore) FetchAllAssets(ctx context.Context, includeSpent,
	includeLeased bool, query *AssetQueryFilters) ([]*asset.ChainAsset,
	error)

FetchAllAssets fetches the set of confirmed assets stored on disk.

func (*AssetStore) FetchAssetMetaByHash

func (a *AssetStore) FetchAssetMetaByHash(ctx context.Context,
	metaHash [asset.MetaHashLen]byte) (*proof.MetaReveal, error)

FetchAssetMetaByHash attempts to fetch an asset meta based on an asset hash.

func (*AssetStore) FetchAssetMetaForAsset

func (a *AssetStore) FetchAssetMetaForAsset(ctx context.Context,
	assetID asset.ID) (*proof.MetaReveal, error)

FetchAssetMetaForAsset attempts to fetch an asset meta based on an asset ID.

func (*AssetStore) FetchAssetProofs

func (a *AssetStore) FetchAssetProofs(ctx context.Context,
	targetAssets ...proof.Locator) (proof.AssetBlobs, error)

FetchAssetProofs returns the latest proof file for either the set of target assets, or all assets if no script keys for an asset are passed in.

TODO(roasbeef): potentially have a version that writes thru a reader instead?

func (*AssetStore) FetchCommitment

func (a *AssetStore) FetchCommitment(ctx context.Context, id asset.ID,
	anchorPoint wire.OutPoint, groupKey *asset.GroupKey,
	scriptKey *asset.ScriptKey,
	mustBeLeased bool) (*tapfreighter.AnchoredCommitment, error)

FetchCommitment returns a specific commitment identified by the given asset parameters. If no commitment is found, ErrNoCommitment is returned. With mustBeLeased the caller decides whether the asset output should've been leased before or not. If mustBeLeased is false, then the state of the lease is not checked.

func (*AssetStore) FetchGroupedAssets

func (a *AssetStore) FetchGroupedAssets(ctx context.Context) (
	[]*AssetHumanReadable, error)

FetchGroupedAssets fetches the set of assets with non-nil group keys.

func (*AssetStore) FetchManagedUTXOs

func (a *AssetStore) FetchManagedUTXOs(ctx context.Context) (
	[]*ManagedUTXO, error)

FetchManagedUTXOs fetches all UTXOs we manage.

func (*AssetStore) FetchProof

func (a *AssetStore) FetchProof(ctx context.Context,
	locator proof.Locator) (proof.Blob, error)

FetchProof fetches a proof for an asset uniquely identified by the passed ProofIdentifier.

If a proof cannot be found, then ErrProofNotFound should be returned. If multiple proofs exist for the given fields of the locator then ErrMultipleProofs is returned to indicate more specific fields need to be set in the Locator (e.g. the OutPoint).

NOTE: This implements the proof.Archiver interface.

func (*AssetStore) FetchProofs added in v0.3.0

func (a *AssetStore) FetchProofs(ctx context.Context,
	id asset.ID) ([]*proof.AnnotatedProof, error)

FetchProofs fetches all proofs for assets uniquely identified by the passed asset ID.

NOTE: This implements the proof.Archiver interface.

func (*AssetStore) HasProof added in v0.3.3

func (a *AssetStore) HasProof(ctx context.Context, locator proof.Locator) (bool,
	error)

HasProof returns true if the proof for the given locator exists. This is intended to be a performance optimized lookup compared to fetching a proof and checking for ErrProofNotFound.

func (*AssetStore) ImportProofs

func (a *AssetStore) ImportProofs(ctx context.Context, _ proof.HeaderVerifier,
	_ proof.GroupVerifier, replace bool,
	proofs ...*proof.AnnotatedProof) error

ImportProofs attempts to store fully populated proofs on disk. The previous outpoint of the first state transition will be used as the Genesis point. The final resting place of the asset will be used as the script key itself.

NOTE: This implements the proof.ArchiveBackend interface.

func (*AssetStore) LeaseCoins added in v0.3.0

func (a *AssetStore) LeaseCoins(ctx context.Context, leaseOwner [32]byte,
	expiry time.Time, utxoOutpoints ...wire.OutPoint) error

LeaseCoins leases/locks/reserves coins for the given lease owner until the given expiry. This is used to prevent multiple concurrent coin selection attempts from selecting the same coin(s).

func (*AssetStore) ListEligibleCoins

func (a *AssetStore) ListEligibleCoins(ctx context.Context,
	constraints tapfreighter.CommitmentConstraints) (
	[]*tapfreighter.AnchoredCommitment, error)

ListEligibleCoins lists eligible commitments given a set of constraints.

NOTE: This implements the tapfreighter.CoinLister interface.

func (*AssetStore) LogPendingParcel

func (a *AssetStore) LogPendingParcel(ctx context.Context,
	spend *tapfreighter.OutboundParcel, finalLeaseOwner [32]byte,
	finalLeaseExpiry time.Time) error

LogPendingParcel marks an outbound parcel as pending on disk. This commits the set of changes to disk (the pending inputs and outputs) but doesn't mark the batched spend as being finalized. The final lease owner and expiry are the lease parameters that are set on the input UTXOs, since we assume the parcel will be broadcast after this call. So we'll want to lock the input UTXOs for forever, which means the expiry should be far in the future.

func (*AssetStore) LogProofTransferAttempt added in v0.3.1

func (a *AssetStore) LogProofTransferAttempt(ctx context.Context,
	locator proof.Locator, transferType proof.TransferType) error

LogProofTransferAttempt logs a proof delivery attempt to disk.

func (*AssetStore) PendingParcels

func (a *AssetStore) PendingParcels(
	ctx context.Context) ([]*tapfreighter.OutboundParcel, error)

PendingParcels returns the set of parcels that haven't yet been finalized. This can be used to query the set of unconfirmed transactions for re-broadcast.

func (*AssetStore) QueryAssetBalancesByGroup

func (a *AssetStore) QueryAssetBalancesByGroup(ctx context.Context,
	groupKey *btcec.PublicKey) (map[asset.SerializedKey]AssetGroupBalance,
	error)

QueryAssetBalancesByGroup queries the asset balances for asset groups or alternatively for a selected one that matches the passed filter.

func (*AssetStore) QueryBalancesByAsset

func (a *AssetStore) QueryBalancesByAsset(ctx context.Context,
	assetID *asset.ID) (map[asset.ID]AssetBalance, error)

QueryBalancesByAsset queries the balances for assets or alternatively for a selected one that matches the passed asset ID filter.

func (*AssetStore) QueryParcels

func (a *AssetStore) QueryParcels(ctx context.Context,
	pending bool) ([]*tapfreighter.OutboundParcel, error)

QueryParcels returns the set of confirmed or unconfirmed parcels.

func (*AssetStore) QueryProofTransferLog added in v0.3.1

func (a *AssetStore) QueryProofTransferLog(ctx context.Context,
	locator proof.Locator,
	transferType proof.TransferType) ([]time.Time, error)

QueryProofTransferLog returns timestamps which correspond to logged proof transfer attempts.

func (*AssetStore) RegisterSubscriber

func (a *AssetStore) RegisterSubscriber(
	receiver *fn.EventReceiver[proof.Blob],
	deliverExisting bool, deliverFrom []*proof.Locator) error

RegisterSubscriber adds a new subscriber for receiving events. The deliverExisting boolean indicates whether already existing items should be sent to the NewItemCreated channel when the subscription is started. An optional deliverFrom can be specified to indicate from which timestamp/index/ marker onward existing items should be delivered on startup. If deliverFrom is nil/zero/empty then all existing items will be delivered.

func (*AssetStore) ReleaseCoins added in v0.3.0

func (a *AssetStore) ReleaseCoins(ctx context.Context,
	utxoOutpoints ...wire.OutPoint) error

ReleaseCoins releases/unlocks coins that were previously leased and makes them available for coin selection again.

func (*AssetStore) RemoveSubscriber

func (a *AssetStore) RemoveSubscriber(
	subscriber *fn.EventReceiver[proof.Blob]) error

RemoveSubscriber removes the given subscriber and also stops it from processing events.

type AssetStoreTxOptions

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

AssetStoreTxOptions defines the set of db txn options the PendingAssetStore understands.

func NewAddrBookReadTx

func NewAddrBookReadTx() AssetStoreTxOptions

NewAddrBookReadTx creates a new read transaction option set.

func NewAssetStoreReadTx

func NewAssetStoreReadTx() AssetStoreTxOptions

NewAssetStoreReadTx creates a new read transaction option set.

func (*AssetStoreTxOptions) ReadOnly

func (r *AssetStoreTxOptions) ReadOnly() bool

ReadOnly returns true if the transaction should be read only.

NOTE: This implements the TxOptions

type AssetTransfer

type AssetTransfer = sqlc.AssetTransfer

AssetTransfer tracks an asset transfer.

type AssetTransferRow

type AssetTransferRow = sqlc.QueryAssetTransfersRow

AssetTransferRow wraps a single transfer row.

type AssetWitness

type AssetWitness = sqlc.FetchAssetWitnessesRow

AssetWitness is the full prev input for an asset that also couples along the asset ID that the witness belong to.

type BaseDB

type BaseDB struct {
	*sql.DB

	*sqlc.Queries
}

BaseDB is the base database struct that each implementation can embed to gain some common functionality.

func (*BaseDB) Backend added in v0.2.3

func (s *BaseDB) Backend() sqlc.BackendType

Backend returns the type of the database backend used.

func (*BaseDB) BeginTx

func (s *BaseDB) BeginTx(ctx context.Context, opts TxOptions) (*sql.Tx, error)

BeginTx wraps the normal sql specific BeginTx method with the TxOptions interface. This interface is then mapped to the concrete sql tx options struct.

type BaseMultiverseOptions added in v0.3.0

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

BaseMultiverseOptions is the set of options for multiverse queries.

func NewBaseMultiverseReadTx added in v0.3.0

func NewBaseMultiverseReadTx() BaseMultiverseOptions

NewBaseMultiverseReadTx creates a new read-only transaction for the multiverse.

func (*BaseMultiverseOptions) ReadOnly added in v0.3.0

func (b *BaseMultiverseOptions) ReadOnly() bool

ReadOnly returns true if the transaction is read-only.

type BaseMultiverseStore added in v0.3.0

type BaseMultiverseStore interface {
	BaseUniverseStore

	UniverseRoots(ctx context.Context,
		params UniverseRootsParams) ([]BaseUniverseRoot, error)
}

BaseMultiverseStore is used to interact with a set of base universe roots, also known as a multiverse.

type BaseUniverseRoot

type BaseUniverseRoot = sqlc.UniverseRootsRow

type BaseUniverseStore

type BaseUniverseStore interface {
	UpsertAssetStore

	TreeStore

	FetchGenesisStore

	GroupStore

	// QueryUniverseLeaves is used to query for the set of leaves that
	// reside in a universe tree.
	QueryUniverseLeaves(ctx context.Context,
		arg UniverseLeafQuery) ([]UniverseLeaf, error)

	// DeleteUniverseLeaves is used to delete leaves that reside in a
	// universe tree.
	DeleteUniverseLeaves(ctx context.Context, namespace string) error

	// DeleteUniverseRoot is used to delete the root of a universe tree.
	DeleteUniverseRoot(ctx context.Context, namespace string) error

	// DeleteUniverseEvents is used to delete a universe sync event.
	DeleteUniverseEvents(ctx context.Context, namespace string) error

	// FetchUniverseRoot fetches the root of a universe based on the
	// namespace key, which is a function of the asset ID and the group
	// key.
	FetchUniverseRoot(ctx context.Context,
		namespace string) (UniverseRoot, error)

	// UpsertUniverseLeaf upserts a Universe leaf in the database.
	UpsertUniverseLeaf(ctx context.Context, arg UpsertUniverseLeaf) error

	// UpsertUniverseRoot attempts to insert a universe root, returning the
	// existing primary key of the root if already exists.
	UpsertUniverseRoot(ctx context.Context, arg NewUniverseRoot) (int64,
		error)

	// FetchUniverseKeys fetches the set of keys that are currently stored
	// for a given namespace.
	FetchUniverseKeys(ctx context.Context,
		arg UniverseLeafKeysQuery) ([]UniverseKeys, error)
}

BaseUniverseStore is the main interface for the Taproot Asset universe store. This is a composite of the capabilities to insert new asset genesis, update the SMT tree, and finally fetch a genesis. We then combine that with Universe specific information to implement all the required interaction.

type BaseUniverseStoreOptions

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

BaseUniverseStoreOptions is the set of options for universe tree queries.

func NewBaseUniverseReadTx

func NewBaseUniverseReadTx() BaseUniverseStoreOptions

NewBaseUniverseReadTx creates a new read-only transaction for the base universe.

func (*BaseUniverseStoreOptions) ReadOnly

func (b *BaseUniverseStoreOptions) ReadOnly() bool

ReadOnly returns true if the transaction is read-only.

type BaseUniverseTree

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

BaseUniverseTree implements the persistent storage for the Base universe for a given asset. The minting outpoints stored of the asset are used to key into the universe tree.

NOTE: This implements the universe.Base interface.

func NewBaseUniverseTree

func NewBaseUniverseTree(db BatchedUniverseTree,
	id universe.Identifier) *BaseUniverseTree

NewBaseUniverseTree creates a new base Universe tree.

func (*BaseUniverseTree) DeleteUniverse added in v0.2.1

func (b *BaseUniverseTree) DeleteUniverse(ctx context.Context) (string, error)

DeleteUniverse deletes the entire universe tree.

func (*BaseUniverseTree) FetchIssuanceProof

func (b *BaseUniverseTree) FetchIssuanceProof(ctx context.Context,
	universeKey universe.LeafKey) ([]*universe.Proof, error)

FetchIssuanceProof returns an issuance proof for the target key. If the key doesn't have a script key specified, then all the proofs for the minting outpoint will be returned. If neither are specified, then proofs for all the inserted leaves will be returned.

func (*BaseUniverseTree) MintingKeys

MintingKeys returns all the keys inserted in the universe.

func (*BaseUniverseTree) MintingLeaves

func (b *BaseUniverseTree) MintingLeaves(
	ctx context.Context) ([]universe.Leaf, error)

MintingLeaves returns all the minting leaves inserted into the universe.

func (*BaseUniverseTree) RegisterIssuance

func (b *BaseUniverseTree) RegisterIssuance(ctx context.Context,
	key universe.LeafKey, leaf *universe.Leaf,
	metaReveal *proof.MetaReveal) (*universe.Proof, error)

RegisterIssuance inserts a new minting leaf within the universe tree, stored at the base key.

func (*BaseUniverseTree) RootNode

func (b *BaseUniverseTree) RootNode(ctx context.Context) (mssmt.Node, string,
	error)

RootNode returns the root node of a universe tree.

type BatchChainUpdate

type BatchChainUpdate = sqlc.BindMintingBatchWithTxParams

BatchChainUpdate is used to update a batch with the minting transaction associated with it.

type BatchStateUpdate

type BatchStateUpdate = sqlc.UpdateMintingBatchStateParams

BatchStateUpdate holds the arguments to update the state of a batch.

type BatchedAddrBook

type BatchedAddrBook interface {
	AddrBook

	BatchedTx[AddrBook]
}

BatchedAddrBook is a version of the AddrBook that's capable of batched database operations.

type BatchedAssetStore

type BatchedAssetStore interface {
	ActiveAssetsStore

	BatchedTx[ActiveAssetsStore]
}

BatchedAssetStore combines the AssetStore interface with the BatchedTx interface, allowing for multiple queries to be executed in a single SQL transaction.

type BatchedKeyStore

type BatchedKeyStore interface {
	KeyStore

	// BatchedTx parametrizes the BatchedTx generic interface w/ KeyStore,
	// which allows us to perform operations to the key store in an atomic
	// transaction. Also add in the TxOptions interface which our defined
	// KeyStoreTxOptions satisfies.
	BatchedTx[KeyStore]
}

BatchedKeyStore is the main storage interface for the RootKeyStore. It supports all the basic queries as well as running the set of queries in a single database transaction.

TODO(roasbeef) use type params here to use slimmer interface instead of sqlc.Querier?

type BatchedMultiverse added in v0.3.0

type BatchedMultiverse interface {
	BaseMultiverseStore

	BatchedTx[BaseMultiverseStore]
}

BatchedMultiverse is a wrapper around the base multiverse that allows us to perform batch transactional database queries with all the relevant query interfaces.

type BatchedPendingAssetStore

type BatchedPendingAssetStore interface {
	PendingAssetStore

	BatchedTx[PendingAssetStore]
}

BatchedPendingAssetStore combines the PendingAssetStore interface with the BatchedTx interface, allowing for multiple queries to be executed in a single SQL transaction.

type BatchedQuerier

type BatchedQuerier interface {
	// Querier is the underlying query source, this is in place so we can
	// pass a BatchedQuerier implementation directly into objects that
	// create a batched version of the normal methods they need.
	sqlc.Querier

	// BeginTx creates a new database transaction given the set of
	// transaction options.
	BeginTx(ctx context.Context, options TxOptions) (*sql.Tx, error)

	// Backend returns the type of the database backend used.
	Backend() sqlc.BackendType
}

BatchedQuerier is a generic interface that allows callers to create a new database transaction based on an abstract type that implements the TxOptions interface.

type BatchedTreeStore

type BatchedTreeStore interface {
	TreeStore

	BatchedTx[TreeStore]
}

BatchedTreeStore is a version of the AddrBook that's capable of batched database operations.

type BatchedTx

type BatchedTx[Q any] interface {
	// ExecTx will execute the passed txBody, operating upon generic
	// parameter Q (usually a storage interface) in a single transaction.
	// The set of TxOptions are passed in in order to allow the caller to
	// specify if a transaction should be read-only and optionally what
	// type of concurrency control should be used.
	ExecTx(ctx context.Context, txOptions TxOptions,
		txBody func(Q) error) error

	// Backend returns the type of the database backend used.
	Backend() sqlc.BackendType
}

BatchedTx is a generic interface that represents the ability to execute several operations to a given storage interface in a single atomic transaction. Typically, Q here will be some subset of the main sqlc.Querier interface allowing it to only depend on the routines it needs to implement any additional business logic.

type BatchedUniverseServerStore

type BatchedUniverseServerStore interface {
	UniverseServerStore

	BatchedTx[UniverseServerStore]
}

BatchedUniverseServerStore allows for batched DB transactions for the universe server store.

type BatchedUniverseStats

type BatchedUniverseStats interface {
	UniverseStatsStore

	BatchedTx[UniverseStatsStore]
}

BatchedUniverseStats is a wrapper around the set of UniverseSyncEvents that supports batched DB operations.

type BatchedUniverseTree

type BatchedUniverseTree interface {
	BaseUniverseStore

	BatchedTx[BaseUniverseStore]
}

BatchedUniverseTree is a wrapper around the base universe tree that allows us to perform batch queries with all the relevant query interfaces.

type ChainTx

type ChainTx = sqlc.ChainTxn

ChainTx is used to fetch a chain tx from disk.

type ChainTxConf

type ChainTxConf = sqlc.ConfirmChainTxParams

ChainTxConf is used to mark a chain tx as being confirmed.

type ChainTxParams

type ChainTxParams = sqlc.UpsertChainTxParams

ChainTxParams is used to insert a new chain tx on disk.

type ChildQuery

type ChildQuery = sqlc.FetchChildrenParams

ChildQuery wraps the args we need to fetch the children of a node.

type ConfirmedAsset

type ConfirmedAsset = sqlc.QueryAssetsRow

ConfirmedAsset is an asset that has been fully confirmed on chain.

type DelNode

type DelNode = sqlc.DeleteNodeParams

DelNode wraps the args we need to delete a node.

type DelUniverseServer

type DelUniverseServer = sqlc.DeleteUniverseServerParams

DelUniverseServer is used to delete a universe server.

type DeleteFedProofSyncLogParams added in v0.3.3

type DeleteFedProofSyncLogParams = sqlc.DeleteFederationProofSyncLogParams

DeleteFedProofSyncLogParams is used to delete proof sync log entries.

type ErrSerializationError added in v0.2.1

type ErrSerializationError struct {
	DbError error
}

ErrSerializationError is an error type which represents a database agnostic error that a transaction couldn't be serialized with other concurrent db transactions.

func (ErrSerializationError) Error added in v0.2.1

func (e ErrSerializationError) Error() string

Error returns the error message.

func (ErrSerializationError) Unwrap added in v0.2.1

func (e ErrSerializationError) Unwrap() error

Unwrap returns the wrapped error.

type ErrSqlUniqueConstraintViolation

type ErrSqlUniqueConstraintViolation struct {
	DbError error
}

ErrSqlUniqueConstraintViolation is an error type which represents a database agnostic SQL unique constraint violation.

func (ErrSqlUniqueConstraintViolation) Error

type FedGlobalSyncConfig added in v0.3.0

type FedGlobalSyncConfig = sqlc.FederationGlobalSyncConfig

FedGlobalSyncConfig is the proof type specific global federation sync config returned from a query.

type FedUniSyncConfigs added in v0.3.0

type FedUniSyncConfigs = sqlc.FederationUniSyncConfig

FedUniSyncConfigs is the universe specific federation sync config returned from a query.

type FederationProofSyncLogStore added in v0.3.3

type FederationProofSyncLogStore interface {
	BaseUniverseStore

	// UpsertFederationProofSyncLog upserts a proof sync log entry for a
	// given proof leaf and server.
	UpsertFederationProofSyncLog(ctx context.Context,
		arg UpsertFedProofSyncLogParams) (int64, error)

	// QueryFederationProofSyncLog returns the set of proof sync logs for a
	// given proof leaf.
	QueryFederationProofSyncLog(ctx context.Context,
		arg QueryFedProofSyncLogParams) ([]ProofSyncLogEntry, error)

	// DeleteFederationProofSyncLog deletes proof sync log entries.
	DeleteFederationProofSyncLog(ctx context.Context,
		arg DeleteFedProofSyncLogParams) error
}

FederationProofSyncLogStore is used to log the sync status of individual universe proofs.

type FederationSyncConfigStore added in v0.3.0

type FederationSyncConfigStore interface {
	// UpsertFederationGlobalSyncConfig sets the global federation sync
	// config for a given proof type.
	UpsertFederationGlobalSyncConfig(ctx context.Context,
		arg UpsertFedGlobalSyncConfigParams) error

	// QueryFederationGlobalSyncConfigs returns all global federation sync
	// configurations.
	QueryFederationGlobalSyncConfigs(
		ctx context.Context) ([]FedGlobalSyncConfig, error)

	// UpsertFederationUniSyncConfig inserts or updates a universe specific
	// federation sync config.
	UpsertFederationUniSyncConfig(ctx context.Context,
		arg UpsertFedUniSyncConfigParams) error

	// QueryFederationUniSyncConfigs returns the set of universe specific
	// federation sync configs.
	QueryFederationUniSyncConfigs(ctx context.Context) ([]FedUniSyncConfigs,
		error)
}

FederationSyncConfigStore is used to manage the set of Universe servers as part of a federation.

type FetchAssetProof added in v0.3.3

type FetchAssetProof = sqlc.FetchAssetProofParams

FetchAssetProof are the query parameters for fetching an asset proof.

type FetchGenesisStore

type FetchGenesisStore interface {
	// FetchGenesisByID returns a single genesis asset by its primary key
	// ID.
	FetchGenesisByID(ctx context.Context, assetID int64) (Genesis, error)
}

FetchGenesisStore houses the methods related to fetching genesis assets.

type Genesis

type Genesis = sqlc.FetchGenesisByIDRow

Genesis is a type alias for fetching the genesis asset information.

type GenesisAsset

type GenesisAsset = sqlc.UpsertGenesisAssetParams

GenesisAsset is used to insert the base information of an asset into the DB.

type GenesisPointAnchor

type GenesisPointAnchor = sqlc.AnchorGenesisPointParams

GenesisPointAnchor is used to update the genesis point with the final information w.r.t where it's confirmed on chain.

type GenesisTxUpdate

type GenesisTxUpdate = sqlc.UpdateBatchGenesisTxParams

GenesisTxUpdate is used to update the existing batch TX associated with a batch.

type GroupStore

type GroupStore interface {
	FetchGenesisStore

	// FetchGroupByGenesis fetches information on the asset group created
	// with the asset genesis referenced by a specific genesis ID.
	FetchGroupByGenesis(ctx context.Context,
		genesisID int64) (sqlc.FetchGroupByGenesisRow, error)

	// FetchGroupByGroupKey fetches information on the asset group with
	// a matching group key.
	FetchGroupByGroupKey(ctx context.Context,
		groupKey []byte) (sqlc.FetchGroupByGroupKeyRow, error)
}

GroupStore houses the methods related to fetching specific asset groups.

type InternalKey

type InternalKey = sqlc.UpsertInternalKeyParams

InternalKey holds the arguments to update an internal key.

type KeyStore

type KeyStore interface {
	// GetRootKey fetches the root key associated with the passed ID.
	GetRootKey(ctx context.Context, id []byte) (MacaroonRootKey, error)

	// InsertRootKey inserts a new (id, rootKey) tuple into the database.
	InsertRootKey(ctx context.Context, arg MacaroonID) error
}

KeyStore represents access to a persistence key store for macaroon root key IDs.

type KeyStoreTxOptions

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

KeyStoreTxOptions defines the set of db txn options the KeyStore understands.

func NewKeyStoreReadOpts

func NewKeyStoreReadOpts() *KeyStoreTxOptions

NewKeyStoreReadOpts returns a new KeyStoreTxOptions instance triggers a read transaction.

func (*KeyStoreTxOptions) ReadOnly

func (r *KeyStoreTxOptions) ReadOnly() bool

ReadOnly returns true if the transaction should be read only.

NOTE: This implements the TxOptions

type LogProofTransAttemptParams added in v0.3.1

type LogProofTransAttemptParams = sqlc.LogProofTransferAttemptParams

LogProofTransAttemptParams is a type alias for the params needed to log a proof transfer attempt.

type MacaroonID

type MacaroonID = sqlc.InsertRootKeyParams

MacaroonID is used to insert new (id, rootKey) into the database.

type MacaroonRootKey

type MacaroonRootKey = sqlc.Macaroon

MacaroonRootKey is a tuple of (id, rootKey) that is used to validate + create macaroons.

type ManagedUTXO

type ManagedUTXO struct {
	// OutPoint is the outpoint of the UTXO.
	OutPoint wire.OutPoint

	// OutputValue is the satoshi output value of the UTXO.
	OutputValue btcutil.Amount

	// InternalKey is the internal key that's used to anchor the commitment
	// in the outpoint.
	InternalKey keychain.KeyDescriptor

	// TaprootAssetRoot is the Taproot Asset commitment root hash committed
	// to by this outpoint.
	TaprootAssetRoot []byte

	// MerkleRoot is the Taproot merkle root hash committed to by this
	// outpoint. If there is no Tapscript sibling, this is equal to
	// TaprootAssetRoot.
	MerkleRoot []byte

	// TapscriptSibling is the serialized tapscript sibling preimage of
	// this asset. This will usually be blank.
	TapscriptSibling []byte
}

ManagedUTXO holds information about a given UTXO we manage.

type ManagedUTXORow

type ManagedUTXORow = sqlc.FetchManagedUTXOsRow

ManagedUTXORow wraps a managed UTXO listing row.

type MintingBatchA

type MintingBatchA = sqlc.AllMintingBatchesRow

MintingBatchA is an alias for a minting batch returned when querying for all minting batches.

type MintingBatchF

type MintingBatchF = sqlc.FetchMintingBatchRow

MintingBatchF is an alias for a specific minting batch.

type MintingBatchI

MintingBatchI is an alias for a minting batch including the internal key info. This is used to query for batches where the state doesn't match a certain value.

type MintingBatchInit

type MintingBatchInit = sqlc.NewMintingBatchParams

MintingBatchInit is used to create a new minting batch.

type MintingBatchTuple

type MintingBatchTuple = sqlc.UpdateMintingBatchStateParams

MintingBatchTuple is used to update a batch state based on the raw key.

type MultiverseStore added in v0.3.0

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

MultiverseStore implements the persistent storage for a multiverse.

NOTE: This implements the universe.MultiverseArchive interface.

func NewMultiverseStore added in v0.3.0

func NewMultiverseStore(db BatchedMultiverse) *MultiverseStore

NewMultiverseStore creates a new multiverse DB store handle.

func (*MultiverseStore) DeleteUniverse added in v0.3.1

func (b *MultiverseStore) DeleteUniverse(ctx context.Context,
	id universe.Identifier) (string, error)

DeleteUniverse delete an entire universe sub-tre.

func (*MultiverseStore) FetchProof added in v0.3.3

func (b *MultiverseStore) FetchProof(ctx context.Context,
	originLocator proof.Locator) (proof.Blob, error)

FetchProof fetches a proof for an asset uniquely identified by the passed Locator. The returned blob contains the encoded full proof file, representing the complete provenance of the asset.

If a proof cannot be found, then ErrProofNotFound is returned.

NOTE: This is part of the proof.NotifyArchiver interface.

func (*MultiverseStore) FetchProofLeaf added in v0.3.0

func (b *MultiverseStore) FetchProofLeaf(ctx context.Context,
	id universe.Identifier,
	universeKey universe.LeafKey) ([]*universe.Proof, error)

FetchProofLeaf returns a proof leaf for the target key. If the key doesn't have a script key specified, then all the proof leafs for the minting outpoint will be returned. If neither are specified, then all inserted proof leafs will be returned.

func (*MultiverseStore) RegisterSubscriber added in v0.3.3

func (b *MultiverseStore) RegisterSubscriber(
	receiver *fn.EventReceiver[proof.Blob], deliverExisting bool,
	deliverFrom []*proof.Locator) error

RegisterSubscriber adds a new subscriber for receiving events. The deliverExisting boolean indicates whether already existing items should be sent to the NewItemCreated channel when the subscription is started. An optional deliverFrom can be specified to indicate from which timestamp/index/ marker onward existing items should be delivered on startup. If deliverFrom is nil/zero/empty then all existing items will be delivered.

func (*MultiverseStore) RemoveSubscriber added in v0.3.3

func (b *MultiverseStore) RemoveSubscriber(
	subscriber *fn.EventReceiver[proof.Blob]) error

RemoveSubscriber removes the given subscriber and also stops it from processing events.

func (*MultiverseStore) RootNode added in v0.3.0

RootNode returns the root multiverse node for the given proof type.

func (*MultiverseStore) RootNodes added in v0.3.0

RootNodes returns the complete set of known base universe root nodes for the set of base universes tracked in the multiverse.

func (*MultiverseStore) UniverseLeafKeys added in v0.3.1

UniverseLeafKeys returns the set of leaf keys for the given universe.

func (*MultiverseStore) UniverseRootNode added in v0.3.1

func (b *MultiverseStore) UniverseRootNode(ctx context.Context,
	id universe.Identifier) (universe.Root, error)

UniverseRootNode returns the Universe root node for the given asset ID.

func (*MultiverseStore) UpsertProofLeaf added in v0.3.0

func (b *MultiverseStore) UpsertProofLeaf(ctx context.Context,
	id universe.Identifier, key universe.LeafKey,
	leaf *universe.Leaf,
	metaReveal *proof.MetaReveal) (*universe.Proof, error)

UpsertProofLeaf upserts a proof leaf within the multiverse tree and the universe tree that corresponds to the given key.

func (*MultiverseStore) UpsertProofLeafBatch added in v0.3.1

func (b *MultiverseStore) UpsertProofLeafBatch(ctx context.Context,
	items []*universe.Item) error

UpsertProofLeafBatch upserts a proof leaf batch within the multiverse tree and the universe tree that corresponds to the given key(s).

type NewAddr

type NewAddr = sqlc.InsertAddrParams

NewAddr is a type alias for the params to create a new address.

type NewAssetMeta

type NewAssetMeta = sqlc.UpsertAssetMetaParams

NewAssetMeta wraps the params needed to insert a new asset meta on disk.

type NewAssetTransfer

type NewAssetTransfer = sqlc.InsertAssetTransferParams

NewAssetTransfer wraps the params needed to insert a new asset transfer.

type NewBranch

type NewBranch = sqlc.InsertBranchParams

NewBranch is a type alias for the params to create a new mssmt branch node.

type NewCompactedLeaf

type NewCompactedLeaf = sqlc.InsertCompactedLeafParams

NewCompactedLeaf is a type alias for the params to create a new mssmt compacted leaf node.

type NewLeaf

type NewLeaf = sqlc.InsertLeafParams

NewLeaf is a type alias for the params to create a new mssmt leaf node.

type NewPassiveAsset

type NewPassiveAsset = sqlc.InsertPassiveAssetParams

NewPassiveAsset wraps the params needed to insert a new passive asset.

type NewProofEvent

type NewProofEvent = sqlc.InsertNewProofEventParams

NewProofEvent is used to create a new event that logs insertion of a new proof.

type NewScriptKey

type NewScriptKey = sqlc.UpsertScriptKeyParams

NewScriptKey wraps the params needed to insert a new script key on disk.

type NewSyncEvent

type NewSyncEvent = sqlc.InsertNewSyncEventParams

NewSyncEvent is used to create a new event that logs a new Universe leaf sync.

type NewTransferInput

type NewTransferInput = sqlc.InsertAssetTransferInputParams

NewTransferInput wraps the params needed to insert a new transfer input.

type NewTransferOutput

type NewTransferOutput = sqlc.InsertAssetTransferOutputParams

NewTransferOutput wraps the params needed to insert a new transfer output.

type NewUniverseRoot

type NewUniverseRoot = sqlc.UpsertUniverseRootParams

NewUniverseRoot is used to insert a new universe root.

type NewUniverseServer

type NewUniverseServer = sqlc.InsertUniverseServerParams

NewUniverseServer is used to create a new universe server.

type PassiveAsset

type PassiveAsset = sqlc.QueryPassiveAssetsRow

PassiveAsset tracks a passive asset.

type PendingAssetStore

type PendingAssetStore interface {
	// UpsertAssetStore houses the methods related to inserting/updating
	// assets.
	UpsertAssetStore

	// GroupStore houses the methods related to querying asset groups.
	GroupStore

	// NewMintingBatch creates a new minting batch.
	NewMintingBatch(ctx context.Context, arg MintingBatchInit) error

	// UpdateMintingBatchState updates the state of an existing minting
	// batch.
	UpdateMintingBatchState(ctx context.Context,
		arg BatchStateUpdate) error

	// InsertAssetSeedling inserts a new asset seedling (base description)
	// into the database.
	InsertAssetSeedling(ctx context.Context, arg AssetSeedlingShell) error

	// InsertAssetSeedlingIntoBatch inserts a new asset seedling into a
	// batch based on the batch key its included in.
	InsertAssetSeedlingIntoBatch(ctx context.Context,
		arg AssetSeedlingItem) error

	// AllMintingBatches is used to fetch all minting batches.
	AllMintingBatches(ctx context.Context) ([]MintingBatchA, error)

	// FetchMintingBatchesByInverseState is used to fetch minting batches
	// that don't have a particular state.
	FetchMintingBatchesByInverseState(ctx context.Context,
		batchState int16) ([]MintingBatchI, error)

	// FetchMintingBatch is used to fetch a single minting batch specified
	// by the batch key.
	FetchMintingBatch(ctx context.Context,
		rawKey []byte) (MintingBatchF, error)

	// FetchSeedlingsForBatch is used to fetch all the seedlings by the key
	// of the batch they're included in.
	FetchSeedlingsForBatch(ctx context.Context,
		rawKey []byte) ([]sqlc.FetchSeedlingsForBatchRow, error)

	// FetchSeedlingID is used to look up the ID of a specific seedling
	// in a batch.
	FetchSeedlingID(ctx context.Context, arg AssetSeedlingTuple) (int64,
		error)

	// FetchSeedlingByID is used to look up a specific seedling.
	FetchSeedlingByID(ctx context.Context,
		seedlingID int64) (AssetSeedling, error)

	// BindMintingBatchWithTx adds the minting transaction to an existing
	// batch.
	BindMintingBatchWithTx(ctx context.Context, arg BatchChainUpdate) error

	// UpdateBatchGenesisTx updates the batch tx attached to an existing
	// batch.
	UpdateBatchGenesisTx(ctx context.Context, arg GenesisTxUpdate) error

	// UpsertManagedUTXO inserts a new or updates an existing managed UTXO
	// to disk and returns the primary key.
	UpsertManagedUTXO(ctx context.Context, arg RawManagedUTXO) (int64,
		error)

	// AnchorPendingAssets associated an asset on disk with the transaction
	// that once confirmed will mint the asset.
	AnchorPendingAssets(ctx context.Context, arg AssetAnchor) error

	// UpsertChainTx inserts a new or updates an existing chain tx into the
	// DB.
	UpsertChainTx(ctx context.Context, arg ChainTxParams) (int64, error)

	// ConfirmChainTx confirms an existing chain tx.
	ConfirmChainTx(ctx context.Context, arg ChainTxConf) error

	// FetchAssetsForBatch fetches all the assets created by a particular
	// batch.
	FetchAssetsForBatch(ctx context.Context, rawKey []byte) ([]AssetSprout,
		error)

	// UpsertAssetProof inserts a new or updates an existing asset proof on
	// disk.
	//
	// TODO(roasbeef): move somewhere else??
	UpsertAssetProof(ctx context.Context,
		arg sqlc.UpsertAssetProofParams) error

	// FetchAssetMetaForAsset fetches the asset meta for a given asset.
	FetchAssetMetaForAsset(ctx context.Context,
		assetID []byte) (sqlc.FetchAssetMetaForAssetRow, error)
}

PendingAssetStore is a sub-set of the main sqlc.Querier interface that contains only the methods needed to drive the process of batching and creating a new set of assets.

type PostgresConfig

type PostgresConfig struct {
	SkipMigrations     bool          `long:"skipmigrations" description:"Skip applying migrations on startup."`
	Host               string        `long:"host" description:"Database server hostname."`
	Port               int           `long:"port" description:"Database server port."`
	User               string        `long:"user" description:"Database user."`
	Password           string        `long:"password" description:"Database user's password."`
	DBName             string        `long:"dbname" description:"Database name to use."`
	MaxOpenConnections int           `long:"maxconnections" description:"Max open connections to keep alive to the database server."`
	MaxIdleConnections int           `long:"maxidleconnections" description:"Max number of idle connections to keep in the connection pool."`
	ConnMaxLifetime    time.Duration `long:"connmaxlifetime" description:"Max amount of time a connection can be reused for before it is closed."`
	ConnMaxIdleTime    time.Duration `long:"connmaxidletime" description:"Max amount of time a connection can be idle for before it is closed."`
	RequireSSL         bool          `long:"requiressl" description:"Whether to require using SSL (mode: require) when connecting to the server."`
}

PostgresConfig holds the postgres database configuration.

func (*PostgresConfig) DSN

func (s *PostgresConfig) DSN(hidePassword bool) string

DSN returns the dns to connect to the database.

type PostgresStore

type PostgresStore struct {
	*BaseDB
	// contains filtered or unexported fields
}

PostgresStore is a database store implementation that uses a Postgres backend.

func NewPostgresStore

func NewPostgresStore(cfg *PostgresConfig) (*PostgresStore, error)

NewPostgresStore creates a new store that is backed by a Postgres database backend.

func NewTestPostgresDB

func NewTestPostgresDB(t *testing.T) *PostgresStore

NewTestPostgresDB is a helper function that creates a Postgres database for testing.

type PrevInput

type PrevInput = sqlc.UpsertAssetWitnessParams

PrevInput stores the full input information including the prev out, and also the witness information itself.

type ProofKey added in v0.3.1

type ProofKey [32]byte

ProofKey is used to uniquely identify a proof within a universe. This is used for the LRU cache for the proofs themselves, which are considered to be immutable.

func NewProofKey added in v0.3.1

func NewProofKey(id universe.Identifier, key universe.LeafKey) ProofKey

NewProofKey takes a universe identifier and leaf key, and returns a proof key.

type ProofSyncLogEntry added in v0.3.3

type ProofSyncLogEntry = sqlc.QueryFederationProofSyncLogRow

ProofSyncLogEntry is a single entry from the proof sync log.

type ProofUpdate

type ProofUpdate = sqlc.UpsertAssetProofParams

ProofUpdate is used to update a proof file on disk.

type ProofUpdateByID added in v0.3.3

type ProofUpdateByID = sqlc.UpsertAssetProofByIDParams

ProofUpdateByID is used to update a proof file on disk by asset database ID.

type QueryAssetFilters

type QueryAssetFilters = sqlc.QueryAssetsParams

QueryAssetFilters lets us query assets in the database based on some set filters. This is useful to get the balance of a set of assets, or for things like coin selection.

type QueryCreator

type QueryCreator[Q any] func(*sql.Tx) Q

QueryCreator is a generic function that's used to create a Querier, which is a type of interface that implements storage related methods from a database transaction. This will be used to instantiate an object callers can use to apply multiple modifications to an object interface in a single atomic transaction.

type QueryFedProofSyncLogParams added in v0.3.3

type QueryFedProofSyncLogParams = sqlc.QueryFederationProofSyncLogParams

QueryFedProofSyncLogParams is used to query for federation proof sync logs.

type QueryProofTransAttemptsParams added in v0.3.1

type QueryProofTransAttemptsParams = sqlc.QueryProofTransferAttemptsParams

QueryProofTransAttemptsParams is a type alias for the params needed to query the proof transfer attempts log.

type QueryUniServersParams added in v0.3.3

type QueryUniServersParams = sqlc.QueryUniverseServersParams

QueryUniServersParams is used to query for universe servers.

type RawAssetBalance

type RawAssetBalance = sqlc.QueryAssetBalancesByAssetRow

RawAssetBalance holds a balance query result for a particular asset or all assets tracked by this daemon.

type RawAssetGroupBalance

type RawAssetGroupBalance = sqlc.QueryAssetBalancesByGroupRow

RawAssetGroupBalance holds a balance query result for a particular asset group or all asset groups tracked by this daemon.

type RawGroupedAsset

type RawGroupedAsset = sqlc.FetchGroupedAssetsRow

RawGroupedAsset holds the human-readable fields of a single asset with a non-nil group key.

type RawManagedUTXO

type RawManagedUTXO = sqlc.UpsertManagedUTXOParams

RawManagedUTXO is used to insert a new managed UTXO into the database.

type ReAnchorParams

type ReAnchorParams = sqlc.ReAnchorPassiveAssetsParams

ReAnchorParams wraps the params needed to re-anchor a passive asset.

type RootKeyStore

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

RootKeyStore is an implementation of the bakery.RootKeyStore interface that'll be used to store macaroons for the project. This uses the sql.Querier interface to have access to the set of storage routines we need to implement the interface.

func NewRootKeyStore

func NewRootKeyStore(db BatchedKeyStore) *RootKeyStore

NewRootKeyStore creates a new RKS from the passed querier interface.

func (*RootKeyStore) Get

func (r *RootKeyStore) Get(ctx context.Context, id []byte) ([]byte, error)

Get returns the root key for the given id. If the item is not there, it returns ErrNotFound.

NOTE: This implements the bakery.RootKeyStore interface.

func (*RootKeyStore) RootKey

func (r *RootKeyStore) RootKey(ctx context.Context) ([]byte, []byte, error)

RootKey returns the root key to be used for making a new macaroon, and an id that can be used to look it up later with the Get method.

NOTE: This implements the bakery.RootKeyStore interface.

type ScriptKey

ScriptKey is a type alias for fetching the script key information.

type SetAssetSpentParams

type SetAssetSpentParams = sqlc.SetAssetSpentParams

SetAssetSpentParams is used to mark an asset as spent.

type SqliteConfig

type SqliteConfig struct {
	// SkipMigrations if true, then all the tables will be created on start
	// up if they don't already exist.
	SkipMigrations bool `long:"skipmigrations" description:"Skip applying migrations on startup."`

	// DatabaseFileName is the full file path where the database file can be
	// found.
	DatabaseFileName string `long:"dbfile" description:"The full path to the database."`
}

SqliteConfig holds all the config arguments needed to interact with our sqlite DB.

type SqliteStore

type SqliteStore struct {
	*BaseDB
	// contains filtered or unexported fields
}

SqliteStore is a sqlite3 based database for the Taproot Asset daemon.

func NewSqliteStore

func NewSqliteStore(cfg *SqliteConfig) (*SqliteStore, error)

NewSqliteStore attempts to open a new sqlite database based on the passed config.

func NewTestDB

func NewTestDB(t *testing.T) *SqliteStore

NewTestDB is a helper function that creates an SQLite database for testing.

func NewTestSqliteDB

func NewTestSqliteDB(t *testing.T) *SqliteStore

NewTestSqliteDB is a helper function that creates an SQLite database for testing.

type StoredNode

type StoredNode = sqlc.FetchChildrenRow

StoredNode is a type alias for an arbitrary child of an mssmt branch.

type TapAddressBook

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

TapAddressBook represents a storage backend for all the Taproot Asset addresses a daemon has created.

func NewTapAddressBook

func NewTapAddressBook(db BatchedAddrBook, params *address.ChainParams,
	clock clock.Clock) *TapAddressBook

NewTapAddressBook creates a new TapAddressBook instance given a open BatchedAddrBook storage backend.

func (*TapAddressBook) AddrByTaprootOutput

func (t *TapAddressBook) AddrByTaprootOutput(ctx context.Context,
	key *btcec.PublicKey) (*address.AddrWithKeyInfo, error)

AddrByTaprootOutput returns a single address based on its Taproot output key or a sql.ErrNoRows error if no such address exists.

func (*TapAddressBook) CompleteEvent

func (t *TapAddressBook) CompleteEvent(ctx context.Context,
	event *address.Event, status address.Status,
	anchorPoint wire.OutPoint) error

CompleteEvent updates an address event as being complete and links it with the proof and asset that was imported/created for it.

func (*TapAddressBook) FetchScriptKey

func (t *TapAddressBook) FetchScriptKey(ctx context.Context,
	tweakedScriptKey *btcec.PublicKey) (*asset.TweakedScriptKey, error)

FetchScriptKey attempts to fetch the full tweaked script key struct (including the key descriptor) for the given tweaked script key. If the key cannot be found, then ErrScriptKeyNotFound is returned.

func (*TapAddressBook) GetOrCreateEvent

func (t *TapAddressBook) GetOrCreateEvent(ctx context.Context,
	status address.Status, addr *address.AddrWithKeyInfo,
	walletTx *lndclient.Transaction, outputIdx uint32) (*address.Event,
	error)

GetOrCreateEvent creates a new address event for the given status, address and transaction. If an event for that address and transaction already exists, then the status and transaction information is updated instead.

func (*TapAddressBook) InsertAddrs

func (t *TapAddressBook) InsertAddrs(ctx context.Context,
	addrs ...address.AddrWithKeyInfo) error

InsertAddrs inserts a new address into the database.

func (*TapAddressBook) InsertAssetGen

func (t *TapAddressBook) InsertAssetGen(ctx context.Context,
	gen *asset.Genesis, group *asset.GroupKey) error

InsertAssetGen inserts a new asset genesis into the database. This is exported primarily for external tests so a genesis can be in place before addr insertion.

func (*TapAddressBook) InsertInternalKey

func (t *TapAddressBook) InsertInternalKey(ctx context.Context,
	keyDesc keychain.KeyDescriptor) error

InsertInternalKey inserts an internal key into the database to make sure it is identified as a local key later on when importing proofs. The key can be an internal key for an asset script key or the internal key of an anchor output.

func (*TapAddressBook) InsertScriptKey

func (t *TapAddressBook) InsertScriptKey(ctx context.Context,
	scriptKey asset.ScriptKey) error

InsertScriptKey inserts an address related script key into the database, so it can be recognized as belonging to the wallet when a transfer comes in later on.

func (*TapAddressBook) QueryAddrEvents

func (t *TapAddressBook) QueryAddrEvents(
	ctx context.Context, params address.EventQueryParams) ([]*address.Event,
	error)

QueryAddrEvents returns a list of event that match the given query parameters.

func (*TapAddressBook) QueryAddrs

QueryAddrs attempts to query for the set of addresses on disk given the passed set of query params.

func (*TapAddressBook) QueryAssetGroup

func (t *TapAddressBook) QueryAssetGroup(ctx context.Context,
	assetID asset.ID) (*asset.AssetGroup, error)

QueryAssetGroup attempts to fetch an asset group by its asset ID. If the asset group cannot be found, then ErrAssetGroupUnknown is returned.

func (*TapAddressBook) SetAddrManaged

func (t *TapAddressBook) SetAddrManaged(ctx context.Context,
	addr *address.AddrWithKeyInfo, managedFrom time.Time) error

SetAddrManaged sets an address as being managed by the internal wallet.

type TaprootAssetTreeStore

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

TaprootAssetTreeStore is an persistent MS-SMT implementation backed by a live SQL database.

func NewTaprootAssetTreeStore

func NewTaprootAssetTreeStore(db BatchedTreeStore,
	namespace string) *TaprootAssetTreeStore

NewTaprootAssetTreeStore creates a new TaprootAssetTreeStore instance given an open BatchedTreeStore storage backend. The namespace argument is required, as it allow us to store several distinct trees on disk in the same table.

func (*TaprootAssetTreeStore) Update

func (t *TaprootAssetTreeStore) Update(ctx context.Context,
	update func(tx mssmt.TreeStoreUpdateTx) error) error

Update updates the persistent tree in the passed-in update closure using the update transaction.

func (*TaprootAssetTreeStore) View

func (t *TaprootAssetTreeStore) View(ctx context.Context,
	update func(tx mssmt.TreeStoreViewTx) error) error

View gives a view of the persistent tree in the passed view closure using the view transaction.

type TestPgFixture

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

TestPgFixture is a test fixture that starts a Postgres 11 instance in a docker container.

func NewTestPgFixture

func NewTestPgFixture(t *testing.T, expiry time.Duration,
	autoRemove bool) *TestPgFixture

NewTestPgFixture constructs a new TestPgFixture starting up a docker container running Postgres 11. The started container will expire in after the passed duration.

func (*TestPgFixture) ClearDB

func (f *TestPgFixture) ClearDB(t *testing.T)

ClearDB clears the database.

func (*TestPgFixture) GetConfig

func (f *TestPgFixture) GetConfig() *PostgresConfig

GetConfig returns the full config of the Postgres node.

func (*TestPgFixture) GetDSN

func (f *TestPgFixture) GetDSN() string

GetDSN returns the DSN (Data Source Name) for the started Postgres node.

func (*TestPgFixture) TearDown

func (f *TestPgFixture) TearDown(t *testing.T)

TearDown stops the underlying docker container.

type TransactionExecutor

type TransactionExecutor[Query any] struct {
	BatchedQuerier
	// contains filtered or unexported fields
}

TransactionExecutor is a generic struct that abstracts away from the type of query a type needs to run under a database transaction, and also the set of options for that transaction. The QueryCreator is used to create a query given a database transaction created by the BatchedQuerier.

func NewTransactionExecutor

func NewTransactionExecutor[Querier any](db BatchedQuerier,
	createQuery QueryCreator[Querier],
	opts ...TxExecutorOption) *TransactionExecutor[Querier]

NewTransactionExecutor creates a new instance of a TransactionExecutor given a Querier query object and a concrete type for the type of transactions the Querier understands.

func (*TransactionExecutor[Q]) Backend added in v0.2.3

func (t *TransactionExecutor[Q]) Backend() sqlc.BackendType

Backend returns the type of the database backend used.

func (*TransactionExecutor[Q]) ExecTx

func (t *TransactionExecutor[Q]) ExecTx(ctx context.Context,
	txOptions TxOptions, txBody func(Q) error) error

ExecTx is a wrapper for txBody to abstract the creation and commit of a db transaction. The db transaction is embedded in a `*Queries` that txBody needs to use when executing each one of the queries that need to be applied atomically. This can be used by other storage interfaces to parameterize the type of query and options run, in order to have access to batched operations related to a storage object.

type TransferInput

type TransferInput = sqlc.AssetTransferInput

TransferInput tracks the inputs to an asset transfer.

type TransferInputRow

type TransferInputRow = sqlc.FetchTransferInputsRow

TransferInputRow wraps a single transfer input row.

type TransferOutput

type TransferOutput = sqlc.AssetTransferOutput

TransferOutput tracks the outputs to an asset transfer.

type TransferOutputRow

type TransferOutputRow = sqlc.FetchTransferOutputsRow

TransferOutputRow wraps a single transfer output row.

type TransferQuery

type TransferQuery = sqlc.QueryAssetTransfersParams

TransferQuery allows callers to filter out the set of transfers based on set information.

type TreeStore

type TreeStore interface {
	// InsertBranch inserts a new branch to the store.
	InsertBranch(ctx context.Context, newNode NewBranch) error

	// InsertLeaf inserts a new leaf to the store.
	InsertLeaf(ctx context.Context, newNode NewLeaf) error

	// InsertCompactedLeaf inserts a new compacted leaf to the store.
	InsertCompactedLeaf(ctx context.Context, newNode NewCompactedLeaf) error

	// FetchChildren fetches the children (at most two currently) of the
	// passed branch hash key.
	FetchChildren(ctx context.Context, c ChildQuery) ([]StoredNode, error)

	// DeleteNode deletes a node (can be either branch, leaf of compacted
	// leaf) from the store.
	DeleteNode(ctx context.Context, n DelNode) (int64, error)

	// DeleteAllNodes deletes all nodes from the store.
	DeleteAllNodes(ctx context.Context, namespace string) (int64, error)

	// DeleteRoot deletes a root node from the store.
	DeleteRoot(ctx context.Context, namespace string) (int64, error)

	// FetchRootNode fetches the root node for the specified namespace.
	FetchRootNode(ctx context.Context,
		namespace string) (sqlc.MssmtNode, error)

	// UpsertRootNode allows us to update the root node in place for a
	// given namespace.
	UpsertRootNode(ctx context.Context, arg UpdateRoot) error
}

TreeStore is a sub-set of the main sqlc.Querier interface that contains only the methods needed to manipulate and query stored MSSMT trees.

type TreeStoreTxOptions

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

func NewTreeStoreReadTx

func NewTreeStoreReadTx() TreeStoreTxOptions

NewTreeStoreReadTx creates a new read transaction option set.

func (*TreeStoreTxOptions) ReadOnly

func (t *TreeStoreTxOptions) ReadOnly() bool

ReadOnly returns true if the transaction should be read only.

NOTE: This implements the TxOptions

type Tx

type Tx interface {
	// Commit commits the database transaction, an error should be returned
	// if the commit isn't possible.
	Commit() error

	// Rollback rolls back an incomplete database transaction.
	// Transactions that were able to be committed can still call this as a
	// noop.
	Rollback() error
}

Tx represents a database transaction that can be committed or rolled back.

type TxExecutorOption added in v0.2.1

type TxExecutorOption func(*txExecutorOptions)

TxExecutorOption is a functional option that allows us to pass in optional argument when creating the executor.

func WithTxRetries added in v0.2.1

func WithTxRetries(numRetries int) TxExecutorOption

WithTxRetries is a functional option that allows us to specify the number of times a transaction should be retried if it fails with a repeatable error.

func WithTxRetryDelay added in v0.2.1

func WithTxRetryDelay(delay time.Duration) TxExecutorOption

WithTxRetryDelay is a functional option that allows us to specify the delay to wait before a transaction is retried.

type TxOptions

type TxOptions interface {
	// ReadOnly returns true if the transaction should be read only.
	ReadOnly() bool
}

TxOptions represents a set of options one can use to control what type of database transaction is created. Transaction can wither be read or write.

type UniverseFederationDB

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

UniverseFederationDB is used to manage the set of universe servers by sub-systems that need to manage syncing and pushing new proofs amongst the federation set.

func NewUniverseFederationDB

func NewUniverseFederationDB(db BatchedUniverseServerStore,
	clock clock.Clock) *UniverseFederationDB

NewUniverseFederationDB makes a new Universe federation DB.

func (*UniverseFederationDB) AddServers

func (u *UniverseFederationDB) AddServers(ctx context.Context,
	addrs ...universe.ServerAddr) error

AddServers adds a slice of servers to the federation.

func (*UniverseFederationDB) DeleteProofsSyncLogEntries added in v0.3.3

func (u *UniverseFederationDB) DeleteProofsSyncLogEntries(ctx context.Context,
	servers ...universe.ServerAddr) error

DeleteProofsSyncLogEntries deletes a set of proof sync log entries.

func (*UniverseFederationDB) FetchPendingProofsSyncLog added in v0.3.3

func (u *UniverseFederationDB) FetchPendingProofsSyncLog(ctx context.Context,
	syncDirection *universe.SyncDirection) ([]*universe.ProofSyncLogEntry,
	error)

FetchPendingProofsSyncLog queries the federation proof sync log and returns all log entries with sync status pending.

func (*UniverseFederationDB) LogNewSyncs

func (u *UniverseFederationDB) LogNewSyncs(ctx context.Context,
	addrs ...universe.ServerAddr) error

LogNewSyncs logs a new sync event for each server. This can be used to keep track of the last time we synced with a remote server.

func (*UniverseFederationDB) QueryFederationProofSyncLog added in v0.3.3

func (u *UniverseFederationDB) QueryFederationProofSyncLog(
	ctx context.Context, uniID universe.Identifier,
	leafKey universe.LeafKey,
	syncDirection universe.SyncDirection,
	syncStatus universe.ProofSyncStatus) ([]*universe.ProofSyncLogEntry,
	error)

QueryFederationProofSyncLog queries the federation proof sync log and returns the log entries which correspond to the given universe proof leaf.

func (*UniverseFederationDB) QueryFederationSyncConfigs added in v0.3.0

func (u *UniverseFederationDB) QueryFederationSyncConfigs(
	ctx context.Context) ([]*universe.FedGlobalSyncConfig,
	[]*universe.FedUniSyncConfig, error)

QueryFederationSyncConfigs returns the global and universe specific federation sync configs.

func (*UniverseFederationDB) RemoveServers

func (u *UniverseFederationDB) RemoveServers(ctx context.Context,
	addrs ...universe.ServerAddr) error

RemoveServers removes a set of servers from the federation.

func (*UniverseFederationDB) UniverseServers

func (u *UniverseFederationDB) UniverseServers(
	ctx context.Context) ([]universe.ServerAddr, error)

UniverseServers returns the set of servers in the federation.

func (*UniverseFederationDB) UpsertFederationProofSyncLog added in v0.3.3

func (u *UniverseFederationDB) UpsertFederationProofSyncLog(
	ctx context.Context, uniID universe.Identifier,
	leafKey universe.LeafKey, addr universe.ServerAddr,
	syncDirection universe.SyncDirection,
	syncStatus universe.ProofSyncStatus,
	bumpSyncAttemptCounter bool) (int64, error)

UpsertFederationProofSyncLog upserts a federation proof sync log entry for a given universe server and proof.

func (*UniverseFederationDB) UpsertFederationSyncConfig added in v0.3.0

func (u *UniverseFederationDB) UpsertFederationSyncConfig(
	ctx context.Context, globalSyncConfigs []*universe.FedGlobalSyncConfig,
	uniSyncConfigs []*universe.FedUniSyncConfig) error

UpsertFederationSyncConfig upserts both the global and universe specific federation sync configs.

type UniverseFederationOptions

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

UniverseFederationOptions is the database tx object for the universe server store.

func NewUniverseFederationReadTx

func NewUniverseFederationReadTx() UniverseFederationOptions

NewUniverseFederationReadTx returns a new read tx for the federation.

func (*UniverseFederationOptions) ReadOnly

func (b *UniverseFederationOptions) ReadOnly() bool

ReadOnly returns a new read only server.

type UniverseKeys

type UniverseKeys = sqlc.FetchUniverseKeysRow

UniverseKeys is the set of leaf keys inserted into a universe.

type UniverseLeaf

type UniverseLeaf = sqlc.QueryUniverseLeavesRow

UniverseLeaf is a universe leaf.

type UniverseLeafKeysQuery added in v0.3.1

type UniverseLeafKeysQuery = sqlc.FetchUniverseKeysParams

UniverseLeafKeysQuery is used to query for the set of keys that are currently stored for a given namespace.

type UniverseLeafQuery

type UniverseLeafQuery = sqlc.QueryUniverseLeavesParams

UniverseLeafQuery allows callers to query for a set of leaves based on the minting point or the script key.

type UniverseRoot

type UniverseRoot = sqlc.FetchUniverseRootRow

UniverseRoot is the root of a universe tree.

type UniverseRootsParams added in v0.3.1

type UniverseRootsParams = sqlc.UniverseRootsParams

type UniverseServerStore

type UniverseServerStore interface {
	FederationSyncConfigStore
	FederationProofSyncLogStore

	// InsertUniverseServer inserts a new universe server in to the DB.
	InsertUniverseServer(ctx context.Context, arg NewUniverseServer) error

	// DeleteUniverseServer removes a universe server from the store.
	DeleteUniverseServer(ctx context.Context, r DelUniverseServer) error

	// LogServerSync marks that a server was just synced in the DB.
	LogServerSync(ctx context.Context, arg sqlc.LogServerSyncParams) error

	// QueryUniverseServers returns a set of universe servers.
	QueryUniverseServers(ctx context.Context,
		arg sqlc.QueryUniverseServersParams) ([]sqlc.UniverseServer,
		error)
}

UniverseServerStore is used to manage the set of Universe servers as part of a federation.

type UniverseStats

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

UniverseStats is an implementation of the universe.Telemetry interface that is backed by the on-disk Universe event and MS-SMT tree store.

func NewUniverseStats

func NewUniverseStats(db BatchedUniverseStats, clock clock.Clock,
	options ...UniverseStatsOption) *UniverseStats

NewUniverseStats creates a new instance of the UniverseStats backed by the database.

func (*UniverseStats) AggregateSyncStats

func (u *UniverseStats) AggregateSyncStats(
	ctx context.Context) (universe.AggregateStats, error)

AggregateSyncStats returns stats aggregated over all assets within the Universe.

func (*UniverseStats) LogNewProofEvent

func (u *UniverseStats) LogNewProofEvent(ctx context.Context,
	uniID universe.Identifier, key universe.LeafKey) error

LogNewProofEvent logs a new proof insertion event for the target universe.

func (*UniverseStats) LogNewProofEvents added in v0.3.0

func (u *UniverseStats) LogNewProofEvents(ctx context.Context,
	uniIDs ...universe.Identifier) error

LogNewProofEvents logs new proof insertion events for the target universe.

func (*UniverseStats) LogSyncEvent

func (u *UniverseStats) LogSyncEvent(ctx context.Context,
	uniID universe.Identifier, key universe.LeafKey) error

LogSyncEvent logs a sync event for the target universe.

func (*UniverseStats) LogSyncEvents added in v0.3.0

func (u *UniverseStats) LogSyncEvents(ctx context.Context,
	uniIDs ...universe.Identifier) error

LogSyncEvents logs sync events for the target universe.

func (*UniverseStats) QueryAssetStatsPerDay added in v0.2.3

func (u *UniverseStats) QueryAssetStatsPerDay(ctx context.Context,
	q universe.GroupedStatsQuery) ([]*universe.GroupedStats, error)

QueryAssetStatsPerDay returns the stats for all assets grouped by day.

func (*UniverseStats) QuerySyncStats

QuerySyncStats attempts to query the stats for the target universe. For a given asset ID, tag, or type, the set of universe stats is returned which lists information such as the total number of syncs and known proofs for a given Universe server instance.

type UniverseStatsOption added in v0.3.1

type UniverseStatsOption func(*statsOpts)

UniverseStatOption is a functional option that can be used to modify the way that the UniverseStats struct is created.

func WithStatsCacheDuration added in v0.3.1

func WithStatsCacheDuration(d time.Duration) UniverseStatsOption

WithStatsCacheDuration is a functional option that can be used to set the amount of time the stats are cached for.

type UniverseStatsOptions

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

UniverseStatsOptions defines the set of txn options for the universe stats.

func NewUniverseStatsReadTx

func NewUniverseStatsReadTx() UniverseStatsOptions

NewUniverseStatsReadTx creates a new read-only transaction for the universe stats instance.

func (*UniverseStatsOptions) ReadOnly

func (u *UniverseStatsOptions) ReadOnly() bool

ReadOnly returns true if the transaction is read-only.

type UniverseStatsQuery

type UniverseStatsQuery = sqlc.QueryUniverseAssetStatsParams

UniverseStatsQuery is used to query the stats for a given universe.

type UniverseStatsResp

type UniverseStatsResp = sqlc.QueryUniverseAssetStatsRow

UniverseStatsResp is used to return the stats for a given universe.

type UniverseStatsStore

type UniverseStatsStore interface {
	// InsertNewProofEvent inserts a new proof event into the database.
	InsertNewProofEvent(ctx context.Context, arg NewProofEvent) error

	// InsertNewSyncEvent inserts a new sync event into the database.
	InsertNewSyncEvent(ctx context.Context, arg NewSyncEvent) error

	// QueryUniverseStats returns the aggregated stats for the entire
	QueryUniverseStats(ctx context.Context) (AggregateStats, error)

	// QueryUniverseAssetStats returns the stats for a given asset within a
	// universe/
	QueryUniverseAssetStats(ctx context.Context,
		arg UniverseStatsQuery) ([]UniverseStatsResp, error)

	// QueryAssetStatsPerDaySqlite returns the stats for a given asset
	// grouped by day in a SQLite specific format.
	QueryAssetStatsPerDaySqlite(ctx context.Context,
		q AssetStatsPerDayQuery) ([]AssetStatsPerDay, error)

	// QueryAssetStatsPerDayPostgres returns the stats for a given asset
	// grouped by day in a Postgres specific format.
	QueryAssetStatsPerDayPostgres(ctx context.Context,
		q AssetStatsPerDayQueryPg) ([]AssetStatsPerDayPg, error)
}

UniverseStatsStore is an interface that defines the methods required to implement the universe.Telemetry interface.

type UpdateRoot

type UpdateRoot = sqlc.UpsertRootNodeParams

UpdateRoot wraps the args we need to update a root node.

type UpdateUTXOLease added in v0.3.0

type UpdateUTXOLease = sqlc.UpdateUTXOLeaseParams

UpdateUTXOLease wraps the params needed to lease a managed UTXO.

type UpsertAddrEvent

type UpsertAddrEvent = sqlc.UpsertAddrEventParams

UpsertAddrEvent is a type alias for creating a new address event or updating an existing one.

type UpsertAssetStore

type UpsertAssetStore interface {
	// UpsertGenesisPoint inserts a new or updates an existing genesis point
	// on disk, and returns the primary key.
	UpsertGenesisPoint(ctx context.Context, prevOut []byte) (int64, error)

	// AnchorGenesisPoint associates a genesis point with the transaction
	// that mints the associated assets on disk.
	AnchorGenesisPoint(ctx context.Context, arg GenesisPointAnchor) error

	// UpsertChainTx inserts a new or updates an existing chain tx into the
	// DB.
	UpsertChainTx(ctx context.Context, arg ChainTxParams) (int64, error)

	// UpsertGenesisAsset inserts a new or updates an existing genesis asset
	// (the base asset info) in the DB, and returns the primary key.
	//
	// TODO(roasbeef): hybrid version of the main tx interface that an
	// accept two diff storage interfaces?
	//
	//  * or use a sort of mix-in type?
	UpsertGenesisAsset(ctx context.Context, arg GenesisAsset) (int64, error)

	// FetchGenesisID is used to fetch the database ID of asset genesis
	// information already in the DB.
	FetchGenesisID(ctx context.Context,
		arg sqlc.FetchGenesisIDParams) (int64, error)

	// FetchScriptKeyIDByTweakedKey determines the database ID of a script
	// key by querying it by the tweaked key.
	FetchScriptKeyIDByTweakedKey(ctx context.Context,
		tweakedScriptKey []byte) (int64, error)

	// UpsertInternalKey inserts a new or updates an existing internal key
	// into the database.
	UpsertInternalKey(ctx context.Context, arg InternalKey) (int64, error)

	// UpsertScriptKey inserts a new script key on disk into the DB.
	UpsertScriptKey(context.Context, NewScriptKey) (int64, error)

	// UpsertAssetGroupWitness inserts a new asset group witness into the DB.
	UpsertAssetGroupWitness(ctx context.Context,
		arg AssetGroupWitness) (int64, error)

	// UpsertAssetGroupKey inserts a new or updates an existing group key
	// on disk, and returns the primary key.
	UpsertAssetGroupKey(ctx context.Context, arg AssetGroupKey) (int64,
		error)

	// QueryAssets fetches a filtered set of fully confirmed assets.
	QueryAssets(context.Context, QueryAssetFilters) ([]ConfirmedAsset,
		error)

	// InsertNewAsset inserts a new asset on disk.
	InsertNewAsset(ctx context.Context,
		arg sqlc.InsertNewAssetParams) (int64, error)

	// UpsertAssetMeta inserts a new asset meta into the DB.
	UpsertAssetMeta(ctx context.Context, arg NewAssetMeta) (int64, error)

	// SetAssetSpent marks an asset as being spent in the database. The
	// updated asset's database ID is returned.
	SetAssetSpent(ctx context.Context, arg SetAssetSpentParams) (int64,
		error)
}

UpsertAssetStore is a sub-set of the main sqlc.Querier interface that contains methods related to inserting/updating assets.

type UpsertFedGlobalSyncConfigParams added in v0.3.0

type UpsertFedGlobalSyncConfigParams = sqlc.UpsertFederationGlobalSyncConfigParams

UpsertFedGlobalSyncConfigParams is used to set the global federation sync configuration for a given proof type.

type UpsertFedProofSyncLogParams added in v0.3.3

type UpsertFedProofSyncLogParams = sqlc.UpsertFederationProofSyncLogParams

UpsertFedProofSyncLogParams is used to upsert federation proof sync logs.

type UpsertFedUniSyncConfigParams added in v0.3.0

type UpsertFedUniSyncConfigParams = sqlc.UpsertFederationUniSyncConfigParams

UpsertFedUniSyncConfigParams is used to set the universe specific federation sync configuration.

type UpsertUniverseLeaf added in v0.3.0

type UpsertUniverseLeaf = sqlc.UpsertUniverseLeafParams

UpsertUniverseLeaf is used to upsert universe leaves.

type UtxoQuery

type UtxoQuery = sqlc.FetchManagedUTXOParams

UtxoQuery lets us query a managed UTXO by either the transaction it references, or the outpoint.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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