Skip to content

Commit

Permalink
Merge pull request #145 from poanetwork/141-UserRequestForAffirmation…
Browse files Browse the repository at this point in the history
…-erc677-erc677

Add support for UserRequestForAffirmation event on erc-to-erc mode
  • Loading branch information
akolotov authored May 3, 2019
2 parents 879e5e5 + f2610a9 commit ac4c704
Show file tree
Hide file tree
Showing 9 changed files with 1,361 additions and 6 deletions.
597 changes: 597 additions & 0 deletions abis/ERC677BridgeToken.abi.json

Large diffs are not rendered by default.

699 changes: 699 additions & 0 deletions abis/ForeignBridgeErc677ToErc677.abi.json

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion config/affirmation-request-watcher.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
require('dotenv').config()
const baseConfig = require('./base.config')
const erc20Abi = require('../abis/ERC20.abi')
const { ERC_TYPES } = require('../src/utils/constants')

const initialChecksJson = process.argv[3]

if (!initialChecksJson) {
throw new Error('initial check parameter was not provided.')
}

let initialChecks
try {
initialChecks = JSON.parse(initialChecksJson)
} catch (e) {
throw new Error('Error on decoding values from initial checks.')
}

if (baseConfig.id === 'erc-erc' && initialChecks.foreignERC === ERC_TYPES.ERC677) {
baseConfig.id = 'erc677-erc677'
}

const id = `${baseConfig.id}-affirmation-request`

module.exports =
baseConfig.id === 'erc-erc' || baseConfig.id === 'erc-native'
(baseConfig.id === 'erc-erc' && initialChecks.foreignERC === ERC_TYPES.ERC20) ||
baseConfig.id === 'erc-native'
? {
...baseConfig.bridgeConfig,
...baseConfig.foreignConfig,
Expand Down
4 changes: 2 additions & 2 deletions config/base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const homeNativeErcAbi = require('../abis/HomeBridgeNativeToErc.abi')
const foreignNativeErcAbi = require('../abis/ForeignBridgeNativeToErc.abi')

const homeErcErcAbi = require('../abis/HomeBridgeErcToErc.abi')
const foreignErcErcAbi = require('../abis/ForeignBridgeErcToErc.abi')
const foreignErc677Erc677Abi = require('../abis/ForeignBridgeErc677ToErc677.abi')

const homeErcNativeAbi = require('../abis/HomeBridgeErcToNative.abi')
const foreignErcNativeAbi = require('../abis/ForeignBridgeErcToNative.abi')
Expand All @@ -27,7 +27,7 @@ switch (process.env.BRIDGE_MODE) {
break
case 'ERC_TO_ERC':
homeAbi = homeErcErcAbi
foreignAbi = foreignErcErcAbi
foreignAbi = foreignErc677Erc677Abi
id = 'erc-erc'
break
case 'ERC_TO_NATIVE':
Expand Down
2 changes: 1 addition & 1 deletion e2e/parity/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM parity/parity:v2.2.11
FROM parity/parity:v2.3.3

WORKDIR /stuff

Expand Down
33 changes: 33 additions & 0 deletions scripts/initialChecks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const path = require('path')
require('dotenv').config({
path: path.join(__dirname, '../.env')
})
const Web3 = require('web3')
const ERC677BridgeTokenABI = require('../abis/ERC677BridgeToken.abi')
const { ERC_TYPES } = require('../src/utils/constants')

async function initialChecks() {
const { ERC20_TOKEN_ADDRESS, BRIDGE_MODE, FOREIGN_RPC_URL, FOREIGN_BRIDGE_ADDRESS } = process.env
const result = {}

if (BRIDGE_MODE === 'ERC_TO_ERC') {
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(FOREIGN_RPC_URL))
const tokenContract = new foreignWeb3.eth.Contract(ERC677BridgeTokenABI, ERC20_TOKEN_ADDRESS)
try {
const bridgeContract = await tokenContract.methods.bridgeContract().call()
if (bridgeContract === FOREIGN_BRIDGE_ADDRESS) {
result.foreignERC = ERC_TYPES.ERC677
} else {
result.foreignERC = ERC_TYPES.ERC20
}
} catch (e) {
result.foreignERC = ERC_TYPES.ERC20
}
}
console.log(JSON.stringify(result))
return result
}

initialChecks()

module.exports = initialChecks
6 changes: 4 additions & 2 deletions scripts/start-worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ WORKER="${WORKERS_DIR}${1}.js"
CONFIG="${2}.config.js"
LOG="${LOGS_DIR}${2}.txt"

CHECKS=$(node scripts/initialChecks.js)

if [ "${NODE_ENV}" = "production" ]; then
exec node "${WORKER}" "${CONFIG}"
exec node "${WORKER}" "${CONFIG}" "$CHECKS"
else
node "${WORKER}" "${CONFIG}" | tee -a "${LOG}" | pino-pretty
node "${WORKER}" "${CONFIG}" "$CHECKS" | tee -a "${LOG}" | pino-pretty
fi
4 changes: 4 additions & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ module.exports = {
GAS_PRICE_BOUNDARIES: {
MIN: 1,
MAX: 250
},
ERC_TYPES: {
ERC20: 'ERC20',
ERC677: 'ERC677'
}
}
1 change: 1 addition & 0 deletions src/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function processEvents(events) {
case 'erc-native-collected-signatures':
return processCollectedSignatures(events)
case 'native-erc-affirmation-request':
case 'erc677-erc677-affirmation-request':
return processAffirmationRequests(events)
case 'erc-erc-affirmation-request':
case 'erc-native-affirmation-request':
Expand Down

0 comments on commit ac4c704

Please sign in to comment.