@@ -1670,25 +1670,70 @@ func (a *AuxSweeper) resolveContract(
16701670 log .Infof ("Sweeping %v asset outputs: %v" , len (assetOutputs ),
16711671 limitSpewer .Sdump (assetOutputs ))
16721672
1673- // With the sweep desc constructed above, we'll create vPackets for
1674- // each of the local assets, then sign them all.
1675- sPkts := a .createAndSignSweepVpackets (
1676- assetOutputs , req .SignDesc , sweepDesc ,
1677- )
1673+ tapSweepDesc , err := sweepDesc .Unpack ()
1674+ if err != nil {
1675+ return lfn.Err [tlv.Blob ](err )
1676+ }
1677+
1678+ // With the sweep desc constructed above, we'll create vPackets for each
1679+ // of the local assets, then sign them all.
1680+ firstLevelPkts , err := a .createAndSignSweepVpackets (
1681+ lfn .Ok (tapSweepDesc .firstLevel ), assetOutputs , req ,
1682+ ).Unpack ()
1683+ if err != nil {
1684+ return lfn.Err [tlv.Blob ](err )
1685+ }
1686+
1687+ // We can't yet make the second level proof as we don't know exactly
1688+ // what the final txid of the sweep transaction will be. So we'll use a
1689+ // blank proof in place.
1690+ //
1691+ // TODO(roasbeef): need to set internal key? already known
1692+ var proof proof.Proof
1693+
1694+ // We'll make a place holder for the second level output based on the
1695+ // assetID+value tuple.
1696+ secondLevelInputs := []* cmsg.AssetOutput {cmsg .NewAssetOutput (
1697+ assetOutputs [0 ].AssetID .Val , assetOutputs [0 ].Amount .Val , proof ,
1698+ )}
1699+
1700+ // Unlike the first level packets, we can't yet sign the second level
1701+ // packets yet, as we don't know what the sweeping transaction will look
1702+ // like. So we'll just create them.
1703+ secondLevelPkts , err := lfn .MapOption (
1704+ func (desc tapscriptSweepDesc ) lfn.Result [[]* tappsbt.VPacket ] {
1705+ return a .createSweepVpackets (
1706+ secondLevelInputs , lfn .Ok (desc ), req ,
1707+ )
1708+ },
1709+ )(tapSweepDesc .secondLevel ).UnwrapOr (
1710+ lfn.Ok [[]* tappsbt.VPacket ](nil ),
1711+ ).Unpack ()
1712+ if err != nil {
1713+ return lfn.Err [tlv.Blob ](err )
1714+ }
16781715
16791716 // With the vPackets fully generated and signed above, we'll serialize
16801717 // it into a resolution blob to return.
1681- return lfn .AndThen (
1682- sPkts , func (vPkts []* tappsbt.VPacket ) lfn.Result [tlv.Blob ] {
1683- res := cmsg .NewContractResolution (vPkts )
1718+ secondLevelSigDesc := lfn .MapOption (
1719+ func (d tapscriptSweepDesc ) cmsg.TapscriptSigDesc {
1720+ return cmsg .NewTapscriptSigDesc (
1721+ d .scriptTree .TapTweak (), d .ctrlBlockBytes ,
1722+ )
1723+ },
1724+ )(tapSweepDesc .secondLevel )
1725+ res := cmsg .NewContractResolution (
1726+ firstLevelPkts , secondLevelPkts , secondLevelSigDesc ,
1727+ )
16841728
1685- var b bytes.Buffer
1686- if err := res .Encode (& b ); err != nil {
1687- return lfn.Err [tlv.Blob ](err )
1688- }
1729+ var b bytes.Buffer
1730+ if err := res .Encode (& b ); err != nil {
1731+ return lfn.Err [tlv.Blob ](err )
1732+ }
1733+
1734+ return lfn .Ok (b .Bytes ())
1735+ }
16891736
1690- return lfn .Ok (b .Bytes ())
1691- },
16921737// preimageDesc is a helper struct that contains the preimage and the witness
16931738// index that the preimage should be placed within the witness stack. This is
16941739// useful as in an earlier step, we've already pre-signed the witness, but will
0 commit comments