OSDN Git Service

update
authorChengcheng Zhang <943420582@qq.com>
Sat, 25 May 2019 11:30:36 +0000 (19:30 +0800)
committerChengcheng Zhang <943420582@qq.com>
Sat, 25 May 2019 11:30:36 +0000 (19:30 +0800)
crypto/csp/util.go
protocol/validation/test/tx_ugly_test.go
test/tx_test_util.go
test/wallet_test_util.go

index eae5e6b..5615e84 100644 (file)
@@ -51,21 +51,21 @@ func DeriveXPubs(xpubs []vcrypto.XPubKeyer, path [][]byte) []vcrypto.XPubKeyer {
        for _, xpub := range xpubs {
                fmt.Println("DeriveXPubs type xpubs:", reflect.TypeOf(xpubs), "type xpubs[0]:", reflect.TypeOf(xpubs[0]))
                fmt.Println("xpubs[0] is:", xpubs[0])
-               newxpub, err := edchainkd.NewXPub(reflect.ValueOf(xpub).String())
-               if err != nil {
-                       fmt.Println("csp DeriveXPubs err:", err)
-               } else {
-                       d := newxpub.Derive(path)
+               switch xpb := xpub.(type) {
+               case edchainkd.XPub:
+                       d := xpb.Derive(path)
                        res = append(res, d)
                        fmt.Println("DeriveXPubs d is:", d)
+               default:
+                       newxpub, err := edchainkd.NewXPub(reflect.ValueOf(xpub).String())
+                       if err != nil {
+                               fmt.Println("csp DeriveXPubs err:", err)
+                       } else {
+                               d := newxpub.Derive(path)
+                               res = append(res, d)
+                               fmt.Println("DeriveXPubs d is:", d)
+                       }
                }
-
-               // switch xpb := xpub.(type) {
-               // case edchainkd.XPub:
-               //      d := xpb.Derive(path)
-               //      res = append(res, d)
-               //      fmt.Println("DeriveXPubs d is:", d)
-               // }
        }
        fmt.Println("DeriveXPubs len(res) is:", len(res))
        return res
index b988f94..aaada6f 100644 (file)
@@ -8,6 +8,7 @@ import (
        "github.com/vapor/account"
        "github.com/vapor/blockchain/signers"
        "github.com/vapor/consensus"
+       vcrypto "github.com/vapor/crypto"
        "github.com/vapor/crypto/csp"
        edchainkd "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/protocol/bc"
@@ -636,7 +637,7 @@ func mockCtrlProgram(txData types.TxData, insts []*signingInst) {
                        if inp.ControlProgram != nil {
                                continue
                        }
-                       acc := &account.Account{Signer: &signers.Signer{KeyIndex: insts[i].keyIndex, DeriveRule: signers.BIP0044, XPubs: xPubs, Quorum: insts[i].quorum}}
+                       acc := &account.Account{Signer: &signers.Signer{KeyIndex: insts[i].keyIndex, DeriveRule: signers.BIP0044, XPubs: []vcrypto.XPubKeyer{xPubs}, Quorum: insts[i].quorum}}
                        program, err := account.CreateCtrlProgram(acc, insts[i].ctrlProgramIndex, insts[i].change)
                        if err != nil {
                                panic(err)
@@ -672,7 +673,7 @@ func mockSignTx(tx *types.Tx, insts []*signingInst) {
                                derivePK := childPrv.XPub()
                                arguments = append(arguments, derivePK.PublicKey())
                        } else {
-                               derivedXPubs := csp.DeriveXPubs(xPubs, path)
+                               derivedXPubs := csp.DeriveXPubs([]vcrypto.XPubKeyer{xPubs}, path)
                                derivedPKs := csp.XPubKeys(derivedXPubs)
                                script, err := vmutil.P2SPMultiSigProgram(derivedPKs, inst.quorum)
                                if err != nil {
index cbf8641..706c668 100644 (file)
@@ -12,6 +12,7 @@ import (
        "github.com/vapor/blockchain/txbuilder"
        "github.com/vapor/common"
        "github.com/vapor/consensus"
+       vcrypto "github.com/vapor/crypto"
        "github.com/vapor/crypto/csp"
        edchainkd "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/crypto/sha3pool"
@@ -53,9 +54,12 @@ func (g *TxGenerator) createKey(alias string, auth string) error {
 
 func (g *TxGenerator) getPubkey(keyAlias string) *edchainkd.XPub {
        pubKeys := g.Hsm.ListKeys()
-       for i, key := range pubKeys {
+       for _, key := range pubKeys {
                if key.Alias == keyAlias {
-                       return &pubKeys[i].XPub
+                       switch pbk := key.XPub.(type) {
+                       case edchainkd.XPub:
+                               return &pbk
+                       }
                }
        }
        return nil
@@ -71,7 +75,11 @@ func (g *TxGenerator) createAccount(name string, keys []string, quorum int) erro
                }
                xpubs = append(xpubs, *xpub)
        }
-       _, err := g.AccountManager.Create(xpubs, quorum, name, signers.BIP0044)
+       xpubers := make([]vcrypto.XPubKeyer, len(xpubs))
+       for i, xpub := range xpubs {
+               xpubers[i] = xpub
+       }
+       _, err := g.AccountManager.Create(xpubers, quorum, name, signers.BIP0044)
        return err
 }
 
@@ -304,8 +312,11 @@ func SignInstructionFor(input *types.SpendInput, db dbm.DB, signer *signers.Sign
        case *common.AddressWitnessPubKeyHash:
                sigInst.AddRawWitnessKeys(signer.XPubs, path, signer.Quorum)
                derivedXPubs := csp.DeriveXPubs(signer.XPubs, path)
-               derivedPK := derivedXPubs[0].PublicKey()
-               sigInst.WitnessComponents = append(sigInst.WitnessComponents, txbuilder.DataWitness([]byte(derivedPK)))
+               switch dxpub := derivedXPubs[0].(type) {
+               case edchainkd.XPub:
+                       derivedPK := dxpub.PublicKey()
+                       sigInst.WitnessComponents = append(sigInst.WitnessComponents, txbuilder.DataWitness([]byte(derivedPK)))
+               }
 
        case *common.AddressWitnessScriptHash:
                sigInst.AddRawWitnessKeys(signer.XPubs, path, signer.Quorum)
index 454c0d7..239cd4a 100644 (file)
@@ -11,6 +11,7 @@ import (
        "github.com/vapor/asset"
        "github.com/vapor/blockchain/pseudohsm"
        "github.com/vapor/blockchain/signers"
+       vcrypto "github.com/vapor/crypto"
        edchainkd "github.com/vapor/crypto/ed25519/chainkd"
        dbm "github.com/vapor/database/leveldb"
        "github.com/vapor/event"
@@ -135,7 +136,11 @@ func (ctx *walletTestContext) getPubkey(keyAlias string) *edchainkd.XPub {
        pubKeys := ctx.Wallet.Hsm.ListKeys()
        for i, key := range pubKeys {
                if key.Alias == keyAlias {
-                       return &pubKeys[i].XPub
+                       switch xpub := pubKeys[i].XPub.(type) {
+                       case edchainkd.XPub:
+                               return &xpub
+                       }
+
                }
        }
        return nil
@@ -164,7 +169,11 @@ func (ctx *walletTestContext) createAccount(name string, keys []string, quorum i
                }
                xpubs = append(xpubs, *xpub)
        }
-       _, err := ctx.Wallet.AccountMgr.Create(xpubs, quorum, name, signers.BIP0044)
+       xpubers := make([]vcrypto.XPubKeyer, len(xpubs))
+       for i, xpub := range xpubs {
+               xpubers[i] = xpub
+       }
+       _, err := ctx.Wallet.AccountMgr.Create(xpubers, quorum, name, signers.BIP0044)
        return err
 }