Support manual signatures in erc to native mode (#646)
This commit is contained in:
parent
981231fb47
commit
2b51d4c209
@ -5,14 +5,15 @@ const {
|
|||||||
COMMON_FOREIGN_BRIDGE_ADDRESS,
|
COMMON_FOREIGN_BRIDGE_ADDRESS,
|
||||||
ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY,
|
ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY,
|
||||||
ORACLE_HOME_START_BLOCK,
|
ORACLE_HOME_START_BLOCK,
|
||||||
ORACLE_HOME_END_BLOCK
|
ORACLE_HOME_END_BLOCK,
|
||||||
|
ORACLE_BRIDGE_MODE
|
||||||
} = process.env
|
} = process.env
|
||||||
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const promiseLimit = require('promise-limit')
|
const promiseLimit = require('promise-limit')
|
||||||
|
|
||||||
const { web3Home, web3Foreign } = require('../src/services/web3')
|
const { web3Home, web3Foreign } = require('../src/services/web3')
|
||||||
const { HOME_AMB_ABI, FOREIGN_AMB_ABI, getPastEvents, parseAMBMessage } = require('../../commons')
|
const { getBridgeABIs, getPastEvents, parseAMBMessage, BRIDGE_MODES } = require('../../commons')
|
||||||
const { setLogger } = require('../src/services/injectedLogger')
|
const { setLogger } = require('../src/services/injectedLogger')
|
||||||
|
|
||||||
const mockLogger = { debug: () => {}, info: () => {}, error: () => {}, child: () => mockLogger }
|
const mockLogger = { debug: () => {}, info: () => {}, error: () => {}, child: () => mockLogger }
|
||||||
@ -23,9 +24,10 @@ const limit = promiseLimit(50)
|
|||||||
const output = process.argv[2]
|
const output = process.argv[2]
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
const { HOME_ABI, FOREIGN_ABI } = getBridgeABIs(ORACLE_BRIDGE_MODE)
|
||||||
const wallet = web3Home.eth.accounts.wallet.add(ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY)
|
const wallet = web3Home.eth.accounts.wallet.add(ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY)
|
||||||
const homeBridge = new web3Home.eth.Contract(HOME_AMB_ABI, COMMON_HOME_BRIDGE_ADDRESS)
|
const homeBridge = new web3Home.eth.Contract(HOME_ABI, COMMON_HOME_BRIDGE_ADDRESS)
|
||||||
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_AMB_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
|
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
|
||||||
const fromBlock = parseInt(ORACLE_HOME_START_BLOCK, 10) || 0
|
const fromBlock = parseInt(ORACLE_HOME_START_BLOCK, 10) || 0
|
||||||
let toBlock = parseInt(ORACLE_HOME_END_BLOCK, 10)
|
let toBlock = parseInt(ORACLE_HOME_END_BLOCK, 10)
|
||||||
if (!toBlock) {
|
if (!toBlock) {
|
||||||
@ -36,7 +38,7 @@ async function main() {
|
|||||||
console.log(`Found ${events.length} CollectedSignatures events`)
|
console.log(`Found ${events.length} CollectedSignatures events`)
|
||||||
console.log('Getting messages')
|
console.log('Getting messages')
|
||||||
let messages = await Promise.all(
|
let messages = await Promise.all(
|
||||||
events.map((event, i) => () => getMessage(homeBridge, foreignBridge, event, i)).map(limit)
|
events.map((event, i) => () => getMessage(ORACLE_BRIDGE_MODE, homeBridge, foreignBridge, event, i)).map(limit)
|
||||||
)
|
)
|
||||||
messages = messages.filter(x => x)
|
messages = messages.filter(x => x)
|
||||||
console.log(`Filtered ${messages.length} pending messages`)
|
console.log(`Filtered ${messages.length} pending messages`)
|
||||||
@ -53,15 +55,20 @@ async function main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getMessage(homeBridge, foreignBridge, event, i) {
|
async function getMessage(bridgeMode, homeBridge, foreignBridge, event, i) {
|
||||||
if (i % 50 === 0) {
|
if (i % 50 === 0) {
|
||||||
console.log(`Processing event #${i}`)
|
console.log(`Processing event #${i}`)
|
||||||
}
|
}
|
||||||
const msgHash = event.returnValues.messageHash
|
const msgHash = event.returnValues.messageHash
|
||||||
const message = await homeBridge.methods.message(msgHash).call()
|
const message = await homeBridge.methods.message(msgHash).call()
|
||||||
|
|
||||||
const { messageId } = parseAMBMessage(message)
|
let msgId
|
||||||
const alreadyProcessed = await foreignBridge.methods.relayedMessages(messageId).call()
|
if (bridgeMode === BRIDGE_MODES.ARBITRARY_MESSAGE) {
|
||||||
|
msgId = parseAMBMessage(message).messageId
|
||||||
|
} else {
|
||||||
|
msgId = `0x${message.slice(106, 170)}`
|
||||||
|
}
|
||||||
|
const alreadyProcessed = await foreignBridge.methods.relayedMessages(msgId).call()
|
||||||
|
|
||||||
if (alreadyProcessed) {
|
if (alreadyProcessed) {
|
||||||
return null
|
return null
|
||||||
|
Loading…
Reference in New Issue
Block a user