Skip to content

Commit

Permalink
fixup! clearly separate selection of tokens owned sololy by a single …
Browse files Browse the repository at this point in the history
…wallet from selection of tokens whose ownership might be shared

Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
  • Loading branch information
adecaro authored and alexandrosfilios committed Sep 4, 2024
1 parent 83e00ef commit ee0790a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion token/driver/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type UnspentTokensIterator interface {
Next() (*token.UnspentToken, error)
}

type UnspentTokensInWalletIterator interface {
type SpendableTokensIterator interface {
Close()
Next() (*token.UnspentTokenInWallet, error)
}
Expand Down
8 changes: 5 additions & 3 deletions token/driver/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ type WalletLookupID = any
// and wallets (owner, auditor, etc.)
type Authorization interface {
// IsMine returns true if the passed token is owned by an owner wallet.
// It returns the ID of the owner wallet and any additional owner identifier, if supported.
// It is possible that the wallet ID is empty an the additional owner identifier list is not.
IsMine(tok *token.Token) (string, []string, bool)
// It returns the ID of the owner wallet (walletID) and any additional owner identifier (additionalOwners), if supported.
// It is possible that walletID is empty additionalOwners is not.
// If walletID is not empty, this means that the corresponding wallet can spend the token directly.
// If walletID is empty, then additionalOwners must cooperate in some way in order to spend the token.
IsMine(tok *token.Token) (walletID string, additionalOwners []string, mine bool)
// AmIAnAuditor return true if the passed TMS contains an auditor wallet for any of the auditor identities
// defined in the public parameters of the passed TMS.
AmIAnAuditor() bool
Expand Down
6 changes: 3 additions & 3 deletions token/services/db/driver/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ type TokenDB interface {
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 identifier and of a given type
// UnspentTokensIteratorBy returns an iterator over all tokens owned by the passed wallet identifier and of a given type
UnspentTokensIteratorBy(ctx context.Context, walletID, tokenType string) (driver.UnspentTokensIterator, error)
// UnspentTokensInWalletIterator returns an iterator over all tokens owned solely by the passed identifier and of a given type
UnspentTokensInWalletIterator(ctx context.Context, walletID string, typ string) (driver.UnspentTokensInWalletIterator, 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 string) (driver.SpendableTokensIterator, error)
// ListUnspentTokensBy returns the list of all tokens owned by the passed identifier of a given type
ListUnspentTokensBy(walletID, typ string) (*token.UnspentTokens, error)
// ListUnspentTokens returns the list of all owned tokens
Expand Down
3 changes: 1 addition & 2 deletions token/services/db/sql/common/querybuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ func tokenQuerySqlNoJoin(params driver.QueryTokenDetailsParams) (where string, a
}

if len(params.TransactionIDs) > 0 {
colTxID := "tx_id"
and = append(and, in(&args, colTxID, params.TransactionIDs))
and = append(and, in(&args, "tx_id", params.TransactionIDs))
}
if ids := whereTokenIDs(&args, params.IDs); ids != "" {
and = append(and, ids)
Expand Down
2 changes: 1 addition & 1 deletion token/services/db/sql/common/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (db *TokenDB) UnspentTokensIteratorBy(ctx context.Context, walletID, tokenT
}

// UnspentTokensInWalletIterator returns the minimum information about the tokens needed for the selector
func (db *TokenDB) UnspentTokensInWalletIterator(ctx context.Context, walletID string, typ string) (tdriver.UnspentTokensInWalletIterator, error) {
func (db *TokenDB) SpendableTokensIteratorBy(ctx context.Context, walletID string, typ string) (tdriver.SpendableTokensIterator, error) {
span := trace.SpanFromContext(ctx)
where, args := tokenQuerySqlNoJoin(driver.QueryTokenDetailsParams{
WalletID: walletID,
Expand Down
6 changes: 3 additions & 3 deletions token/services/selector/sherdlock/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type tokenFetcher interface {
}

type TokenDB interface {
UnspentTokensInWalletIterator(ctx context.Context, walletID string, typ string) (driver.UnspentTokensInWalletIterator, error)
SpendableTokensIteratorBy(ctx context.Context, walletID string, typ string) (driver.SpendableTokensIterator, error)
}

type enhancedIterator[T any] interface {
Expand Down Expand Up @@ -141,7 +141,7 @@ func NewLazyFetcher(tokenDB TokenDB) *lazyFetcher {

func (f *lazyFetcher) UnspentTokensIteratorBy(walletID, currency string) (iterator[*token2.UnspentTokenInWallet], error) {
logger.Debugf("Query the DB for new tokens")
it, err := f.tokenDB.UnspentTokensInWalletIterator(context.TODO(), walletID, currency)
it, err := f.tokenDB.SpendableTokensIteratorBy(context.TODO(), walletID, currency)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func (f *cachedFetcher) update() {
return
}
logger.Debugf("Renew token cache")
it, err := f.tokenDB.UnspentTokensInWalletIterator(context.TODO(), "", "")
it, err := f.tokenDB.SpendableTokensIteratorBy(context.TODO(), "", "")
if err != nil {
logger.Warnf("Failed to get token iterator: %v", err)
return
Expand Down
2 changes: 1 addition & 1 deletion token/services/selector/testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (q *MockQueryService) UnspentTokensIterator() (*token.UnspentTokensIterator
return &token.UnspentTokensIterator{UnspentTokensIterator: &MockIterator{q, q.allKeys, 0}}, nil
}

func (q *MockQueryService) UnspentTokensInWalletIterator(ctx context.Context, walletID string, typ string) (driver.UnspentTokensInWalletIterator, error) {
func (q *MockQueryService) SpendableTokensIteratorBy(ctx context.Context, walletID string, typ string) (driver.SpendableTokensIterator, error) {
it, err := q.UnspentTokensIteratorBy(ctx, walletID, typ)
if err != nil {
return nil, err
Expand Down

0 comments on commit ee0790a

Please sign in to comment.