common

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Overview

Copyright IBM Corp. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	// ConfigKeyTableNames is the absolute configuration key for global SQL table name overrides.
	//
	// This key is resolved against the root configuration provider (not a TMS-scoped
	// configuration), so it applies to all TMS instances on the node and maps directly
	// to token.storage.tableNames in the configuration file.
	//
	// Example YAML:
	//
	//   token:
	//     storage:
	//       tableNames:
	//         id_signers: identity_signers
	//         tokens: my_tokens
	ConfigKeyTableNames = "token.storage.tableNames"

	// ConfigKeySkipPrefix is the absolute configuration key for disabling the
	// FSC-generated prefix on SQL table names.
	//
	// When set to true, table names are produced without any prefix, regardless
	// of what prefix is supplied at runtime. Default is false.
	//
	// Example YAML:
	//
	//   token:
	//     storage:
	//       skipPrefix: true
	ConfigKeySkipPrefix = "token.storage.skipPrefix"
)
View Source
const (
	SelectStatement         = `SELECT`
	SelectDistinctStatement = `SELECT DISTINCT`
	InsertStatement         = `INSERT INTO`
	UpdateStatement         = `UPDATE`
	DeleteStatement         = `DELETE FROM`
)

Variables

This section is empty.

Functions

func Close

func Close(closer Closer)

func CloseFunc

func CloseFunc(closer func() error)

func HasMovementsParams

func HasMovementsParams(params driver2.QueryMovementsParams) cond.Condition

func HasTokenDetails

func HasTokenDetails(params driver2.QueryTokenDetailsParams, tokenTable common.Table) cond.Condition

func HasTokens

func HasTokens(colTxID, colIdx common.FieldName, ids ...*token.ID) cond.Condition

func HasTransactionParams

func HasTransactionParams(params driver2.QueryTransactionsParams, table common.Table) cond.Condition

func HasValidationParams

func HasValidationParams(params driver2.QueryValidationRecordsParams, tableName string) cond.Condition

func IsExpiredToken

func IsExpiredToken(tokenRequests, tokenLocks common3.Table, leaseExpiry time.Duration) cond.Condition

func RunTokenStoreBenchmarks

func RunTokenStoreBenchmarks(b *testing.B, store *TokenStore)

func SeedBenchTokens

func SeedBenchTokens(b *testing.B, store *TokenStore, n int)

func TestAWAddMovement

func TestAWAddMovement(t *testing.T, store transactionsStoreConstructor)

func TestAWAddTokenRequest

func TestAWAddTokenRequest(t *testing.T, store transactionsStoreConstructor)

func TestAWAddTransaction

func TestAWAddTransaction(t *testing.T, store transactionsStoreConstructor)

func TestAWAddValidationRecord

func TestAWAddValidationRecord(t *testing.T, store endorserStoreConstructor)

func TestAddTransactionEndorsementAck

func TestAddTransactionEndorsementAck(t *testing.T, store transactionsStoreConstructor)

func TestGetStatus

func TestGetStatus(t *testing.T, store transactionsStoreConstructor)

func TestGetStatusEndorser

func TestGetStatusEndorser(t *testing.T, store endorserStoreConstructor)

func TestGetTokenRequest

func TestGetTokenRequest(t *testing.T, store transactionsStoreConstructor)

func TestGetTransactionEndorsementAcks

func TestGetTransactionEndorsementAcks(t *testing.T, store transactionsStoreConstructor)

func TestGetWalletID

func TestGetWalletID(t *testing.T, store walletStoreConstructor)

func TestGetWalletIDs

func TestGetWalletIDs(t *testing.T, store walletStoreConstructor)

func TestIdentityExists

func TestIdentityExists(t *testing.T, store walletStoreConstructor)

func TestLoadMeta

func TestLoadMeta(t *testing.T, store walletStoreConstructor)

func TestLock

func TestLock(t *testing.T, store tokenLockStoreConstructor)

func TestQueryMovements

func TestQueryMovements(t *testing.T, store transactionsStoreConstructor, traits QueryConstructorTraits)

func TestQueryTokenRequests

func TestQueryTokenRequests(t *testing.T, store transactionsStoreConstructor, traits QueryConstructorTraits)

func TestQueryTransactions

func TestQueryTransactions(t *testing.T, store transactionsStoreConstructor)

func TestQueryValidations

func TestQueryValidations(t *testing.T, store endorserStoreConstructor, traits QueryConstructorTraits)

func TestSetStatus

func TestSetStatus(t *testing.T, store transactionsStoreConstructor)

func TestSetStatusEndorser

func TestSetStatusEndorser(t *testing.T, store endorserStoreConstructor)

func TestStoreIdentity

func TestStoreIdentity(t *testing.T, store walletStoreConstructor)

