OSDN Git Service

fix all crash
authorChengcheng Zhang <943420582@qq.com>
Sat, 25 May 2019 17:11:27 +0000 (01:11 +0800)
committerChengcheng Zhang <943420582@qq.com>
Sat, 25 May 2019 17:11:27 +0000 (01:11 +0800)
account/builder.go
crypto/ed25519/chainkd/serialize.go
protocol/validation/test/tx_ugly_test.go
wallet/wallet_test.go

index 0f15688..52958dc 100644 (file)
@@ -329,10 +329,14 @@ func UtxoToInputs(signer *signers.Signer, u *UTXO) (*types.TxInput, *txbuilder.S
        if err != nil {
                return nil, nil, err
        }
-
        sigInst.AddRawWitnessKeys(signer.XPubs, path, signer.Quorum)
        derivedXPubs := csp.DeriveXPubs(signer.XPubs, path)
 
+       /////////
+       if len(derivedXPubs) == 0 {
+               panic("UtxoToInputs derivedXPubs is nil.")
+       }
+
        switch address.(type) {
        case *common.AddressWitnessPubKeyHash:
                switch dxpub := derivedXPubs[0].(type) {
index b903dcb..7a2231d 100644 (file)
@@ -70,7 +70,6 @@ func NewXPub(str string) (*XPub, error) {
        if xpubBytes, err := hex.DecodeString(str); err != nil {
                return nil, err
        } else {
-
                fmt.Println("NewXPub xpub is:", xpub)
                fmt.Println("NewXPub xpubBytes is:", xpubBytes)
                copy(xpub[:], xpubBytes[:])
index aaada6f..846c2b9 100644 (file)
@@ -637,7 +637,11 @@ 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: []vcrypto.XPubKeyer{xPubs}, Quorum: insts[i].quorum}}
+                       xpubers := make([]vcrypto.XPubKeyer, len(xPubs))
+                       for i, xpub := range xPubs {
+                               xpubers[i] = xpub
+                       }
+                       acc := &account.Account{Signer: &signers.Signer{KeyIndex: insts[i].keyIndex, DeriveRule: signers.BIP0044, XPubs: xpubers, Quorum: insts[i].quorum}}
                        program, err := account.CreateCtrlProgram(acc, insts[i].ctrlProgramIndex, insts[i].change)
                        if err != nil {
                                panic(err)
@@ -673,7 +677,11 @@ func mockSignTx(tx *types.Tx, insts []*signingInst) {
                                derivePK := childPrv.XPub()
                                arguments = append(arguments, derivePK.PublicKey())
                        } else {
-                               derivedXPubs := csp.DeriveXPubs([]vcrypto.XPubKeyer{xPubs}, path)
+                               xpubers := make([]vcrypto.XPubKeyer, len(xPubs))
+                               for i, xpub := range xPubs {
+                                       xpubers[i] = xpub
+                               }
+                               derivedXPubs := csp.DeriveXPubs(xpubers, path)
                                derivedPKs := csp.XPubKeys(derivedXPubs)
                                script, err := vmutil.P2SPMultiSigProgram(derivedPKs, inst.quorum)
                                if err != nil {
index 3a120ed..9ac69e3 100644 (file)
@@ -295,7 +295,7 @@ func TestMemPoolTxQueryLoop(t *testing.T) {
        }
        fmt.Println("TestMemPoolTxQueryLoop xpub1 is:", xpub1)
 
-       edXPub := new(edchainkd.XPub)
+       edXPub := edchainkd.XPub{}
        edXPubKey, _ := hex.DecodeString("e0072a38408cfe4b70d322f8ed2d8acecab41615d2f091ddcd0d0622a8003de915569bd3e316d7e3c44ebebd21bfcc84f6428e60dbf17bef34f2e04a62f6cd2b")
        copy(edXPub[:], edXPubKey[:])
        xpub2 := pseudohsm.XPub{
@@ -303,12 +303,16 @@ func TestMemPoolTxQueryLoop(t *testing.T) {
                XPub:  edXPub,
                File:  "",
        }
+       xpubers := make([]vcrypto.XPubKeyer, 1)
+       xpubers[0] = xpub2.XPub
 
-       testAccount, err := accountManager.Create([]vcrypto.XPubKeyer{xpub2.XPub}, 1, "testAccount", signers.BIP0044)
+       testAccount, err := accountManager.Create(xpubers, 1, "testAccount", signers.BIP0044)
        if err != nil {
                t.Fatal(err)
        }
        fmt.Println("TestMemPoolTxQueryLoop testAccount is:", testAccount)
+       fmt.Println("TestMemPoolTxQueryLoop testAccount xpubs is:", testAccount.XPubs[0])
+       fmt.Println("TestMemPoolTxQueryLoop testAccount xpubs type is:", reflect.TypeOf(testAccount.XPubs[0]))
 
        controlProg, err := accountManager.CreateAddress(testAccount.ID, false)
        if err != nil {