OSDN Git Service

modify input address to xpub
[bytom/bytom.git] / account / image.go
index 1b97bc4..14d240d 100644 (file)
@@ -1,9 +1,11 @@
-// Package account stores and tracks accounts within a Chain Core.
+// Package account stores and tracks accounts within a Bytom Core.
 package account
 
 import (
        "encoding/json"
 
+       log "github.com/sirupsen/logrus"
+
        "github.com/bytom/common"
 )
 
@@ -45,6 +47,13 @@ func (m *Manager) Restore(image *Image) error {
        maxAccountIndex := uint64(0)
        storeBatch := m.db.NewBatch()
        for _, slice := range image.Slice {
+               if existed := m.db.Get(Key(slice.Account.ID)); existed != nil {
+                       log.WithFields(log.Fields{
+                               "alias": slice.Account.Alias,
+                               "id":    slice.Account.ID,
+                       }).Warning("skip restore account due to already existed")
+                       continue
+               }
                if existed := m.db.Get(aliasKey(slice.Account.Alias)); existed != nil {
                        return ErrDuplicateAlias
                }
@@ -59,7 +68,6 @@ func (m *Manager) Restore(image *Image) error {
                }
                storeBatch.Set(Key(slice.Account.ID), rawAccount)
                storeBatch.Set(aliasKey(slice.Account.Alias), []byte(slice.Account.ID))
-               storeBatch.Set(contractIndexKey(slice.Account.ID), common.Unit64ToBytes(slice.ContractIndex))
        }
 
        if localIndex := m.getNextAccountIndex(); localIndex < maxAccountIndex {
@@ -68,7 +76,7 @@ func (m *Manager) Restore(image *Image) error {
        storeBatch.Write()
 
        for _, slice := range image.Slice {
-               for i := uint64(1); i < slice.ContractIndex; i++ {
+               for i := uint64(1); i <= slice.ContractIndex; i++ {
                        if _, err := m.createAddress(nil, slice.Account, false); err != nil {
                                return err
                        }