Skip to content

Commit 2a8c960

Browse files
author
Soumya Mohapatra
committed
Add time-range filtering, ORDER BY, OutstandingBalance, and unit tests
- Issue #3: Thread From/To *time.Time params through all 6 layers for IssuedBalance, ListRedeemedTokens, and RedeemedBalance. SQL uses cond.Gte/cond.Lte on stored_at column. - Issue #4: Thread SortBy/SortDirection to ListRedeemedTokens SQL. SortByQuantity maps to ORDER BY amount ASC/DESC. - Issue #5: Add unit tests for IssuedBalance, RedeemedTokens, RedeemedBalance, and OutstandingBalance (happy path, error propagation, edge cases). - Issue #6: Add OutstandingBalance method to IssuerWallet (IssuedBalance minus RedeemedBalance) with overflow guard.
1 parent fbe4a85 commit 2a8c960

14 files changed

Lines changed: 467 additions & 147 deletions

File tree

token/driver/mock/iw.go

Lines changed: 79 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token/driver/mock/qe.go

Lines changed: 41 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token/driver/vault.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package driver
88

99
import (
1010
"context"
11+
"time"
1112

1213
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/collections/iterators"
1314
"github.com/hyperledger-labs/fabric-token-sdk/token/token"
@@ -87,15 +88,17 @@ type QueryEngine interface {
8788
// IssuedBalance returns the sum of amounts of non-deleted tokens flagged as issued.
8889
// If tokenType is non-empty, only tokens of that type are included.
8990
// If issuerRaw is non-empty, only tokens issued by that identity are included.
90-
IssuedBalance(ctx context.Context, tokenType token.Type, issuerRaw Identity) (uint64, error)
91+
IssuedBalance(ctx context.Context, tokenType token.Type, issuerRaw Identity, from, to *time.Time) (uint64, error)
9192
// ListRedeemedTokens returns issued tokens that were spent by a Redeem action.
9293
// If tokenType is non-empty, only tokens of that type are included.
9394
// If issuerRaw is non-empty, only tokens issued by that identity are included.
94-
ListRedeemedTokens(ctx context.Context, tokenType token.Type, issuerRaw Identity) (*token.IssuedTokens, error)
95+
// If from/to are non-nil, only tokens stored within that time range are included.
96+
ListRedeemedTokens(ctx context.Context, tokenType token.Type, issuerRaw Identity, from, to *time.Time, sortBy SortField, sortDirection SortDirection) (*token.IssuedTokens, error)
9597
// RedeemedBalance returns the sum of amounts of issued tokens spent by a Redeem action.
9698
// If tokenType is non-empty, only tokens of that type are included.
9799
// If issuerRaw is non-empty, only tokens issued by that identity are included.
98-
RedeemedBalance(ctx context.Context, tokenType token.Type, issuerRaw Identity) (uint64, error)
100+
// If from/to are non-nil, only tokens stored within that time range are included.
101+
RedeemedBalance(ctx context.Context, tokenType token.Type, issuerRaw Identity, from, to *time.Time) (uint64, error)
99102
// PublicParams returns the serialized public parameters used by the driver.
100103
PublicParams(ctx context.Context) ([]byte, error)
101104
// GetTokenMetadata retrieves the private information (metadata) for the given token IDs.

token/driver/wallet.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package driver
88

99
import (
1010
"context"
11+
"time"
1112

1213
"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
1314
"github.com/hyperledger-labs/fabric-token-sdk/token/token"
@@ -98,6 +99,10 @@ type ListTokensOptions struct {
9899
SortBy SortField
99100
// SortDirection specifies ascending or descending order.
100101
SortDirection SortDirection
102+
// From, if non-nil, restricts results to tokens stored at or after this time.
103+
From *time.Time
104+
// To, if non-nil, restricts results to tokens stored at or before this time.
105+
To *time.Time
101106
}
102107

103108
// Wallet models a generic wallet
@@ -184,6 +189,9 @@ type IssuerWallet interface {
184189

185190
// RedeemedBalance returns the total amount of redeemed tokens that were originally issued by this wallet.
186191
RedeemedBalance(ctx context.Context, opts *ListTokensOptions) (uint64, error)
192+
193+
// OutstandingBalance returns the net amount still in circulation: IssuedBalance − RedeemedBalance.
194+
OutstandingBalance(ctx context.Context, opts *ListTokensOptions) (uint64, error)
187195
}
188196

189197
// AuditorWallet models the wallet of an auditor

0 commit comments

Comments
 (0)