func TestStoreIdentityIdempotent

func TestStoreIdentityIdempotent(t *testing.T, store walletStoreConstructor)

func TestUnlockByTxID

func TestUnlockByTxID(t *testing.T, store tokenLockStoreConstructor)

Types

type AnyUUID

type AnyUUID struct{}

func (AnyUUID) Match

func (a AnyUUID) Match(v driver2.Value) bool

type BigInt

type BigInt struct {
	*big.Int
}

BigInt is a custom wrapper around math/big.Int that implements sql.Scanner for reading NUMERIC values from the DB

func (*BigInt) Scan

func (b *BigInt) Scan(value any) error

Scan implements the sql.Scanner interface for reading from the DB

type Closer

type Closer interface {
	Close() error
}

type Delete

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

func NewDeleteFrom

func NewDeleteFrom(table string) *Delete

func (*Delete) Compile

func (s *Delete) Compile() (string, error)

func (*Delete) Where

func (s *Delete) Where(where string) *Delete

type EndorserStore

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

EndorserStore manages validation records for token transaction endorsements

func NewEndorserStore

func NewEndorserStore(
	readDB, writeDB *sql.DB,
	tables TableNames,
	ci common3.CondInterpreter,
	pi common3.PagInterpreter,
) (*EndorserStore, error)

NewEndorserStore creates a new EndorserStore

func (*EndorserStore) Close

func (db *EndorserStore) Close() error

Close closes the database connections

func (*EndorserStore) CreateSchema

func (db *EndorserStore) CreateSchema() error

CreateSchema creates the database schema for the endorser store

func (*EndorserStore) GetSchema

func (db *EndorserStore) GetSchema() string

GetSchema returns the SQL schema for creating the endorser store tables

func (*EndorserStore) GetStatus

func (db *EndorserStore) GetStatus(ctx context.Context, txID string) (dbdriver.TxStatus, string, error)

GetStatus returns the status of a validation record

func (*EndorserStore) NewEndorserStoreTransaction

func (db *EndorserStore) NewEndorserStoreTransaction() (dbdriver.EndorserStoreTransaction, error)

NewEndorserStoreTransaction creates a new transaction for endorser operations

func (*EndorserStore) QueryValidations

QueryValidations returns an iterator over validation records matching the given params

type EndorserStoreTransaction

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

EndorserStoreTransaction represents a database transaction for endorser operations

func (*EndorserStoreTransaction) AddValidationRecord

func (w *EndorserStoreTransaction) AddValidationRecord(ctx context.Context, txID string, tokenRequest []byte, meta map[string][]byte, ppHash driver2.PPHash) error

AddValidationRecord adds a validation record to the database

func (*EndorserStoreTransaction) Commit

func (w *EndorserStoreTransaction) Commit() error

Commit commits the transaction

func (*EndorserStoreTransaction) Impl

Impl returns the underlying transaction implementation

func (*EndorserStoreTransaction) Rollback

func (w *EndorserStoreTransaction) Rollback()

Rollback rolls back the transaction

func (*EndorserStoreTransaction) SetStatus

func (w *EndorserStoreTransaction) SetStatus(ctx context.Context, txID string, status dbdriver.TxStatus, message string) error

SetStatus sets the status of a validation record

type IdentityStore

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

IdentityStore is a SQL-backed implementation of the IdentityStore interface.

func NewCachedIdentityStore

func NewCachedIdentityStore(
	readDB, writeDB *sql.DB,
	tables TableNames,
	ci common3.CondInterpreter,
	errorWrapper driver2.SQLErrorWrapper,
) (*IdentityStore, error)

func NewIdentityStore

func NewIdentityStore(
	readDB, writeDB *sql.DB,
	tables TableNames,
	signerInfoCache cache[bool],
	auditInfoCache cache[[]byte],
	ci common3.CondInterpreter,
	errorWrapper driver2.SQLErrorWrapper,
) (*IdentityStore, error)

func NewIdentityStoreWithNotifier

func NewIdentityStoreWithNotifier(
	readDB, writeDB *sql.DB,
	tables TableNames,
	signerInfoCache cache[bool],
	auditInfoCache cache[[]byte],
	ci common3.CondInterpreter,
	errorWrapper driver2.SQLErrorWrapper,
	notifier idriver.IdentityConfigurationNotifier,
) (*IdentityStore, error)

NewIdentityStoreWithNotifier creates a new IdentityStore with a notifier.

func NewNoCacheIdentityStore

func NewNoCacheIdentityStore(
	readDB, writeDB *sql.DB,
	tables TableNames,
	ci common3.CondInterpreter,
	errorWrapper driver2.SQLErrorWrapper,
) (*IdentityStore, error)

