-
Notifications
You must be signed in to change notification settings - Fork 10
/
werc20tk2erc20tk-redeem.js
64 lines (45 loc) · 2.02 KB
/
werc20tk2erc20tk-redeem.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
54
55
56
57
58
59
60
61
62
63
64
global.wanchain_js_testnet = true;// define testnet or mainnet
let ccUtil = require("wanchain-js-sdk").ccUtil;
let WalletCore = require("wanchain-js-sdk").walletCore;
const {config, SLEEPTIME} = require('./conf/config');
const { e20OutboundInput } = require('./conf/input');
/**
* Requirements:
* - Ethereum account has enough gas to cover the value defined in `WAN_PARA`
*/
// define wan gasPrice and gasLimit
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function sleepAndUpdateReceipt(time, option) {
let tmp;
await sleep(time);
try {
tmp = await ccUtil.getTxReceipt(...option)
} catch(e) {}
return Promise.resolve(tmp);
};
// define lock hash para from the lock
lockTxHash = '0xe0d0b80c5c7d70b2cd66ca6ca7a019784fd960973006b1522d3095c0f580be4c';
async function main(){
let redeemReceipt;
walletCore = new WalletCore(config);
await walletCore.init();
console.log('Starting init walletCore');
srcChain = global.crossInvoker.getSrcChainNameByContractAddr('WAN', 'WAN');
dstChain = global.crossInvoker.getSrcChainNameByContractAddr(e20OutboundInput.tokenAddr, 'ETH');
txHashList = global.wanDb.getItem(walletCore.config.crossCollection, {lockTxHash: lockTxHash});
console.log('checking txHashList for redeem', txHashList);
redeemInputCopy = Object.assign({}, e20OutboundInput.redeemInput)
redeemInputCopy.x = txHashList.x;
redeemInputCopy.hashX = txHashList.hashX;
console.log('Starting eth outbound redeem', redeemInputCopy);
retReddem = await global.crossInvoker.invoke(srcChain, dstChain, 'REDEEM', redeemInputCopy)
console.log(`The Redeem Hash is ${retReddem.result}`);
txHashList = global.wanDb.getItem(walletCore.config.crossCollection, {redeemTxHash: retReddem.result});
while (!redeemReceipt) {
redeemReceipt = await sleepAndUpdateReceipt(SLEEPTIME, ['ETH', retReddem.result]);
}
process.exit(0);
}
main();