OSDN Git Service

fix address set marshal bug
authorYongfeng LI <wliyongfeng@gmail.com>
Tue, 17 Apr 2018 03:17:55 +0000 (11:17 +0800)
committerYongfeng LI <wliyongfeng@gmail.com>
Tue, 17 Apr 2018 05:33:44 +0000 (13:33 +0800)
wallet/indexer.go
wallet/set.go
wallet/wallet.go
wallet/wallet_test.go

index c41d00b..772ca1e 100644 (file)
@@ -390,7 +390,7 @@ transactionLoop:
                        if bytes := w.DB.Get(account.CPKey(hash)); bytes != nil {
                                cp := &account.CtrlProgram{}
                                if err := json.Unmarshal(bytes, cp); err == nil {
-                                       w.status.selfProgramsOnChain.Add(cp.Address)
+                                       w.status.OnChainAddresses.Add(cp.Address)
                                }
 
                                annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
index 627ebd2..5a8c785 100644 (file)
@@ -1,13 +1,13 @@
 package wallet
 
-type Set map[interface{}]bool
+type AddressSet map[string]bool
 
-func NewSet() Set {
-       return make(Set)
+func NewAddressSet() AddressSet {
+       return make(AddressSet)
 }
 
 // Add Add the specified element to this set if it is not already present (optional operation)
-func (s *Set) Add(i interface{}) bool {
+func (s *AddressSet) Add(i string) bool {
        _, found := (*s)[i]
        if found {
                return false //False if it existed already
@@ -18,7 +18,7 @@ func (s *Set) Add(i interface{}) bool {
 }
 
 // Contains Returns true if this set contains the specified elements
-func (s *Set) Contains(i ...interface{}) bool {
+func (s *AddressSet) Contains(i ...string) bool {
        for _, val := range i {
                if _, ok := (*s)[val]; !ok {
                        return false
index 5a061ae..f5245c5 100644 (file)
@@ -29,11 +29,11 @@ var dbKeyForimportingPrivateKey = []byte("importingKeysInfo")
 
 //StatusInfo is base valid block info to handle orphan block rollback
 type StatusInfo struct {
-       WorkHeight uint64
-       WorkHash   bc.Hash
-       BestHeight uint64
-       BestHash   bc.Hash
-       selfProgramsOnChain Set
+       WorkHeight       uint64
+       WorkHash         bc.Hash
+       BestHeight       uint64
+       BestHash         bc.Hash
+       OnChainAddresses AddressSet
 }
 
 //KeyInfo is key import status
@@ -92,7 +92,7 @@ func (w *Wallet) loadWalletInfo() error {
                return json.Unmarshal(rawWallet, &w.status)
        }
 
-       w.status.selfProgramsOnChain = NewSet()
+       w.status.OnChainAddresses = NewAddressSet()
        block, err := w.chain.GetBlockByHeight(0)
        if err != nil {
                return err
@@ -364,7 +364,7 @@ func (w *Wallet) updateRescanStatus() {
 
                if cps, err := w.AccountMgr.ListCtrlProgramsByXpubs(nil, keyInfo.account.XPubs); err == nil {
                        for _, cp := range cps {
-                               if !w.status.selfProgramsOnChain.Contains(cp.Address) {
+                               if !w.status.OnChainAddresses.Contains(cp.Address) {
                                        w.AccountMgr.DeleteAccountControlProgram(cp.ControlProgram)
                                }
                        }
index 76c8009..4ba4ce7 100644 (file)
@@ -235,14 +235,17 @@ func mockTxData(utxos []*account.UTXO, testAccount *account.Account) (*txbuilder
 }
 
 func mockWallet(walletDB dbm.DB, account *account.Manager, asset *asset.Registry, chain *protocol.Chain) *Wallet {
-       return &Wallet{
+       wallet := &Wallet{
                DB:                  walletDB,
                AccountMgr:          account,
                AssetReg:            asset,
                chain:               chain,
                rescanProgress:      make(chan struct{}, 1),
-               selfProgramsOnChain: NewSet(),
        }
+       wallet.status = StatusInfo{
+               OnChainAddresses: NewAddressSet(),
+       }
+       return wallet
 }
 
 func mockSingleBlock(tx *types.Tx) *types.Block {