OSDN Git Service

modify multi sign result for same password (#1232)
authoroysheng <33340252+oysheng@users.noreply.github.com>
Mon, 6 Aug 2018 10:52:56 +0000 (18:52 +0800)
committerPaladz <yzhu101@uottawa.ca>
Mon, 6 Aug 2018 10:52:56 +0000 (18:52 +0800)
* modify multi sign result for same password

* optimise

* fix unit test

blockchain/txbuilder/rawtxsig_witness.go
blockchain/txbuilder/signature_witness.go
test/integration/standard_transaction_test.go

index e730146..750d36c 100644 (file)
@@ -43,7 +43,12 @@ func (sw *RawTxSigWitness) sign(ctx context.Context, tpl *Template, index uint32
                        log.WithField("err", err).Warningf("computing signature %d", i)
                        continue
                }
+
+               // This break is ordered to avoid signing transaction successfully only once for a multiple-sign account
+               // that consist of different keys by the same password. Exit immediately when the signature is success,
+               // it means that only one signature will be successful in the loop for this multiple-sign account.
                sw.Sigs[i] = sigBytes
+               break
        }
        return nil
 }
index 2d3de8f..ebdb3fb 100644 (file)
@@ -89,7 +89,12 @@ func (sw *SignatureWitness) sign(ctx context.Context, tpl *Template, index uint3
                        log.WithField("err", err).Warningf("computing signature %d", i)
                        continue
                }
+
+               // This break is ordered to avoid signing transaction successfully only once for a multiple-sign account
+               // that consist of different keys by the same password. Exit immediately when the signature is success,
+               // it means that only one signature will be successful in the loop for this multiple-sign account.
                sw.Sigs[i] = sigBytes
+               break
        }
        return nil
 }
index 3ea937f..bca188d 100644 (file)
@@ -114,6 +114,10 @@ func TestP2SH(t *testing.T) {
                t.Fatal(err)
        }
 
+       // the number of sign transaction is equal to the count of xpub for account
+       if _, err := test.MockSign(tpl, hsm, "password"); err != nil {
+               t.Fatal(err)
+       }
        if _, err := test.MockSign(tpl, hsm, "password"); err != nil {
                t.Fatal(err)
        }