ttx

package
v0.14.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// recipients.go
	TypeRecipientRequest         = "recipient_req"
	TypeRecipientResponse        = "recipient_resp"
	TypeExchangeRecipientRequest = "exchange_req"
	TypeExchangeRecipientResp    = "exchange_resp"
	TypeMultisigRecipientData    = "multisig_data"
	TypePolicyRecipientData      = "policy_data"

	// withdrawal.go
	TypeWithdrawalRequest = "withdrawal_req"

	// upgrade.go
	TypeUpgradeAgreement = "upgrade_agree"
	TypeUpgradeRequest   = "upgrade_req"

	// multisig/spend.go and boolpolicy/spend.go
	TypeSpendRequest  = "spend_req"
	TypeSpendResponse = "spend_resp"

	// collectendorsements.go, endorse.go, accept.go, auditor.go, receivetx.go
	TypeSignatureRequest    = "sig_req"
	TypeSignature           = "signature"
	TypeTransaction         = "transaction"
	TypeTransactionResponse = "tx_resp"

	// collectactions.go
	TypeActions        = "actions"
	TypeActionTransfer = "action_transfer"
)

Message-type discriminators stamped on the versioned envelope for every interactive ttx protocol message. These live with the service that uses them rather than in the generic session package.

View Source
const (
	IssuerFSCIdentityKey        = "IssuerFSCIdentityKey"
	IssuerPublicParamsPublicKey = "IssuerPublicParamsPublicKey"
)
View Source
const (
	// NonceSize is the default NonceSize
	NonceSize = 24
)
View Source
const (
	TokenNamespace = "tns"
)

Variables

View Source
var (
	// ErrTimeout signals that a timeout happened
	ErrTimeout = errors.New("timeout reached")
	// ErrFailedCompilingOptions signals a failure when compiling the options
	ErrFailedCompilingOptions = errors.New("failed to compiling options")
	// ErrInvalidInput signals that the input is invalid
	ErrInvalidInput = errors.New("invalid input")
	// ErrHandlingSignatureRequests signals that an error occurred while handling the signature requests
	ErrHandlingSignatureRequests = errors.New("failed to handle signature requests")
	// ErrDepNotAvailableInContext signals that a dependency is not available
	ErrDepNotAvailableInContext = errors.New("dependency not available")
	// ErrTxUnmarshalling signals that an error occurred while unmarshalling a token transaction
	ErrTxUnmarshalling = errors.New("failed to unmarshal tx")
	// ErrStorage signals a generic storage failure
	ErrStorage = errors.New("storage failure")
	// ErrSignerIdentityMismatch signals that an identity mismatch
	ErrSignerIdentityMismatch = errors.New("signer identity mismatch")
	// ErrProvider signals a failure with a provider
	ErrProvider = errors.New("provider failure")
	// ErrFinalityInvalidTransaction signals that the transaction is invalid
	ErrFinalityInvalidTransaction = errors.New("invalid transaction")
	// ErrFinalityTimeout signals that a timeout occurred
	ErrFinalityTimeout = errors.New("finality timeout")
	// ErrTransactionUnknown signals that the transaction is unknown
	ErrTransactionUnknown = errors.New("transaction unknown")
)
View Source
var (
	ErrNetworkNotSet   = errors.New("network not set")
	ErrNamespaceNotSet = errors.New("namespace not set")
)
View Source
var TxStatusMessage = storage.TxStatusMessage

TxStatusMessage maps TxStatus to string

Functions

func CompileServiceOptions

func CompileServiceOptions(opts ...token.ServiceOption) (*token.ServiceOptions, error)

CompileServiceOptions applies all provided service options and returns the compiled ServiceOptions. Returns an error if any option fails to apply.

func ExchangeRecipientIdentities

func ExchangeRecipientIdentities(context view.Context, walletID string, recipient view.Identity, opts ...token.ServiceOption) (view.Identity, view.Identity, error)

ExchangeRecipientIdentities executes the ExchangeRecipientIdentitiesView using by passed wallet id to derive the recipient identity to send to the passed recipient. The function returns, the recipient identity of the sender, the recipient identity of the recipient

func GetAuditorWallet

func GetAuditorWallet(context view.Context, opts ...token.ServiceOption) *token.AuditorWallet

GetAuditorWallet returns the wallet whose id is the passed id. If the passed id is empty, GetAuditorWallet has the same behaviour of MyAuditorWallet. It returns nil, if no wallet is found.

func GetFSCIssuerIdentityFromOpts

func GetFSCIssuerIdentityFromOpts(attributes map[string]any) (view.Identity, error)

GetFSCIssuerIdentityFromOpts extracts an issuer's node identity from the appropriate attribute in a given attribute map.

func GetIssuerPublicParamsPublicKeyFromOpts

func GetIssuerPublicParamsPublicKeyFromOpts(attributes map[string]any) (view.Identity, error)

func GetIssuerWallet

func GetIssuerWallet(context view.Context, id string, opts ...token.ServiceOption) *token.IssuerWallet

GetIssuerWallet returns the issuer wallet whose id is the passed id. If the passed id is empty, GetIssuerWallet has the same behaviour of MyIssuerWallet. It returns nil, if no wallet is found.

func GetIssuerWalletForChannel

func GetIssuerWalletForChannel(context view.Context, channel, id string, opts ...token.ServiceOption) *token.IssuerWallet

GetIssuerWalletForChannel returns the issuer wallet whose id is the passed id for the passed channel. If the passed id is empty, GetIssuerWalletForChannel has the same behaviour of MyIssuerWallet. It returns nil, if no wallet is found.

func GetRandomBytes

func GetRandomBytes(length int) ([]byte, error)

GetRandomBytes returns length random bytes, guaranteeing the buffer is fully filled

func GetRandomNonce

func GetRandomNonce() ([]byte, error)

GetRandomNonce returns a random byte array of length NonceSize

func GetWallet

func GetWallet(context view.Context, id string, opts ...token.ServiceOption) *token.OwnerWallet

GetWallet returns the wallet whose id is the passed id. If the passed id is empty, GetWallet has the same behaviour of MyWallet. It returns nil, if no wallet is found.

func GetWalletForChannel

func GetWalletForChannel(context view.Context, channel, id string, opts ...token.ServiceOption) *token.OwnerWallet

GetWalletForChannel returns the wallet whose id is the passed id for the passed channel. If the passed id is empty, GetWalletForChannel has the same behaviour of MyWalletFromTx. It returns nil, if no wallet is found.

func IssueDistributionList

func IssueDistributionList(r *token.Request) []view.Identity

IssueDistributionList extracts all parties involved in issue operations from the token request. Returns a list containing all issuers and receivers from all issue actions.

func Marshal

func Marshal(v any) ([]byte, error)

func MarshalMeta

func MarshalMeta(v map[string][]byte) ([]byte, error)

func MyAuditorWallet

func MyAuditorWallet(context view.Context, opts ...token.ServiceOption) *token.AuditorWallet

MyAuditorWallet returns the default auditor wallet, nil if not found.

func MyIssuerWallet

func MyIssuerWallet(context view.Context, opts ...token.ServiceOption) *token.IssuerWallet

MyIssuerWallet returns the default issuer wallet, nil if not found

func MyWallet

func MyWallet(context view.Context, opts ...token.ServiceOption) *token.OwnerWallet

