Skip to content

Commit

Permalink
add ws reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander committed Dec 12, 2019
1 parent 55368e2 commit c8456ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion conf.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"permission": "active",
"Net": "https://api.daovalidator.com",
"ChainId": "74d023a9293d9b68c3c52e2f738ee681c1671cc3dc0f263cf2c533cd5523ff95",
"ethNet": "wss://mainnet.infura.io/ws/v3/c5a0c015c60649819408397a9bd277ce",
"ethNet": "wss://mainnet.infura.io/ws/v3/7573e2497d66440eab2a06c712ada570",
"ethContractAddress": "0x8895345ad1c1a2bff799a575f83d89669ba4bce3",
"Contract": "eosio.bridge",
"blocksBehind": 0,
Expand Down
26 changes: 21 additions & 5 deletions src/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export class Oracle {
public contract: Contract;
public eosApi: Api;
public eosRpc: JsonRpc;
public ethereumAPI: string;
public ethContractAddress: string;
public multiSig: string;
public permission: string;
public accountName: string;
Expand Down Expand Up @@ -46,6 +48,8 @@ export class Oracle {
blocksBehind: number
) {
this.web3 = new Web3(ethNet);
this.ethereumAPI = ethNet;
this.ethContractAddress = ethContractAddress
this.contract = new this.web3.eth.Contract(abiArrayListener.abi, ethContractAddress);
const { eosApi, eosRpc } = getApi(eosKeyProvider, eosNet, eosChainId);
this.eosApi = eosApi;
Expand Down Expand Up @@ -89,14 +93,14 @@ export class Oracle {
let requested: AccountPermission[] = [];
while (true) {
if (!this.attemptsToApprove) {
await sleep(300 * SLEEP);
this.attemptsToApprove = ATTEMPTS_TO_APPROVE
await sleep(15 * SLEEP);
continue;
}

try {
requested = await this.getRequested();
} catch (err) {
}
catch (err) {
this.logger.info(JSON.stringify(err));
await sleep(60 * SLEEP);
continue;
Expand Down Expand Up @@ -130,7 +134,11 @@ export class Oracle {
this.logger.info(`Attempts remain: ${this.attemptsToApprove}`);
await sleep(15 * SLEEP);
}
} catch (err) { this.logger.info(`${err}`); continue; }
}
catch (err) {
this.logger.info(`${err}`);
continue;
}
}
}

Expand All @@ -143,7 +151,15 @@ export class Oracle {
this.finishBlock = await this.web3.eth.getBlockNumber();
this.attemptsToApprove = ATTEMPTS_TO_APPROVE;
})
.on('error', (err) => { this.logger.info(err); });
.on('error', (err) => {
this.logger.info(err);
});

setInterval(() => {
this.web3 = new Web3(this.ethereumAPI)
this.contract = new this.web3.eth.Contract(abiArrayListener.abi, this.ethContractAddress);
this.attemptsToApprove = ATTEMPTS_TO_APPROVE
}, 50 * 60 * 1000)
}


Expand Down

0 comments on commit c8456ca

Please sign in to comment.