func (*IdentityStore) AddConfiguration

func (db *IdentityStore) AddConfiguration(ctx context.Context, wp driver.IdentityConfiguration) error

AddConfiguration stores an identity configuration in the database. It also enqueues an event to the notifier if available.

func (*IdentityStore) Close

func (db *IdentityStore) Close() error

func (*IdentityStore) ConfigurationExists

func (db *IdentityStore) ConfigurationExists(ctx context.Context, id, typ, url string) (bool, error)

func (*IdentityStore) CreateSchema

func (db *IdentityStore) CreateSchema() error

func (*IdentityStore) GetAuditInfo

func (db *IdentityStore) GetAuditInfo(ctx context.Context, id []byte) ([]byte, error)

func (*IdentityStore) GetConfiguration

func (db *IdentityStore) GetConfiguration(ctx context.Context, id, typ, url string) (*driver.IdentityConfiguration, error)

GetConfiguration returns the configuration with the given id, type, and url.

func (*IdentityStore) GetExistingSignerInfo

func (db *IdentityStore) GetExistingSignerInfo(ctx context.Context, ids ...tdriver.Identity) ([]string, error)

func (*IdentityStore) GetSchema

func (db *IdentityStore) GetSchema() string

func (*IdentityStore) GetSignerInfo

func (db *IdentityStore) GetSignerInfo(ctx context.Context, identity []byte) ([]byte, error)

func (*IdentityStore) GetTokenInfo

func (db *IdentityStore) GetTokenInfo(ctx context.Context, id []byte) ([]byte, []byte, error)

func (*IdentityStore) IterateSigners

func (db *IdentityStore) IterateSigners(ctx context.Context, offset, limit int) ([]idriver.SignerEntry, error)

IterateSigners returns a page of SignerEntry values from the Signers table, ordered by identity_hash, starting at the given offset and returning at most limit entries.

func (*IdentityStore) IteratorConfigurations

func (db *IdentityStore) IteratorConfigurations(ctx context.Context, configurationType string) (idriver.IdentityConfigurationIterator, error)

IteratorConfigurations returns an iterator to all configurations of the given type.

func (*IdentityStore) Notifier

Notifier returns the IdentityNotifier associated with this store.

func (*IdentityStore) RegisterIdentityDescriptor

func (db *IdentityStore) RegisterIdentityDescriptor(ctx context.Context, descriptor *idriver.IdentityDescriptor, alias tdriver.Identity) error

func (*IdentityStore) SignerInfoExists

func (db *IdentityStore) SignerInfoExists(ctx context.Context, id []byte) (bool, error)

func (*IdentityStore) StoreIdentityData

func (db *IdentityStore) StoreIdentityData(ctx context.Context, id []byte, identityAudit []byte, tokenMetadata []byte, tokenMetadataAudit []byte) error

func (*IdentityStore) StoreSignerInfo

func (db *IdentityStore) StoreSignerInfo(ctx context.Context, id tdriver.Identity, info []byte) error

type Insert

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

func NewInsertInto

func NewInsertInto(table string) *Insert

func (*Insert) Compile

func (i *Insert) Compile() (string, error)

func (*Insert) Rows

func (i *Insert) Rows(rows string) *Insert

type KeystoreStore

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

func NewKeystoreStore

func NewKeystoreStore(readDB, writeDB *sql.DB, tables TableNames, ci qcommon.CondInterpreter, errorWrapper driver.SQLErrorWrapper) (*KeystoreStore, error)

func (*KeystoreStore) Close

func (db *KeystoreStore) Close() error

func (*KeystoreStore) CreateSchema

func (db *KeystoreStore) CreateSchema() error

func (*KeystoreStore) Delete

func (db *KeystoreStore) Delete(key string) error

func (*KeystoreStore) Get

func (db *KeystoreStore) Get(key string, state any) error

func (*KeystoreStore) GetRaw

func (db *KeystoreStore) GetRaw(key string) ([]byte, error)

func (*KeystoreStore) GetSchema

func (db *KeystoreStore) GetSchema() string

func (*KeystoreStore) Put

func (db *KeystoreStore) Put(key string, state any) error

type PersistenceConstructor

type PersistenceConstructor[V common.DBObject] func(*common.RWDB, TableNames) (V, error)

type QueryConstructorTraits

type QueryConstructorTraits struct {
	SupportsIN          bool
	MultipleParenthesis bool
}

type Select

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

func NewSelect

func NewSelect(columns ...string) *Select

func NewSelectDistinct

func NewSelectDistinct(columns ...string) *Select

func (*Select) Compile

func (s *Select) Compile() (string, error)

func (*Select) From

func (s *Select) From(tables ...string) *Select

func (*Select) OrderBy

func (s *Select) OrderBy(orderBy string) *Select

