Skip to content

Commit

Permalink
Merge pull request lightninglabs#603 from Roasbeef/batch-txid
Browse files Browse the repository at this point in the history
multi: add txid of batch when returning the MintingBatch
  • Loading branch information
Roasbeef authored Oct 19, 2023
2 parents dfff7e9 + 0698b7f commit c7d57c5
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 83 deletions.
13 changes: 13 additions & 0 deletions itest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,18 @@ func MintAssetsConfirmBatch(t *testing.T, minerClient *rpcclient.Client,
mintrpc.BatchState_BATCH_STATE_FINALIZED,
)

// We should be able to fetch the batch, and also find that the txid of
// the batch tx is populated.
batchResp, err := tapClient.ListBatches(ctxt, &mintrpc.ListBatchRequest{
Filter: &mintrpc.ListBatchRequest_BatchKey{
BatchKey: batchKey,
},
})
require.NoError(t, err)
require.Len(t, batchResp.Batches, 1)

batch := batchResp.Batches[0]
require.NotEmpty(t, batch.BatchTxid)

return AssertAssetsMinted(t, tapClient, assetRequests, mintTXID, blockHash)
}
13 changes: 13 additions & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/btcutil/psbt"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/davecgh/go-spew/spew"
Expand Down Expand Up @@ -2321,6 +2322,18 @@ func marshalMintingBatch(batch *tapgarden.MintingBatch,
State: rpcBatchState,
}

// If we have the genesis packet available (funded+signed), then we'll
// display the txid as well.
if batch.GenesisPacket != nil {
batchTx, err := psbt.Extract(batch.GenesisPacket.Pkt)
if err == nil {
rpcBatch.BatchTxid = batchTx.TxHash().String()
} else {
rpcsLog.Errorf("unable to extract batch tx: %v", err)
}

}

// If we don't need to include the seedlings, we can return here.
if skipSeedlings {
return rpcBatch, nil
Expand Down
166 changes: 89 additions & 77 deletions taprpc/mintrpc/mint.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions taprpc/mintrpc/mint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,17 @@ message MintingBatch {
*/
bytes batch_key = 1;

// The assets that are part of the batch.
repeated MintAsset assets = 2;
/*
The transaction ID of the batch. Only populated if the batch has been
committed.
*/
string batch_txid = 2;

// The state of the batch.
BatchState state = 3;

// The assets that are part of the batch.
repeated MintAsset assets = 4;
}

enum BatchState {
Expand Down
12 changes: 8 additions & 4 deletions taprpc/mintrpc/mint.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,20 @@
"format": "byte",
"description": "A public key serialized in compressed format that can be used to uniquely\nidentify a pending minting batch. Responses that share the same key will be\nbatched into the same minting transaction."
},
"batch_txid": {
"type": "string",
"description": "The transaction ID of the batch. Only populated if the batch has been\ncommitted."
},
"state": {
"$ref": "#/definitions/mintrpcBatchState",
"description": "The state of the batch."
},
"assets": {
"type": "array",
"items": {
"$ref": "#/definitions/mintrpcMintAsset"
},
"description": "The assets that are part of the batch."
},
"state": {
"$ref": "#/definitions/mintrpcBatchState",
"description": "The state of the batch."
}
}
},
Expand Down

0 comments on commit c7d57c5

Please sign in to comment.