MyWallet returns the default wallet, nil if not found.

func MyWalletFromTx

func MyWalletFromTx(context view.Context, tx *Transaction) *token.OwnerWallet

MyWalletFromTx returns the default wallet for the tuple (network, channel, namespace) as identified by the passed transaction. Returns nil if no wallet is found.

func NewCollectActionsResponderView

func NewCollectActionsResponderView(tx *Transaction, action *ActionTransfer) *collectActionsResponderView

NewCollectActionsResponderView returns an instance of the collectActionsResponderView. The view does the following: Sends back the transaction.

func NewCollectActionsView

func NewCollectActionsView(tx *Transaction, actions ...*ActionTransfer) *collectActionsView

NewCollectActionsView returns an instance of collectActionsView. The view does the following: For each action, the view contact the recipient by sending as first message the transaction. Then, the view waits for the answer and append it to the transaction.

func NewFinalityView

func NewFinalityView(tx *Transaction, opts ...TxOption) *finalityView

NewFinalityView returns an instance of the finalityView. The view does the following: It waits for the finality of the passed transaction. If the transaction is final, the vault is updated.

func NewFinalityWithOpts

func NewFinalityWithOpts(opts ...TxOption) *finalityView

func NewOrderingAndFinalityView

func NewOrderingAndFinalityView(tx *Transaction) *orderingAndFinalityView

NewOrderingAndFinalityView returns a new instance of the orderingAndFinalityView struct. The view does the following: 1. It broadcasts the token transaction to the proper backend. 2. It waits for finality of the token transaction. The default timeout is used and it is set to 10mins.

func NewOrderingAndFinalityWithTimeoutView

func NewOrderingAndFinalityWithTimeoutView(tx *Transaction, timeout time.Duration) *orderingAndFinalityView

NewOrderingAndFinalityWithTimeoutView returns a new instance of the orderingAndFinalityView struct. The view does the following: 1. It broadcasts the token transaction to the proper backend. 2. It waits for finality of the token transaction.

func NewOrderingView

func NewOrderingView(tx *Transaction, opts ...TxOption) *orderingView

NewOrderingView returns a new instance of the orderingView struct. The view does the following: 1. It broadcasts the token transaction to the proper backend.

func NewOrderingViewWithOpts

func NewOrderingViewWithOpts(opts ...TxOption) *orderingView

NewOrderingViewWithOpts creates a new ordering view with the provided transaction options. This is a lower-level constructor that allows passing options directly without a transaction instance.

func ReceiveAction

func ReceiveAction(context view.Context) (*Transaction, *ActionTransfer, error)

ReceiveAction runs the receiveActionsView. The view does the following: It receives the transaction, the collection of actions, and the requested action.

func RequestMultisigIdentity

func RequestMultisigIdentity(context view.Context, ids []view.Identity, opts ...token.ServiceOption) (token.Identity, error)

RequestMultisigIdentity collects the recipient identities from all the passed identities. It merges them into a single multisig identity and distributes it to all the participants.

func RequestPolicyIdentity

func RequestPolicyIdentity(context view.Context, policy string, ids []view.Identity, opts ...token.ServiceOption) (token.Identity, error)

RequestPolicyIdentity collects recipient identities from all the passed parties, wraps them into a single PolicyIdentity governed by the given boolean policy expression, and distributes the composite identity back to all participants.

func RequestRecipientIdentity

func RequestRecipientIdentity(context view.Context, recipient view.Identity, opts ...token.ServiceOption) (token.Identity, error)

RequestRecipientIdentity executes the RequestRecipientIdentityView. The sender contacts the recipient's FSC node identified via the passed view identity. The sender gets back the identity the recipient wants to use to assign ownership of tokens.

func RequestTokensUpgrade

func RequestTokensUpgrade(context view.Context, issuer view.Identity, wallet string, tokens []token2.LedgerToken, notAnonymous bool, opts ...token.ServiceOption) (view.Identity, view.Session, error)

RequestTokensUpgrade runs UpgradeTokensInitiatorView with the passed arguments. The view will generate a recipient identity and pass it to the issuer.

func RequestTokensUpgradeForRecipient

func RequestTokensUpgradeForRecipient(context view.Context, issuer view.Identity, wallet string, tokens []token2.LedgerToken, notAnonymous bool, recipientData *RecipientData, opts ...token.ServiceOption) (view.Identity, view.Session, error)

RequestTokensUpgradeForRecipient runs UpgradeTokensInitiatorView with the passed arguments. The view will send the passed recipient data to the issuer.

func RequestWithdrawal

func RequestWithdrawal(context view.Context, issuer view.Identity, wallet string, tokenType token2.Type, amount uint64, notAnonymous bool, opts ...token.ServiceOption) (view.Identity, view.Session, error)

RequestWithdrawal runs RequestWithdrawalView with the passed arguments. The view will generate a recipient identity and pass it to the issuer.

func RequestWithdrawalForRecipient

func RequestWithdrawalForRecipient(context view.Context, issuer view.Identity, wallet string, tokenType token2.Type, amount uint64, notAnonymous bool, recipientData *RecipientData, opts ...token.ServiceOption) (view.Identity, view.Session, error)

RequestWithdrawalForRecipient runs RequestWithdrawalView with the passed arguments. The view will send the passed recipient data to the issuer.

func RespondExchangeRecipientIdentities

func RespondExchangeRecipientIdentities(context view.Context, opts ...token.ServiceOption) (view.Identity, view.Identity, error)

RespondExchangeRecipientIdentities executes the RespondExchangeRecipientIdentitiesView. The recipient sends back the identity to receive ownership of tokens. The identity is taken from the default wallet, unless an ExchangeWalletSelector option (see WithExchangeWalletSelector) overrides the choice.

func RespondRequestRecipientIdentity

func RespondRequestRecipientIdentity(context view.Context, opts ...token.ServiceOption) (view.Identity, error)

RespondRequestRecipientIdentity executes the RespondRequestRecipientIdentityView. The recipient sends back the identity to receive ownership of tokens. The identity is taken from the default wallet, unless a WalletSelector option (see WithWalletSelector) overrides the choice. If the wallet is not found, an error is returned.

func RespondRequestRecipientIdentityUsingWallet

func RespondRequestRecipientIdentityUsingWallet(context view.Context, wallet string, opts ...token.ServiceOption) (view.Identity, error)

RespondRequestRecipientIdentityUsingWallet executes the RespondRequestRecipientIdentityView. The recipient sends back the identity to receive ownership of tokens. The identity is taken from the passed wallet, unless a WalletSelector option (see WithWalletSelector) overrides the choice. If the wallet is not found, an error is returned. If the wallet is the empty string, the identity is taken from the default wallet.

func StoreTransactionRecords

func StoreTransactionRecords(ctx view.Context, tx *Transaction) error

StoreTransactionRecords stores the transaction records extracted from the passed transaction to the Storage bound to the transaction's TMS ID

func TransferDistributionList

func TransferDistributionList(r *token.Request) []view.Identity

TransferDistributionList extracts all parties involved in transfer operations from the token request. Returns a list containing all senders and receivers from all transfer actions.

func Unmarshal

func Unmarshal(data []byte, v any) error

func UnmarshalMeta

func UnmarshalMeta(raw []byte) (map[string][]byte, error)

