"github.com/vapor/blockchain/signers"
"github.com/vapor/crypto/ed25519/chainkd"
"github.com/vapor/crypto/sha3pool"
"github.com/vapor/blockchain/signers"
"github.com/vapor/crypto/ed25519/chainkd"
"github.com/vapor/crypto/sha3pool"
"github.com/vapor/errors"
"github.com/vapor/protocol/bc"
"github.com/vapor/protocol/bc/types"
"github.com/vapor/errors"
"github.com/vapor/protocol/bc"
"github.com/vapor/protocol/bc/types"
// ErrRecoveryBusy another recovery in progress, can not get recovery manager lock
ErrRecoveryBusy = errors.New("another recovery in progress")
// ErrInvalidAcctID can not find account by account id
// ErrRecoveryBusy another recovery in progress, can not get recovery manager lock
ErrRecoveryBusy = errors.New("another recovery in progress")
// ErrInvalidAcctID can not find account by account id
- ErrInvalidAcctID = errors.New("invalid account id")
+ ErrInvalidAcctID = errors.New("invalid account id")
+ ErrGetRecoveryStatus = errors.New("failed to get recovery status.")
+ ErrRecoveryStatus = errors.New("recovery status is nil.")
// stateForScope returns a ScopeRecoveryState for the provided key scope. If one
// does not already exist, a new one will be generated with the RecoveryState's
// recoveryWindow.
// stateForScope returns a ScopeRecoveryState for the provided key scope. If one
// does not already exist, a new one will be generated with the RecoveryState's
// recoveryWindow.
// If the account recovery state already exists, return it.
if _, ok := rs.AccountsStatus[account.ID]; ok {
return
// If the account recovery state already exists, return it.
if _, ok := rs.AccountsStatus[account.ID]; ok {
return
// state encapsulates and allocates the necessary recovery state for all
// key scopes and subsidiary derivation paths.
// state encapsulates and allocates the necessary recovery state for all
// key scopes and subsidiary derivation paths.
//addresses all addresses derivation lookahead used when
// attempting to recover the set of used addresses.
addresses map[bc.Hash]*account.CtrlProgram
}
//addresses all addresses derivation lookahead used when
// attempting to recover the set of used addresses.
addresses map[bc.Hash]*account.CtrlProgram
}
-// newRecoveryManager create recovery manger.
-func newRecoveryManager(db dbm.DB, accountMgr *account.Manager) *recoveryManager {
+// NewRecoveryManager create recovery manger.
+func NewRecoveryManager(store WalletStore, accountMgr *account.Manager) *recoveryManager {
accountMgr: accountMgr,
addresses: make(map[bc.Hash]*account.CtrlProgram),
state: newRecoveryState(),
accountMgr: accountMgr,
addresses: make(map[bc.Hash]*account.CtrlProgram),
state: newRecoveryState(),
func (m *recoveryManager) processBlock(b *types.Block) error {
for _, tx := range b.Transactions {
for _, output := range tx.Outputs {
func (m *recoveryManager) processBlock(b *types.Block) error {
for _, tx := range b.Transactions {
for _, output := range tx.Outputs {
- rawStatus := m.db.Get(recoveryKey)
- if rawStatus == nil {
+ if m.state == nil {
+ return ErrRecoveryStatus
+ }
+ status, err := m.store.GetRecoveryStatus()
+ if err == ErrGetRecoveryStatus {