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))
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
}
// 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
//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
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
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)
}
}
}
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 {