-
Notifications
You must be signed in to change notification settings - Fork 18
/
transferCfxs.js
54 lines (42 loc) · 1.68 KB
/
transferCfxs.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
41
42
43
44
45
46
47
48
49
50
51
52
53
const { transferCFXs, account, cfxsMainContract } = require('./conflux');
const { address } = require('js-conflux-sdk');
const { waitMilliseconds, getIDsFromAnother } = require('./utils.js');
const mappedAddress = address.cfxMappedEVMSpaceAddress(account.address);
const STEP = 8;
async function main() {
let receiver = process.argv[2];
if (!receiver) {
console.error('Usage: node transferCfxs.js <receiver>');
return;
}
const ids = await getIDsFromAnother(mappedAddress);
for(let i = 0; i < ids.length; i += STEP) {
try {
// prepare batch ids
let exIds = [];
for(let j = 0; j < STEP; j++) {
if (i + j >= ids.length) break;
let id = ids[i+j];
if (id === '0') continue;
let cfxsId = parseInt(id);
// check owner
let info = await cfxsMainContract.CFXss(cfxsId);
if(!info || info.length === 0 || info[1] != mappedAddress) {
await waitMilliseconds(100);
console.log(`Id ${cfxsId} is not yours`)
continue;
}
exIds.push(cfxsId);
}
if (exIds.length === 0) continue;
console.log(`Transfer cfxs id ${exIds} to ${receiver}`);
const receipt = await transferCFXs(exIds, receiver);
console.log(`Result: ${receipt.outcomeStatus === 0 ? 'success' : 'fail'}`);
} catch(e) {
console.log('Transfer Error', e);
await waitMilliseconds(500);
}
}
console.log('Done');
}
main().catch(e => console.error(e));