From 145eda8c5e28b9fa8f0a435a2ec0bb6df53ba453 Mon Sep 17 00:00:00 2001 From: Chengcheng Zhang <943420582@qq.com> Date: Sat, 6 Jul 2019 14:36:14 +0800 Subject: [PATCH] update --- account/accounts.go | 13 +++++++++++-- account/builder.go | 2 ++ account/utxo_keeper.go | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/account/accounts.go b/account/accounts.go index 4dc8610d..8a312c94 100644 --- a/account/accounts.go +++ b/account/accounts.go @@ -173,6 +173,7 @@ func (m *Manager) Create(xpubs []chainkd.XPub, quorum int, alias string, deriveR if currentIndex := m.store.GetAccountIndex(xpubs); currentIndex != 0 { acctIndex = currentIndex + 1 } + account, err := CreateAccount(xpubs, quorum, alias, acctIndex, deriveRule) if err != nil { return nil, err @@ -217,6 +218,7 @@ func (m *Manager) UpdateAccountAlias(accountID string, newAlias string) error { if err := m.store.DeleteAccount(&oldAccount); err != nil { return err } + if err := m.store.SetAccount(account); err != nil { return err } @@ -443,6 +445,7 @@ func (m *Manager) GetMiningAddress() (string, error) { if err != nil { return "", err } + return cp.Address, nil } @@ -494,10 +497,10 @@ func (m *Manager) SetMiningAddress(miningAddress string) (string, error) { Address: miningAddress, ControlProgram: program, } - if err := m.store.SetMiningAddress(cp); err != nil { return cp.Address, err } + return m.GetMiningAddress() } @@ -517,9 +520,11 @@ func CreateCtrlProgram(account *Account, addrIdx uint64, change bool) (cp *CtrlP } else { cp, err = createP2SH(account, path) } + if err != nil { return nil, err } + cp.KeyIndex, cp.Change = addrIdx, change return cp, nil } @@ -553,8 +558,8 @@ func createP2SH(account *Account, path [][]byte) (*CtrlProgram, error) { if err != nil { return nil, err } - scriptHash := crypto.Sha256(signScript) + scriptHash := crypto.Sha256(signScript) address, err := common.NewAddressWitnessScriptHash(scriptHash, &consensus.ActiveNetParams) if err != nil { return nil, err @@ -591,6 +596,7 @@ func (m *Manager) getProgramByAddress(address string) ([]byte, error) { if err != nil { return nil, err } + redeemContract := addr.ScriptAddress() program := []byte{} switch addr.(type) { @@ -604,6 +610,7 @@ func (m *Manager) getProgramByAddress(address string) ([]byte, error) { if err != nil { return nil, err } + return program, nil } @@ -619,9 +626,11 @@ func (m *Manager) saveControlProgram(prog *CtrlProgram, updateIndex bool) error if err := m.store.InitBatch(); err != nil { return err } + if err := m.store.SetControlProgram(bc.NewHash(hash), prog); err != nil { return nil } + if updateIndex { switch acct.DeriveRule { case signers.BIP0032: diff --git a/account/builder.go b/account/builder.go index ff5098ac..8195a865 100644 --- a/account/builder.go +++ b/account/builder.go @@ -166,6 +166,7 @@ func SpendAccountChain(ctx context.Context, builder *txbuilder.TemplateBuilder, if !ok { return nil, errors.New("fail to convert the spend action") } + if *act.AssetId != *consensus.BTMAssetID { return nil, errors.New("spend chain action only support BTM") } @@ -324,6 +325,7 @@ func UtxoToInputs(signer *signers.Signer, u *UTXO) (*types.TxInput, *txbuilder.S if err != nil { return nil, nil, err } + if u.Address == "" { sigInst.AddWitnessKeys(signer.XPubs, path, signer.Quorum) return txInput, sigInst, nil diff --git a/account/utxo_keeper.go b/account/utxo_keeper.go index 64c2b662..4af1a5db 100644 --- a/account/utxo_keeper.go +++ b/account/utxo_keeper.go @@ -213,6 +213,7 @@ func (uk *utxoKeeper) findUtxos(accountID string, assetID *bc.AssetID, useUnconf if u.AccountID != accountID || u.AssetID != *assetID || !bytes.Equal(u.Vote, vote) { return } + if u.ValidHeight > currentHeight { immatureAmount += u.Amount } else { -- 2.11.0