/
close_recovery.js
40 lines (35 loc) 路 1.35 KB
/
close_recovery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const { BaseAsset } = require('lisk-sdk');
const { closeRecoverySchema } = require('../schemas');
const { CLOSE_RECOVERY_ASSET_ID } = require('../constants');
class CloseRecoveryAsset extends BaseAsset {
name = 'closeRecovery';
id = CLOSE_RECOVERY_ASSET_ID;
schema = closeRecoverySchema;
async apply({
asset,
transaction,
stateStore,
reducerHandler,
}) {
const lostAccount = await stateStore.account.get(transaction.senderAddress);
if (!lostAccount.srs.status.active) {
throw new Error(`No active recovery found for address ${lostAccount.address.toString('hex')}.`);
}
if (!lostAccount.srs.status.rescuer.equals(asset.rescuer)) {
throw new Error(`Incorrect rescuer address`);
}
// Credit deposit amount to the lost account
await reducerHandler.invoke('token:credit', {
address: lostAccount.address,
amount: lostAccount.srs.config.deposit,
});
// Reset recovery status
lostAccount.srs.status.active = false;
lostAccount.srs.status.rescuer = Buffer.from('');
lostAccount.srs.status.created = 0;
lostAccount.srs.status.deposit = BigInt('0');
lostAccount.srs.status.vouchList = [];
await stateStore.account.set(lostAccount.address, lostAccount);
}
}
module.exports = CloseRecoveryAsset;