Skip to content

Commit

Permalink
Merge pull request #969 from lightninglabs/add-unconfirmedtransfersco…
Browse files Browse the repository at this point in the history
…unt-to-listassets

Add field `UnconfirmedTransfers` to RPC endpoint `ListAssets`
  • Loading branch information
guggero authored Jun 25, 2024
2 parents b7117ea + eeb8a5b commit b0de73b
Show file tree
Hide file tree
Showing 5 changed files with 736 additions and 693 deletions.
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

0 comments on commit b0de73b

Please sign in to comment.