-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for AMB contracts (#199)
- Loading branch information
Showing
35 changed files
with
1,018 additions
and
133 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
const constants = require('./constants') | ||
const abis = require('./abis') | ||
const utils = require('./utils') | ||
const message = require('./message') | ||
|
||
module.exports = { | ||
...constants, | ||
...abis, | ||
...utils | ||
...utils, | ||
...message | ||
} |
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,27 @@ | ||
function strip0x(input) { | ||
return input.replace(/^0x/, '') | ||
} | ||
|
||
function addTxHashToData({ encodedData, transactionHash }) { | ||
return encodedData.slice(0, 2) + strip0x(transactionHash) + encodedData.slice(2) | ||
} | ||
|
||
function parseAMBMessage(message) { | ||
message = strip0x(message) | ||
|
||
const txHash = `0x${message.slice(0, 64)}` | ||
const sender = `0x${message.slice(64, 104)}` | ||
const executor = `0x${message.slice(104, 144)}` | ||
|
||
return { | ||
sender, | ||
executor, | ||
txHash | ||
} | ||
} | ||
|
||
module.exports = { | ||
addTxHashToData, | ||
parseAMBMessage, | ||
strip0x | ||
} |
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,69 @@ | ||
const { BN } = require('web3-utils') | ||
const { expect } = require('chai').use(require('bn-chai')(BN)) | ||
const { parseAMBMessage, strip0x, addTxHashToData } = require('../message') | ||
|
||
describe('strip0x', () => { | ||
it('should remove 0x from input', () => { | ||
// Given | ||
const input = '0x12345' | ||
|
||
// When | ||
const result = strip0x(input) | ||
|
||
// Then | ||
expect(result).to.be.equal('12345') | ||
}) | ||
it('should not modify input if 0x is not present', () => { | ||
// Given | ||
const input = '12345' | ||
|
||
// When | ||
const result = strip0x(input) | ||
|
||
// Then | ||
expect(result).to.be.equal(input) | ||
}) | ||
}) | ||
describe('addTxHashToData', () => { | ||
it('should add txHash to encoded data at position 2', () => { | ||
// Given | ||
const msgSender = '0x003667154bb32e42bb9e1e6532f19d187fa0082e' | ||
const msgExecutor = '0xf4bef13f9f4f2b203faf0c3cbbaabe1afe056955' | ||
const msgGasLimit = '000000000000000000000000000000000000000000000000000000005b877705' | ||
const msgDataType = '00' | ||
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03' | ||
const encodedData = `0x${strip0x(msgSender)}${strip0x(msgExecutor)}${msgGasLimit}${msgDataType}${strip0x(msgData)}` | ||
|
||
const transactionHash = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10' | ||
const message = `0x${strip0x(transactionHash)}${strip0x(msgSender)}${strip0x( | ||
msgExecutor | ||
)}${msgGasLimit}${msgDataType}${strip0x(msgData)}` | ||
|
||
// When | ||
const result = addTxHashToData({ encodedData, transactionHash }) | ||
|
||
// Then | ||
expect(result).to.be.equal(message) | ||
}) | ||
}) | ||
describe('parseAMBMessage', () => { | ||
it('should parse data type 00', () => { | ||
const msgSender = '0x003667154bb32e42bb9e1e6532f19d187fa0082e' | ||
const msgExecutor = '0xf4bef13f9f4f2b203faf0c3cbbaabe1afe056955' | ||
const msgTxHash = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10' | ||
const msgGasLimit = '000000000000000000000000000000000000000000000000000000005b877705' | ||
const msgDataType = '00' | ||
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03' | ||
const message = `0x${strip0x(msgTxHash)}${strip0x(msgSender)}${strip0x( | ||
msgExecutor | ||
)}${msgGasLimit}${msgDataType}${strip0x(msgData)}` | ||
|
||
// when | ||
const { sender, executor, txHash } = parseAMBMessage(message) | ||
|
||
// then | ||
expect(sender).to.be.equal(msgSender) | ||
expect(executor).to.be.equal(msgExecutor) | ||
expect(txHash).to.be.equal(msgTxHash) | ||
}) | ||
}) |
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,23 @@ | ||
|
||
ORACLE_BRIDGE_MODE=ARBITRARY_MESSAGE | ||
ORACLE_QUEUE_URL=amqp://rabbit | ||
ORACLE_REDIS_URL=redis://redis | ||
COMMON_HOME_RPC_URL=http://parity1:8545 | ||
COMMON_FOREIGN_RPC_URL=http://parity2:8545 | ||
COMMON_HOME_BRIDGE_ADDRESS=0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0 | ||
COMMON_FOREIGN_BRIDGE_ADDRESS=0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0 | ||
ORACLE_VALIDATOR_ADDRESS=0xaaB52d66283F7A1D5978bcFcB55721ACB467384b | ||
ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=8e829f695aed89a154550f30262f1529582cc49dc30eff74a6b491359e0230f9 | ||
COMMON_HOME_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/ | ||
COMMON_HOME_GAS_PRICE_SPEED_TYPE=standard | ||
COMMON_HOME_GAS_PRICE_FALLBACK=1000000000 | ||
ORACLE_HOME_GAS_PRICE_UPDATE_INTERVAL=600000 | ||
COMMON_HOME_GAS_PRICE_FACTOR=1 | ||
COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/ | ||
COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE=standard | ||
COMMON_FOREIGN_GAS_PRICE_FALLBACK=10000000000 | ||
ORACLE_FOREIGN_GAS_PRICE_UPDATE_INTERVAL=600000 | ||
COMMON_FOREIGN_GAS_PRICE_FACTOR=1 | ||
ORACLE_HOME_RPC_POLLING_INTERVAL=500 | ||
ORACLE_FOREIGN_RPC_POLLING_INTERVAL=500 | ||
ORACLE_ALLOW_HTTP_FOR_RPC=yes |
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,25 @@ | ||
BRIDGE_MODE=ARBITRARY_MESSAGE | ||
DEPLOYMENT_ACCOUNT_PRIVATE_KEY=8e829f695aed89a154550f30262f1529582cc49dc30eff74a6b491359e0230f9 | ||
HOME_DEPLOYMENT_GAS_PRICE=10000000000 | ||
FOREIGN_DEPLOYMENT_GAS_PRICE=10000000000 | ||
GET_RECEIPT_INTERVAL_IN_MILLISECONDS=50 | ||
DEPLOYMENT_GAS_LIMIT_EXTRA=0.2 | ||
|
||
HOME_RPC_URL=http://parity1:8545 | ||
HOME_BRIDGE_OWNER=0xaaB52d66283F7A1D5978bcFcB55721ACB467384b | ||
HOME_VALIDATORS_OWNER=0xaaB52d66283F7A1D5978bcFcB55721ACB467384b | ||
HOME_UPGRADEABLE_ADMIN=0xaaB52d66283F7A1D5978bcFcB55721ACB467384b | ||
HOME_MAX_AMOUNT_PER_TX=8000000 | ||
HOME_REQUIRED_BLOCK_CONFIRMATIONS=1 | ||
HOME_GAS_PRICE=1000000000 | ||
|
||
FOREIGN_RPC_URL=http://parity2:8545 | ||
FOREIGN_BRIDGE_OWNER=0xaaB52d66283F7A1D5978bcFcB55721ACB467384b | ||
FOREIGN_VALIDATORS_OWNER=0xaaB52d66283F7A1D5978bcFcB55721ACB467384b | ||
FOREIGN_UPGRADEABLE_ADMIN=0xaaB52d66283F7A1D5978bcFcB55721ACB467384b | ||
FOREIGN_MAX_AMOUNT_PER_TX=8000000 | ||
FOREIGN_REQUIRED_BLOCK_CONFIRMATIONS=1 | ||
FOREIGN_GAS_PRICE=10000000000 | ||
|
||
REQUIRED_NUMBER_OF_VALIDATORS=1 | ||
VALIDATORS=0xaaB52d66283F7A1D5978bcFcB55721ACB467384b |
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
Oops, something went wrong.