-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from poanetwork/develop
Merge the develop branch to the master branch, preparation to v2.2.0
- Loading branch information
Showing
11 changed files
with
1,483 additions
and
44 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const { toBN } = require('web3').utils | ||
|
||
const ONE = toBN(1) | ||
const TWO = toBN(2) | ||
|
||
async function getPastEvents({ contract, event, fromBlock, toBlock, options }) { | ||
let events | ||
try { | ||
events = await contract.getPastEvents(event, { | ||
...options, | ||
fromBlock, | ||
toBlock | ||
}) | ||
} catch (e) { | ||
if (e.message.includes('query returned more than 1000 results')) { | ||
const middle = fromBlock.add(toBlock).divRound(TWO) | ||
const middlePlusOne = middle.add(ONE) | ||
|
||
const firstHalfEvents = await getPastEvents({ | ||
contract, | ||
event, | ||
fromBlock, | ||
toBlock: middle, | ||
options | ||
}) | ||
const secondHalfEvents = await getPastEvents({ | ||
contract, | ||
event, | ||
fromBlock: middlePlusOne, | ||
toBlock, | ||
options | ||
}) | ||
events = [...firstHalfEvents, ...secondHalfEvents] | ||
} else { | ||
throw new Error(e) | ||
} | ||
} | ||
return events | ||
} | ||
|
||
const getBlockNumberCall = web3 => web3.eth.getBlockNumber() | ||
|
||
async function getBlockNumber(web3Home, web3Foreign) { | ||
return (await Promise.all([web3Home, web3Foreign].map(getBlockNumberCall))).map(toBN) | ||
} | ||
|
||
module.exports = { | ||
getPastEvents, | ||
getBlockNumber | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { ERC_TYPES } = require('./bridgeMode') | ||
|
||
const getTokenType = async (contract, bridgeAddress) => { | ||
try { | ||
const bridgeContract = await contract.methods.bridgeContract().call() | ||
if (bridgeContract === bridgeAddress) { | ||
return ERC_TYPES.ERC677 | ||
} else { | ||
return ERC_TYPES.ERC20 | ||
} | ||
} catch (e) { | ||
return ERC_TYPES.ERC20 | ||
} | ||
} | ||
|
||
module.exports = { | ||
getTokenType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.