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