Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add field UnconfirmedTransfers to RPC endpoint ListAssets #969

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion itest/multi_send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ func testAnchorMultipleVirtualTransactions(t *harnessTest) {
)
require.NoError(t.t, err)

// We'll attempt to list assets immediately after initiating the
// transfer. The unconfirmed assets should not be listed yet, but the
// unconfirmed transfer count should be 1.
aliceAssets, err := aliceTapd.ListAssets(
ctxt, &taprpc.ListAssetRequest{},
)
require.NoError(t.t, err)
require.Nil(t.t, aliceAssets.Assets)
require.EqualValues(t.t, aliceAssets.UnconfirmedTransfers, 1)

t.Logf("Send response: %v", toJSON(t.t, sendResp))

ConfirmAndAssertOutboundTransferWithOutputs(
Expand All @@ -272,7 +282,7 @@ func testAnchorMultipleVirtualTransactions(t *harnessTest) {
assetXTranche3.AssetGenesis,
)

aliceAssets, err := aliceTapd.ListAssets(
aliceAssets, err = aliceTapd.ListAssets(
ctxt, &taprpc.ListAssetRequest{},
)
require.NoError(t.t, err)
Expand Down
15 changes: 13 additions & 2 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,18 @@ func (r *rpcServer) ListAssets(ctx context.Context,
return nil, err
}

// We will also report the number of unconfirmed transfers. This is
// useful for clients as unconfirmed asset coins are not included in the
// asset list.
outboundParcels, err := r.cfg.AssetStore.QueryParcels(ctx, nil, true)
if err != nil {
return nil, fmt.Errorf("unable to query for unconfirmed "+
"outgoing parcels: %w", err)
}

return &taprpc.ListAssetResponse{
Assets: rpcAssets,
Assets: rpcAssets,
UnconfirmedTransfers: uint64(len(outboundParcels)),
}, nil
}

Expand Down Expand Up @@ -1240,7 +1250,8 @@ func (r *rpcServer) ListBalances(ctx context.Context,
}
}

// ListTransfers lists all asset transfers managed by this daemon.
// ListTransfers returns a list of all asset transfers managed by this daemon.
// This includes both confirmed and unconfirmed transfers.
func (r *rpcServer) ListTransfers(ctx context.Context,
req *taprpc.ListTransfersRequest) (*taprpc.ListTransfersResponse,
error) {
Expand Down
Loading
Loading