-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrecovery.js
More file actions
79 lines (78 loc) · 3.26 KB
/
recovery.js
File metadata and controls
79 lines (78 loc) · 3.26 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const XrplHelpers = require('./xrplhelpers.js');
const Storage = require('./storage.js')
const xrpl = require("xrpl");
class Recovery {
async RunRecovery(db){
const client = new xrpl.Client(process.env.XRPL_RPC);
try{
let xrplhelper = new XrplHelpers();
let marker = undefined;
let totalTransactions = 0;
await client.connect();
let accountTx = await xrplhelper.getAccountTransactions(client, marker);
totalTransactions = accountTx.transactions.length;
console.log('Found ' + totalTransactions + ' Total Transactions...Processing');
this.ProcessTransactions(accountTx.transactions,db);
marker = accountTx.marker;
while(marker != undefined)
{
await new Promise(r => setTimeout(r, 5000));
accountTx = await xrplhelper.getAccountTransactions(client, marker);
totalTransactions = totalTransactions + accountTx.transactions.length;
console.log('Found ' + totalTransactions + ' Total Transactions...Processing');
this.ProcessTransactions(accountTx.transactions,db);
marker = accountTx.marker;
}
return true;
} catch(err)
{
console.log(err);
return false;
} finally
{
await client.disconnect();
}
}
ProcessTransactions(transactions, db)
{
let storage = new Storage();
for(let i = 0; i < transactions.length; i++)
{
if(transactions[i].tx.TransactionType == 'NFTokenMint')
{
if(transactions[i].tx.Memos != undefined)
{
for(let j = 0; j < transactions[i].tx.Memos.length; j++)
{
try{
let jsonMemo = JSON.parse(xrpl.convertHexToString(transactions[i].tx.Memos[j].Memo.MemoData));
storage.updateSigned(db,jsonMemo.contractAddress,jsonMemo.originOwner,jsonMemo.tokenId);
storage.insertRecovery(db,jsonMemo.contractAddress,jsonMemo.originOwner,jsonMemo.tokenId,1,0);
} catch(err)
{
console.log(err)
}
}
}
}
if(transactions[i].tx.TransactionType == 'NFTokenCreateOffer')
{
if(transactions[i].tx.Memos != undefined)
{
for(let j = 0; j < transactions[i].tx.Memos.length; j++)
{
try{
let jsonMemo = JSON.parse(xrpl.convertHexToString(transactions[i].tx.Memos[j].Memo.MemoData));
storage.updateOfferCreated(db,jsonMemo.contractAddress,jsonMemo.originOwner,jsonMemo.tokenId);
storage.insertRecovery(db,jsonMemo.contractAddress,jsonMemo.originOwner,jsonMemo.tokenId,1,1);
} catch(err)
{
console.log(err)
}
}
}
}
}
}
}
module.exports = Recovery