func WithExchangeWalletSelector added in v0.14.2

func WithExchangeWalletSelector(selector ExchangeWalletSelector) token.ServiceOption

WithExchangeWalletSelector sets a callback used by the responder to an ExchangeRecipientRequest to choose which wallet to use, overriding the default wallet resolution. The returned token.ServiceOption never fails to apply; it always returns a nil error, consistent with the other option setters in this file (e.g. WithRecipientData).

func WithFSCIssuerIdentity

func WithFSCIssuerIdentity(issuerFSCIdentity view.Identity) token.TransferOption

WithFSCIssuerIdentity takes an issuer's node Identity and sets the appropriate attribute in a TransferOptions struct

func WithIssuerPublicParamsPublicKey

func WithIssuerPublicParamsPublicKey(issuerSigningKey view.Identity) token.TransferOption

func WithRecipientData

func WithRecipientData(recipientData *RecipientData) token.ServiceOption

WithRecipientData is used to add a RecipientData to the service options

func WithRecipientWalletID

func WithRecipientWalletID(walletID string) token.ServiceOption

WithRecipientWalletID is used to add a recipient wallet id to the service options

func WithType

func WithType(tokenType token2.Type) token.ListTokensOption

WithType returns a list token option that filter by the passed token type. If the passed token type is the empty string, all token types are selected.

func WithWalletSelector added in v0.14.2

func WithWalletSelector(selector WalletSelector) token.ServiceOption

WithWalletSelector sets a callback used by the responder to a RecipientRequest to choose which wallet to use, overriding the default wallet resolution. The returned token.ServiceOption never fails to apply; it always returns a nil error, consistent with the other option setters in this file (e.g. WithRecipientData).

Types

type AcceptView

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

AcceptView is used to accept tokens without the need to generate any signature. This is a view executed by a responder. This view is to be used in conjunction with CollectEndorsementsView. Usually, AcceptView is preceded by an invocation of `tx.ReceiveTransaction(context)` necessary if the initiator has invoked CollectEndorsementsView.

func NewAcceptView

func NewAcceptView(tx *Transaction, opts ...EndorsementsOpt) *AcceptView

NewAcceptView returns a new instance of AcceptView given in input a transaction.

func (*AcceptView) Call

func (s *AcceptView) Call(context view.Context) (any, error)

Call accepts the tokens created by the transaction this view has been created with.

type ActionTransfer

type ActionTransfer struct {
	// From is the sender
	From view.Identity
	// Type of tokens to transfer
	Type token2.Type
	// Amount to transfer
	Amount uint64
	// Recipient is the recipient of the transfer
	Recipient view.Identity
}

ActionTransfer describe a transfer operation

type Actions

type Actions struct {
	Transfers []*ActionTransfer
}

type AuditApproveView

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

AuditApproveView is a responder view that handles audit approval requests. It audits the transaction, appends audit records to the database, signs the transaction, and sends the signature back to the initiator.

func NewAuditApproveView

func NewAuditApproveView(w *token.AuditorWallet, tx *Transaction) *AuditApproveView

NewAuditApproveView creates a new AuditApproveView for the given auditor wallet and transaction.

func (*AuditApproveView) Call

func (a *AuditApproveView) Call(context view.Context) (any, error)

Call processes the audit approval by: 1. Appending audit records to the database (with lock acquisition/release) 2. Signing the transaction with the auditor's key 3. Sending the signature back to the initiator 4. Caching the token request for faster future lookups 5. Recording metrics for the approval process

type AuditingViewInitiator

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

AuditingViewInitiator is a view that initiates an auditing session with an auditor. It sends the transaction to the auditor and receives back a signature. The local flag indicates whether the auditor is the same as the initiator (self-audit).

func (*AuditingViewInitiator) Call

func (a *AuditingViewInitiator) Call(context view.Context) (any, error)

Call initiates an auditing session (local or remote), sends the transaction to the auditor, receives the auditor's signature, verifies it, and adds it to the transaction. Returns the session used for communication.

type Auditor

type Auditor struct {
	dauditor.Service
	dauditor.StoreService
}

Auditor wraps the functionalities of the auditor service and the audit db for the ttx service

func NewAuditor

func NewAuditor(sp token.ServiceProvider, w *token.AuditorWallet) (*Auditor, error)

NewAuditor returns a new Auditor for the given wallet. This constructor uses NewAuditorFromTMSID with the wallet's TMSID.

func NewAuditorFromTMSID

func NewAuditorFromTMSID(sp token.ServiceProvider, tmsID token.TMSID) (*Auditor, error)

NewAuditorFromTMSID returns a new Auditor for the given TMS ID

func (*Auditor) Audit

Audit extracts the list of inputs and outputs from the passed transaction. In addition, Audit acquires locks on the enrollment IDs involved in the transaction. The caller MUST call Release() to unlock these enrollment IDs after processing.

IMPORTANT: The defer Release() statement MUST be placed immediately after checking the error returned by Audit(). This ensures locks are released even if subsequent operations fail. Example:

inputs, outputs, err := auditor.Audit(ctx, tx)
if err != nil {
    return errors.Wrap(err, "audit failed")
}
defer auditor.Release(ctx, tx)

Note: The semaphore-based locking mechanism handles context cancellation during lock acquisition, ensuring proper cleanup in case of timeouts or cancellations.

func (*Auditor) Check

func (a *Auditor) Check(ctx context.Context) ([]string, error)

Check performs a health check on the auditor service and returns any issues found. It delegates to the underlying audit service for the check.

func (*Auditor) GetTokenRequest

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

GetTokenRequest retrieves the serialized token request for the given transaction ID. Returns an error if the transaction is not found in the audit database.

func (*Auditor) NewHoldingsFilter

func (a *Auditor) NewHoldingsFilter() *auditdb.HoldingsFilter

NewHoldingsFilter returns a programmable filter over the holdings owned by enrollment IDs.

func (*Auditor) NewPaymentsFilter

func (a *Auditor) NewPaymentsFilter() *auditdb.PaymentsFilter

NewPaymentsFilter returns a programmable filter over the payments sent or received by enrollment IDs.

func (*Auditor) Release

func (a *Auditor) Release(ctx context.Context, tx *Transaction)

Release unlocks the passed enrollment IDs.

func (*Auditor) SetStatus

func (a *Auditor) SetStatus(ctx context.Context, txID string, status storage.TxStatus, message string) error

SetStatus sets the status of the audit records with the passed transaction id to the passed status

func (*Auditor) Transactions

func (a *Auditor) Transactions(ctx context.Context, params db.QueryTransactionsParams, pagination db.Pagination) (*db.PageTransactionsIterator, error)

Transactions returns an iterator of transaction records filtered by the given params.

func (*Auditor) Validate

func (a *Auditor) Validate(tx *Transaction) error

Validate checks if the token request in the transaction is valid according to audit rules. It delegates to the underlying audit service for validation.

type CheckService

type CheckService interface {
	Check(ctx context.Context) ([]string, error)
}

type CheckServiceProvider

type CheckServiceProvider interface {
	CheckService(id token.TMSID, adb *ttxdb.StoreService, tdb *tokens.Service) (CheckService, error)
}

CheckServiceProvider provides health check services for transaction and token databases.

type CollectEndorsementsView

