-
Notifications
You must be signed in to change notification settings - Fork 22
/
eos21.js
87 lines (75 loc) · 3.21 KB
/
eos21.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const fs = require('fs');
const Web3 = require('web3');
const EosJs = require('eosjs');
const check = require('./utils/Check');
const createWormHole = require('./oracle/TeleportOracle.js');
console.log("ERC20 teleporting starts ...");
const getParams = () => {
const argv = require('minimist')(process.argv.slice(2), {
default: {
config: 'config.json'
}
});
const configFile = argv.config;
check(fs.existsSync(configFile), "configuration file: " + configFile);
const config = JSON.parse(fs.readFileSync(configFile));
return config;
}
const params = getParams();
const eosioTokenKey = params.eosiotoken.private_key;
const eosProvider = params.eosiotoken.http_endpoint;
const blackHoleFile = "./blackhole/build/contracts/BlackHoleEosAccount.json";
const ethereumProvider = params.blackhole.websocket_provider;
const eosioTokenAddress = params.eosiotoken.account;
const blackHoleAddress = fs.readFileSync('./blackhole_address', 'utf-8')
const decimals = params.blackhole.decimals;
const symbol = params.blackhole.symbol;
const chainId = params.eosiotoken.chain_id;
check(Web3.utils.isAddress(blackHoleAddress), "blackhole account: " + blackHoleAddress);
check(eosioTokenAddress, "eosio.token account: " + eosioTokenAddress);
check(eosioTokenKey, 'eosio.token key: ' + eosioTokenKey);
check(ethereumProvider, "Ethereum provider: " + ethereumProvider);
//check(fs.existsSync(blackHoleFile), "blackhole file: " + blackHoleFile);
check(eosProvider, "EOS provider: " + eosProvider);
check(symbol, "ERC20 symbol: " + symbol);
check(decimals, "ERC20 decimals: " + decimals);
check(chainId, "chain_id: " + chainId);
eosConfig = {
chainId: chainId, // 32 byte (64 char) hex string
keyProvider: [eosioTokenKey], // WIF string or array of keys..
httpEndpoint: eosProvider,
expireInSeconds: 60,
broadcast: true,
verbose: false, // API activity
sign: true,
authorization: eosioTokenAddress + '@active'
};
const input = fs.readFileSync(blackHoleFile);
const contract = JSON.parse(input.toString());
const abi = contract.abi;
const websocketProvider = new Web3.providers.WebsocketProvider(ethereumProvider);
const web3 = new Web3(websocketProvider);
const blackHole = new web3.eth.Contract(abi, blackHoleAddress);
const eos = EosJs(eosConfig);
eos.getInfo({})
.then(result => {
return eos.contract(eosioTokenAddress)
.then(eosioToken => {
createWormHole({
blackHole,
onData: event => {
const { amount, note } = event.returnValues;
const amountFloat = (amount/10**decimals).toFixed(decimals);
const amountWithSymbol = amountFloat + " " + symbol;
console.log("(EVENT) amount=" + amountWithSymbol + ", to=" + note);
eosioToken.issue(note, amountWithSymbol, "Emerged from eosioToken")
.catch(console.error);
}
});
console.log("(II) waiting blackhole events ...");
})
.catch(reason => {
console.log("error" + reason);
process.exit();
});
});