OSDN Git Service

p2sh use RawWitnessKeys (#386)
authorPaladz <yzhu101@uottawa.ca>
Tue, 27 Feb 2018 05:00:02 +0000 (13:00 +0800)
committerGitHub <noreply@github.com>
Tue, 27 Feb 2018 05:00:02 +0000 (13:00 +0800)
* p2sh use RawWitnessKeys

* change test key name for fix delay issue

* edit test dir name

blockchain/account/builder.go
protocol/vm/vmutil/script.go
protocol/vm/vmutil/script_test.go
test/integration/standard_transaction_test.go

index bd7b452..8585a90 100755 (executable)
@@ -160,7 +160,7 @@ func UtxoToInputs(signer *signers.Signer, u *UTXO, refData []byte) (*legacy.TxIn
                sigInst.WitnessComponents = append(sigInst.WitnessComponents, txbuilder.DataWitness([]byte(derivedPK)))
 
        case *common.AddressWitnessScriptHash:
-               sigInst.AddWitnessKeys(signer.XPubs, path, signer.Quorum)
+               sigInst.AddRawWitnessKeys(signer.XPubs, path, signer.Quorum)
                path := signers.Path(signer, signers.AccountKeySpace, u.ControlProgramIndex)
                derivedXPubs := chainkd.DeriveXPubs(signer.XPubs, path)
                derivedPKs := chainkd.XPubKeys(derivedXPubs)
index a3fcd1a..57bea29 100644 (file)
@@ -22,16 +22,13 @@ func (b *Builder) addP2SPMultiSig(pubkeys []ed25519.PublicKey, nrequired int) er
                return err
        }
 
-       b.AddOp(vm.OP_DUP).AddOp(vm.OP_TOALTSTACK) // stash a copy of the predicate
-       b.AddOp(vm.OP_SHA3)                        // stack is now [... NARGS SIG SIG SIG PREDICATEHASH]
+       b.AddOp(vm.OP_TXSIGHASH) // stack is now [... NARGS SIG SIG SIG PREDICATEHASH]
        for _, p := range pubkeys {
                b.AddData(p)
        }
-       b.AddInt64(int64(nrequired))                     // stack is now [... SIG SIG SIG PREDICATEHASH PUB PUB PUB M]
-       b.AddInt64(int64(len(pubkeys)))                  // stack is now [... SIG SIG SIG PREDICATEHASH PUB PUB PUB M N]
-       b.AddOp(vm.OP_CHECKMULTISIG).AddOp(vm.OP_VERIFY) // stack is now [... NARGS]
-       b.AddOp(vm.OP_FROMALTSTACK)                      // stack is now [... NARGS PREDICATE]
-       b.AddInt64(0).AddOp(vm.OP_CHECKPREDICATE)
+       b.AddInt64(int64(nrequired))    // stack is now [... SIG SIG SIG PREDICATEHASH PUB PUB PUB M]
+       b.AddInt64(int64(len(pubkeys))) // stack is now [... SIG SIG SIG PREDICATEHASH PUB PUB PUB M N]
+       b.AddOp(vm.OP_CHECKMULTISIG)    // stack is now [... NARGS]
        return nil
 }
 
index ae6b47a..020ac1b 100644 (file)
@@ -1,10 +1,7 @@
 package vmutil
 
 import (
-       "bytes"
        "testing"
-
-       "github.com/bytom/crypto/ed25519"
 )
 
 // TestIsUnspendable ensures the IsUnspendable function returns the expected
@@ -38,22 +35,3 @@ func TestIsUnspendable(t *testing.T) {
                }
        }
 }
-
-func TestP2SP(t *testing.T) {
-       pub1, _, _ := ed25519.GenerateKey(nil)
-       pub2, _, _ := ed25519.GenerateKey(nil)
-       prog, _ := P2SPMultiSigProgram([]ed25519.PublicKey{pub1, pub2}, 1)
-       pubs, n, err := ParseP2SPMultiSigProgram(prog)
-       if err != nil {
-               t.Fatal(err)
-       }
-       if n != 1 {
-               t.Errorf("expected nrequired=1, got %d", n)
-       }
-       if !bytes.Equal(pubs[0], pub1) {
-               t.Errorf("expected first pubkey to be %x, got %x", pub1, pubs[0])
-       }
-       if !bytes.Equal(pubs[1], pub2) {
-               t.Errorf("expected second pubkey to be %x, got %x", pub2, pubs[1])
-       }
-}
index 75057c4..30ac774 100644 (file)
@@ -17,7 +17,7 @@ import (
 )
 
 func TestP2PKH(t *testing.T) {
-       dirPath, err := ioutil.TempDir(".", "")
+       dirPath, err := ioutil.TempDir(".", "TestP2PKH")
        if err != nil {
                t.Fatal(err)
        }
@@ -37,7 +37,7 @@ func TestP2PKH(t *testing.T) {
                t.Fatal(err)
        }
 
-       xpub, err := hsm.XCreate("test_pub", "password")
+       xpub, err := hsm.XCreate("TestP2PKH", "password")
        if err != nil {
                t.Fatal(err)
        }
@@ -72,7 +72,7 @@ func TestP2PKH(t *testing.T) {
 }
 
 func TestP2SH(t *testing.T) {
-       dirPath, err := ioutil.TempDir(".", "")
+       dirPath, err := ioutil.TempDir(".", "TestP2SH")
        if err != nil {
                t.Fatal(err)
        }
@@ -92,12 +92,12 @@ func TestP2SH(t *testing.T) {
                t.Fatal(err)
        }
 
-       xpub1, err := hsm.XCreate("test_pub1", "password")
+       xpub1, err := hsm.XCreate("TestP2SH1", "password")
        if err != nil {
                t.Fatal(err)
        }
 
-       xpub2, err := hsm.XCreate("test_pub2", "password")
+       xpub2, err := hsm.XCreate("TestP2SH2", "password")
        if err != nil {
                t.Fatal(err)
        }
@@ -132,7 +132,7 @@ func TestP2SH(t *testing.T) {
 }
 
 func TestMutilNodeSign(t *testing.T) {
-       dirPath, err := ioutil.TempDir(".", "")
+       dirPath, err := ioutil.TempDir(".", "TestMutilNodeSign")
        if err != nil {
                t.Fatal(err)
        }
@@ -152,12 +152,12 @@ func TestMutilNodeSign(t *testing.T) {
                t.Fatal(err)
        }
 
-       xpub1, err := hsm.XCreate("test_pub1", "password1")
+       xpub1, err := hsm.XCreate("TestMutilNodeSign1", "password1")
        if err != nil {
                t.Fatal(err)
        }
 
-       xpub2, err := hsm.XCreate("test_pub2", "password2")
+       xpub2, err := hsm.XCreate("TestMutilNodeSign2", "password2")
        if err != nil {
                t.Fatal(err)
        }