From ed7ef2a54f8be95fee6b601c9e00966c244321ad Mon Sep 17 00:00:00 2001 From: Yongfeng LI Date: Tue, 17 Apr 2018 15:10:17 +0800 Subject: [PATCH] remove Xpubs in CtrlProgram --- account/accounts.go | 9 +++------ api/accounts.go | 2 +- crypto/ed25519/chainkd/chainkd.go | 12 ------------ wallet/wallet.go | 2 +- 4 files changed, 5 insertions(+), 20 deletions(-) diff --git a/account/accounts.go b/account/accounts.go index 0a3a197d..4d969e8f 100644 --- a/account/accounts.go +++ b/account/accounts.go @@ -268,8 +268,8 @@ func (m *Manager) createAddress(ctx context.Context, account *Account, change bo return cp, nil } -// listAddressesById -func (m *Manager) ListCtrlProgramsByXpubs(ctx context.Context, xpubs []chainkd.XPub) ([]*CtrlProgram, error) { +// ListCtrlProgramsByAccountId +func (m *Manager) ListCtrlProgramsByAccountId(ctx context.Context, accountId string) ([]*CtrlProgram, error) { cps, err := m.ListControlProgram() if err != nil { return nil, err @@ -277,7 +277,7 @@ func (m *Manager) ListCtrlProgramsByXpubs(ctx context.Context, xpubs []chainkd.X var result []*CtrlProgram for _, cp := range cps { - if cp.Address == "" || chainkd.IsXpubsEqual(cp.XPubs, xpubs) { + if cp.Address == "" || cp.AccountID != accountId { continue } result = append(result, cp) @@ -305,7 +305,6 @@ func (m *Manager) createP2PKH(ctx context.Context, account *Account, change bool return &CtrlProgram{ AccountID: account.ID, - XPubs: account.Signer.XPubs, Address: address.EncodeAddress(), KeyIndex: idx, ControlProgram: control, @@ -337,7 +336,6 @@ func (m *Manager) createP2SH(ctx context.Context, account *Account, change bool) return &CtrlProgram{ AccountID: account.ID, - XPubs: account.Signer.XPubs, Address: address.EncodeAddress(), KeyIndex: idx, ControlProgram: control, @@ -348,7 +346,6 @@ func (m *Manager) createP2SH(ctx context.Context, account *Account, change bool) //CtrlProgram is structure of account control program type CtrlProgram struct { AccountID string - XPubs []chainkd.XPub Address string KeyIndex uint64 ControlProgram []byte diff --git a/api/accounts.go b/api/accounts.go index e0cf81c9..c24b31a0 100644 --- a/api/accounts.go +++ b/api/accounts.go @@ -106,7 +106,7 @@ func (a *API) listAddresses(ctx context.Context, ins struct { target = acc } - cps, err := a.wallet.AccountMgr.ListCtrlProgramsByXpubs(ctx, target.XPubs) + cps, err := a.wallet.AccountMgr.ListCtrlProgramsByAccountId(ctx, target.ID) if err != nil { return NewErrorResponse(err) } diff --git a/crypto/ed25519/chainkd/chainkd.go b/crypto/ed25519/chainkd/chainkd.go index eebeef49..6cb19da1 100644 --- a/crypto/ed25519/chainkd/chainkd.go +++ b/crypto/ed25519/chainkd/chainkd.go @@ -1,7 +1,6 @@ package chainkd import ( - "bytes" "crypto/hmac" "crypto/rand" "crypto/sha512" @@ -18,17 +17,6 @@ type ( XPub [64]byte ) -// IsXpubsEqual -func IsXpubsEqual(a, b []XPub) bool { - for i, xpub := range a { - result := bytes.Compare(xpub[:], b[i][:]) - if result != 0 { - return false - } - } - return true -} - // NewXPrv takes a source of random bytes and produces a new XPrv. // If r is nil, crypto/rand.Reader is used. func NewXPrv(r io.Reader) (xprv XPrv, err error) { diff --git a/wallet/wallet.go b/wallet/wallet.go index f5245c5b..55ea6e70 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -362,7 +362,7 @@ func (w *Wallet) updateRescanStatus() { keyInfo.Percent = 100 keyInfo.Complete = true - if cps, err := w.AccountMgr.ListCtrlProgramsByXpubs(nil, keyInfo.account.XPubs); err == nil { + if cps, err := w.AccountMgr.ListCtrlProgramsByAccountId(nil, keyInfo.account.ID); err == nil { for _, cp := range cps { if !w.status.OnChainAddresses.Contains(cp.Address) { w.AccountMgr.DeleteAccountControlProgram(cp.ControlProgram) -- 2.11.0