common

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QueryLabel      tracing.LabelName = "query"
	ResultRowsLabel tracing.LabelName = "result_rows"
)
View Source
const (
	SelectStatement         = `SELECT`
	SelectDistinctStatement = `SELECT DISTINCT`
	InsertStatement         = `INSERT INTO`
	UpdateStatement         = `UPDATE`
	DeleteStatement         = `DELETE FROM`
)
View Source
const (
	TST = token.Type("TST")
	ABC = token.Type("ABC")
)

Variables

View Source
var TokenNotifierCases = []struct {
	Name string
	Fn   func(*testing.T, driver.TokenDB, driver.TokenNotifier)
}{
	{"SubscribeStore", TSubscribeStore},
	{"SubscribeStoreDelete", TSubscribeStoreDelete},
	{"SubscribeStoreNoCommit", TSubscribeStoreNoCommit},
	{"SubscribeRead", TSubscribeRead},
}
View Source
var TokensCases = []struct {
	Name string
	Fn   func(*testing.T, *TokenDB)
}{
	{"Transaction", TTransaction},
	{"SaveAndGetToken", TSaveAndGetToken},
	{"DeleteAndMine", TDeleteAndMine},
	{"GetTokenMetadata", TGetTokenInfos},
	{"ListAuditTokens", TListAuditTokens},
	{"ListIssuedTokens", TListIssuedTokens},
	{"DeleteMultiple", TDeleteMultiple},
	{"PublicParams", TPublicParams},
	{"Certification", TCertification},
	{"QueryTokenDetails", TQueryTokenDetails},
	{"TTokenTypes", TTokenTypes},
}

Functions

func Close

func Close(closer Closer)

func GetTableNames

func GetTableNames(prefix string) (tableNames, error)

func NewAuditTransactionDB

func NewAuditTransactionDB(sqlDB *sql.DB, opts NewDBOpts, ci TokenInterpreter) (driver.AuditTransactionDB, error)

func NewCachedIdentityDB

func NewCachedIdentityDB(db *sql.DB, opts NewDBOpts) (driver.IdentityDB, error)

func NewTokenDB

func NewTokenDB(db *sql.DB, opts NewDBOpts, ci TokenInterpreter) (driver.TokenDB, error)

func NewTransactionDB

func NewTransactionDB(db *sql.DB, opts NewDBOpts, ci TokenInterpreter) (driver.TokenTransactionDB, error)

func NewWalletDB

func NewWalletDB(db *sql.DB, opts NewDBOpts) (driver.WalletDB, error)

func QueryUnique

func QueryUnique[T any](db *sql.DB, query string, args ...any) (T, error)

func StartPostgresContainer

func StartPostgresContainer(t *testing.T) (func(), string)

https://testcontainers.com/guides/getting-started-with-testcontainers-for-go/ Note: Before running tests: docker pull postgres:16.2-alpine Test may time out if image is not present on machine.

func StartPostgresWithFmt

func StartPostgresWithFmt(configs map[string]*PostgresConfig) (func(), error)

func TCertification

func TCertification(t *testing.T, db *TokenDB)

func TDeleteAndMine

func TDeleteAndMine(t *testing.T, db *TokenDB)

func TDeleteMultiple

func TDeleteMultiple(t *testing.T, db *TokenDB)

func TGetTokenInfos

func TGetTokenInfos(t *testing.T, db *TokenDB)

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

func TListAuditTokens

func TListAuditTokens(t *testing.T, db *TokenDB)

// ListAuditTokens returns the audited tokens associated to the passed ids

func TListIssuedTokens

func TListIssuedTokens(t *testing.T, db *TokenDB)

func TPublicParams

func TPublicParams(t *testing.T, db *TokenDB)

func TQueryTokenDetails

func TQueryTokenDetails(t *testing.T, db *TokenDB)

func TSaveAndGetToken

func TSaveAndGetToken(t *testing.T, db *TokenDB)

func TSubscribeRead

func TSubscribeRead(t *testing.T, db driver.TokenDB, notifier driver.TokenNotifier)

func TSubscribeStore

func TSubscribeStore(t *testing.T, db driver.TokenDB, notifier driver.TokenNotifier)

func TSubscribeStoreDelete

func TSubscribeStoreDelete(t *testing.T, db driver.TokenDB, notifier driver.TokenNotifier)

func TSubscribeStoreNoCommit

func TSubscribeStoreNoCommit(t *testing.T, db driver.TokenDB, notifier driver.TokenNotifier)

