Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding rbrelay secret command #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,33 @@ Rinkeby Relay

# Install
`git clone https://github.com/ConsenSys/rb-relay.git`


`npm link`
you have to create a `secrets.json` in the root of the project that looks like this:
`{"mnemonic": "put your twelve word seed in here so you can sign transactions"}`


`rbrelay secret "put your twelve word mnemonic here"`


This will create a json file in the root of the repository with your mnemonic.


MAKE SURE NOT TO PUBLISH THIS FILE ANYWHERE


# Use
Relay headers from Rinkeby to Ropsten


`rbrelay start`


Your wallet must have funds on the destination chain (ropsten)


Relay a TX from rinkeby to ropsten


`rbrelay tx 0x906a8ed7932dea662f1062414e8e558d49b52d1cfb56097247ca123aa4b64261 0x5e8ef53f0fde5347ce873deb9dddfbf7b3411b5b`

# WIP
Expand Down
145 changes: 80 additions & 65 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const option2 = args[2];
const hex = /0x[a-f0-9]/i;

const EthProof = require('eth-proof');
const ep = new EthProof(new Web3.providers.HttpProvider("https://rinkeby.infura.io/"));
const ep = new EthProof(new Web3.providers.HttpProvider("https://rinkeby.infura.io/"));

const rlp = require('rlp');
const Contract = require('truffle-contract');
Expand All @@ -23,14 +23,12 @@ const Rbrelay = Contract(require('./build/contracts/rbrelay.json'))
const Target = Contract(require('./build/contracts/Target.json'))

// Rbrelay.setProvider
// console.log(ep)
var relayProvider = getWalletProvider("ropsten")
const rinkebyWeb3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/"));
const relayWeb3 = new Web3(relayProvider);
Rbrelay.setProvider(relayProvider)
Rb20.setProvider(relayProvider)
Target.setProvider(relayProvider)

var relayProvider = getWalletProvider("ropsten")
const rinkebyWeb3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/"));
const relayWeb3 = new Web3(relayProvider);
Rbrelay.setProvider(relayProvider)
Rb20.setProvider(relayProvider)
Target.setProvider(relayProvider)

renderTitle()
switch(command) {
Expand All @@ -39,6 +37,7 @@ switch(command) {
break;
case "start":
var relayProvider = getWalletProvider(option1)
console.log('relayProvider', relayProvider)
serveHeaders(relayProvider)
break;
case "tx":
Expand All @@ -53,6 +52,18 @@ switch(command) {
}
relayReceipt(option1, option2);
break;
case "secret":
if (!option1) {
console.log('please provide mnemonic with command')
break;
}
if (option1.split(' ').length !== 12) {
console.log('please provide a 12 word mnemonic')
break;
}
writeSecret(option1)
.then(res => console.log('wrote mnemonic to ./secrets.json'))
break;
default:
console.log("Usage: rbrelay <command> <options>");
}
Expand Down Expand Up @@ -82,7 +93,7 @@ function getWalletProvider(network = "ropsten"){

function renderTitle(){
var str = ""

str += "\n __ ___ __ _ \n"
str += " /__\\ / __\\ /__\\ ___ | | __ _ _ _ \n"
str += " / \\// /__\\// ___ / \\// / _ \\| | / _` || | | | \n"
Expand All @@ -104,60 +115,64 @@ function renderTitle(){
return output
}

function relayTx(txHash, targetAddr) {
var proof, rb;
ep.getTransactionProof(txHash).then(function(result) {
proof = web3ify(result);
}).then(function() {
return Rbrelay.deployed();
}).then(function(instance) {
rb = instance;
return rb.head.call();
}).then(function(result) {
return rb.rbchain.call(result);
}).then(function(result) {
if(proof.header.blockNumber > result) {
console.log("tx is too recent");
}
}).then(function() {
console.log("You are being charged 0.1 ether!!!");
return rb.relayTx(proof.value, proof.path, proof.parentNodes, proof.header, targetAddr, {gas: 2000000, gasPrice: 25000000000, value: relayWeb3.toWei(0.1,'ether'), from: relayProvider.getAddress()});
}).then(function(result) {
console.log(JSON.stringify(result) + "\n");
console.log(JSON.stringify(rlp.decode(proof.value)) + "\n");
return Target.deployed()
}).then(function(instance) {
var target = instance;
return target.numTransactionsProcessed();
}).then(function(_numTransactionsProcessed) {
console.log(_numTransactionsProcessed.toNumber())
}).catch((e)=>{console.log(e)});
}

function writeSecret(secret) {
return new Promise((res, rej) => {
fs.writeFile('./secrets.json', secret, function(err) {
if (err) rej(err)
res(true)
})
})
}


function relayTx(txHash, targetAddr) {
var proof, rb;
ep.getTransactionProof(txHash).then(function(result) {
proof = web3ify(result);
}).then(function() {
return Rbrelay.deployed();
}).then(function(instance) {
rb = instance;
return rb.head.call();
}).then(function(result) {
return rb.rbchain.call(result);
}).then(function(result) {
if(proof.header.blockNumber > result) {
console.log("tx is too recent");
}
}).then(function() {
console.log("You are being charged 0.1 ether!!!");
return rb.relayTx(proof.value, proof.path, proof.parentNodes, proof.header, targetAddr, {gas: 2000000, gasPrice: 25000000000, value: relayWeb3.toWei(0.1,'ether'), from: relayProvider.getAddress()});
}).then(function(result) {
console.log(JSON.stringify(result) + "\n");
console.log(JSON.stringify(rlp.decode(proof.value)) + "\n");
return Target.deployed()
}).then(function(instance) {
var target = instance;
return target.numTransactionsProcessed();
}).then(function(_numTransactionsProcessed) {
console.log(_numTransactionsProcessed.toNumber())
}).catch((e)=>{console.log(e)});
}

// function relayReceipt(txHash, targetAddr) {
// var proof, rb;
// ep.getReceiptProof(txHash).then(function(result) {
// proof = web3ify(result);
// }).then(function() {
// return Rbrelay.deployed();
// }).then(function(instance) {
// rb = instance;
// return rb.head.call();
// }).then(function(result) {
// return rb.rbchain.call(result);
// }).then(function(result) {
// if(proof.header.blockNumber > result) {
// console.log("tx is too recent");
// }
// }).then(function() {
// console.log("You are being charged 0.1 ether!!!");
// return rb.relayReceipt(proof.value, proof.path, proof.parentNodes, proof.header, targetAddr, {gas: 200000, gasPrice: 25000000000, value: relayWeb3.toWei(0.1,'ether'), from: relayProvider.getAddress()});
// }).then(function(result) {
// console.log(JSON.stringify(result));
// });
// }


// function relayReceipt(txHash, targetAddr) {
// var proof, rb;
// ep.getReceiptProof(txHash).then(function(result) {
// proof = web3ify(result);
// }).then(function() {
// return Rbrelay.deployed();
// }).then(function(instance) {
// rb = instance;
// return rb.head.call();
// }).then(function(result) {
// return rb.rbchain.call(result);
// }).then(function(result) {
// if(proof.header.blockNumber > result) {
// console.log("tx is too recent");
// }
// }).then(function() {
// console.log("You are being charged 0.1 ether!!!");
// return rb.relayReceipt(proof.value, proof.path, proof.parentNodes, proof.header, targetAddr, {gas: 200000, gasPrice: 25000000000, value: relayWeb3.toWei(0.1,'ether'), from: relayProvider.getAddress()});
// }).then(function(result) {
// console.log(JSON.stringify(result));
// });
// }