44 "bytes"
55 "encoding/hex"
66
7- "github.com/btcsuite/btcd/btcec/v2/schnorr"
87 "github.com/btcsuite/btcd/btcutil/psbt"
98 "github.com/btcsuite/btcd/txscript"
109
@@ -57,33 +56,14 @@ func (k Keeper) UpdateDLCMeta(ctx sdk.Context, loanId string, depositTxs []*psbt
5756 return err
5857 }
5958
60- liquidationScript , _ := hex .DecodeString (dlcMeta .LiquidationScript )
61- repaymentScript , _ := hex .DecodeString (dlcMeta .RepaymentScript )
62- timeoutRefundScript , _ := hex .DecodeString (dlcMeta .TimeoutRefundScript )
59+ internalKey , _ := hex .DecodeString (dlcMeta .InternalKey )
6360
64- merkleTree := types .GetTapscriptTree ([][]byte {
65- liquidationScript , repaymentScript , timeoutRefundScript ,
66- })
67-
68- liquidationScriptProof := merkleTree .LeafMerkleProofs [0 ]
69- repaymentScriptProof := merkleTree .LeafMerkleProofs [1 ]
70-
71- internalKeyBytes , _ := hex .DecodeString (dlcMeta .InternalKey )
72- internalKey , _ := schnorr .ParsePubKey (internalKeyBytes )
73-
74- liquidationScriptControlBlock , err := types .GetControlBlock (internalKey , liquidationScriptProof )
75- if err != nil {
76- return err
77- }
78-
79- repaymentScriptControlBlock , err := types .GetControlBlock (internalKey , repaymentScriptProof )
80- if err != nil {
81- return err
82- }
61+ liquidationScript , liquidationScriptControlBlock , _ := types .UnwrapLeafScript (dlcMeta .LiquidationScript )
62+ repaymentScript , repaymentScriptControlBlock , _ := types .UnwrapLeafScript (dlcMeta .RepaymentScript )
8363
8464 for i := range liquidationCetPsbt .Inputs {
8565 liquidationCetPsbt .Inputs [i ].SighashType = txscript .SigHashDefault
86- liquidationCetPsbt .Inputs [i ].TaprootInternalKey = internalKeyBytes
66+ liquidationCetPsbt .Inputs [i ].TaprootInternalKey = internalKey
8767 liquidationCetPsbt .Inputs [i ].TaprootLeafScript = []* psbt.TaprootTapLeafScript {
8868 {
8969 ControlBlock : liquidationScriptControlBlock ,
@@ -95,7 +75,7 @@ func (k Keeper) UpdateDLCMeta(ctx sdk.Context, loanId string, depositTxs []*psbt
9575
9676 for i := range repaymentCetPsbt .Inputs {
9777 repaymentCetPsbt .Inputs [i ].SighashType = txscript .SigHashDefault
98- repaymentCetPsbt .Inputs [i ].TaprootInternalKey = internalKeyBytes
78+ repaymentCetPsbt .Inputs [i ].TaprootInternalKey = internalKey
9979 repaymentCetPsbt .Inputs [i ].TaprootLeafScript = []* psbt.TaprootTapLeafScript {
10080 {
10181 ControlBlock : repaymentScriptControlBlock ,
@@ -120,7 +100,7 @@ func (k Keeper) UpdateDLCMeta(ctx sdk.Context, loanId string, depositTxs []*psbt
120100 return err
121101 }
122102
123- timeoutRefundTx , err := types .CreateTimeoutRefundTransaction (depositTxs , vaultPkScript , borrowerPkScript , internalKeyBytes , [][] byte { liquidationScript , repaymentScript , timeoutRefundScript } , 1 )
103+ timeoutRefundTx , err := types .CreateTimeoutRefundTransaction (depositTxs , vaultPkScript , borrowerPkScript , internalKey , dlcMeta . TimeoutRefundScript , 1 )
124104 if err != nil {
125105 return err
126106 }
@@ -153,27 +133,8 @@ func (k Keeper) GetCetInfos(ctx sdk.Context, loanId string, collateralAmount sdk
153133 dlcMeta := k .GetDLCMeta (ctx , loanId )
154134 poolConfig := k .GetPool (ctx , loan .PoolId ).Config
155135
156- liquidationScript , _ := hex .DecodeString (dlcMeta .LiquidationScript )
157- repaymentScript , _ := hex .DecodeString (dlcMeta .RepaymentScript )
158- timeoutRefundScript , _ := hex .DecodeString (dlcMeta .TimeoutRefundScript )
159-
160- merkleTree := types .GetTapscriptTree ([][]byte {liquidationScript , repaymentScript , timeoutRefundScript })
161-
162- liquidationScriptProof := merkleTree .LeafMerkleProofs [0 ]
163- repaymentScriptProof := merkleTree .LeafMerkleProofs [1 ]
164-
165- internalKeyBytes , _ := hex .DecodeString (dlcMeta .InternalKey )
166- internalKey , _ := schnorr .ParsePubKey (internalKeyBytes )
167-
168- liquidationScriptControlBlock , err := types .GetControlBlock (internalKey , liquidationScriptProof )
169- if err != nil {
170- return nil , err
171- }
172-
173- repaymentScriptControlBlock , err := types .GetControlBlock (internalKey , repaymentScriptProof )
174- if err != nil {
175- return nil , err
176- }
136+ liquidationScript , liquidationScriptControlBlock , _ := types .UnwrapLeafScript (dlcMeta .LiquidationScript )
137+ repaymentScript , repaymentScriptControlBlock , _ := types .UnwrapLeafScript (dlcMeta .RepaymentScript )
177138
178139 var liquidationEvent * dlctypes.DLCEvent
179140 if loan .LiquidationEventId != 0 {
0 commit comments