func TTokenTypes

func TTokenTypes(t *testing.T, db *TokenDB)

func TTransaction

func TTransaction(t *testing.T, db *TokenDB)

Types

type AtomicWrite

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

func (*AtomicWrite) AddMovement

func (w *AtomicWrite) AddMovement(r *driver.MovementRecord) error

func (*AtomicWrite) AddTokenRequest

func (w *AtomicWrite) AddTokenRequest(txID string, tr []byte, applicationMetadata map[string][]byte, ppHash driver2.PPHash) error

func (*AtomicWrite) AddTransaction

func (w *AtomicWrite) AddTransaction(r *driver.TransactionRecord) error

func (*AtomicWrite) AddValidationRecord

func (w *AtomicWrite) AddValidationRecord(txID string, meta map[string][]byte) error

func (*AtomicWrite) Commit

func (w *AtomicWrite) Commit() error

func (*AtomicWrite) Rollback

func (w *AtomicWrite) Rollback()

type Closer

type Closer interface {
	Close() error
}

type DBOpener

type DBOpener = Opener[*sql.DB]

func NewSQLDBOpener

func NewSQLDBOpener(optsKey, envVarKey string) *DBOpener

type DataSourceProvider

type DataSourceProvider = postgres2.DataSourceProvider

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 IdentityConfigurationIterator

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

func (*IdentityConfigurationIterator) Close

func (*IdentityConfigurationIterator) HasNext

func (w *IdentityConfigurationIterator) HasNext() bool

func (*IdentityConfigurationIterator) Next

type IdentityDB

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

func NewIdentityDB

func NewIdentityDB(db *sql.DB, tablePrefix string, createSchema bool, signerInfoCache cache[bool], auditInfoCache cache[[]byte]) (*IdentityDB, error)

func (*IdentityDB) AddConfiguration

func (db *IdentityDB) AddConfiguration(wp driver.IdentityConfiguration) error

func (*IdentityDB) ConfigurationExists

func (db *IdentityDB) ConfigurationExists(id, typ string) (bool, error)

func (*IdentityDB) GetAuditInfo

func (db *IdentityDB) GetAuditInfo(id []byte) ([]byte, error)

func (*IdentityDB) GetSchema

func (db *IdentityDB) GetSchema() string

func (*IdentityDB) GetSignerInfo

func (db *IdentityDB) GetSignerInfo(identity []byte) ([]byte, error)

func (*IdentityDB) GetTokenInfo

func (db *IdentityDB) GetTokenInfo(id []byte) ([]byte, []byte, error)

func (*IdentityDB) IteratorConfigurations

func (db *IdentityDB) IteratorConfigurations(configurationType string) (driver.Iterator[driver.IdentityConfiguration], error)

func (*IdentityDB) SignerInfoExists

func (db *IdentityDB) SignerInfoExists(id []byte) (bool, error)

func (*IdentityDB) StoreIdentityData

func (db *IdentityDB) StoreIdentityData(id []byte, identityAudit []byte, tokenMetadata []byte, tokenMetadataAudit []byte) error

func (*IdentityDB) StoreSignerInfo

