Skip to content

Commit 254224e

Browse files
committed
tapchannel: properly create ContractResolution in createAndSignSweepVpackets
With all the prior commits in place, we can now create the new contract resolution that includes the 1st and 2nd level packets, and the information that we'll need to re-sign the second level packets later.
1 parent 68b78ef commit 254224e

File tree

1 file changed

+60
-14
lines changed

1 file changed

+60
-14
lines changed

tapchannel/aux_sweeper.go

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,25 +1679,71 @@ func (a *AuxSweeper) resolveContract(
16791679
log.Infof("Sweeping %v asset outputs: %v", len(assetOutputs),
16801680
limitSpewer.Sdump(assetOutputs))
16811681

1682-
// With the sweep desc constructed above, we'll create vPackets for
1683-
// each of the local assets, then sign them all.
1684-
sPkts := a.createAndSignSweepVpackets(
1685-
assetOutputs, req.SignDesc, sweepDesc,
1686-
)
1682+
tapSweepDesc, err := sweepDesc.Unpack()
1683+
if err != nil {
1684+
return lfn.Err[tlv.Blob](err)
1685+
}
1686+
1687+
// With the sweep desc constructed above, we'll create vPackets for each
1688+
// of the local assets, then sign them all.
1689+
firstLevelPkts, err := a.createAndSignSweepVpackets(
1690+
lfn.Ok(tapSweepDesc.firstLevel), assetOutputs, req,
1691+
).Unpack()
1692+
if err != nil {
1693+
return lfn.Err[tlv.Blob](err)
1694+
}
1695+
1696+
// We can't yet make the second level proof as we don't know exactly
1697+
// what the final txid of the sweep transaction will be. So we'll use a
1698+
// blank proof in place.
1699+
//
1700+
// TODO(roasbeef): need to set internal key? already known
1701+
var proof proof.Proof
1702+
1703+
// We'll make a place holder for the second level output based on the
1704+
// assetID+value tuple.
1705+
secondLevelInputs := []*cmsg.AssetOutput{cmsg.NewAssetOutput(
1706+
assetOutputs[0].AssetID.Val, assetOutputs[0].Amount.Val, proof,
1707+
)}
1708+
1709+
// Unlike the first level packets, we can't yet sign the second level
1710+
// packets yet, as we don't know what the sweeping transaction will look
1711+
// like. So we'll just create them.
1712+
secondLevelPkts, err := lfn.MapOption(
1713+
func(desc tapscriptSweepDesc) lfn.Result[[]*tappsbt.VPacket] {
1714+
return a.createSweepVpackets(
1715+
secondLevelInputs, lfn.Ok(desc), req,
1716+
)
1717+
},
1718+
)(tapSweepDesc.secondLevel).UnwrapOr(
1719+
lfn.Ok[[]*tappsbt.VPacket](nil),
1720+
).Unpack()
1721+
if err != nil {
1722+
return lfn.Err[tlv.Blob](err)
1723+
}
16871724

16881725
// With the vPackets fully generated and signed above, we'll serialize
16891726
// it into a resolution blob to return.
1690-
return lfn.AndThen(
1691-
sPkts, func(vPkts []*tappsbt.VPacket) lfn.Result[tlv.Blob] {
1692-
res := cmsg.NewContractResolution(vPkts)
1727+
secondLevelSigDesc := lfn.MapOption(
1728+
func(d tapscriptSweepDesc) cmsg.TapscriptSigDesc {
1729+
return cmsg.NewTapscriptSigDesc(
1730+
d.scriptTree.TapTweak(), d.ctrlBlockBytes,
1731+
)
1732+
},
1733+
)(tapSweepDesc.secondLevel)
16931734

1694-
var b bytes.Buffer
1695-
if err := res.Encode(&b); err != nil {
1696-
return lfn.Err[returnType](err)
1697-
}
1735+
res := cmsg.NewContractResolution(
1736+
firstLevelPkts, secondLevelPkts, secondLevelSigDesc,
1737+
)
1738+
1739+
var b bytes.Buffer
1740+
if err := res.Encode(&b); err != nil {
1741+
return lfn.Err[tlv.Blob](err)
1742+
}
1743+
1744+
return lfn.Ok(b.Bytes())
1745+
}
16981746

1699-
return lfn.Ok(b.Bytes())
1700-
},
17011747
// preimageDesc is a helper struct that contains the preimage and the witness
17021748
// index that the preimage should be placed within the witness stack. This is
17031749
// useful as in an earlier step, we've already pre-signed the witness, but will

0 commit comments

Comments
 (0)