Documentation ¶
Index ¶
- Constants
- Variables
- type ActionType
- type AtomicWrite
- type AuditDBDriver
- type AuditTransactionDB
- type CertificationDB
- type ConfigProvider
- type IdentityConfiguration
- type IdentityDB
- type IdentityDBDriver
- type Iterator
- type MovementDirection
- type MovementRecord
- type QueryMovementsParams
- type QueryTokenDetailsParams
- type QueryTokenRequestsParams
- type QueryTransactionsParams
- type QueryValidationRecordsParams
- type SearchDirection
- type SpendableFilter
- type TTXDBDriver
- type TokenDB
- type TokenDBDriver
- type TokenDBTransaction
- type TokenDetails
- type TokenLockDB
- type TokenLockDBDriver
- type TokenNotifier
- type TokenNotifierDriver
- type TokenRecord
- type TokenRequestIterator
- type TokenRequestRecord
- type TokenTransactionDB
- type TransactionDB
- type TransactionEndorsementAckDB
- type TransactionIterator
- type TransactionRecord
- type TxStatus
- type ValidationRecord
- type ValidationRecordsIterator
- type WalletDB
- type WalletID
Constants ¶
const ( // Unknown is the status of a transaction that is unknown Unknown = driver2.Unknown // Pending is the status of a transaction that has been submitted to the ledger Pending = driver2.Pending // Confirmed is the status of a transaction that has been confirmed by the ledger Confirmed = driver2.Confirmed // Deleted is the status of a transaction that has been deleted due to a failure to commit Deleted = driver2.Deleted )
Variables ¶
var (
ErrTokenDoesNotExist = errors.New("token does not exist")
)
var (
ErrTokenRequestDoesNotExist = errors.New("token request does not exist")
)
Functions ¶
This section is empty.
Types ¶
type ActionType ¶
type ActionType int
ActionType is the type of transaction
const ( // Issue is the action type for issuing tokens. Issue ActionType = iota // Transfer is the action type for transferring tokens. Transfer // Redeem is the action type for redeeming tokens. Redeem )
type AtomicWrite ¶
type AtomicWrite interface { // Commit commits the current update to the database Commit() error // Rollback discards the in progress database transaction. // It logs but otherwise ignores errors rolling back: // the result is always the end of the transaction. Rollback() // AddTokenRequest binds the passed transaction id to the passed token request AddTokenRequest(txID string, tr []byte, applicationMetadata map[string][]byte, ppHash driver.PPHash) error // AddMovement adds a movement record to the database transaction. // Each token transaction can be seen as a list of movements. // This operation _requires_ a TokenRequest with the same tx_id to exist AddMovement(record *MovementRecord) error // AddTransaction adds a transaction record to the database transaction. // This operation _requires_ a TokenRequest with the same tx_id to exist AddTransaction(record *TransactionRecord) error // AddValidationRecord adds a new validation records for the given params // This operation _requires_ a TokenRequest with the same tx_id to exist AddValidationRecord(txID string, meta map[string][]byte) error }
type AuditDBDriver ¶
type AuditDBDriver interface { // Open opens an audit database connection Open(cp ConfigProvider, tmsID token.TMSID) (AuditTransactionDB, error) }
AuditDBDriver is the interface for an audit database driver
type AuditTransactionDB ¶
type AuditTransactionDB interface { // Close closes the database Close() error // BeginAtomicWrite opens an atomic database transaction. It must be committed or discarded. BeginAtomicWrite() (AtomicWrite, error) // SetStatus sets the status of a TokenRequest // (and with that, the associated ValidationRecord, Movement and Transaction) SetStatus(ctx context.Context, txID string, status TxStatus, message string) error // GetStatus returns the status of a given transaction. // It returns an error if the transaction is not found GetStatus(txID string) (TxStatus, string, error) // QueryTransactions returns a list of transactions that match the passed params QueryTransactions(params QueryTransactionsParams) (TransactionIterator, error) // QueryMovements returns a list of movement records QueryMovements(params QueryMovementsParams) ([]*MovementRecord, error) // QueryValidations returns an iterator over the validation records matching the passed params QueryValidations(params QueryValidationRecordsParams) (ValidationRecordsIterator, error) // QueryTokenRequests returns an iterator over the token requests matching the passed params QueryTokenRequests(params QueryTokenRequestsParams) (TokenRequestIterator, error) // GetTokenRequest returns the token request bound to the passed transaction id, if available. // It returns nil without error if the key is not found. GetTokenRequest(txID string) ([]byte, error) }
AuditTransactionDB defines the interface for a database to store the audit records of token transactions.
type CertificationDB ¶
type CertificationDB interface { // ExistsCertification returns true if a certification for the passed token exists, // false otherwise ExistsCertification(id *token.ID) bool // StoreCertifications stores the passed certifications StoreCertifications(certifications map[*token.ID][]byte) error // GetCertifications returns the certifications of the passed tokens. // For each token, the callback function is invoked. // If a token doesn't have a certification, the function returns an error GetCertifications(ids []*token.ID) ([][]byte, error) }
CertificationDB defines a database to manager token certifications
type ConfigProvider ¶
type IdentityConfiguration ¶
type IdentityDB ¶
type IdentityDB interface { // AddConfiguration stores an identity and the path to the credentials relevant to this identity AddConfiguration(wp IdentityConfiguration) error // ConfigurationExists returns true if a configuration with the given id and type exists. ConfigurationExists(id, typ string) (bool, error) // IteratorConfigurations returns an iterator to all configurations stored IteratorConfigurations(configurationType string) (Iterator[IdentityConfiguration], error) // StoreIdentityData stores the passed identity and token information StoreIdentityData(id []byte, identityAudit []byte, tokenMetadata []byte, tokenMetadataAudit []byte) error // GetAuditInfo retrieves the audit info bounded to the given identity GetAuditInfo(id []byte) ([]byte, error) // GetTokenInfo returns the token information related to the passed identity GetTokenInfo(id []byte) ([]byte, []byte, error) // StoreSignerInfo stores the passed signer info and bound it to the given identity StoreSignerInfo(id, info []byte) error // SignerInfoExists returns true if StoreSignerInfo was called on input the given identity SignerInfoExists(id []byte) (bool, error) // GetSignerInfo returns the signer info bound to the given identity GetSignerInfo(id []byte) ([]byte, error) }
type IdentityDBDriver ¶
type IdentityDBDriver interface { // OpenWalletDB opens a connection to the wallet DB OpenWalletDB(cp ConfigProvider, tmsID token.TMSID) (WalletDB, error) // OpenIdentityDB opens a connection to the identity DB OpenIdentityDB(cp ConfigProvider, tmsID token.TMSID) (IdentityDB, error) }
IdentityDBDriver is the interface for an identity database driver
type MovementDirection ¶
type MovementDirection int
MovementDirection defines the direction of a movement.
const ( // Sent amount transferred from. Sent MovementDirection = iota // Received amount transferred to. Received // All amount transferred to and from. All )
type MovementRecord ¶
type MovementRecord struct { // TxID is the transaction ID TxID string // EnrollmentID is the enrollment ID of the account that is receiving or sending EnrollmentID string // TokenType is the type of token TokenType token2.Type // Amount is positive if tokens are received. Negative otherwise Amount *big.Int // Timestamp is the time the transaction was submitted to the db Timestamp time.Time // Status is the status of the transaction Status TxStatus }
MovementRecord is a record of a movement of assets. Given a Token Transaction, a movement record is created for each enrollment ID that participated in the transaction and each token type that was transferred. The movement record contains the total amount of the token type that was transferred to/from the enrollment ID in a given token transaction.
type QueryMovementsParams ¶
type QueryMovementsParams struct { // EnrollmentIDs is the enrollment IDs of the accounts to query EnrollmentIDs []string // TokenTypes is the token types to query TokenTypes []token2.Type // TxStatuses is the statuses of the transactions to query TxStatuses []TxStatus // SearchDirection is the direction of the search SearchDirection SearchDirection // MovementDirection is the direction of the movement MovementDirection MovementDirection // NumRecords is the number of records to return // If 0, all records are returned NumRecords int }
QueryMovementsParams defines the parameters for querying movements. Movement records will be filtered by EnrollmentID, TokenFormat, and Status. SearchDirection tells if the search should start from the oldest to the newest records or vice versa. MovementDirection which amounts to consider. Sent correspond to a negative amount, Received to a positive amount, and All to both.
type QueryTokenDetailsParams ¶
type QueryTokenDetailsParams struct { // WalletID is the optional identifier of the wallet owning the token WalletID string // OwnerType is the type of owner, for instance 'idemix' or 'htlc' OwnerType string // TokenType (optional) is the type of token TokenType token.Type // IDs is an optional list of specific token ids to return IDs []*token.ID // TransactionIDs selects tokens that are the output of the provided transaction ids. TransactionIDs []string // IncludeDeleted determines whether to include spent tokens. It defaults to false. IncludeDeleted bool // Spendable determines whether to include only spendable/non-spendable or any tokens. It defaults to nil (any tokens) Spendable SpendableFilter // LedgerTokenFormats selects tokens whose output on the ledger has a format in the list LedgerTokenFormats []token.Format }
QueryTokenDetailsParams defines the parameters for querying token details
type QueryTokenRequestsParams ¶
type QueryTokenRequestsParams struct { // Statuses is the list of transaction status to accept // If empty, any status is accepted Statuses []TxStatus }
QueryTokenRequestsParams defines the parameters for querying token requests
type QueryTransactionsParams ¶
type QueryTransactionsParams struct { // IDs is the list of transaction ids. If nil or empty, all transactions are returned IDs []string // ExcludeToSelf can be used to filter out 'change' transactions where the sender and // recipient have the same enrollment id. ExcludeToSelf bool // SenderWallet is the wallet of the sender // If empty, any sender is accepted // If the sender does not match but the recipient matches, the transaction is returned SenderWallet string // RecipientWallet is the wallet of the recipient // If empty, any recipient is accepted // If the recipient does not match but the sender matches, the transaction is returned RecipientWallet string // From is the start time of the query // If nil, the query starts from the first transaction From *time.Time // To is the end time of the query // If nil, the query ends at the last transaction To *time.Time // ActionTypes is the list of action types to accept // If empty, any action type is accepted ActionTypes []ActionType // Statuses is the list of transaction status to accept // If empty, any status is accepted Statuses []TxStatus }
QueryTransactionsParams defines the parameters for querying transactions. One can filter by sender, by recipient, and by time range.
type QueryValidationRecordsParams ¶
type QueryValidationRecordsParams struct { // From is the start time of the query // If nil, the query starts from the first transaction From *time.Time // To is the end time of the query // If nil, the query ends at the last transaction To *time.Time // Statuses is the list of transaction status to accept // If empty, any status is accepted Statuses []TxStatus // Filter defines a custom filter function. // If specified, this filter will be applied. // the filter returns true if the record must be selected, false otherwise. Filter func(record *ValidationRecord) bool }
QueryValidationRecordsParams defines the parameters for querying validation records.
type SearchDirection ¶
type SearchDirection int
SearchDirection defines the direction of a search.
const ( // FromLast defines the direction of a search from the last key. FromLast SearchDirection = iota // FromBeginning defines the direction of a search from the first key. FromBeginning )
type SpendableFilter ¶
type SpendableFilter int
const ( Any SpendableFilter = iota SpendableOnly NonSpendableOnly )
type TTXDBDriver ¶
type TTXDBDriver interface { // Open opens a token transaction database Open(cp ConfigProvider, tmsID token.TMSID) (TokenTransactionDB, error) }
TTXDBDriver is the interface for a token transaction db driver
type TokenDB ¶
type TokenDB interface { CertificationDB // DeleteTokens marks the passsed tokens as deleted DeleteTokens(deletedBy string, toDelete ...*token.ID) error // IsMine return true if the passed token was stored before IsMine(txID string, index uint64) (bool, error) // UnspentTokensIterator returns an iterator over all owned tokens UnspentTokensIterator() (driver.UnspentTokensIterator, error) // UnspentTokensIteratorBy returns an iterator over all tokens owned by the passed wallet identifier and of a given type UnspentTokensIteratorBy(ctx context.Context, walletID string, tokenType token.Type) (driver.UnspentTokensIterator, error) // SpendableTokensIteratorBy returns an iterator over all tokens owned solely by the passed wallet identifier and of a given type SpendableTokensIteratorBy(ctx context.Context, walletID string, typ token.Type) (driver.SpendableTokensIterator, error) // ListUnspentTokensBy returns the list of all tokens owned by the passed identifier of a given type ListUnspentTokensBy(walletID string, typ token.Type) (*token.UnspentTokens, error) // ListUnspentTokens returns the list of all owned tokens ListUnspentTokens() (*token.UnspentTokens, error) // ListAuditTokens returns the audited tokens for the passed ids ListAuditTokens(ids ...*token.ID) ([]*token.Token, error) // ListHistoryIssuedTokens returns the list of all issued tokens ListHistoryIssuedTokens() (*token.IssuedTokens, error) // GetTokenOutputs returns the value of the tokens as they appear on the ledger for the passed ids. // For each token, the call-back function is invoked. The call-back function is invoked respecting the order of the passed ids. GetTokenOutputs(ids []*token.ID, callback driver.QueryCallbackFunc) error // GetTokenMetadata returns the metadata of the tokens for the passed ids. GetTokenMetadata(ids []*token.ID) ([][]byte, error) // GetTokenOutputsAndMeta retrieves both the token output, metadata, and type for the passed ids. GetTokenOutputsAndMeta(ctx context.Context, ids []*token.ID) ([][]byte, [][]byte, []token.Format, error) // GetTokens returns the owned tokens and their identifier keys for the passed ids. GetTokens(inputs ...*token.ID) ([]*token.Token, error) // WhoDeletedTokens for each id, the function return if it was deleted and by who as per the Delete function WhoDeletedTokens(inputs ...*token.ID) ([]string, []bool, error) // TransactionExists returns true if a token with that transaction id exists in the db TransactionExists(ctx context.Context, id string) (bool, error) // StorePublicParams stores the public parameters. // If they already exist, the function return with no error. No changes are applied. StorePublicParams(raw []byte) error // PublicParams returns the stored public parameters. // If not public parameters are available, it returns nil with no error PublicParams() ([]byte, error) // PublicParamsByHash returns the public parameters whose hash matches the passed one. // If not public parameters are available for that hash, it returns an error PublicParamsByHash(rawHash driver.PPHash) ([]byte, error) // NewTokenDBTransaction returns a new Transaction to commit atomically multiple operations NewTokenDBTransaction() (TokenDBTransaction, error) // QueryTokenDetails provides detailed information about tokens QueryTokenDetails(params QueryTokenDetailsParams) ([]TokenDetails, error) // Balance returns the sun of the amounts of the tokens with type and EID equal to those passed as arguments. Balance(ownerEID string, typ token.Type) (uint64, error) // SetSupportedTokenFormats sets the supported token formats SetSupportedTokenFormats(formats []token.Format) error }
TokenDB defines a database to store token related info
type TokenDBDriver ¶
type TokenDBDriver interface { // Open opens a token database Open(cp ConfigProvider, tmsID token2.TMSID) (TokenDB, error) }
TokenDBDriver is the interface for a token database driver
type TokenDBTransaction ¶
type TokenDBTransaction interface { // GetToken returns the owned tokens and their identifier keys for the passed ids. GetToken(ctx context.Context, tokenID token.ID, includeDeleted bool) (*token.Token, []string, error) // Delete marks the passed token as deleted by a given identifier (idempotent) Delete(ctx context.Context, tokenID token.ID, deletedBy string) error // StoreToken stores the passed token record in relation to the passed owner identifiers, if any StoreToken(ctx context.Context, tr TokenRecord, owners []string) error // SetSpendable updates the spendable flag of the passed token SetSpendable(ctx context.Context, tokenID token.ID, spendable bool) error // SetSpendableBySupportedTokenFormats sets the spendable flag to true for all the tokens having one of the passed token type. // The spendable flag is set to false for the other tokens SetSpendableBySupportedTokenFormats(ctx context.Context, formats []token.Format) error // Commit commits this transaction Commit() error // Rollback rollbacks this transaction Rollback() error }
type TokenDetails ¶
type TokenDetails struct { // TxID is the ID of the transaction that created the token TxID string // Index is the index in the transaction Index uint64 // OwnerIdentity is the serialization of the owner identity OwnerIdentity []byte // OwnerType is the deserialized type inside OwnerRaw OwnerType string // OwnerEnrollment is the enrollment id of the owner OwnerEnrollment string // Type is the type of token Type string // Amount is the Quantity converted to decimal Amount uint64 // IsSpent is true if the token has been spent IsSpent bool // SpentBy is the transactionID that spent this token, if available SpentBy string // StoredAt is the moment the token was stored by this wallet StoredAt time.Time }
TokenDetails provides details about an owned (spent or unspent) token
type TokenLockDB ¶
type TokenLockDB interface { // Lock locks a specific token for the consumer TX Lock(tokenID *token.ID, consumerTxID transaction.ID) error // UnlockByTxID unlocks all tokens locked by the consumer TX UnlockByTxID(consumerTxID transaction.ID) error // Cleanup removes the locks such that either: // 1. The transaction that locked that token is valid or invalid; // 2. The lock is too old. Cleanup(leaseExpiry time.Duration) error // Close closes the database Close() error }
TokenLockDB enforces that a token be used only by one process A housekeeping job can clean up expired locks (e.g. created_at is more than 5 minutes ago) in order to: - avoid that the table grows infinitely - unlock tokens that were locked by a process that exited unexpectedly
type TokenLockDBDriver ¶
type TokenLockDBDriver interface { // Open opens a token database Open(cp ConfigProvider, tmsID token2.TMSID) (TokenLockDB, error) }
TokenLockDBDriver is the interface for a token database driver
type TokenNotifier ¶
TokenNotifier is the observable version of TokenDB
type TokenNotifierDriver ¶
type TokenNotifierDriver interface { // Open opens a token database with its listeners Open(cp ConfigProvider, tmsID token2.TMSID) (TokenNotifier, error) }
TokenNotifierDriver is the interface for a token database driver
type TokenRecord ¶
type TokenRecord struct { // TxID is the ID of the transaction that created the token TxID string // Index is the index in the transaction Index uint64 // IssuerRaw represents the serialization of the issuer identity // if this is an IssuedToken. IssuerRaw []byte // OwnerRaw is the serialization of the owner TypedIdentity OwnerRaw []byte // OwnerType is the deserialized type inside OwnerRaw OwnerType string // OwnerIdentity is the deserialized Identity inside OwnerRaw OwnerIdentity []byte // OwnerWalletID is the identifier of the wallet that owns this token, it might be empty OwnerWalletID string // Ledger is the raw token as stored on the ledger Ledger []byte // LedgerFormat is the type of the raw token as stored on the ledger LedgerFormat token.Format // LedgerMetadata is the metadata associated to the content of Ledger LedgerMetadata []byte // Quantity is the number of units of Type carried in the token. // It is encoded as a string containing a number in base 16. The string has prefix “0x”. Quantity string // Type is the type of token Type token.Type // Amount is the Quantity converted to decimal Amount uint64 // Owner is used to mark the token as owned by this node Owner bool // Auditor is used to mark this token as audited by this node Auditor bool // Issuer issued to mark this token as issued by this node Issuer bool }
type TokenRequestIterator ¶
type TokenRequestIterator = collections.Iterator[*TokenRequestRecord]
TokenRequestIterator is an iterator for token requests
type TokenRequestRecord ¶
type TokenTransactionDB ¶
type TokenTransactionDB interface { TransactionDB TransactionEndorsementAckDB }
TokenTransactionDB defines the interface for a token transaction database. This database is used to store records related to the processed token transactions.
type TransactionDB ¶
type TransactionDB interface { // Close closes the databases Close() error // BeginAtomicWrite opens an atomic database transaction. It must be committed or discarded. BeginAtomicWrite() (AtomicWrite, error) // SetStatus sets the status of a TokenRequest // (and with that, the associated ValidationRecord, Movement and Transaction) SetStatus(ctx context.Context, txID string, status TxStatus, message string) error // GetStatus returns the status of a given transaction. // It returns an error if the transaction is not found GetStatus(txID string) (TxStatus, string, error) // QueryTransactions returns a list of transactions that match the given criteria QueryTransactions(params QueryTransactionsParams) (TransactionIterator, error) // QueryMovements returns a list of movement records QueryMovements(params QueryMovementsParams) ([]*MovementRecord, error) // QueryValidations returns a list of validation records QueryValidations(params QueryValidationRecordsParams) (ValidationRecordsIterator, error) // QueryTokenRequests returns an iterator over the token requests matching the passed params QueryTokenRequests(params QueryTokenRequestsParams) (TokenRequestIterator, error) // GetTokenRequest returns the token request bound to the passed transaction id, if available. // It returns nil without error if the key is not found. GetTokenRequest(txID string) ([]byte, error) }
type TransactionEndorsementAckDB ¶
type TransactionEndorsementAckDB interface { // AddTransactionEndorsementAck records the signature of a given endorser for a given transaction AddTransactionEndorsementAck(txID string, endorser token.Identity, sigma []byte) error // GetTransactionEndorsementAcks returns the endorsement signatures for the given transaction id GetTransactionEndorsementAcks(txID string) (map[string][]byte, error) }
type TransactionIterator ¶
type TransactionIterator = collections.Iterator[*TransactionRecord]
TransactionIterator is an iterator for transactions
type TransactionRecord ¶
type TransactionRecord struct { // TxID is the transaction ID TxID string // ActionType is the type of action performed by this transaction record ActionType ActionType // SenderEID is the enrollment ID of the account that is sending tokens SenderEID string // RecipientEID is the enrollment ID of the account that is receiving tokens RecipientEID string // TokenType is the type of token TokenType token2.Type // Amount is positive if tokens are received. Negative otherwise Amount *big.Int // Timestamp is the time the transaction was submitted to the db Timestamp time.Time // Status is the status of the transaction Status TxStatus // ApplicationMetadata is the metadata sent by the application in the // transient field. It is not validated or recorded on the ledger. ApplicationMetadata map[string][]byte }
TransactionRecord is a more finer-grained version of a movement record. Given a Token Transaction, for each token action in the Token Request, a transaction record is created for each unique enrollment ID found in the outputs. The transaction record contains the total amount of the token type that was transferred to/from that enrollment ID in that action.
func (*TransactionRecord) String ¶
func (t *TransactionRecord) String() string
type ValidationRecord ¶
type ValidationRecord struct { // TxID is the transaction ID TxID string // TokenRequest is the token request marshalled TokenRequest []byte // Metadata is the metadata produced by the validator when evaluating the token request Metadata map[string][]byte // Timestamp is the time the transaction was submitted to the db Timestamp time.Time // Status is the status of the transaction Status TxStatus }
ValidationRecord is a record that contains information about the validation of a given token request
type ValidationRecordsIterator ¶
type ValidationRecordsIterator = collections.Iterator[*ValidationRecord]
ValidationRecordsIterator is an iterator for transactions
type WalletDB ¶
type WalletDB interface { // GetWalletID fetches a walletID that is bound to the identity passed GetWalletID(identity token.Identity, roleID int) (WalletID, error) // GetWalletIDs fetches all walletID's that have been stored so far without duplicates GetWalletIDs(roleID int) ([]WalletID, error) // StoreIdentity binds an identity to a walletID and its metadata StoreIdentity(identity token.Identity, eID string, wID WalletID, roleID int, meta []byte) error // IdentityExists checks whether an identity-wallet binding has already been stored IdentityExists(identity token.Identity, wID WalletID, roleID int) bool // LoadMeta returns the metadata stored for a specific identity LoadMeta(identity token.Identity, wID WalletID, roleID int) ([]byte, error) }