func (*Select) Where

func (s *Select) Where(where string) *Select

type StorageConfig

type StorageConfig struct {
	// TableNames contains optional short-code overrides for individual table names.
	TableNames TableNamesConfig
	// SkipPrefix disables the FSC-generated prefix on all table names when true.
	// Default is false.
	SkipPrefix bool
}

StorageConfig holds all SQL storage configuration options that can be read from the configuration provider.

func LoadStorageConfig

func LoadStorageConfig(cfg driver2.Config) (StorageConfig, error)

LoadStorageConfig reads all SQL storage options from cfg. It returns a zero-value StorageConfig (and nil error) when cfg is nil.

type TableNameCreator

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

func NewTableNameCreator

func NewTableNameCreator(defaultPrefix string) *TableNameCreator

func (*TableNameCreator) CreateTableName

func (c *TableNameCreator) CreateTableName(tablePrefix, name string, params ...string) (string, error)

func (*TableNameCreator) GetFormatter

func (c *TableNameCreator) GetFormatter(prefix string) (*tableNameFormatter, error)

func (*TableNameCreator) MustGetTableName

func (c *TableNameCreator) MustGetTableName(tablePrefix, name string, params ...string) string

type TableNames

type TableNames struct {
	Prefix                 string
	Params                 []string
	Movements              string
	Transactions           string
	Requests               string
	Validations            string
	TransactionEndorseAck  string
	Certifications         string
	Tokens                 string
	Ownership              string
	PublicParams           string
	Wallets                string
	IdentityConfigurations string
	IdentityInfo           string
	Signers                string
	TokenLocks             string
	KeyStore               string
	EIDLeases              string
	TokenSKICleanups       string
}

func GetTableNames

func GetTableNames(prefix string, params ...string) (TableNames, error)

GetTableNames returns the SQL table names for the given prefix and params using the default short codes. It is equivalent to calling GetTableNamesWithOverrides with a nil overrides map.

func GetTableNamesWithConfig

func GetTableNamesWithConfig(prefix string, cfg StorageConfig, params ...string) (TableNames, error)

GetTableNamesWithConfig returns the SQL table names using all options from cfg.

func GetTableNamesWithOverrides

func GetTableNamesWithOverrides(prefix string, overrides TableNamesConfig, params ...string) (TableNames, error)

GetTableNamesWithOverrides returns the SQL table names for the given prefix and params, applying any short-code substitutions from overrides before the FSC formatter wraps them with the prefix and params.

The overrides map key is the canonical short code (e.g. "id_signers") and the value is the replacement short code (e.g. "identity_signers"). Unknown keys produce a warning and are ignored; all other fields keep their default values.

func GetTableNamesWithOverridesSkipPrefix

func GetTableNamesWithOverridesSkipPrefix(prefix string, overrides TableNamesConfig, params ...string) (TableNames, error)

GetTableNamesWithOverridesSkipPrefix is like GetTableNamesWithOverrides but omits the FSC-generated prefix from every table name.

type TableNamesConfig

type TableNamesConfig map[string]string

TableNamesConfig maps a short code (e.g. "id_signers") to the replacement short code that will be used when generating the final SQL table name. The FSC-generated prefix and params are still applied around the replacement value.

Unknown keys are warned and ignored. Omitted keys keep their default short codes.

func LoadTableNamesConfig

func LoadTableNamesConfig(cfg driver2.Config) (TableNamesConfig, error)

LoadTableNamesConfig reads the table name overrides from cfg. It returns an empty map (and nil error) when cfg is nil or the config key is absent.

type TokenLockStore

type TokenLockStore struct {
	ReadDB  *sql.DB
	WriteDB *sql.DB
	Table   tokenLockTables
	Logger  logging.Logger
	// contains filtered or unexported fields
}

func NewTokenLockStore

func NewTokenLockStore(readDB, writeDB *sql.DB, tables TableNames, ci common3.CondInterpreter) (*TokenLockStore, error)

func (*TokenLockStore) Close

func (db *TokenLockStore) Close() error

func (*TokenLockStore) CreateSchema

func (db *TokenLockStore) CreateSchema() error

func (*TokenLockStore) GetSchema

func (db *TokenLockStore) GetSchema() string

func (*TokenLockStore) Lock

func (db *TokenLockStore) Lock(ctx context.Context, tokenID *token.ID, consumerTxID transaction.ID) error

func (*TokenLockStore) UnlockByTxID

func (db *TokenLockStore) UnlockByTxID(ctx context.Context, consumerTxID transaction.ID) error

type TokenStore

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

func NewTokenStoreWithNotifier

func NewTokenStoreWithNotifier(readDB, writeDB *sql.DB, tables TableNames, ci common3.CondInterpreter, notifier driver.TokenNotifier) (*TokenStore, error)

