Extend IssuerWallet with balance and redemption queries#1624
Extend IssuerWallet with balance and redemption queries#1624Soumya8898 wants to merge 26 commits into
Conversation
2a8c960 to
6083c16
Compare
6083c16 to
76d9847
Compare
|
Hi @Soumya8898 , thanks for this effort. I'll review ASAP. A quick note already: Please, extend the fungible integration test Thanks a lot 🙏 |
76d9847 to
74c672a
Compare
74c672a to
2e42941
Compare
1ee94bf to
ba79a30
Compare
d3c4f5b to
1667520
Compare
|
Hi @adecaro can you please give it another review. Thanks |
9c811de to
5b5bc89
Compare
|
Hi @Soumya8898 , there is something failing in the integration tests, please, have a look. Thanks 🙏 |
47a0dc3 to
b37a5b2
Compare
|
Hi @Soumya8898 , thanks for the effort so far 🙏 |
|
Hi @adecaro I am doing a last round of verification of all the changes, if unable to resolve it, will surely ask you for help. Thanks |
53e3c2d to
8da2b44
Compare
Hi @adecaro i think i need support here, can you please share your views like wht is going wrong in the changes for which these panic calls are getting triggered. |
|
Hi @Soumya8898 , I think I got the problem. The question is: Which are the tokens that represent a redeem? Those whose owner field is empty. Now, this means that the query performed by RedeemedBalance on the token store needs to be adjusted. Please, double check also that Thanks for the effort @Soumya8898 🙏 |
|
Hi @adecaro Thanks for these catches, let me give them a look will update here. |
Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
…dBalance SQL queries Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
…emedBalance Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
- Issue hyperledger-labs#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 hyperledger-labs#4: Thread SortBy/SortDirection to ListRedeemedTokens SQL. SortByQuantity maps to ORDER BY amount ASC/DESC. - Issue hyperledger-labs#5: Add unit tests for IssuedBalance, RedeemedTokens, RedeemedBalance, and OutstandingBalance (happy path, error propagation, edge cases). - Issue hyperledger-labs#6: Add OutstandingBalance method to IssuerWallet (IssuedBalance minus RedeemedBalance) with overflow guard. Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
Add IssuedBalanceView, RedeemedBalanceView, and OutstandingBalanceView with corresponding view factories, support helpers (CheckIssuedBalance, CheckRedeemedBalance, CheckOutstandingBalance), and two assertion blocks in TestAll that exercise the new APIs after issue+redeem cycles. Signed-off-by: Soumya Mohapatra <soumyaranjanmohapatra8@gmail.com> Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
…e; add GoDocs Signed-off-by: Soumya Mohapatra <soumyaranjanmohapatra8@gmail.com> Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
CallView returns JSON-encoded []byte, not the raw Go type. The Check*Balance functions were doing res.(uint64) which panics because res is actually []byte. Use JSONUnmarshalUint64 helper (analogous to existing JSONUnmarshalFloat64) to properly decode the result. Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
ListRedeemedTokens and RedeemedBalance previously JOINed with the transactions table to identify tokens spent by a Redeem action. However, the issuer node does not have entries in the transactions table for redeem transactions initiated by other nodes, because StoreTransactionRecords is only called by view initiators/responders and the issuer is not in the redeem distribution list. Instead, identify redeemed tokens by LEFT JOINing the tokens table with itself: a redeemed token (issuer=true, is_deleted=true) has a spent_by tx_id that has NO output tokens in the tokens table (Parse() skips redeem outputs with empty owner), whereas a transferred token's spent_by tx_id DOES have output tokens. This fixes all 8 failing CI integration tests that were panicking with 'close of closed channel' due to the view assertion failure when CheckRedeemedBalance returned 0 instead of the expected value. Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
8da2b44 to
dc53d86
Compare
Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
dc53d86 to
28ab079
Compare
…tion - Update role wallets_test.go to use driver.BalanceOpts instead of driver.ListTokensOptions for IssuedBalance, RedeemedBalance, and OutstandingBalance test calls (go vet failures) - Fix QueryTokenDetails in sql/common/tokens.go to scan the BIGINT amount column into int64 first, then convert to *big.Int, since the SQL driver cannot scan int64 directly into *big.Int - Align OwnerWallet.Balance in token/wallet.go to return *big.Int and properly convert BalanceOption to driver ListTokensOptions Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
- run gofmt-compliant updates in token/wallet.go\n- satisfy golangci-lint nlreturn in QueryTokenDetails callback\n- keep big.Int scan conversion path intact Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
Integration suites panic in BeforeEach when FAB_BINS lacks configtxgen.\nInstall configtxgen unconditionally in the itest workflow so both fabric and fabricx matrix jobs have the required binary. Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
Root cause of repeated integration panics is missing binaries in FAB_BINS during BeforeEach bootstrap. Set FAB_BINS explicitly for itest jobs and fail fast by validating required Fabric binaries (configtxgen, configtxlator, cryptogen, discover, orderer, osnadmin, peer) before running suites. Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
All failing suites panic in BeforeEach during binary lookup.\nExport FAB_BINS in the same shell that runs make integration-tests-* and log the directory contents to eliminate env propagation ambiguity and aid root-cause diagnosis. Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
When SQL SUM(amount) returns NULL for no matching tokens, Balance was returning (nil, nil).\nRecipients then called balance.Cmp(...) in AcceptCashView and panicked with nil pointer during issue/update integration tests.\n\nChanges:\n- Return big.NewInt(0) when SUM(amount) is NULL in sql/common TokenStore balance\n- Add dbtest regression asserting empty balance is non-nil zero Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
cd1e31f to
e6c44ad
Compare
…alance test Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
e84dc66 to
1ef3293
Compare
…alance test Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
d9cf618 to
9324273
Compare
…em and transfer lineage Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
9324273 to
3cf8252
Compare
Summary
Added changes to close #872
This PR extends the
IssuerWalletinterface with five new methods that give issuers full visibility into their token lifecycle — from issuance through redemption — with flexible query filtering and sorting.Motivation
The existing
IssuerWalletonly exposedHistoryTokens, which lists issued tokens. There was no way for an issuer to:Issuers operating multi-wallet nodes or managing multiple token types had no first-class API for these common reporting needs.
New API Surface
Five methods added to
IssuerWallet(driver and public interfaces):IssuedBalance(ctx, opts)uint64RedeemedTokens(ctx, opts)*IssuedTokensRedeemedBalance(ctx, opts)uint64OutstandingBalance(ctx, opts)uint64IssuedBalance − RedeemedBalanceAll methods accept
*ListTokensOptionswhich now supports:TokenTypetoken.Type"USD")SortBySortFieldSortByDefaultorSortByQuantitySortDirectionSortDirectionSortAscendingorSortDescendingFrom/To*time.TimeThe issuer identity filter is applied automatically — each wallet scopes queries to its own identity.
Data Model Changes
Added two fields to
IssuedToken:IsSpent bool— whether the token has been deleted/spentSpentBy string— the transaction ID that spent the tokenThese fields enable the SQL layer to JOIN tokens with transactions and identify redemptions (
action_type = Redeem).SQL Implementation
IssuedBalance:SELECT SUM(amount)over non-deleted tokens withissuer = true, filtered by token type, issuer identity, and time rangeListRedeemedTokens:SELECT ... FROM tokens JOIN transactionswhereis_deleted = true AND action_type = Redeem, with optionalORDER BY amount ASC|DESCRedeemedBalance: Same join as above but returnsSUM(amount)OutstandingBalance: Computed at the wallet layer asIssuedBalance − RedeemedBalance(no extra SQL query)All SQL conditions are built dynamically — empty/nil filters are skipped, so callers only supply what they need.
Testing
IssuedBalance,RedeemedTokens,RedeemedBalance, andOutstandingBalancemock.IssuerTokenVault)