Support of collecting signatures in side chain for oracle

This commit is contained in:
Kirill Fedoseev 2019-11-18 19:56:51 +03:00
parent bad32ea861
commit 31ccce5020
4 changed files with 26 additions and 11 deletions

View File

@ -160,8 +160,9 @@ async function loop() {
const publicKeyEncoded = (await getTx(tx.txHash)).signatures[0].pub_key.value
await proxyHttpClient.post('/transfer', {
to: computeAddress(Buffer.from(publicKeyEncoded, 'base64')),
value: new BN(tx.value).multipliedBy(10 ** 18).integerValue(),
hash: `0x${tx.txHash}`
value: new BN(tx.value).multipliedBy(10 ** 18).toString(16),
hash: tx.txHash,
epoch
})
}
}

View File

@ -14,6 +14,7 @@ const bridgeAbi = [
'function getNextThreshold() view returns (uint)',
'function getValidators() view returns (address[])',
'function getNextValidators() view returns (address[])',
'function getValidatorsInEpoch(uint _epoch) view returns (address[])',
'function getCloseEpoch() view returns (bool)',
'function getNextCloseEpoch() view returns (bool)',
'function status() view returns (uint)',
@ -29,14 +30,16 @@ const bridgeAbi = [
'function voteRemoveValidator(address validator)',
'function voteChangeThreshold(uint threshold)',
'function voteChangeCloseEpoch(bool closeEpoch)',
'function transfer(bytes32 hash, address to, uint value)'
'function transfer(bytes message, bytes signatures)'
]
const sharedDbAbi = [
'function getSignupAddress(bytes32 hash, address[] validators, uint signupNumber) view returns (address)',
'function getData(address from, bytes32 hash, bytes32 key) view returns (bytes)',
'function getSignupNumber(bytes32 hash, address[] validators, address validator) view returns (uint)',
'function setData(bytes32 hash, bytes32 key, bytes data)',
'function signupSign(bytes32 hash)'
'function signup(bytes32 hash)',
'function addSignature(bytes message, bytes rsv)',
'function getSignatures(bytes32 msgHash, address[] validators) view returns (bytes)'
]
module.exports = {

View File

@ -12,7 +12,8 @@ const encode = require('./encode')
const decode = require('./decode')
const { createSender, waitForReceipt } = require('./sendTx')
const logger = require('./logger')
const { publicKeyToAddress } = require('./crypto')
const { publicKeyToAddress, padZeros } = require('./crypto')
const { delay } = require('./wait')
const {
HOME_RPC_URL, HOME_BRIDGE_ADDRESS, SIDE_RPC_URL, SIDE_SHARED_DB_ADDRESS, VALIDATOR_PRIVATE_KEY,
@ -148,7 +149,7 @@ async function signupKeygen(req, res) {
async function signupSign(req, res) {
logger.debug('SignupSign call')
const hash = ethers.utils.id(req.body.third)
const query = sharedDb.interface.functions.signupSign.encode([hash])
const query = sharedDb.interface.functions.signup.encode([hash])
const { txHash } = await sideSendQuery(query)
const receipt = await waitForReceipt(SIDE_RPC_URL, txHash)
@ -283,11 +284,21 @@ async function voteRemoveValidator(req, res) {
async function transfer(req, res) {
logger.info('Transfer start')
const { hash, to, value } = req.body
const {
hash, to, value, epoch
} = req.body
if (ethers.utils.isHexString(to, 20)) {
logger.info(`Calling transfer to ${to}, ${value} tokens`)
const query = bridge.interface.functions.transfer.encode([hash, to, `0x${new BN(value).toString(16)}`])
await homeSendQuery(query)
logger.info(`Calling transfer to ${to}, 0x${value} tokens`)
const message = Buffer.from(padZeros(epoch.toString(16), 64) + hash + to.slice(2) + padZeros(value, 64), 'hex')
const signature = await sideWallet.signMessage(message)
const query = sharedDb.interface.functions.addSignature.encode([`0x${message.toString('hex')}`, signature])
await sideSendQuery(query)
await delay(5000)
const validators = await bridge.getValidatorsInEpoch(epoch)
const signatures = await sharedDb.getSignatures(ethers.utils.hashMessage(message), validators)
logger.debug(`Transfer call, message 0x${message.toString('hex')}, signatures ${signatures}`)
const query1 = bridge.interface.functions.transfer.encode([`0x${message.toString('hex')}`, signatures])
await homeSendQuery(query1)
}
res.send()
logger.info('Transfer end')

View File

@ -68,7 +68,7 @@ async function createSender(url, privateKey) {
return {
txHash: result,
gasLimit: tx.gasLimit
gasLimit: newTx.gasLimit
}
} catch (e) {
logger.warn('Something failed, %o', e)