OSDN Git Service

remove redundant code (#1400)
authorcancelloveyan <39250387+cancelloveyan@users.noreply.github.com>
Tue, 16 Oct 2018 05:51:42 +0000 (13:51 +0800)
committerPaladz <yzhu101@uottawa.ca>
Tue, 16 Oct 2018 05:51:42 +0000 (13:51 +0800)
* 删除重复定义的变量代码

* 优化抽出公共代码

account/builder.go

index 69d53a5..8947a34 100644 (file)
@@ -324,17 +324,15 @@ func UtxoToInputs(signer *signers.Signer, u *UTXO) (*types.TxInput, *txbuilder.S
                return nil, nil, err
        }
 
+       sigInst.AddRawWitnessKeys(signer.XPubs, path, signer.Quorum)
+       derivedXPubs := chainkd.DeriveXPubs(signer.XPubs, path)
+
        switch address.(type) {
        case *common.AddressWitnessPubKeyHash:
-               sigInst.AddRawWitnessKeys(signer.XPubs, path, signer.Quorum)
-               derivedXPubs := chainkd.DeriveXPubs(signer.XPubs, path)
                derivedPK := derivedXPubs[0].PublicKey()
                sigInst.WitnessComponents = append(sigInst.WitnessComponents, txbuilder.DataWitness([]byte(derivedPK)))
 
        case *common.AddressWitnessScriptHash:
-               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)
                script, err := vmutil.P2SPMultiSigProgram(derivedPKs, signer.Quorum)
                if err != nil {