func NewTokenStoreWithNotifierAndCleanup

func NewTokenStoreWithNotifierAndCleanup(
	readDB, writeDB *sql.DB,
	tables TableNames,
	ci common3.CondInterpreter,
	notifier driver.TokenNotifier,
	cleanupLeaderFactory func(context.Context, *sql.DB, int64) (driver.CleanupLeadership, bool, error),
) (*TokenStore, error)

func (*TokenStore) AcquireCleanupLeadership

func (db *TokenStore) AcquireCleanupLeadership(ctx context.Context, lockID int64) (driver.CleanupLeadership, bool, error)

AcquireCleanupLeadership attempts to acquire leadership for keystore cleanup operations. When no leader factory is configured, leadership is granted locally (for non-distributed deployments). In distributed deployments (PostgreSQL), this uses advisory locks to ensure only one instance performs cleanup. AcquireCleanupLeadership returns a leadership handle for cleanup sweeping. When no leader factory is configured, leadership is granted locally.

func (*TokenStore) Balance

func (db *TokenStore) Balance(ctx context.Context, walletID string, typ token.Type) (*big.Int, error)

Balance returns the sum of the amounts of the tokens with type and EID equal to those passed as arguments. The result is returned as a *big.Int to support arbitrary precision and prevent overflow.

func (*TokenStore) Close

func (db *TokenStore) Close() error

func (*TokenStore) ContinueTokenDBTransaction

func (db *TokenStore) ContinueTokenDBTransaction(tx driver.Transaction) (driver.TokenStoreTransaction, error)

func (*TokenStore) CreateSchema

func (db *TokenStore) CreateSchema() error

func (*TokenStore) DeleteTokens

func (db *TokenStore) DeleteTokens(ctx context.Context, deletedBy string, ids ...*token.ID) error

DeleteTokens deletes multiple tokens at the same time (when spent, invalid or expired)

func (*TokenStore) ExistsCertification

func (db *TokenStore) ExistsCertification(ctx context.Context, tokenID *token.ID) bool

func (*TokenStore) GetAllTokenInfos

func (db *TokenStore) GetAllTokenInfos(ctx context.Context, ids []*token.ID) ([][]byte, error)

GetAllTokenInfos retrieves the token information for the passed ids.

func (*TokenStore) GetCertifications

func (db *TokenStore) GetCertifications(ctx context.Context, ids []*token.ID) ([][]byte, error)

func (*TokenStore) GetDeletedTokensPendingSKICleanup

func (db *TokenStore) GetDeletedTokensPendingSKICleanup(ctx context.Context, olderThan time.Duration, limit int) ([]driver.DeletedToken, error)

GetDeletedTokensPendingSKICleanup returns deleted tokens older than the specified duration that haven't had their SKI keys cleaned up yet (no record in token_ski_cleanups table).

func (*TokenStore) GetSchema

func (db *TokenStore) GetSchema() string

func (*TokenStore) GetTokenMetadata

func (db *TokenStore) GetTokenMetadata(ctx context.Context, ids []*token.ID) ([][]byte, error)

GetTokenMetadata retrieves the token metadata for the passed ids. For each id, the callback is invoked to unmarshal the token metadata

func (*TokenStore) GetTokenOutputs

func (db *TokenStore) GetTokenOutputs(ctx context.Context, ids []*token.ID, callback tdriver.QueryCallbackFunc) error

func (*TokenStore) GetTokenOutputsAndMeta

func (db *TokenStore) GetTokenOutputsAndMeta(ctx context.Context, ids []*token.ID) ([][]byte, [][]byte, []token.Format, error)

GetTokenOutputsAndMeta retrieves both the token output, metadata, and type for the passed ids.

func (*TokenStore) GetTokens

func (db *TokenStore) GetTokens(ctx context.Context, inputs ...*token.ID) ([]*token.Token, error)

GetTokens returns the owned tokens and their identifier keys for the passed ids.

func (*TokenStore) HasTokenForIdentity

func (db *TokenStore) HasTokenForIdentity(ctx context.Context, ownerIdentity []byte, ownerType string) (bool, error)

HasTokenForIdentity returns true if any token in the Tokens table has the given owner identity and owner type, regardless of whether the token has been spent or not.

func (*TokenStore) IsMine

func (db *TokenStore) IsMine(ctx context.Context, txID string, index uint64) (bool, error)

IsMine just checks if the token is in the local storage and not deleted

func (*TokenStore) ListAuditTokens

func (db *TokenStore) ListAuditTokens(ctx context.Context, ids ...*token.ID) ([]*token.Token, error)

ListAuditTokens returns the audited tokens associated to the passed ids