type CollectEndorsementsView struct {
	Opts *EndorsementsOpts
	// contains filtered or unexported fields
}

func NewCollectEndorsementsView

func NewCollectEndorsementsView(tx *Transaction, opts ...EndorsementsOpt) *CollectEndorsementsView

NewCollectEndorsementsView returns an instance of the CollectEndorsementsView struct. This view does the following: 1. It collects all the required signatures to authorize any issue and transfer operation contained in the token transaction. 2. It invokes the Token Chaincode to collect endorsements on the Token Request and prepare the relative transaction. 3. Before completing, all recipients receive the approved transaction. Depending on the token driver implementation, the recipient's signature might or might not be needed to make the token transaction valid.

func (*CollectEndorsementsView) Call

func (c *CollectEndorsementsView) Call(context view.Context) (any, error)

Call executes the view. This view does the following: 1. It collects all the required signatures to authorize any issue and transfer operation contained in the token transaction. 2. It invokes the Token Chaincode to collect endorsements on the Token Request and prepare the relative transaction. 3. Before completing, all recipients receive the approved transaction. Depending on the token driver implementation, the recipient's signature might or might not be needed to make the token transaction valid.

func (*CollectEndorsementsView) CleanupExternalWallets

func (c *CollectEndorsementsView) CleanupExternalWallets(context view.Context, externalWallets map[string]ExternalWalletSigner)

CleanupExternalWallets calls Done() on all external wallets to signal completion

type Context

type Context = view.Context

Context is an alias of view.Context

type EndorseView

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

EndorseView is used to accept tokens with, possibly, the need to generate some signature for the tokens that belong to this node. This is a view executed by a responder. This view is to be used in conjunction with CollectEndorsementsView. Usually, EndorseView is preceded by an invocation of `tx.ReceiveTransaction(context)` or alike.

func NewEndorseView

func NewEndorseView(tx *Transaction) *EndorseView

NewEndorseView returns an instance of the EndorseView embedding the passed transaction. The view expects that the transaction has been already checked by the business logic for containing the expected context.

func (*EndorseView) Call

func (s *EndorseView) Call(context view.Context) (any, error)

Call handles the signature requests with the respect to the transaction this view has been constructed with. It expects to deal with messages coming from CollectEndorsementsView. Here are the steps: - Storage of the transaction's records. - Generation of the required signatures. - Reception of the endorsed transaction - Acknowledgement of the reception of the endorsed transaction - Finalization

type EndorsementsOpt

type EndorsementsOpt func(*EndorsementsOpts) error

EndorsementsOpt is a function that configures a EndorsementsOpts

func WithApprovalMetadata

func WithApprovalMetadata(metadata map[string][]byte) EndorsementsOpt

WithApprovalMetadata attaches application-level metadata to be forwarded to the approver. Each key-value pair is delivered to the approver backend in a driver-specific way (e.g. transient data for Fabric FSC endorsement, extra transient entries for chaincode).

func WithExternalWalletSigner

func WithExternalWalletSigner(walletID string, ews ExternalWalletSigner) EndorsementsOpt

func WithPolicySigners

func WithPolicySigners(signers ...token.Identity) EndorsementsOpt

WithPolicySigners restricts signature collection for PolicyIdentity owners to the given component identities. Unlisted components produce nil slots in the PolicySignature, satisfying OR branches without contacting the other parties.

func WithSkipApproval

func WithSkipApproval() EndorsementsOpt

WithSkipApproval to skip approval

func WithSkipAuditing

func WithSkipAuditing() EndorsementsOpt

WithSkipAuditing to skip auditing

func WithSkipAuditorSignatureVerification

func WithSkipAuditorSignatureVerification() EndorsementsOpt

WithSkipAuditorSignatureVerification to skip auditor signature verification

func WithSkipDistributeEnv

func WithSkipDistributeEnv() EndorsementsOpt

WithSkipDistributeEnv to skip approval

type EndorsementsOpts

type EndorsementsOpts struct {
	// SkipAuditing set it to true to skip the auditing phase
	SkipAuditing bool
	// SkipAuditorSignatureVerification set it to true to skip the verification of the auditor signature
	SkipAuditorSignatureVerification bool
	// SkipApproval set it to true to skip the approval phase
	SkipApproval bool
	// SkipDistributeEnv set it to true to skip the distribution phase
	SkipDistributeEnv bool
	// External Signers
	ExternalWalletSigners map[string]ExternalWalletSigner
	// PolicySigners, when non-nil, restricts signature collection for policy
	// identities to the listed component identities.  Component identities not
	// in the list produce a nil slot in the PolicySignature, which is valid for
	// OR branches.  When nil, all component identities are contacted (default).
	PolicySigners []token.Identity
	// ApprovalMetadata carries optional application-level metadata forwarded to approvers.
	// Each driver decides how to deliver this information to the approver backend.
	ApprovalMetadata map[string][]byte
}

EndorsementsOpts is used to configure the CollectEndorsementsView

func CompileCollectEndorsementsOpts

func CompileCollectEndorsementsOpts(opts ...EndorsementsOpt) (*EndorsementsOpts, error)

CompileCollectEndorsementsOpts compiles the given list of ServiceOption

func (*EndorsementsOpts) ExternalWalletSigner

func (o *EndorsementsOpts) ExternalWalletSigner(id string) ExternalWalletSigner

type ExchangeRecipientIdentitiesView

type ExchangeRecipientIdentitiesView struct {
	TMSID  token.TMSID
	Wallet string
	Other  view.Identity
}

func (*ExchangeRecipientIdentitiesView) Call

type ExchangeRecipientRequest

type ExchangeRecipientRequest struct {
	TMSID         token.TMSID
	WalletID      []byte
	RecipientData *RecipientData
	Nonce         []byte
}

func (*ExchangeRecipientRequest) Bytes

func (r *ExchangeRecipientRequest) Bytes() ([]byte, error)

Bytes serializes the ExchangeRecipientRequest to bytes.

func (*ExchangeRecipientRequest) FromBytes

func (r *ExchangeRecipientRequest) FromBytes(raw []byte) error

FromBytes deserializes the ExchangeRecipientRequest from bytes.

type ExchangeRecipientResponse

type ExchangeRecipientResponse struct {
	RecipientData *RecipientData
	Signature     []byte
}

ExchangeRecipientResponse carries the responder's identity material together with a key-ownership attestation: a signature over the request-bound attestation message (see buildAttestationMessage).

type ExchangeWalletSelector added in v0.14.2

type ExchangeWalletSelector func(request *ExchangeRecipientRequest, defaultWallet string) (string, error)

ExchangeWalletSelector is the WalletSelector equivalent for ExchangeRecipientRequest.

type ExternalWalletSigner

type ExternalWalletSigner interface {
	Sign(party view.Identity, message []byte) ([]byte, error)
	Done() error
}

ExternalWalletSigner defines the interface for signing with external wallets that are not managed by the local node.

type GetNetworkFunc

type GetNetworkFunc = func(network string, channel string) (dep.Network, error)

type LocalBidirectionalChannel

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

