OSDN Git Service

remove Xpubs in CtrlProgram
authorYongfeng LI <wliyongfeng@gmail.com>
Tue, 17 Apr 2018 07:10:17 +0000 (15:10 +0800)
committerYongfeng LI <wliyongfeng@gmail.com>
Tue, 17 Apr 2018 07:10:17 +0000 (15:10 +0800)
account/accounts.go
api/accounts.go
crypto/ed25519/chainkd/chainkd.go
wallet/wallet.go

index 0a3a197..4d969e8 100644 (file)
@@ -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
index e0cf81c..c24b31a 100644 (file)
@@ -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)
        }
index eebeef4..6cb19da 100644 (file)
@@ -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) {
index f5245c5..55ea6e7 100644 (file)
@@ -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)