Skip to content

Commit 3d299cf

Browse files
committed
tapfreighter: fix missing bits in OutboundParcel.Copy
1 parent 4476e7d commit 3d299cf

File tree

1 file changed

+44
-14
lines changed

1 file changed

+44
-14
lines changed

tapfreighter/interface.go

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -458,30 +458,60 @@ type OutboundParcel struct {
458458
// Copy creates a deep copy of the OutboundParcel.
459459
func (o *OutboundParcel) Copy() *OutboundParcel {
460460
newParcel := &OutboundParcel{
461-
AnchorTxHeightHint: o.AnchorTxHeightHint,
462-
TransferTime: o.TransferTime,
463-
ChainFees: o.ChainFees,
464-
PassiveAssets: fn.CopyAll(o.PassiveAssets),
465-
Inputs: fn.CopySlice(o.Inputs),
466-
Outputs: fn.CopySlice(o.Outputs),
461+
AnchorTxHeightHint: o.AnchorTxHeightHint,
462+
AnchorTxBlockHeight: o.AnchorTxBlockHeight,
463+
TransferTime: o.TransferTime,
464+
ChainFees: o.ChainFees,
465+
Inputs: fn.CopySlice(o.Inputs),
466+
Outputs: fn.CopySlice(o.Outputs),
467+
Label: o.Label,
468+
SkipAnchorTxBroadcast: o.SkipAnchorTxBroadcast,
467469
}
468470

471+
newParcel.PassiveAssets = make(
472+
[]*tappsbt.VPacket, 0, len(o.PassiveAssets),
473+
)
474+
475+
for _, pa := range o.PassiveAssets {
476+
newParcel.PassiveAssets = append(
477+
newParcel.PassiveAssets, pa.Copy(),
478+
)
479+
}
480+
481+
o.AnchorTxBlockHash.WhenSome(func(h chainhash.Hash) {
482+
newParcel.AnchorTxBlockHash = fn.Some(h)
483+
})
484+
469485
if o.AnchorTx != nil {
470486
newParcel.AnchorTx = o.AnchorTx.Copy()
471487
}
472488

473489
if o.PassiveAssetsAnchor != nil {
474490
oldAnchor := o.PassiveAssetsAnchor
491+
475492
newParcel.PassiveAssetsAnchor = &Anchor{
476-
OutPoint: oldAnchor.OutPoint,
477-
Value: oldAnchor.Value,
478-
InternalKey: oldAnchor.InternalKey,
479-
TaprootAssetRoot: oldAnchor.TaprootAssetRoot,
480-
CommitmentVersion: oldAnchor.CommitmentVersion,
481-
MerkleRoot: oldAnchor.MerkleRoot,
482-
TapscriptSibling: oldAnchor.TapscriptSibling,
483-
NumPassiveAssets: oldAnchor.NumPassiveAssets,
493+
OutPoint: oldAnchor.OutPoint,
494+
Value: oldAnchor.Value,
495+
InternalKey: oldAnchor.InternalKey,
496+
TaprootAssetRoot: fn.CopySlice(
497+
oldAnchor.TaprootAssetRoot,
498+
),
499+
MerkleRoot: fn.CopySlice(oldAnchor.MerkleRoot),
500+
TapscriptSibling: fn.CopySlice(
501+
oldAnchor.TapscriptSibling,
502+
),
503+
NumPassiveAssets: oldAnchor.NumPassiveAssets,
504+
PkScript: fn.CopySlice(oldAnchor.PkScript),
505+
}
506+
507+
// Leave CommitmentVersion nil if it was unset or set it to
508+
// point to a new uint8 otherwise.
509+
if oldAnchor.CommitmentVersion != nil {
510+
commitmentVersion := *oldAnchor.CommitmentVersion
511+
newParcel.PassiveAssetsAnchor.CommitmentVersion =
512+
&commitmentVersion
484513
}
514+
485515
}
486516

487517
return newParcel

0 commit comments

Comments
 (0)