LocalBidirectionalChannel is a bidirectional channel that is used to simulate a session between two views (let's call them L and R) running in the same process.

func NewLocalBidirectionalChannel

func NewLocalBidirectionalChannel(ctx context.Context, caller string, contextID string, endpoint string, pkid []byte) (*LocalBidirectionalChannel, error)

NewLocalBidirectionalChannel creates a new bidirectional channel

func (*LocalBidirectionalChannel) LeftSession

func (c *LocalBidirectionalChannel) LeftSession() view.Session

LeftSession returns the session from the L to R

func (*LocalBidirectionalChannel) RightSession

func (c *LocalBidirectionalChannel) RightSession() view.Session

RightSession returns the session from the R to L

type Metrics

type Metrics struct {
	EndorsedTransactions      metrics.Counter
	AuditApprovedTransactions metrics.Counter
	AcceptedTransactions      metrics.Counter
	EndorsementDuration       metrics.Histogram
	AuditApprovalDuration     metrics.Histogram
	OrderingDuration          metrics.Histogram
}

func GetMetrics

func GetMetrics(sp token.ServiceProvider) *Metrics

func NewMetrics

func NewMetrics(p metrics.Provider) *Metrics

type MultisigRecipientData

type MultisigRecipientData struct {
	RecipientData *token.RecipientData
	Nodes         []view.Identity
	Recipients    []token.Identity
}

type Payload

type Payload struct {
	TxID network.TxID
	ID   string

	Signer    view.Identity
	Transient network.TransientMap

	TokenRequest *token.Request
	Envelope     *network.Envelope
	// contains filtered or unexported fields
}

Payload contains the core data of a token transaction including the transaction ID, signer identity, token request, and network envelope. It represents the serializable portion of a transaction that can be transmitted over the network.

type PolicyRecipientData

type PolicyRecipientData struct {
	RecipientData *token.RecipientData
	Nodes         []view.Identity
	Recipients    []token.Identity
	Policy        string
}

PolicyRecipientData carries the composite policy identity back to each co-owner.

type ReceiveTransactionView

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

ReceiveTransactionView is a view to read a transaction from the context's session.

func NewReceiveTransactionView

func NewReceiveTransactionView(opts ...TxOption) *ReceiveTransactionView

NewReceiveTransactionView returns a new instance of ReceiveTransactionView with the given options.

func (*ReceiveTransactionView) Call

func (f *ReceiveTransactionView) Call(context view.Context) (any, error)

Call listens to a versioned envelope from the context's session and returns a transaction. Supported message types are TypeTransaction, TypeTransactionResponse, and TypeSignatureRequest. If no timeout is specified via the opts, 4 minutes is used as default.

type ReceiveWithdrawalRequestView

type ReceiveWithdrawalRequestView struct{}

ReceiveWithdrawalRequestView this is the view used by the issuer to receive a withdrawal request

func NewReceiveIssuanceRequestView

func NewReceiveIssuanceRequestView() *ReceiveWithdrawalRequestView

func (*ReceiveWithdrawalRequestView) Call

func (r *ReceiveWithdrawalRequestView) Call(context view.Context) (any, error)

type Recipient

type Recipient struct {
	Identity      view.Identity
	WalletID      string
	RecipientData *RecipientData
}

type RecipientData

type RecipientData = token.RecipientData

type RecipientRequest

type RecipientRequest struct {
	TMSID         token.TMSID
	WalletID      []byte
	RecipientData *RecipientData
	MultiSig      bool
	// Policy, when non-empty, signals that the initiator will follow up with a PolicyRecipientData message.
	Policy string
	Nonce  []byte
}

func (*RecipientRequest) Bytes

func (r *RecipientRequest) Bytes() ([]byte, error)

Bytes serializes the RecipientRequest to bytes.

func (*RecipientRequest) FromBytes

func (r *RecipientRequest) FromBytes(raw []byte) error

FromBytes deserializes the RecipientRequest from bytes.

type RecipientResponse

type RecipientResponse struct {
	RecipientData *RecipientData
	Signature     []byte
}

RecipientResponse is the response for single-recipient identity requests. On the echo path (initiator supplied RecipientData), RecipientData is nil and the initiator uses its own copy; on the fresh path RecipientData carries the full identity material. Signature covers the request-bound attestation message (see buildAttestationMessage).

type Recipients

type Recipients []Recipient

func (Recipients) Identities

func (r Recipients) Identities() []view.Identity

Identities extracts and returns all recipient identities from the Recipients slice.

type RegisterAuditorView

type RegisterAuditorView struct {
	TMSID     token.TMSID
	AuditView view.View
}

RegisterAuditorView is a view that registers an auditor responder view for handling audit requests from token transaction initiators.

func NewRegisterAuditorView

func NewRegisterAuditorView(auditView view.View, opts ...token.ServiceOption) *RegisterAuditorView

NewRegisterAuditorView creates a new RegisterAuditorView with the provided audit view and service options. Returns nil if the options cannot be compiled.

func (*RegisterAuditorView) Call

func (r *RegisterAuditorView) Call(context view.Context) (any, error)

Call registers the audit view as a responder for AuditingViewInitiator requests. This allows the auditor to respond to audit requests from transaction initiators.

type RequestRecipientIdentityView

type RequestRecipientIdentityView struct {
	TMSID      token.TMSID
	Recipients Recipients
	// Policy, when non-empty, causes the collected identities to be wrapped
	// as a PolicyIdentity instead of a MultiIdentity.
	Policy string
}

func (*RequestRecipientIdentityView) Call

func (f *RequestRecipientIdentityView) Call(context view.Context) (any, error)

type RequestWithdrawalView

type RequestWithdrawalView struct {
	Issuer       view.Identity
	TokenType    token2.Type
	Amount       uint64
	TMSID        token.TMSID
	Wallet       string
	NotAnonymous bool

	RecipientData *RecipientData
}

RequestWithdrawalView is the initiator view to request an issuer the issuance of tokens. The view prepares an instance of WithdrawalRequest and send it to the issuer.

func NewRequestWithdrawalView

func NewRequestWithdrawalView(issuer view.Identity, tokenType token2.Type, amount uint64, notAnonymous bool) *RequestWithdrawalView

func (*RequestWithdrawalView) Call

func (r *RequestWithdrawalView) Call(context view.Context) (any, error)

func (*RequestWithdrawalView) WithRecipientData

func (r *RequestWithdrawalView) WithRecipientData(data *RecipientData) *RequestWithdrawalView

WithRecipientData sets the recipient data to use

func (*RequestWithdrawalView) WithTMSID

WithTMSID sets the TMS ID to be used

func (*RequestWithdrawalView) WithWallet

func (r *RequestWithdrawalView) WithWallet(wallet string) *RequestWithdrawalView

WithWallet sets the wallet to use to retrieve a recipient identity if it has not been passed already

type RespondExchangeRecipientIdentitiesView

type RespondExchangeRecipientIdentitiesView struct {
	Wallet         string
	WalletSelector ExchangeWalletSelector
}

func (*RespondExchangeRecipientIdentitiesView) Call

type RespondRequestRecipientIdentityView

type RespondRequestRecipientIdentityView struct {
	Wallet         string
	WalletSelector WalletSelector
}

func (*RespondRequestRecipientIdentityView) Call

type Service

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

Service is the interface for the owner service

func Get

Get returns the Service instance for the passed TMS

func (*Service) Append

func (a *Service) Append(ctx context.Context, tx *Transaction) error

Append adds the passed transaction to the database

func (*Service) AppendTransactionEndorseAck

func (a *Service) AppendTransactionEndorseAck(ctx context.Context, txID string, id view.Identity, sigma []byte) error

func (*Service) Check

func (a *Service) Check(ctx context.Context) ([]string, error)

func (*Service) GetStatus

func (a *Service) GetStatus(ctx context.Context, txID string) (TxStatus, string, error)

GetStatus return the status of the given transaction id. It returns an error if no transaction with that id is found

func (*Service) GetTokenRequest

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

GetTokenRequest returns the token request bound to the passed transaction id, if available.

func (*Service) GetTransactionEndorsementAcks

func (a *Service) GetTransactionEndorsementAcks(ctx context.Context, id string) (map[string][]byte, error)

func (*Service) SetStatus

func (a *Service) SetStatus(ctx context.Context, txID string, status storage.TxStatus, message string) error

SetStatus sets the status of the audit records with the passed transaction id to the passed status

type ServiceManager

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

ServiceManager handles the services

func NewServiceManager

func NewServiceManager(
	networkProvider dep.NetworkProvider,
	tmsProvider dep.TokenManagementServiceProvider,
	ttxStoreServiceManager StoreServiceManager,
	tokensServiceManager TokensServiceManager,
	tracerProvider trace.TracerProvider,
	metricsProvider metrics.Provider,
	checkServiceProvider CheckServiceProvider,
) *ServiceManager

NewServiceManager creates a new Service manager.

func (*ServiceManager) CacheRequest

func (m *ServiceManager) CacheRequest(ctx context.Context, tmsID token.TMSID, request *token.Request) error

CacheRequest stores the request's details for later use.

func (*ServiceManager) ServiceByTMSId

func (m *ServiceManager) ServiceByTMSId(tmsID token.TMSID) (*Service, error)

ServiceByTMSId returns the Service for the given TMS

type Session

type Session = view.Session

Session is an alias of view.Session

type SignaturePayload

type SignaturePayload struct {
	Signature []byte `json:"signature"`
}

SignaturePayload carries a signature on the wire.

type SignatureRequest

type SignatureRequest struct {
	TX     []byte
	Signer view.Identity
}

SignatureRequest represents a request for a party to sign a transaction.

func (*SignatureRequest) Bytes

func (sr *SignatureRequest) Bytes() ([]byte, error)

Bytes returns the serialization of this struct

type SignerProvider

type SignerProvider interface {
	GetSigner(party view.Identity) (token.Signer, error)
}

type Storage

type Storage interface {
	Append(ctx context.Context, tx *Transaction) error
}

Storage defines the interface for storing token transaction records

type StorageProvider

type StorageProvider interface {
	// GetStorage returns the Storage instance for the given TMS ID
	GetStorage(id token.TMSID) (Storage, error)
	// CacheRequest caches the given token request for the given TMS ID
	CacheRequest(ctx context.Context, tmsID token.TMSID, request *token.Request) error
}

StorageProvider defines the interface for obtaining token transaction storage instances

func GetStorageProvider

func GetStorageProvider(sp token.ServiceProvider) (StorageProvider, error)

GetStorageProvider retrieves the StorageProvider instance from the given service provider

type StoreServiceManager

type StoreServiceManager = ttxdb.StoreServiceManager

StoreServiceManager manages transaction store services for different TMS instances.

type StreamExternalWalletMsg

type StreamExternalWalletMsg struct {
	// Type is the type of this message
	Type StreamExternalWalletMsgType
	// Raw will be interpreted following Type
	Raw []byte
}

StreamExternalWalletMsg is the root message that the remote wallet and the ttx package exchange.

func NewStreamExternalWalletMsg

func NewStreamExternalWalletMsg(Type StreamExternalWalletMsgType, v any) (*StreamExternalWalletMsg, error)

NewStreamExternalWalletMsg creates a new root message for the given type and value

type StreamExternalWalletMsgType

type StreamExternalWalletMsgType = int
const (
	SigRequest StreamExternalWalletMsgType
	SignResponse
	Done
)

type StreamExternalWalletSignRequest

type StreamExternalWalletSignRequest struct {
	Party   view.Identity
	Message []byte
}

StreamExternalWalletSignRequest is a message to request a signature

type StreamExternalWalletSignResponse

type StreamExternalWalletSignResponse struct {
	Sigma []byte
}

StreamExternalWalletSignResponse is a message to respond to a request of signature

type StreamExternalWalletSignerClient

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

StreamExternalWalletSignerClient is the signer client executed where Panurus is in execution

func NewStreamExternalWalletSignerClient

func NewStreamExternalWalletSignerClient(sp SignerProvider, stream view2.Stream, _ int) *StreamExternalWalletSignerClient

func NewStreamExternalWalletSignerClientWithTimeout

func NewStreamExternalWalletSignerClientWithTimeout(sp SignerProvider, stream view2.Stream, timeout time.Duration) *StreamExternalWalletSignerClient

func (*StreamExternalWalletSignerClient) Respond

type StreamExternalWalletSignerServer

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

StreamExternalWalletSignerServer is the signer server executed by the remote wallet

func NewStreamExternalWalletSignerServer

func NewStreamExternalWalletSignerServer(stream view2.Stream) *StreamExternalWalletSignerServer

func (*StreamExternalWalletSignerServer) Done

func (*StreamExternalWalletSignerServer) Sign

func (s *StreamExternalWalletSignerServer) Sign(party view.Identity, message []byte) ([]byte, error)

type TokenTransactionDB

type TokenTransactionDB interface {
	GetTokenRequest(ctx context.Context, txID string) ([]byte, error)
	GetTransactionEndorsementAcks(ctx context.Context, id string) (map[string][]byte, error)
}

type TokensServiceManager

type TokensServiceManager services.ServiceManager[*tokens.Service]

TokensServiceManager manages token services for different TMS instances.

type Transaction

type Transaction struct {
	*Payload

	TMS              dep.TokenManagementServiceWithExtensions
	NetworkProvider  GetNetworkFunc
	Opts             *TxOptions
	Context          context.Context
	EndpointResolver *endpoint.Service
	// FromRaw contains the raw material used to unmarshall this transaction.
	// It is nil if the transaction was created from scratch.
	FromRaw              []byte
	FromSignatureRequest *SignatureRequest
}

Transaction models a token transaction

func NewAnonymousTransaction

func NewAnonymousTransaction(context view.Context, opts ...TxOption) (*Transaction, error)

NewAnonymousTransaction returns a new Transaction whose envelope will be signed by an anonymous identities. Options can be further used to customize the transaction.

func NewTransaction

func NewTransaction(context view.Context, signer view.Identity, opts ...TxOption) (*Transaction, error)

NewTransaction returns a new token transaction whose envelope will be signed by the signer bound to the given identity.. Options can be further used to customize the transaction. The given identity must be recognizable by the target network. For example, in case of fabric, the signer must be a valid fabric identity. If the passed signer is nil, then the default identity is used.

func NewTransactionFromBytes

func NewTransactionFromBytes(context view.Context, raw []byte) (*Transaction, error)

NewTransactionFromBytes unmarshals the given bytes into a Transaction, if possible.

func NewTransactionFromSignatureRequest

func NewTransactionFromSignatureRequest(context view.Context, sr *SignatureRequest) (*Transaction, error)

NewTransactionFromSignatureRequest calls NewTransactionFromBytes with the content of the signature request. It sets the transaction's `FromSignatureRequest` upon a success in the deserialization.

func ReceiveTransaction

func ReceiveTransaction(context view.Context, opts ...TxOption) (*Transaction, error)

ReceiveTransaction reads from the context's session a message and tries to unmarshal the message payload as a Transaction.

func (*Transaction) ApplicationMetadata

func (t *Transaction) ApplicationMetadata(k string) []byte

ApplicationMetadata returns the application metadata value for the given key.

func (*Transaction) Bytes

func (t *Transaction) Bytes(eIDs ...string) ([]byte, error)

Bytes returns the serialized version of the transaction. If eIDs is not nil, then metadata is filtered by the passed eIDs.

func (*Transaction) Channel

func (t *Transaction) Channel() string

Channel returns the channel ID of this transaction.

func (*Transaction) CloseSelector

func (t *Transaction) CloseSelector() error

CloseSelector closes the token selector for this transaction.

func (*Transaction) ID

func (t *Transaction) ID() string

ID returns the ID of this transaction. It is equal to the underlying transaction's ID.

func (*Transaction) Inputs

func (t *Transaction) Inputs() (*token.InputStream, error)

Inputs returns the inputs of this transaction over all the actions. The input stream returned can by further filter via the methods it exposes.

func (*Transaction) InputsAndOutputs

InputsAndOutputs returns the inputs and outputs of this transaction over all the actions. The input and output streams returned can by further filter via the methods they expose. The map returned contains the application metadata for all the involved tokens.

func (*Transaction) IsValid

func (t *Transaction) IsValid(ctx context.Context) error

IsValid checks that the transaction is well-formed. This means checking that the embedded TokenRequest is valid.

func (*Transaction) Issue

func (t *Transaction) Issue(wallet *token.IssuerWallet, receiver view.Identity, typ token2.Type, q uint64, opts ...token.IssueOption) error

Issue appends a new Issue action to the TokenRequest of this transaction

func (*Transaction) MarshallToAudit

func (t *Transaction) MarshallToAudit() ([]byte, error)

MarshallToAudit returns the marshalled version of this transaction for audit purposes.

func (*Transaction) Namespace

func (t *Transaction) Namespace() string

Namespace returns the namespace ID of this transaction.

func (*Transaction) Network

func (t *Transaction) Network() string

Network returns the network ID of this transaction.

func (*Transaction) NetworkTxID

func (t *Transaction) NetworkTxID() network.TxID

NetworkTxID returns the network transaction ID of this transaction. The network transaction ID is the identifier the underlying network understands.

func (*Transaction) Outputs

func (t *Transaction) Outputs() (*token.OutputStream, error)

Outputs returns the outputs of this transaction over all the actions. The output stream returned can by further filter via the methods it exposes.

func (*Transaction) Redeem

func (t *Transaction) Redeem(wallet *token.OwnerWallet, typ token2.Type, value uint64, opts ...token.TransferOption) error

Redeem appends a new Redeem action to the TokenRequest of this transaction

func (*Transaction) Release

func (t *Transaction) Release()

Release releases all the resources held by this transaction. In particular, all the tokens locked by this transaction are unlocked.

func (*Transaction) Request

func (t *Transaction) Request() *token.Request

Request returns the underlying TokenRequest of this transaction.

func (*Transaction) Selector

func (t *Transaction) Selector() (token.Selector, error)

Selector returns the default token selector for this transaction

func (*Transaction) SetApplicationMetadata

func (t *Transaction) SetApplicationMetadata(k string, v []byte)

SetApplicationMetadata sets the application metadata key-value pair.

func (*Transaction) TMSID

func (t *Transaction) TMSID() token.TMSID

TMSID returns the TMSID of this transaction.

func (*Transaction) TokenService

TokenService returns the token management service associated to this transaction.

func (*Transaction) Transfer

func (t *Transaction) Transfer(wallet *token.OwnerWallet, typ token2.Type, values []uint64, owners []view.Identity, opts ...token.TransferOption) error

Transfer appends a new Transfer action to the TokenRequest of this transaction

func (*Transaction) Upgrade

func (t *Transaction) Upgrade(
	wallet *token.IssuerWallet,
	receiver token.Identity,
	challenge token.TokensUpgradeChallenge,
	tokens []token2.LedgerToken,
	proof token.TokensUpgradeProof,
	opts ...token.IssueOption,
) error

Upgrade performs an upgrade operation of the passed ledger tokens. A proof and its challenge will be used to verify that the request of upgrade is legit. If the proof verifies then the passed wallet will be used to issue a new amount of tokens matching those whose upgrade has been requested.

type TransactionInfo

type TransactionInfo struct {
	// EndorsementAcks contains the endorsement ACKs received at time of dissemination.
	EndorsementAcks map[string][]byte
	// ApplicationMetadata contains the application metadata
	ApplicationMetadata map[string][]byte

	TokenRequest []byte
}

TransactionInfo contains the transaction info.

type TransactionInfoProvider

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

TransactionInfoProvider allows the retrieval of the transaction info

func (*TransactionInfoProvider) TransactionInfo

func (a *TransactionInfoProvider) TransactionInfo(ctx context.Context, txID string) (*TransactionInfo, error)

TransactionInfo returns the transaction info for the given transaction ID.

type TransactionPayload

type TransactionPayload struct {
	Raw []byte `json:"raw"`
}

TransactionPayload carries a serialized transaction on the wire.

type TransactionRecord

type TransactionRecord = db.TransactionRecord

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.

type TransactionSer

type TransactionSer struct {
	Nonce        []byte
	Creator      []byte
	ID           string
	Network      string
	Channel      string
	Namespace    string
	Signer       []byte
	Transient    []byte
	TokenRequest []byte
	Envelope     []byte
}

type TxOption

type TxOption func(*TxOptions) error

TxOption is a function that modifies TxOptions. It follows the functional options pattern for flexible and extensible configuration of token transactions.

func WithAnonymousTransaction

func WithAnonymousTransaction(v bool) TxOption

WithAnonymousTransaction is used to tell if the transaction needs to be anonymous or not

func WithAuditor

func WithAuditor(auditor view.Identity) TxOption

WithAuditor sets the auditor identity for the transaction. The auditor will validate and sign the transaction before it's submitted to the network.

func WithChannel

func WithChannel(channel string) TxOption

WithChannel sets the channel identifier for the transaction's TMS.

func WithNamespace

func WithNamespace(namespace string) TxOption

WithNamespace sets the namespace identifier for the transaction's TMS.

func WithNetwork

func WithNetwork(network string) TxOption

WithNetwork sets the network identifier for the transaction's TMS.

func WithNetworkTxID

func WithNetworkTxID(id network.TxID) TxOption

WithNetworkTxID sets the network-specific transaction ID for the transaction. This allows using a pre-existing network transaction ID instead of generating a new one.

func WithNoCachingRequest

func WithNoCachingRequest() TxOption

WithNoCachingRequest is used to tell the ordering view to not cache the token request

func WithNoTransactionVerification

func WithNoTransactionVerification() TxOption

WithNoTransactionVerification disables transaction verification when receiving transactions. This should only be used in trusted environments or for testing purposes.

func WithPollingTimeout

func WithPollingTimeout(timeout time.Duration) TxOption

WithPollingTimeout sets the polling interval for finality checks

func WithTMS

func WithTMS(network, channel, namespace string) TxOption

WithTMS filters by network, channel and namespace. Each of them can be empty

func WithTMSID

func WithTMSID(id token.TMSID) TxOption

WithTMSID filters by TMS identifier

func WithTMSIDPointer

func WithTMSIDPointer(id *token.TMSID) TxOption

WithTMSIDPointer filters by TMS identifier, if passed

func WithTimeout

func WithTimeout(timeout time.Duration) TxOption

WithTimeout sets the overall timeout for transaction operations.

func WithTransactions

func WithTransactions(tx *Transaction) TxOption

WithTransactions sets an existing transaction to be used in the options.

func WithTxID

func WithTxID(txID string) TxOption

WithTxID sets a specific transaction ID for the transaction.

type TxOptions

type TxOptions struct {
	Auditor                   view.Identity
	TMSID                     token.TMSID
	NoTransactionVerification bool
	Timeout                   time.Duration
	PollingTimeout            time.Duration
	TxID                      string
	Transaction               *Transaction
	NetworkTxID               network.TxID
	NoCachingRequest          bool
	AnonymousTransaction      bool
}

TxOptions contains configuration options for token transactions including auditor selection, TMS identification, verification settings, timeouts, and transaction identifiers.

func CompileOpts

func CompileOpts(opts ...TxOption) (*TxOptions, error)

CompileOpts applies all provided transaction options and returns the compiled TxOptions. Returns an error if any option fails to apply.

type TxOwner

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

func NewOwner

NewOwner returns a new owner service.

func NewTxOwner

func NewTxOwner(tms dep.TokenManagementService, backend *Service) *TxOwner

NewTxOwner creates a new TxOwner with the given token management service and backend service. This is a lower-level constructor used internally when the backend service is already available.

func (*TxOwner) Append

func (a *TxOwner) Append(ctx context.Context, tx *Transaction) error

Append adds a new transaction to the token transaction database.

func (*TxOwner) Check

func (a *TxOwner) Check(ctx context.Context) ([]string, error)

Check performs a health check on the owner service and returns any issues found. It delegates to the underlying service for the check.

func (*TxOwner) GetStatus

func (a *TxOwner) GetStatus(ctx context.Context, txID string) (TxStatus, string, error)

GetStatus return the status of the given transaction id. It returns an error if no transaction with that id is found

func (*TxOwner) GetTokenRequest

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

GetTokenRequest retrieves the serialized token request for the given transaction ID. Returns an error if the transaction is not found in the database.

func (*TxOwner) SetStatus

func (a *TxOwner) SetStatus(ctx context.Context, txID string, status storage.TxStatus, message string) error

SetStatus sets the status of the audit records with the passed transaction id to the passed status

func (*TxOwner) TransactionInfo

func (a *TxOwner) TransactionInfo(ctx context.Context, txID string) (*TransactionInfo, error)

TransactionInfo returns the transaction info for the given transaction ID.

func (*TxOwner) Transactions

Transactions returns an iterators of transaction records filtered by the given params.

type TxStatus

type TxStatus = storage.TxStatus

TxStatus is the status of a transaction

const (
	// Unknown is the status of a transaction that is unknown
	Unknown TxStatus = storage.Unknown
	// Pending is the status of a transaction that has been submitted to the ledger
	Pending TxStatus = storage.Pending
	// Confirmed is the status of a transaction that has been confirmed by the ledger
	Confirmed TxStatus = storage.Confirmed
	// Deleted is the status of a transaction that has been deleted due to a failure to commit
	Deleted TxStatus = storage.Deleted
	// Orphan is the status of a transaction that never reached the ledger
	Orphan TxStatus = storage.Orphan
)

type UpgradeTokensAgreement

type UpgradeTokensAgreement struct {
	Challenge []byte
	TMSID     token.TMSID
}

type UpgradeTokensInitiatorView

type UpgradeTokensInitiatorView struct {
	Issuer       view.Identity
	TokenType    token2.Type
	Amount       uint64
	TMSID        token.TMSID
	Wallet       string
	NotAnonymous bool

	RecipientData *RecipientData
	Tokens        []token2.LedgerToken
}

UpgradeTokensInitiatorView is the initiator view to request an issuer the upgrade of tokens. The view prepares an instance of UpgradeTokensRequest and send it to the issuer.

func NewRequestTokensUpgradeView

func NewRequestTokensUpgradeView(issuer view.Identity, wallet string, tokens []token2.LedgerToken, notAnonymous bool) *UpgradeTokensInitiatorView

func (*UpgradeTokensInitiatorView) Call

func (r *UpgradeTokensInitiatorView) Call(context view.Context) (any, error)

func (*UpgradeTokensInitiatorView) WithRecipientData

WithRecipientData sets the recipient data to use

func (*UpgradeTokensInitiatorView) WithTMSID

WithTMSID sets the TMS ID to be used

func (*UpgradeTokensInitiatorView) WithWallet

WithWallet sets the wallet to use to retrieve a recipient identity if it has not been passed already

type UpgradeTokensRequest

type UpgradeTokensRequest struct {
	TMSID token.TMSID // The TMSID this request refers to

	ID     token.TokensUpgradeChallenge // The unique ID of this request, it used as challenge of the upgrade protocol
	Tokens []token2.LedgerToken         // The tokens to be upgraded
	Proof  token.TokensUpgradeProof     // The proof

	RecipientData RecipientData // The info about the recipient of the new issues tokens
	NotAnonymous  bool          // Should be the transaction anonymous
}

func ReceiveTokensUpgradeRequest

func ReceiveTokensUpgradeRequest(context view.Context) (*UpgradeTokensRequest, error)

type UpgradeTokensResponderView

type UpgradeTokensResponderView struct{}

UpgradeTokensResponderView this is the view used by the issuer to receive a upgrade request

func NewReceiveUpgradeRequestView

func NewReceiveUpgradeRequestView() *UpgradeTokensResponderView

func (*UpgradeTokensResponderView) Call

func (r *UpgradeTokensResponderView) Call(context view.Context) (any, error)

type WalletSelector added in v0.14.2

type WalletSelector func(request *RecipientRequest, defaultWallet string) (string, error)

WalletSelector lets the responder to a RecipientRequest choose which wallet to use to answer the request. defaultWallet is the wallet that would be used absent a selector (the responder's configured wallet, or the request's WalletID as fallback). Returning defaultWallet unchanged preserves the default behavior.

type WithdrawalRequest

type WithdrawalRequest struct {
	TMSID         token.TMSID
	RecipientData RecipientData
	TokenType     token2.Type
	Amount        uint64
	NotAnonymous  bool
}

func ReceiveWithdrawalRequest

func ReceiveWithdrawalRequest(context view.Context) (*WithdrawalRequest, error)

Directories

Path Synopsis
Package boolpolicy provides a spend-coordination protocol for policy identity tokens.
Package boolpolicy provides a spend-coordination protocol for policy identity tokens.
dep
auditor/mock
Code generated by counterfeiter.
Code generated by counterfeiter.
db
mock
Code generated by counterfeiter.
Code generated by counterfeiter.
deps
mock
Code generated by counterfeiter.
Code generated by counterfeiter.
mock
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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