func (*TokenStore) ListHistoryIssuedTokens

func (db *TokenStore) ListHistoryIssuedTokens(ctx context.Context) (*token.IssuedTokens, error)

ListHistoryIssuedTokens returns the list of issued tokens

func (*TokenStore) ListUnspentTokens

func (db *TokenStore) ListUnspentTokens(ctx context.Context) (*token.UnspentTokens, error)

ListUnspentTokens returns the list of unspent tokens

func (*TokenStore) ListUnspentTokensBy

func (db *TokenStore) ListUnspentTokensBy(ctx context.Context, walletID string, typ token.Type) (*token.UnspentTokens, error)

ListUnspentTokensBy returns the list of unspent tokens, filtered by owner and token type

func (*TokenStore) ListUnspentTokensByWallets

func (db *TokenStore) ListUnspentTokensByWallets(ctx context.Context, walletIDs []string, typ token.Type) (map[string]*token.UnspentTokens, error)

ListUnspentTokensByWallets issues a single SELECT with an IN clause on the owning wallet, then partitions the result rows in Go. This avoids the N round-trip cost of calling ListUnspentTokensBy in a loop when a caller (e.g. a bank-node wallet list endpoint) needs balances for many wallets at once. Empty input returns an empty map without querying.

func (*TokenStore) MarkTokenCleaned

func (db *TokenStore) MarkTokenCleaned(ctx context.Context, txID string, index uint64, cleanedBy string) error

MarkTokenCleaned marks a token as having its cryptographic keys cleaned up. This prevents the cleanup service from processing the same token multiple times. The cleanedBy parameter identifies which instance performed the cleanup.

func (*TokenStore) NewTokenDBTransaction

func (db *TokenStore) NewTokenDBTransaction() (driver.TokenStoreTransaction, error)

func (*TokenStore) Notifier

func (db *TokenStore) Notifier() (driver.TokenNotifier, error)

func (*TokenStore) PublicParams

func (db *TokenStore) PublicParams(ctx context.Context) ([]byte, error)

func (*TokenStore) PublicParamsByHash

func (db *TokenStore) PublicParamsByHash(ctx context.Context, rawHash tdriver.PPHash) ([]byte, error)

func (*TokenStore) QueryTokenDetails

func (db *TokenStore) QueryTokenDetails(ctx context.Context, params driver.QueryTokenDetailsParams) ([]driver.TokenDetails, error)

QueryTokenDetails returns details about owned tokens, regardless if they have been spent or not. Filters work cumulatively and may be left empty. If a token is owned by two enrollmentIDs and there is no filter on enrollmentID, the token will be returned twice (once for each owner).

func (*TokenStore) SetSupportedTokenFormats

func (db *TokenStore) SetSupportedTokenFormats(formats []token.Format) error

func (*TokenStore) SpendableTokensIteratorBy

func (db *TokenStore) SpendableTokensIteratorBy(ctx context.Context, walletID string, typ token.Type) (tdriver.SpendableTokensIterator, error)

SpendableTokensIteratorBy returns the minimum information about the tokens needed for the selector

func (*TokenStore) StoreCertifications

func (db *TokenStore) StoreCertifications(ctx context.Context, certifications map[*token.ID][]byte) error

func (*TokenStore) StorePublicParams

func (db *TokenStore) StorePublicParams(ctx context.Context, raw []byte) error

func (*TokenStore) StoreToken

func (db *TokenStore) StoreToken(ctx context.Context, tr driver.TokenRecord, owners []string) (err error)

func (*TokenStore) TransactionExists

func (db *TokenStore) TransactionExists(ctx context.Context, id string) (bool, error)

func (*TokenStore) UnspentLedgerTokensIteratorBy

func (db *TokenStore) UnspentLedgerTokensIteratorBy(ctx context.Context) (tdriver.LedgerTokensIterator, error)

UnspentLedgerTokensIteratorBy returns an iterator over all unspent ledger tokens

func (*TokenStore) UnspentTokensIterator

func (db *TokenStore) UnspentTokensIterator(ctx context.Context) (tdriver.UnspentTokensIterator, error)

UnspentTokensIterator returns an iterator over all unspent tokens

func (*TokenStore) UnspentTokensIteratorBy

func (db *TokenStore) UnspentTokensIteratorBy(ctx context.Context, walletID string, tokenType token.Type) (tdriver.UnspentTokensIterator, error)

UnspentTokensIteratorBy returns an iterator of unspent tokens owned by the passed wallet id and of the passed type. Empty tokenType returns all types.