func (db *IdentityDB) StoreSignerInfo(id, 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 NewDBFunc

type NewDBFunc[V any] func(db *sql.DB, opts NewDBOpts) (V, error)

type NewDBOpts

type NewDBOpts struct {
	DataSource   string
	TablePrefix  string
	CreateSchema bool
}

func NewDBOptsFromOpts

func NewDBOptsFromOpts(o Opts) NewDBOpts

type OpenDBFunc

type OpenDBFunc[V any] func(k Opts) (V, error)

type Opener

type Opener[V any] struct {
	// contains filtered or unexported fields
}

func NewOpener

func NewOpener[V any](optsKey, envVarKey string, constructors OpenDBFunc[V]) *Opener[V]

func NewOpenerFromMap

func NewOpenerFromMap[V any](optsKey, envVarKey string, constructors map[common.SQLDriverType]OpenDBFunc[V]) *Opener[V]

func (*Opener[V]) Open

func (d *Opener[V]) Open(cp driver.ConfigProvider, tmsID token.TMSID) (V, error)

func (*Opener[V]) OpenSQLDB

func (d *Opener[V]) OpenSQLDB(driverName common.SQLDriverType, dataSourceName string, maxOpenConns int, skipPragmas bool) (V, error)

func (*Opener[V]) OpenWithOpts

func (d *Opener[V]) OpenWithOpts(cp driver.ConfigProvider, tmsID token.TMSID) (V, *Opts, error)

type Opts

type Opts = common.Opts

type PostgresConfig

type PostgresConfig = postgres2.ContainerConfig

func DefaultPostgresConfig

func DefaultPostgresConfig(node string) *PostgresConfig

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 TokenDB

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

func (*TokenDB) Balance

func (db *TokenDB) Balance(walletID string, typ token.Type) (uint64, error)

Balance returns the sun of the amounts, with 64 bits of precision, of the tokens with type and EID equal to those passed as arguments.

func (*TokenDB) Close

func (db *TokenDB) Close()

func (*TokenDB) DeleteTokens

func (db *TokenDB) DeleteTokens(deletedBy string, ids ...*token.ID) error

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

func (*TokenDB) ExistsCertification

func (db *TokenDB) ExistsCertification(tokenID *token.ID) bool

func (*TokenDB) GetAllTokenInfos

func (db *TokenDB) GetAllTokenInfos(ids []*token.ID) ([][]byte, error)

GetAllTokenInfos retrieves the token information for the passed ids.

func (*TokenDB) GetCertifications

func (db *TokenDB) GetCertifications(ids []*token.ID) ([][]byte, error)

func (*TokenDB) GetSchema

func (db *TokenDB) GetSchema() string

func (*TokenDB) GetTokenMetadata

func (db *TokenDB) GetTokenMetadata(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 (*TokenDB) GetTokenOutputs

func (db *TokenDB) GetTokenOutputs(ids []*token.ID, callback tdriver.QueryCallbackFunc) error

func (*TokenDB) GetTokenOutputsAndMeta

func (db *TokenDB) 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 (*TokenDB) GetTokens

func (db *TokenDB) GetTokens(inputs ...*token.ID) ([]*token.Token, error)

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

func (*TokenDB) IsMine

func (db *TokenDB) IsMine(txID string, index uint64) (bool, error)

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

func (*TokenDB) ListAuditTokens

func (db *TokenDB) ListAuditTokens(ids ...*token.ID) ([]*token.Token, error)

ListAuditTokens returns the audited tokens associated to the passed ids

func (*TokenDB) ListHistoryIssuedTokens

func (db *TokenDB) ListHistoryIssuedTokens() (*token.IssuedTokens, error)

ListHistoryIssuedTokens returns the list of issued tokens

func (*TokenDB) ListUnspentTokens

func (db *TokenDB) ListUnspentTokens() (*token.UnspentTokens, error)

ListUnspentTokens returns the list of unspent tokens

func (*TokenDB) ListUnspentTokensBy

func (db *TokenDB) ListUnspentTokensBy(walletID string, typ token.Type) (*token.UnspentTokens, error)

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

func (*TokenDB) NewTokenDBTransaction

func (db *TokenDB) NewTokenDBTransaction() (driver.TokenDBTransaction, error)

func (*TokenDB) PublicParams

func (db *TokenDB) PublicParams() ([]byte, error)

func (*TokenDB) PublicParamsByHash

func (db *TokenDB) PublicParamsByHash(rawHash tdriver.PPHash) ([]byte, error)

func (*TokenDB) QueryTokenDetails

func (db *TokenDB) QueryTokenDetails(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 (*TokenDB) SetSupportedTokenFormats

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

func (*TokenDB) SpendableTokensIteratorBy

func (db *TokenDB) 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 (*TokenDB) StoreCertifications

func (db *TokenDB) StoreCertifications(certifications map[*token.ID][]byte) (err error)

func (*TokenDB) StorePublicParams

func (db *TokenDB) StorePublicParams(raw []byte) error

func (*TokenDB) StoreToken

func (db *TokenDB) StoreToken(tr driver.TokenRecord, owners []string) (err error)

func (*TokenDB) TransactionExists

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

func (*TokenDB) UnspentTokensIterator

func (db *TokenDB) UnspentTokensIterator() (tdriver.UnspentTokensIterator, error)

UnspentTokensIterator returns an iterator over all unspent tokens

func (*TokenDB) UnspentTokensIteratorBy

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

UnspentTokensIteratorBy returns an iterator of unspent tokens owned by the passed id and whose type is the passed on. The token type can be empty. In that case, tokens of any type are returned.

func (*TokenDB) WhoDeletedTokens

func (db *TokenDB) WhoDeletedTokens(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 TokenInterpreter

type TokenInterpreter interface {
	common.Interpreter
	HasTokens(colTxID, colIdx common.FieldName, ids ...*token.ID) common.Condition
	HasTokenTypes(colTokenType common.FieldName, tokenTypes ...token.Type) common.Condition
	HasTokenFormats(colTokenType common.FieldName, formats ...token.Format) common.Condition
	HasTokenDetails(params driver.QueryTokenDetailsParams, tokenTable string) common.Condition
	HasMovementsParams(params driver.QueryMovementsParams) common.Condition
	HasValidationParams(params driver.QueryValidationRecordsParams) common.Condition
	HasTransactionParams(params driver.QueryTransactionsParams, table string) common.Condition
}

func NewTokenInterpreter

func NewTokenInterpreter(ci common.Interpreter) TokenInterpreter

type TokenLockDB

type TokenLockDB struct {
	DB     *sql.DB
	Table  tokenLockTables
	Logger logging.Logger
}

func NewTokenLockDB

func NewTokenLockDB(db *sql.DB, opts NewDBOpts) (*TokenLockDB, error)

func (*TokenLockDB) Close

func (db *TokenLockDB) Close() error

func (*TokenLockDB) GetSchema

func (db *TokenLockDB) GetSchema() string

func (*TokenLockDB) Lock

func (db *TokenLockDB) Lock(tokenID *token.ID, consumerTxID transaction.ID) error

func (*TokenLockDB) UnlockByTxID

func (db *TokenLockDB) UnlockByTxID(consumerTxID transaction.ID) error

type TokenRequestIterator

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

func (*TokenRequestIterator) Close

func (t *TokenRequestIterator) Close()

func (*TokenRequestIterator) Next

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 TransactionDB

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

func (*TransactionDB) AddTransactionEndorsementAck

func (db *TransactionDB) AddTransactionEndorsementAck(txID string, endorser token.Identity, sigma []byte) (err error)

func (*TransactionDB) BeginAtomicWrite

func (db *TransactionDB) BeginAtomicWrite() (driver.AtomicWrite, error)

func (*TransactionDB) Close

func (db *TransactionDB) Close() error

func (*TransactionDB) GetSchema

func (db *TransactionDB) GetSchema() string

func (*TransactionDB) GetStatus

func (db *TransactionDB) GetStatus(txID string) (driver.TxStatus, string, error)

func (*TransactionDB) GetTokenRequest

func (db *TransactionDB) GetTokenRequest(txID string) ([]byte, error)

func (*TransactionDB) GetTransactionEndorsementAcks

func (db *TransactionDB) GetTransactionEndorsementAcks(txID string) (map[string][]byte, error)

func (*TransactionDB) QueryMovements

func (db *TransactionDB) QueryMovements(params driver.QueryMovementsParams) (res []*driver.MovementRecord, err error)

func (*TransactionDB) QueryTokenRequests

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

func (*TransactionDB) QueryTransactions

func (*TransactionDB) QueryValidations

func (*TransactionDB) SetStatus

func (db *TransactionDB) SetStatus(ctx context.Context, txID string, status driver.TxStatus, message string) (err error)

type TransactionIterator

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

func (*TransactionIterator) Close

func (t *TransactionIterator) Close()

func (*TransactionIterator) Next

type UnspentTokensInWalletIterator

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

func (*UnspentTokensInWalletIterator) Close

func (u *UnspentTokensInWalletIterator) Close()

func (*UnspentTokensInWalletIterator) Next

type UnspentTokensIterator

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

func (*UnspentTokensIterator) Close

func (u *UnspentTokensIterator) Close()

func (*UnspentTokensIterator) Next

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 ValidationRecordsIterator

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

func (*ValidationRecordsIterator) Close

func (t *ValidationRecordsIterator) Close()

func (*ValidationRecordsIterator) Next

type WalletDB

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

func (*WalletDB) GetSchema

func (db *WalletDB) GetSchema() string

func (*WalletDB) GetWalletID

func (db *WalletDB) GetWalletID(identity token.Identity, roleID int) (driver.WalletID, error)

func (*WalletDB) GetWalletIDs

func (db *WalletDB) GetWalletIDs(roleID int) ([]driver.WalletID, error)

func (*WalletDB) IdentityExists

func (db *WalletDB) IdentityExists(identity token.Identity, wID driver.WalletID, roleID int) bool

func (*WalletDB) LoadMeta

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

func (*WalletDB) StoreIdentity

func (db *WalletDB) StoreIdentity(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