Skip to content

Commit 97819b6

Browse files
authored
Merge pull request #1536 from lightninglabs/1535-nil-ptr-listbatches
Fix panic when listing unfunded pending batch with verbose
2 parents 8b9cfa0 + 091d89d commit 97819b6

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

itest/assets_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,17 @@ func testMintBatchResume(t *harnessTest) {
174174

175175
// Build one batch, but leave it as pending.
176176
BuildMintingBatch(t.t, t.tapd, simpleAssets)
177-
batchResp, err := t.tapd.ListBatches(ctxt, &mintrpc.ListBatchRequest{})
177+
178+
// The batch is pending and unfunded, so the verbose batch listing
179+
// should return an empty list. An anchor transaction (BTC funding) is
180+
// required for verbose listing to include group key requests.
181+
batchResp, err := t.tapd.ListBatches(ctxt, &mintrpc.ListBatchRequest{
182+
Verbose: true,
183+
})
184+
require.NoError(t.t, err)
185+
require.Empty(t.t, batchResp.Batches)
186+
187+
batchResp, err = t.tapd.ListBatches(ctxt, &mintrpc.ListBatchRequest{})
178188
require.NoError(t.t, err)
179189
require.Len(t.t, batchResp.Batches, 1)
180190
t.Logf("batches: %v", toJSON(t.t, batchResp))

tapgarden/planter.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ func listBatches(ctx context.Context, batchStore MintingStore,
15161516
}
15171517

15181518
// Formulate verbose batches from the sorted batches.
1519-
verboseBatches := make([]*VerboseBatch, len(sortedBatches))
1519+
verboseBatches := make([]*VerboseBatch, 0, len(sortedBatches))
15201520

15211521
for idx := range sortedBatches {
15221522
currentBatch := sortedBatches[idx]
@@ -1527,6 +1527,10 @@ func listBatches(ctx context.Context, batchStore MintingStore,
15271527
case currentBatch.State() != BatchStatePending:
15281528
continue
15291529
case !currentBatch.IsFunded():
1530+
// The batch isn't funded yet, so we can't display any
1531+
// pending asset group information. Funding is required
1532+
// because the anchor transaction outpoint is needed to
1533+
// formulate pending asset group key requests.
15301534
continue
15311535
case len(currentBatch.Seedlings) == 0:
15321536
continue
@@ -1538,7 +1542,7 @@ func listBatches(ctx context.Context, batchStore MintingStore,
15381542
return nil, err
15391543
}
15401544

1541-
verboseBatches[idx] = verboseBatch
1545+
verboseBatches = append(verboseBatches, verboseBatch)
15421546
}
15431547

15441548
return verboseBatches, nil

taprpc/mintrpc/mint.pb.go

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

taprpc/mintrpc/mint.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ message ListBatchRequest {
420420
string batch_key_str = 2;
421421
}
422422

423-
// If true, pending asset group information will be shown for the pending
424-
// batch.
423+
// If true, pending asset group details will be included for any funded,
424+
// non-empty pending batch. Unfunded or empty batches will be excluded.
425425
bool verbose = 3;
426426
}
427427

taprpc/mintrpc/mint.swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
},
8686
{
8787
"name": "verbose",
88-
"description": "If true, pending asset group information will be shown for the pending\nbatch.",
88+
"description": "If true, pending asset group details will be included for any funded,\nnon-empty pending batch. Unfunded or empty batches will be excluded.",
8989
"in": "query",
9090
"required": false,
9191
"type": "boolean"

0 commit comments

Comments
 (0)