Implemented as a single SQL with two UNION ALL branches so each side can use its own index, instead of a cross-table OR predicate that PostgreSQL cannot resolve with the partial index on (owner_wallet_id, token_type) WHERE is_deleted=false AND owner=true:

  1. tokens directly owned: filters tokens.owner_wallet_id, hits the partial index in microseconds. Joins ownership by primary key to preserve the pre-PR semantic that a token must have at least one ownership row to be visible (StoreToken can persist a tokens row without an ownership row when the owners slice is empty, and the original INNER JOIN intentionally excluded those).
  2. tokens reachable via the ownership-delegation table: joins ownership -> tokens by primary key. Returns zero rows when delegation is not configured, at which point that branch is essentially free.

Both branches share a single SQL statement and therefore a single connection from the pool, which avoids the deadlock that would arise if two concurrent QueryContexts each tried to acquire a second connection. PostgreSQL 9.6+ may also execute the branches in parallel via parallel append. UNION ALL is used (not UNION) to skip the per-row sort/hash dedup pass; duplicates between the two branches (and within branch 1 when a token has multiple ownership rows) are filtered at the iterator layer.

func (*TokenStore) UnsupportedTokensIteratorBy

func (db *TokenStore) UnsupportedTokensIteratorBy(ctx context.Context, walletID string, tokenType token.Type) (tdriver.UnsupportedTokensIterator, error)

UnsupportedTokensIteratorBy returns the minimum information for upgrade about the tokens that are not supported

func (*TokenStore) WhoDeletedTokens

func (db *TokenStore) WhoDeletedTokens(ctx context.Context, inputs ...*token.ID) ([]string, []bool, error)

WhoDeletedTokens returns information about which transaction deleted the passed tokens. The bool array is an indicator used to tell if the token at a given position has been deleted or not

type TokenTransaction

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

func (*TokenTransaction) Commit

func (t *TokenTransaction) Commit() error

func (*TokenTransaction) Delete

func (t *TokenTransaction) Delete(ctx context.Context, tokenID token.ID, deletedBy string) error

func (*TokenTransaction) GetToken

func (t *TokenTransaction) GetToken(ctx context.Context, tokenID token.ID, includeDeleted bool) (*token.Token, []string, error)

func (*TokenTransaction) Rollback

func (t *TokenTransaction) Rollback() error

func (*TokenTransaction) SetSpendable

func (t *TokenTransaction) SetSpendable(ctx context.Context, tokenID token.ID, spendable bool) error

func (*TokenTransaction) SetSpendableBySupportedTokenFormats

func (t *TokenTransaction) SetSpendableBySupportedTokenFormats(ctx context.Context, formats []token.Format) error

func (*TokenTransaction) StoreToken

func (t *TokenTransaction) StoreToken(ctx context.Context, tr driver.TokenRecord, owners []string) error

type TransactionStore

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

func NewAuditTransactionStore

func NewAuditTransactionStore(readDB, writeDB *sql.DB, tables TableNames, ci common3.CondInterpreter, pi common3.PagInterpreter) (*TransactionStore, error)

func NewOwnerTransactionStore

func NewOwnerTransactionStore(readDB, writeDB *sql.DB, tables TableNames, ci common3.CondInterpreter, pi common3.PagInterpreter) (*TransactionStore, error)

func NewTransactionStoreWithNotifierAndRecovery

func NewTransactionStoreWithNotifierAndRecovery(
	readDB, writeDB *sql.DB,
	tables TableNames,
	ci common3.CondInterpreter,
	pi common3.PagInterpreter,
	notifier dbdriver.TransactionNotifier,
	recoveryLeaderFactory func(context.Context, *sql.DB, int64) (dbdriver.RecoveryLeadership, bool, error),
) (*TransactionStore, error)

func (*TransactionStore) AcquireRecoveryLeadership

func (db *TransactionStore) AcquireRecoveryLeadership(ctx context.Context, lockID int64) (dbdriver.RecoveryLeadership, bool, error)

AcquireRecoveryLeadership returns a leadership handle for recovery sweeping. When no leader factory is configured, leadership is granted locally.

func (*TransactionStore) AddTransactionEndorsementAck

func (db *TransactionStore) AddTransactionEndorsementAck(ctx context.Context, txID string, endorser token.Identity, sigma []byte) (err error)

func (*TransactionStore) ClaimPendingTransactions

func (db *TransactionStore) ClaimPendingTransactions(ctx context.Context, params dbdriver.RecoveryClaimParams) ([]*dbdriver.RecoveryClaim, error)

ClaimPendingTransactions returns a claimed batch of Pending transactions. The default SQL implementation is permissive and does not persist recovery claims. tx_id and stored_at are projected directly from the requests table — the transactions table is no longer joined since it carries no information the recovery loop needs and adding it would re-introduce a fan-out by movement/output that the caller would have to dedupe by tx_id.

func (*TransactionStore) Close

func (db *TransactionStore) Close() error

