From d4c40bfc44abfe1605c8d14b7acbff1c57906558 Mon Sep 17 00:00:00 2001 From: keithsue Date: Mon, 13 Jan 2025 00:46:06 +0800 Subject: [PATCH] fix multisig script --- x/lending/types/taproot.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/x/lending/types/taproot.go b/x/lending/types/taproot.go index c2dfa16..23648f2 100644 --- a/x/lending/types/taproot.go +++ b/x/lending/types/taproot.go @@ -27,16 +27,24 @@ func GetTaprootAddress(script []byte) (*btcutil.AddressTaproot, error) { // Branch 1: multisig signature script func createMultisigScript(pubKeys []string) ([]byte, error) { builder := txscript.NewScriptBuilder() - builder.AddInt64(int64(len(pubKeys))) // Threshold: 2 signatures required - for _, pubKeyHex := range pubKeys { + for i, pubKeyHex := range pubKeys { pubKey, err := hex.DecodeString(pubKeyHex) if err != nil { return nil, err } + builder.AddData(pubKey) + + if i == 0 { + builder.AddOp(txscript.OP_CHECKSIG) + } else { + builder.AddOp(txscript.OP_CHECKSIGADD) + } } - builder.AddInt64(int64(len(pubKeys))) // Total keys - builder.AddOp(txscript.OP_CHECKMULTISIG) + + builder.AddInt64(int64(len(pubKeys))) + builder.AddOp(txscript.OP_NUMEQUAL) + return builder.Script() }