OSDN Git Service

update
authorChengcheng Zhang <943420582@qq.com>
Thu, 23 May 2019 13:23:30 +0000 (21:23 +0800)
committerChengcheng Zhang <943420582@qq.com>
Thu, 23 May 2019 13:23:30 +0000 (21:23 +0800)
account/accounts.go
account/accounts_test.go
account/builder.go
config/genesis.go

index 0dcb58e..2db1b2b 100644 (file)
@@ -20,7 +20,6 @@ import (
        "github.com/vapor/consensus/segwit"
        "github.com/vapor/crypto"
        "github.com/vapor/crypto/csp"
-       "github.com/vapor/crypto/ed25519"
        edchainkd "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/crypto/sha3pool"
        dbm "github.com/vapor/database/leveldb"
@@ -694,11 +693,11 @@ func CreateCtrlProgram(account *Account, addrIdx uint64, change bool) (cp *CtrlP
 
 func createP2PKH(account *Account, path [][]byte) (*CtrlProgram, error) {
        derivedXPubs := csp.DeriveXPubs(account.XPubs, path)
-       derivedPK := derivedXPubs[0].PublicKey()
        pubHash := make([]byte, 0)
-       switch dpk := derivedPK.(type) {
-       case ed25519.PublicKey:
-               pubHash = crypto.Ripemd160(dpk)
+       switch dxpub := derivedXPubs[0].(type) {
+       case edchainkd.XPub:
+               derivedPK := dxpub.PublicKey()
+               pubHash = crypto.Ripemd160(derivedPK)
        }
 
        address, err := common.NewAddressWitnessPubKeyHash(pubHash, &consensus.ActiveNetParams)
index a9e6bbd..8386453 100644 (file)
@@ -10,7 +10,7 @@ import (
        "github.com/vapor/blockchain/pseudohsm"
        "github.com/vapor/blockchain/signers"
        "github.com/vapor/config"
-       vcrypto "github.com/vapor/crypto"
+       edchainkd "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/database"
        dbm "github.com/vapor/database/leveldb"
        "github.com/vapor/errors"
@@ -22,7 +22,7 @@ import (
 func TestCreateAccountWithUppercase(t *testing.T) {
        m := mockAccountManager(t)
        alias := "UPPER"
-       account, err := m.Create([]vcrypto.XPubKeyer{testutil.TestXPub}, 1, alias, signers.BIP0044)
+       account, err := m.Create([]edchainkd.XPub{testutil.TestXPub}, 1, alias, signers.BIP0044)
 
        if err != nil {
                t.Fatal(err)
@@ -36,7 +36,7 @@ func TestCreateAccountWithUppercase(t *testing.T) {
 func TestCreateAccountWithSpaceTrimed(t *testing.T) {
        m := mockAccountManager(t)
        alias := " with space "
-       account, err := m.Create([]vcrypto.XPubKeyer{testutil.TestXPub}, 1, alias, signers.BIP0044)
+       account, err := m.Create([]edchainkd.XPub{testutil.TestXPub}, 1, alias, signers.BIP0044)
 
        if err != nil {
                t.Fatal(err)
@@ -59,7 +59,7 @@ func TestCreateAccountWithSpaceTrimed(t *testing.T) {
 
 func TestCreateAccount(t *testing.T) {
        m := mockAccountManager(t)
-       account, err := m.Create([]vcrypto.XPubKeyer{testutil.TestXPub}, 1, "test-alias", signers.BIP0044)
+       account, err := m.Create([]edchainkd.XPub{testutil.TestXPub}, 1, "test-alias", signers.BIP0044)
        if err != nil {
                testutil.FatalErr(t, err)
        }
@@ -77,7 +77,7 @@ func TestCreateAccountReusedAlias(t *testing.T) {
        m := mockAccountManager(t)
        m.createTestAccount(t, "test-alias", nil)
 
-       _, err := m.Create([]vcrypto.XPubKeyer{testutil.TestXPub}, 1, "test-alias", signers.BIP0044)
+       _, err := m.Create([]edchainkd.XPub{testutil.TestXPub}, 1, "test-alias", signers.BIP0044)
        if errors.Root(err) != ErrDuplicateAlias {
                t.Errorf("expected %s when reusing an alias, got %v", ErrDuplicateAlias, err)
        }
@@ -119,12 +119,12 @@ func TestUpdateAccountAlias(t *testing.T) {
 func TestDeleteAccount(t *testing.T) {
        m := mockAccountManager(t)
 
-       account1, err := m.Create([]vcrypto.XPubKeyer{testutil.TestXPub}, 1, "test-alias1", signers.BIP0044)
+       account1, err := m.Create([]edchainkd.XPub{testutil.TestXPub}, 1, "test-alias1", signers.BIP0044)
        if err != nil {
                testutil.FatalErr(t, err)
        }
 
-       account2, err := m.Create([]vcrypto.XPubKeyer{testutil.TestXPub}, 1, "test-alias2", signers.BIP0044)
+       account2, err := m.Create([]edchainkd.XPub{testutil.TestXPub}, 1, "test-alias2", signers.BIP0044)
        if err != nil {
                testutil.FatalErr(t, err)
        }
@@ -194,8 +194,8 @@ func TestGetAccountIndexKey(t *testing.T) {
                t.Fatal(err)
        }
 
-       xpubs1 := []vcrypto.XPubKeyer{xpub1.XPub, xpub2.XPub}
-       xpubs2 := []vcrypto.XPubKeyer{xpub2.XPub, xpub1.XPub}
+       xpubs1 := []edchainkd.XPub{xpub1.XPub, xpub2.XPub}
+       xpubs2 := []edchainkd.XPub{xpub2.XPub, xpub1.XPub}
        if !reflect.DeepEqual(GetAccountIndexKey(xpubs1), GetAccountIndexKey(xpubs2)) {
                // fmt.Printf("xpubs1 is: %s, xpubs2 is: %s", xpubs1, xpubs2)
                t.Fatal("GetAccountIndexKey test err")
@@ -227,7 +227,7 @@ func mockAccountManager(t *testing.T) *Manager {
 }
 
 func (m *Manager) createTestAccount(t testing.TB, alias string, tags map[string]interface{}) *Account {
-       account, err := m.Create([]vcrypto.XPubKeyer{testutil.TestXPub}, 1, alias, signers.BIP0044)
+       account, err := m.Create([]edchainkd.XPub{testutil.TestXPub}, 1, alias, signers.BIP0044)
        if err != nil {
                testutil.FatalErr(t, err)
        }
index 2e54b97..0f15688 100644 (file)
@@ -9,7 +9,7 @@ import (
        "github.com/vapor/common"
        "github.com/vapor/consensus"
        "github.com/vapor/crypto/csp"
-       "github.com/vapor/crypto/ed25519"
+       edchainkd "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/encoding/json"
        "github.com/vapor/errors"
        "github.com/vapor/protocol/bc"
@@ -335,10 +335,10 @@ func UtxoToInputs(signer *signers.Signer, u *UTXO) (*types.TxInput, *txbuilder.S
 
        switch address.(type) {
        case *common.AddressWitnessPubKeyHash:
-               derivedPK := derivedXPubs[0].PublicKey()
-               switch dpk := derivedPK.(type) {
-               case ed25519.PublicKey:
-                       sigInst.WitnessComponents = append(sigInst.WitnessComponents, txbuilder.DataWitness([]byte(dpk)))
+               switch dxpub := derivedXPubs[0].(type) {
+               case edchainkd.XPub:
+                       derivedPK := dxpub.PublicKey()
+                       sigInst.WitnessComponents = append(sigInst.WitnessComponents, txbuilder.DataWitness([]byte(derivedPK)))
                }
 
        case *common.AddressWitnessScriptHash:
index 58ad266..5f7b22d 100644 (file)
@@ -1,26 +1,31 @@
 package config
 
 import (
+       "crypto"
        "encoding/hex"
 
        log "github.com/sirupsen/logrus"
 
        "github.com/vapor/consensus"
-       "github.com/vapor/crypto"
-       "github.com/vapor/crypto/ed25519/chainkd"
+       vcrypto "github.com/vapor/crypto"
+       edchainkd "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
        "github.com/vapor/protocol/vm/vmutil"
 )
 
 func GenesisArguments(c *Config) []byte {
-       pubKeys := chainkd.XPubKeys(c.Federation.Xpubs)
-       fedpegScript, err := vmutil.P2SPMultiSigProgram(pubKeys, c.Federation.Quorum)
+       pubKeys := edchainkd.XPubKeys(c.Federation.Xpubs)
+       cryptoPub := make([]crypto.PublicKey, 0)
+       for _, pub := range pubKeys {
+               cryptoPub = append(cryptoPub, pub)
+       }
+       fedpegScript, err := vmutil.P2SPMultiSigProgram(cryptoPub, c.Federation.Quorum)
        if err != nil {
                log.Panicf("fail on decode genesis arguments for federation")
        }
 
-       scriptHash := crypto.Sha256(fedpegScript)
+       scriptHash := vcrypto.Sha256(fedpegScript)
 
        control, err := vmutil.P2WSHProgram(scriptHash)
        if err != nil {