func (*TransactionStore) CreateSchema

func (db *TransactionStore) CreateSchema() error

func (*TransactionStore) GetSchema

func (db *TransactionStore) GetSchema() string

func (*TransactionStore) GetStatus

func (db *TransactionStore) GetStatus(ctx context.Context, txID string) (dbdriver.TxStatus, string, error)

func (*TransactionStore) GetTokenRequest

func (db *TransactionStore) GetTokenRequest(ctx context.Context, txID string) ([]byte, error)

func (*TransactionStore) GetTokenRequests

func (db *TransactionStore) GetTokenRequests(ctx context.Context, txIDs []string) (map[string][]byte, error)

GetTokenRequests fetches the token requests for the given tx ids in a single SELECT. Missing tx ids are absent from the returned map — callers should treat a missing key identically to GetTokenRequest returning nil. Empty input returns an empty map without querying.

func (*TransactionStore) GetTransactionEndorsementAcks

func (db *TransactionStore) GetTransactionEndorsementAcks(ctx context.Context, txID string) (map[string][]byte, error)

func (*TransactionStore) NewTransactionStoreTransaction

func (db *TransactionStore) NewTransactionStoreTransaction() (dbdriver.TransactionStoreTransaction, error)

func (*TransactionStore) Notifier

func (*TransactionStore) PrefixedTableName

func (s *TransactionStore) PrefixedTableName(name string) string

PrefixedTableName returns the formatted table name for the given logical name.

func (*TransactionStore) QueryMovements

func (db *TransactionStore) QueryMovements(ctx context.Context, params dbdriver.QueryMovementsParams) (res []*dbdriver.MovementRecord, err error)

func (*TransactionStore) QueryTokenRequests

QueryTokenRequests returns an iterator over the token requests matching the passed params

func (*TransactionStore) QueryTransactions

func (*TransactionStore) ReleaseRecoveryClaim

func (db *TransactionStore) ReleaseRecoveryClaim(context.Context, string, string, string) error

ReleaseRecoveryClaim clears persisted recovery claim metadata and stores the recovery message. The default SQL implementation is a no-op.

func (*TransactionStore) SetStatus

func (db *TransactionStore) SetStatus(ctx context.Context, txID string, status dbdriver.TxStatus, message string) error

type TransactionStoreTransaction

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

func (*TransactionStoreTransaction) AddMovement

func (*TransactionStoreTransaction) AddTokenRequest

func (w *TransactionStoreTransaction) AddTokenRequest(ctx context.Context, txID string, tr []byte, applicationMetadata, publicMetadata map[string][]byte, ppHash driver2.PPHash) error

func (*TransactionStoreTransaction) AddTransaction

func (*TransactionStoreTransaction) Commit

func (w *TransactionStoreTransaction) Commit() error

func (*TransactionStoreTransaction) Impl

func (*TransactionStoreTransaction) Rollback

func (w *TransactionStoreTransaction) Rollback()

func (*TransactionStoreTransaction) SetStatus

func (w *TransactionStoreTransaction) SetStatus(ctx context.Context, txID string, status dbdriver.TxStatus, message string) error

type Update

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

func NewUpdate

func NewUpdate(table string) *Update

func (*Update) Compile

func (u *Update) Compile() (string, error)

func (*Update) Set

func (u *Update) Set(rows string) *Update

func (*Update) Where

func (u *Update) Where(where string) *Update

type WalletStore

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

func NewWalletStore

func NewWalletStore(readDB, writeDB *sql.DB, tables TableNames, ci common3.CondInterpreter) (*WalletStore, error)

func (*WalletStore) Close

func (db *WalletStore) Close() error

func (*WalletStore) CreateSchema

func (db *WalletStore) CreateSchema() error

func (*WalletStore) GetSchema

func (db *WalletStore) GetSchema() string

func (*WalletStore) GetWalletID

func (db *WalletStore) GetWalletID(ctx context.Context, identity token.Identity, roleID int) (driver.WalletID, error)

func (*WalletStore) GetWalletIDs

func (db *WalletStore) GetWalletIDs(ctx context.Context, roleID int) ([]driver.WalletID, error)

func (*WalletStore) IdentityExists

func (db *WalletStore) IdentityExists(ctx context.Context, identity token.Identity, wID driver.WalletID, roleID int) bool

func (*WalletStore) LoadMeta

func (db *WalletStore) LoadMeta(ctx context.Context, identity token.Identity, wID driver.WalletID, roleID int) ([]byte, error)

func (*WalletStore) StoreIdentity

func (db *WalletStore) StoreIdentity(ctx context.Context, identity token.Identity, eID string, wID driver.WalletID, roleID int, meta []byte) error

Jump to

Keyboard shortcuts

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