Skip to content

Commit c56b559

Browse files
committed
tapfreighter: store asset burns
1 parent a2d1de1 commit c56b559

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

rpcserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,7 +2275,7 @@ func (r *rpcServer) AnchorVirtualPsbts(ctx context.Context,
22752275
}
22762276

22772277
resp, err := r.cfg.ChainPorter.RequestShipment(
2278-
tapfreighter.NewPreSignedParcel(vPackets, inputCommitments),
2278+
tapfreighter.NewPreSignedParcel(vPackets, inputCommitments, ""),
22792279
)
22802280
if err != nil {
22812281
return nil, fmt.Errorf("error requesting delivery: %w", err)
@@ -3290,7 +3290,7 @@ func (r *rpcServer) BurnAsset(ctx context.Context,
32903290
resp, err := r.cfg.ChainPorter.RequestShipment(
32913291
tapfreighter.NewPreSignedParcel(
32923292
[]*tappsbt.VPacket{fundResp.VPacket},
3293-
fundResp.InputCommitments,
3293+
fundResp.InputCommitments, "",
32943294
),
32953295
)
32963296
if err != nil {

tapfreighter/chain_porter.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,34 @@ func (p *ChainPorter) storePackageAnchorTxConf(pkg *sendPackage) error {
646646
)
647647
}
648648

649+
// Now we scan through the VPacket for any burns.
650+
var burns []*AssetBurn
651+
652+
for _, v := range pkg.VirtualPackets {
653+
for _, o := range v.Outputs {
654+
if !o.Asset.IsBurn() {
655+
continue
656+
}
657+
658+
assetID := o.Asset.ID()
659+
660+
// We prepare the burn and add it to the list.
661+
b := &AssetBurn{
662+
AssetID: assetID[:],
663+
Amount: o.Amount,
664+
AnchorTxid: pkg.OutboundPkg.AnchorTx.TxHash(),
665+
Note: pkg.Note,
666+
}
667+
668+
if o.Asset.GroupKey != nil {
669+
groupKey := o.Asset.GroupKey.GroupPubKey
670+
b.GroupKey = groupKey.SerializeCompressed()
671+
}
672+
673+
burns = append(burns, b)
674+
}
675+
}
676+
649677
// At this point we have the confirmation signal, so we can mark the
650678
// parcel delivery as completed in the database.
651679
anchorTXID := pkg.OutboundPkg.AnchorTx.TxHash()
@@ -657,7 +685,7 @@ func (p *ChainPorter) storePackageAnchorTxConf(pkg *sendPackage) error {
657685
TxIndex: int32(pkg.TransferTxConfEvent.TxIndex),
658686
FinalProofs: pkg.FinalProofs,
659687
PassiveAssetProofFiles: passiveAssetProofFiles,
660-
}, nil)
688+
}, burns)
661689
if err != nil {
662690
return fmt.Errorf("unable to log parcel delivery "+
663691
"confirmation: %w", err)

tapfreighter/parcel.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ type PreSignedParcel struct {
258258
// inputCommitments are the commitments for the input that are being
259259
// spent in the virtual transaction.
260260
inputCommitments tappsbt.InputCommitments
261+
262+
// note is a string that provides any user defined description for this
263+
// transfer.
264+
note string
261265
}
262266

263267
// A compile-time assertion to ensure PreSignedParcel implements the parcel
@@ -266,7 +270,8 @@ var _ Parcel = (*PreSignedParcel)(nil)
266270

267271
// NewPreSignedParcel creates a new PreSignedParcel.
268272
func NewPreSignedParcel(vPackets []*tappsbt.VPacket,
269-
inputCommitments tappsbt.InputCommitments) *PreSignedParcel {
273+
inputCommitments tappsbt.InputCommitments,
274+
note string) *PreSignedParcel {
270275

271276
return &PreSignedParcel{
272277
parcelKit: &parcelKit{
@@ -275,6 +280,7 @@ func NewPreSignedParcel(vPackets []*tappsbt.VPacket,
275280
},
276281
vPackets: vPackets,
277282
inputCommitments: inputCommitments,
283+
note: note,
278284
}
279285
}
280286

@@ -290,6 +296,7 @@ func (p *PreSignedParcel) pkg() *sendPackage {
290296
SendState: SendStateAnchorSign,
291297
VirtualPackets: p.vPackets,
292298
InputCommitments: p.inputCommitments,
299+
Note: p.note,
293300
}
294301
}
295302

@@ -464,6 +471,10 @@ type sendPackage struct {
464471
// TransferTxConfEvent contains transfer transaction on-chain
465472
// confirmation data.
466473
TransferTxConfEvent *chainntnfs.TxConfirmation
474+
475+
// Note is a user provided description for this transfer. This is
476+
// currently only used by asset burn transfers.
477+
Note string
467478
}
468479

469480
// ConvertToTransfer prepares the finished send data for storing to the database

0 commit comments

Comments
 (0)