diff --git a/README.md b/README.md index 4884247..2205896 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This, along with the wonderful Ethash verification work done by SmartPool, allow ## How It Works * Important Notes: - * In order to do cross-chain verification, we need valid block header informations stored in PeaceRelay contracts so that other proofs (Eg. transaction proof, account state proof) can be verified based on merkle roots in the block header. In this rudimentary version of Peace Relay, we assume the block header submitted is the correct header from the counter chain. In the future, these headers will be verified based on PoW within and chain re-organization will be taken care of. + * In order to do cross-chain verification, we need valid block header information stored in PeaceRelay contracts so that other proofs (Eg. transaction proof, account state proof) can be verified based on merkle roots in the block header. In this rudimentary version of Peace Relay, we assume the block header submitted is the correct header from the counter chain. In the future, these headers will be verified based on PoW within and chain re-organization will be taken care of. * In the demo, when user in one chain (say ETH) wants to transfer his funds to another chain (say ETC). He will lock his ethers in ETH and gets some tokens on ETC in return. He then can use these tokens for his business on ETC chain. If someone wish to trade ethers between chains, they can use Peace Relay the way others use BTC Relay - by verifying a transaction and its value. * Step by step: @@ -22,14 +22,14 @@ This, along with the wonderful Ethash verification work done by SmartPool, allow * `ETHLocking` contract deployed on Kovan * `ETHToken` contract deployed on Rinkeby - ### ETH to ETH tokens on ETC / Kovan to Rinkeby + ### ETH to ETH tokens on ETC || Kovan to Rinkeby 1. Send the desired ETH to be converted to the `ETHLocking` contract on Kovan using the `ETHLocking.lock()` function. - Note that there is no way this function will abort(throw) unless it runs out of gas during execution. 2. Wait for Kovan block which contains the transaction to be relayed to Rinkeby. In the meantime, generate the proof of the transaction off-chain. 3. Send transaction to execute `ETHToken.mint()` function using the generated proof in the previous step. This will mint ETH tokens. - The user can then spend those tokens at will until one day where they wish to convert them back to ethers in ETH / Kovan - ### ETH tokens on ETC back to ETH / Rinkeby back to Kovan + ### ETH tokens on ETC back to ETH || Rinkeby back to Kovan 1. Send tokens to be burnt using the `ETHToken.burn()` function. 2. Wait for Rinkeby block containing the transaction to be relayed to Kovan. In the meantime, generate the proof of the transaction off-chain. - The proof here contains the transaction and corresponding transaction receipt @@ -41,13 +41,15 @@ There are 2 wallets needed: 1 that does the submitting of block headers, and ano ## Contract deployment The contracts' codes can be found in the ./contracts folder. -1. Deploy a `PeaceRelay` contract on Rinkeby. This contract relays block headers from Kovan. -2. Deploy another `PeaceRelay` contract on Kovan. This contract relays block headers from Rinkeby. -3. Deploy a `ETHToken` contract on Rinkeby, which takes in the Rinkeby `PeaceRelay` contract address (Step 1) as a constructor argument. -4. Deploy a `ETHLocking` contract on Kovan, which has the Kovan `PeaceRelay` (Step 2) and Rinkeby `ETHToken` contract (Step 3) addresses as its constructor arguments. +1. Deploy a `PeaceRelay` contract on Rinkeby. This contract relays block headers from Kovan. The constructor argument is the desired **Kovan** block number to start relaying from, such as `7422101`. +2. Deploy a `ETHToken` contract on Rinkeby, which takes in the Rinkeby `PeaceRelay` contract address (previous step) as a constructor argument. Eg. `"0xa469a40f1bfa089761b226c084c6eaec6a19bc4f"` +3. Deploy another `PeaceRelay` contract on Kovan. This contract relays block headers from Rinkeby. The constructor argument is the desired **Rinkeby** block number to start relaying from. +4. Deploy a `ETHLocking` contract on Kovan, which has the Rinkeby `ETHToken` (Step 2) and Kovan `PeaceRelay` (Step 3) contract addresses as its constructor arguments. Eg. `"0xd8f16118cd79042491cde899d4963aae7d35fb7b","0xa469a40f1bfa089761b226c084c6eaec6a19bc4f"` +5. Go back to the deployed `ETHToken` contract on Rinkeby and call the `changeETHLockingAddr()` function using the `ETHLocking` contract address (Step 4) as the input argument. +6. **IMPORTANT:** The relayers' addresses must be authorised in the `PeaceRelay` contracts by calling the `authorise()` function. This need not be done if the creators of the `PeaceRelay` contracts are the relayers themselves. ## Setting up the relayers -We used AWS to do the relaying of block headers. All necessary files can be found in the ./cli folder. Create a linux server (you may run locally as well) and upload those files onto the server. +We use AWS to do the relaying of block headers. All necessary files can be found in the ./cli folder. Create a linux server (you may run locally as well) and upload those files onto the server. 1. Edit the `settings.json` file. Input the different contract addresses and private keys of the 2 wallets that does the block header submissions and transaction submissions. 2. Run the command `node peacerelay.js --from={srcChain} --to={destChain} --start={blockNum}` where * `srcChain` is the chain **from** which the block headers are to be relayed (smallcaps) @@ -57,10 +59,15 @@ We used AWS to do the relaying of block headers. All necessary files can be foun * Eg. `node peacerelay.js --from=rinkeby --to=kovan --start=2136659` (Relays Rinkeby block headers to the Kovan PeaceRelay contract, starting from block 2136659) ## Setting up the website -0. It is assumed that the contracts have been deployed and relayers have been set up. -1. Run `truffle deploy` to compile contracts. You should now have a `build` folder. The json files will be needed for the front-end website. (Namely, the ABI of the contracts) +0. It is assumed that the contracts have been deployed and relayers have been set up, and either `npm` or `yarn` has been installed. +1. Run `truffle deploy` to compile contracts. You should now have a `build` folder. The json files will be needed for the front-end website. To be specific, only the ABI of the contracts is needed, so an alternative is to copy the contract codes to [Remix](http://remix.ethereum.org) to obtain the ABI. 2. Ensure that the `settings.json` file has the correct information as mentioned in step 2 of the 'setting up the relayers' section. -3. Run `npm install` to install dependencies. +3. Run `npm install` or `yarn install` to install dependencies. 4. Run `npm run dev` or `yarn && yarn start`. 5. Website should be available via `localhost:3000` +## Example +1. [PeaceRelay contract](https://rinkeby.etherscan.io/address/0xa469a40f1bfa089761b226c084c6eaec6a19bc4f#code) relaying Kovan blocks to Rinkeby. Note that "imports" will need to have the code concatenated into one file as etherscan does not support "imports" in separate files for verification. +2. [ETHToken contract](https://rinkeby.etherscan.io/address/0xd8f16118cd79042491cde899d4963aae7d35fb7b#code) +3. [PeaceRelay contract](https://kovan.etherscan.io/address/0xa469a40f1bfa089761b226c084c6eaec6a19bc4f#code) relaying Rinkeby blocks to Kovan. +4. [ETHLocking contract](https://kovan.etherscan.io/address/0xd8f16118cd79042491cde899d4963aae7d35fb7b) diff --git a/cli/peacerelay.json b/cli/peacerelay.json index b55ea85..2a7a893 100644 --- a/cli/peacerelay.json +++ b/cli/peacerelay.json @@ -1,311 +1,313 @@ [ - { - "constant": true, - "inputs": [], - "name": "highestBlock", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "genesisBlock", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "", - "type": "uint256" - } - ], - "name": "blocks", - "outputs": [ - { - "name": "prevBlockHash", - "type": "uint256" - }, - { - "name": "stateRoot", - "type": "bytes32" - }, - { - "name": "txRoot", - "type": "bytes32" - }, - { - "name": "receiptRoot", - "type": "bytes32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "name": "blockNumber", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "txRoot", - "type": "bytes32" - } - ], - "name": "TxRootEvent", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "blockHash", - "type": "uint256" - }, - { - "indexed": false, - "name": "submitter", - "type": "address" - } - ], - "name": "SubmitBlock", - "type": "event" - }, - { - "constant": false, - "inputs": [ - { - "name": "user", - "type": "address" - } - ], - "name": "authorize", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "user", - "type": "address" - } - ], - "name": "deAuthorize", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "blockNumber", - "type": "uint256" - } - ], - "name": "resetGenesisBlock", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "blockHash", - "type": "uint256" - }, - { - "name": "rlpHeader", - "type": "bytes" - } - ], - "name": "submitBlock", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "value", - "type": "bytes" - }, - { - "name": "blockHash", - "type": "uint256" - }, - { - "name": "path", - "type": "bytes" - }, - { - "name": "parentNodes", - "type": "bytes" - } - ], - "name": "checkTxProof", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "value", - "type": "bytes" - }, - { - "name": "blockHash", - "type": "uint256" - }, - { - "name": "path", - "type": "bytes" - }, - { - "name": "parentNodes", - "type": "bytes" - } - ], - "name": "checkStateProof", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "value", - "type": "bytes" - }, - { - "name": "blockHash", - "type": "uint256" - }, - { - "name": "path", - "type": "bytes" - }, - { - "name": "parentNodes", - "type": "bytes" - } - ], - "name": "checkReceiptProof", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "blockHash", - "type": "uint256" - } - ], - "name": "getStateRoot", - "outputs": [ - { - "name": "", - "type": "bytes32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "blockHash", - "type": "uint256" - } - ], - "name": "getTxRoot", - "outputs": [ - { - "name": "", - "type": "bytes32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "blockHash", - "type": "uint256" - } - ], - "name": "getReceiptRoot", - "outputs": [ - { - "name": "", - "type": "bytes32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - } - ] \ No newline at end of file + { + "constant": true, + "inputs": [], + "name": "highestBlock", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "value", + "type": "bytes" + }, + { + "name": "blockHash", + "type": "uint256" + }, + { + "name": "path", + "type": "bytes" + }, + { + "name": "parentNodes", + "type": "bytes" + } + ], + "name": "checkTxProof", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "blockHash", + "type": "uint256" + }, + { + "name": "rlpHeader", + "type": "bytes" + } + ], + "name": "submitBlock", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "value", + "type": "bytes" + }, + { + "name": "blockHash", + "type": "uint256" + }, + { + "name": "path", + "type": "bytes" + }, + { + "name": "parentNodes", + "type": "bytes" + } + ], + "name": "checkStateProof", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "genesisBlock", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "user", + "type": "address" + } + ], + "name": "deAuthorize", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "user", + "type": "address" + } + ], + "name": "authorize", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "blockHash", + "type": "uint256" + } + ], + "name": "getStateRoot", + "outputs": [ + { + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "blockHash", + "type": "uint256" + } + ], + "name": "getReceiptRoot", + "outputs": [ + { + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "value", + "type": "bytes" + }, + { + "name": "blockHash", + "type": "uint256" + }, + { + "name": "path", + "type": "bytes" + }, + { + "name": "parentNodes", + "type": "bytes" + } + ], + "name": "checkReceiptProof", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "blockNumber", + "type": "uint256" + } + ], + "name": "resetGenesisBlock", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "", + "type": "uint256" + } + ], + "name": "blocks", + "outputs": [ + { + "name": "prevBlockHash", + "type": "uint256" + }, + { + "name": "stateRoot", + "type": "bytes32" + }, + { + "name": "txRoot", + "type": "bytes32" + }, + { + "name": "receiptRoot", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "blockHash", + "type": "uint256" + } + ], + "name": "getTxRoot", + "outputs": [ + { + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "name": "blockNumber", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "blockHash", + "type": "uint256" + }, + { + "indexed": false, + "name": "submitter", + "type": "address" + } + ], + "name": "SubmitBlock", + "type": "event" + } +] \ No newline at end of file diff --git a/cli/settings.json b/cli/settings.json index e0a9e83..e1767b9 100644 --- a/cli/settings.json +++ b/cli/settings.json @@ -3,8 +3,8 @@ "kovan":{ "url": "https://kovan.infura.io", "chainId": 42, - "peaceRelayAddress": "0x207a378458a04c370adae40f9678d59630ace8fc", - "etcLockingAddress": "0xc912255c5aa515a8fc178da9bb9f467eb02408bc", + "peaceRelayAddress": "0xa469a40f1bfa089761b226c084c6eaec6a19bc4f", + "ethLockingAddress": "0xD8F16118CD79042491cDe899d4963aAE7D35fb7B", "privateKey": "SIGNER PRIVATE KEY HERE", "relayerPrivateKey": "RELAYER PRIVATE KEY HERE" }, @@ -13,7 +13,7 @@ "url": "https://ropsten.infura.io", "chainId": 3, "peaceRelayAddress": "0xaa814956189f35345eacf7bf5aa9eb5a17631ec9", - "etcTokenAddress": "0xbe3b8284e8275d50649cb5016d34705aadc08e55", + "ethTokenAddress": "0xbe3b8284e8275d50649cb5016d34705aadc08e55", "privateKey": "SIGNER PRIVATE KEY HERE", "relayerPrivateKey": "RELAYER PRIVATE KEY HERE" }, @@ -21,8 +21,8 @@ "rinkeby":{ "url":"https://rinkeby.infura.io", "chainId": 4, - "peaceRelayAddress": "0x18ef75ca1c64cd684990903dc8cf878a5d2cbdea", - "etcTokenAddress": "0x4CC1885bEC2FABC9d1B21D0189727f44FEAFCbCf", + "peaceRelayAddress": "0xa469a40f1bfa089761b226c084c6eaec6a19bc4f", + "ethTokenAddress": "0xD8F16118CD79042491cDe899d4963aAE7D35fb7B", "privateKey": "SIGNER PRIVATE KEY HERE", "relayerPrivateKey": "RELAYER PRIVATE KEY HERE" }, diff --git a/contracts/ERC20.sol b/contracts/ERC20.sol index a4f4691..eaa4e68 100644 --- a/contracts/ERC20.sol +++ b/contracts/ERC20.sol @@ -1,13 +1,23 @@ -pragma solidity ^0.4.8; - -contract ERC20 { - uint public totalSupply; - function balanceOf(address who) constant returns (uint); - function allowance(address owner, address spender) constant returns (uint); - - function transfer(address to, uint value) returns (bool ok); - function transferFrom(address from, address to, uint value) returns (bool ok); - function approve(address spender, uint value) returns (bool ok); - event Transfer(address indexed from, address indexed to, uint value); - event Approval(address indexed owner, address indexed spender, uint value); -} +pragma solidity ^0.4.23; + +import "./ERC20Basic.sol"; + + +/** + * @title ERC20 interface + * @dev see https://github.com/ethereum/EIPs/issues/20 + */ +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} \ No newline at end of file diff --git a/contracts/ERC20Basic.sol b/contracts/ERC20Basic.sol new file mode 100644 index 0000000..9cacae8 --- /dev/null +++ b/contracts/ERC20Basic.sol @@ -0,0 +1,14 @@ +pragma solidity ^0.4.23; + + +/** + * @title ERC20Basic + * @dev Simpler version of ERC20 interface + * @dev see https://github.com/ethereum/EIPs/issues/179 + */ +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} \ No newline at end of file diff --git a/contracts/ETHLocking.sol b/contracts/ETHLocking.sol index 37da71c..5b160c8 100644 --- a/contracts/ETHLocking.sol +++ b/contracts/ETHLocking.sol @@ -1,11 +1,11 @@ -pragma solidity ^0.4.21; +pragma solidity ^0.4.24; import "./SafeMath.sol"; import "./PeaceRelay.sol"; import "./RLP.sol"; import "./Ownable.sol"; -contract ETHLocking { +contract ETHLocking is Ownable { using SafeMath for uint256; using RLP for RLP.RLPItem; using RLP for RLP.Iterator; @@ -22,12 +22,6 @@ contract ETHLocking { PeaceRelay public ETHRelay; address public ETHTokenAddr; - modifier onlyOwner() { - if (owner == msg.sender) { - _; - } - } - struct Transaction { uint gasPrice; uint gasLimit; @@ -45,10 +39,10 @@ contract ETHLocking { event Locked(address indexed from, address indexed ethAddr, uint value); event Unlocked(address indexed to, uint value); - function ETHLocking(address _peaceRelayAddr, address _ETHTokenAddr) { + constructor (address _ETHTokenAddr, address _peaceRelayAddr) public { totalSupply = 0; - ETHRelay = PeaceRelay(_peaceRelayAddr); ETHTokenAddr = _ETHTokenAddr; + ETHRelay = PeaceRelay(_peaceRelayAddr); owner = msg.sender; } @@ -88,10 +82,10 @@ contract ETHLocking { rewarded[keccak256(txValue, bytes32(txBlockHash), txPath, txParentNodes)] = true; rewarded[keccak256(recValue, bytes32(txBlockHash), recPath, recParentNodes)] = true; log.ETHAddr.transfer(log.value); - assert(totalSupply == this.balance); emit Unlocked(log.ETHAddr, log.value); return true; } + return false; } } @@ -119,16 +113,6 @@ contract ETHLocking { l.value = logValue[3].toUint(); } - // rlpTransaction is a value at the bottom of the transaction trie. - function testGetReceiptDetails(bytes rlpReceipt) constant public returns (address, address, uint) { - RLP.RLPItem[] memory receipt = rlpReceipt.toRLPItem().toList(); - RLP.RLPItem[] memory logs = receipt[3].toList(); - RLP.RLPItem[] memory log = logs[0].toList(); - RLP.RLPItem[] memory logValue = log[1].toList(); - return (address(logValue[1].toUint()), address(logValue[2].toUint()), logValue[3].toUint()); - } - - // rlpTransaction is a value at the bottom of the transaction trie. function getTransactionDetails(bytes rlpTransaction) constant internal returns (Transaction memory tx) { RLP.RLPItem[] memory list = rlpTransaction.toRLPItem().toList(); @@ -142,20 +126,4 @@ contract ETHLocking { } return tx; } - - // rlpTransaction is a value at the bottom of the transaction trie. - function testGetTransactionDetails(bytes rlpTransaction) constant public returns (uint, uint, address, bytes) { - Transaction memory tx; - RLP.RLPItem[] memory list = rlpTransaction.toRLPItem().toList(); - tx.gasPrice = list[1].toUint(); - tx.gasLimit = list[2].toUint(); - tx.to = address(list[3].toUint()); - - //Ugly hard coding for now. Can only parse burn transactions. - tx.data = new bytes(68); - for (uint i = 0; i < 68; i++) { - tx.data[i] = rlpTransaction[rlpTransaction.length - 135 + i]; - } - return (tx.gasPrice, tx.gasLimit, tx.to, tx.data); - } } diff --git a/contracts/ETHToken.sol b/contracts/ETHToken.sol index a4d8ae3..ed57680 100644 --- a/contracts/ETHToken.sol +++ b/contracts/ETHToken.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.21; +pragma solidity ^0.4.24; import "./SafeMath.sol"; import "./ERC20.sol"; @@ -48,11 +48,11 @@ contract ETHToken is ERC20, Ownable { event Burn(address indexed from, address indexed ethAddr, uint indexed value); event Mint(address indexed to, uint value); - function ETHToken(address peaceRelayAddr) { + constructor (address peaceRelayAddr) public { totalSupply = 0; name = "ETHToken"; // Set the name for display purposes - symbol = "ETH"; // Set the symbol for display purposes - decimals = 9; // Amount of decimals for display purposes + symbol = "ETHT"; // Set the symbol for display purposes + decimals = 9; // Amount of decimals for display purposes ETHRelay = PeaceRelay(peaceRelayAddr); } @@ -92,49 +92,94 @@ contract ETHToken is ERC20, Ownable { return true; } - function checkIfRewarded(bytes value, uint256 blockHash, bytes path, bytes parentNodes) public constant returns (bool) { + function checkIfRewarded(bytes value, uint256 blockHash, bytes path, bytes parentNodes) public view returns (bool) { return rewarded[keccak256(value, bytes32(blockHash),path,parentNodes)]; } - function checkProof(bytes value, uint256 blockHash, bytes path, bytes parentNodes) public constant returns (bool) { + function checkProof(bytes value, uint256 blockHash, bytes path, bytes parentNodes) public view returns (bool) { return ETHRelay.checkTxProof(value, blockHash, path, parentNodes); } + function totalSupply() public view returns (uint256) { + return totalSupply; + } + + function balanceOf(address _owner) public view returns (uint) { + return balances[_owner]; + } + function transfer(address _to, uint _value) public returns (bool) { - // safeSub already has throw, so no need to throw balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } - - function transferFrom(address _from, address _to, uint _value) public returns (bool) { - uint256 allowance = allowed[_from][msg.sender]; - balances[_from] = balances[_from].sub(_value); - allowed[_from][msg.sender] = allowance.sub(_value); - balances[_to] = balances[_to].add(_value); - emit Transfer(_from, _to, _value); - return true; + function allowance(address _owner, address _spender) public view returns (uint) { + return allowed[_owner][_spender]; } - function balanceOf(address _owner) public constant returns (uint) { - return balances[_owner]; + /** + * * @dev Transfer tokens from one address to another + * @param _from address The address which you want to send tokens from + * @param _to address The address which you want to transfer to + * @param _value uint256 the amount of tokens to be transferred + **/ + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; } - function approve(address _spender, uint _value) public returns (bool) { + function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } - function allowance(address _owner, address _spender) public constant returns (uint) { - return allowed[_owner][_spender]; - } + /** + * @dev Increase the amount of tokens that an owner allowed to a spender. + * approve should be called when allowed[_spender] == 0. To increment + * allowed value is better to use this function to avoid 2 calls (and wait until + * the first transaction is mined) + * From MonolithDAO Token.sol + * @param _spender The address which will spend the funds. + * @param _addedValue The amount of tokens to increase the allowance by. + */ - // Non-payable unnamed function prevents Ether from being sent accidentally - function () {} + function increaseApproval(address _spender, uint _addedValue) public returns (bool) { + allowed[msg.sender][_spender] = (allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + /** + * @dev Decrease the amount of tokens that an owner allowed to a spender. + * approve should be called when allowed[_spender] == 0. To decrement + * allowed value is better to use this function to avoid 2 calls (and wait until + * the first transaction is mined) + * From MonolithDAO Token.sol + * @param _spender The address which will spend the funds. + * @param _subtractedValue The amount of tokens to decrease the allowance by. + */ + + function decreaseApproval(address _spender,uint _subtractedValue) public returns (bool) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } // HELPER FUNCTIONS function getSignature(bytes b) public pure returns (bytes4) { @@ -159,7 +204,7 @@ contract ETHToken is ERC20, Ownable { } //txValue is a value at the bottom of the transaction trie. - function getTransactionDetails(bytes txValue) constant internal returns (Transaction memory tx) { + function getTransactionDetails(bytes txValue) view internal returns (Transaction memory tx) { RLP.RLPItem[] memory list = txValue.toRLPItem().toList(); tx.gasPrice = list[1].toUint(); tx.gasLimit = list[2].toUint(); @@ -173,23 +218,4 @@ contract ETHToken is ERC20, Ownable { } return tx; } - - /* - //rlpTransaction is a value at the bottom of the transaction trie. - function testGetTransactionDetails(bytes rlpTransaction) constant returns (uint, uint, address, bytes) { - Transaction memory tx; - RLP.RLPItem[] memory list = rlpTransaction.toRLPItem().toList(); - tx.gasPrice = list[1].toUint(); - tx.gasLimit = list[2].toUint(); - tx.to = address(list[3].toUint()); - tx.value = list[4].toUint(); - - //Ugly hard coding for now. Can only parse burn transactions. - tx.data = new bytes(36); - for (uint i = 0; i < 36; i++) { - tx.data[i] = rlpTransaction[rlpTransaction.length - 103 + i]; - } - return (tx.gasPrice, tx.gasLimit, tx.to, tx.data); - } - */ -} +} \ No newline at end of file diff --git a/contracts/Ownable.sol b/contracts/Ownable.sol index 58f5f86..8d8cf63 100644 --- a/contracts/Ownable.sol +++ b/contracts/Ownable.sol @@ -1,19 +1,53 @@ -pragma solidity ^0.4.8; +pragma solidity ^0.4.23; + +/** + * @title Ownable + * @dev The Ownable contract has an owner address, and provides basic authorization control + * functions, this simplifies the implementation of "user permissions". + */ contract Ownable { address public owner; - function Ownable() { + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + + /** + * @dev The Ownable constructor sets the original `owner` of the contract to the sender + * account. + */ + constructor() public { owner = msg.sender; } + /** + * @dev Throws if called by any account other than the owner. + */ modifier onlyOwner() { - if (msg.sender == owner) - _; + require(msg.sender == owner); + _; } - function transferOwnership(address newOwner) onlyOwner { - if (newOwner != address(0)) owner = newOwner; + /** + * @dev Allows the current owner to transfer control of the contract to a newOwner. + * @param newOwner The address to transfer ownership to. + */ + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0)); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; } + /** + * @dev Allows the current owner to relinquish control of the contract. + */ + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(owner); + owner = address(0); + } } \ No newline at end of file diff --git a/contracts/Pausable.sol b/contracts/Pausable.sol index dd03d72..5531c62 100644 --- a/contracts/Pausable.sol +++ b/contracts/Pausable.sol @@ -1,40 +1,49 @@ -pragma solidity ^0.4.8; +pragma solidity ^0.4.23; import "./Ownable.sol"; -/* - * Pausable - * Abstract contract that allows children to implement an - * emergency stop mechanism. +/** + * @title Pausable + * @dev Base contract which allows children to implement an emergency stop mechanism. */ - contract Pausable is Ownable { - bool public stopped; + event Pause(); + event Unpause(); + + bool public paused = false; + - modifier stopInEmergency { - if (stopped) { - throw; - } + /** + * @dev Modifier to make a function callable only when the contract is not paused. + */ + modifier whenNotPaused() { + require(!paused); _; } - - modifier onlyInEmergency { - if (!stopped) { - throw; - } + + /** + * @dev Modifier to make a function callable only when the contract is paused. + */ + modifier whenPaused() { + require(paused); _; } - // called by the owner on emergency, triggers stopped state - function emergencyStop() external onlyOwner { - stopped = true; + /** + * @dev called by the owner to pause, triggers stopped state + */ + function pause() onlyOwner whenNotPaused public { + paused = true; + emit Pause(); } - // called by the owner on end of emergency, returns to normal state - function release() external onlyOwner onlyInEmergency { - stopped = false; + /** + * @dev called by the owner to unpause, returns to normal state + */ + function unpause() onlyOwner whenPaused public { + paused = false; + emit Unpause(); } - } \ No newline at end of file diff --git a/contracts/PeaceRelay.sol b/contracts/PeaceRelay.sol index 3635cdc..f4cd7f9 100644 --- a/contracts/PeaceRelay.sol +++ b/contracts/PeaceRelay.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.11; +pragma solidity ^0.4.24; import "./RLP.sol"; import "./MerklePatriciaProof.sol"; @@ -34,32 +34,29 @@ contract PeaceRelay { bytes32 receiptRoot; // 5 } - - - event TxRootEvent(bytes32 txRoot); event SubmitBlock(uint256 blockHash, address submitter); - function PeaceRelay(uint256 blockNumber) { + constructor (uint256 blockNumber) public { genesisBlock = blockNumber; highestBlock = blockNumber; authorized[msg.sender] = true; owner = msg.sender; } - function authorize(address user) onlyOwner { + function authorize(address user) onlyOwner public { authorized[user] = true; } - function deAuthorize(address user) onlyOwner { + function deAuthorize(address user) onlyOwner public { authorized[user] = false; } - function resetGenesisBlock(uint256 blockNumber) onlyAuthorized { + function resetGenesisBlock(uint256 blockNumber) onlyAuthorized public { genesisBlock = blockNumber; highestBlock = blockNumber; } - function submitBlock(uint256 blockHash, bytes rlpHeader) onlyAuthorized { + function submitBlock(uint256 blockHash, bytes rlpHeader) onlyAuthorized public { BlockHeader memory header = parseBlockHeader(rlpHeader); uint256 blockNumber = getBlockNumber(rlpHeader); if (blockNumber > highestBlock) { @@ -67,32 +64,28 @@ contract PeaceRelay { } blocks[blockHash] = header; // There is at least one orphan - SubmitBlock(blockHash, msg.sender); + emit SubmitBlock(blockHash, msg.sender); } - function checkTxProof(bytes value, uint256 blockHash, bytes path, bytes parentNodes) constant returns (bool) { + function checkTxProof(bytes value, uint256 blockHash, bytes path, bytes parentNodes) view public returns (bool) { // add fee for checking transaction bytes32 txRoot = blocks[blockHash].txRoot; - TxRootEvent(txRoot); return trieValue(value, path, parentNodes, txRoot); } - // TODO: test - function checkStateProof(bytes value, uint256 blockHash, bytes path, bytes parentNodes) constant returns (bool) { + function checkStateProof(bytes value, uint256 blockHash, bytes path, bytes parentNodes) view public returns (bool) { bytes32 stateRoot = blocks[blockHash].stateRoot; return trieValue(value, path, parentNodes, stateRoot); } - // TODO: test - function checkReceiptProof(bytes value, uint256 blockHash, bytes path, bytes parentNodes) constant returns (bool) { + function checkReceiptProof(bytes value, uint256 blockHash, bytes path, bytes parentNodes) view public returns (bool) { bytes32 receiptRoot = blocks[blockHash].receiptRoot; return trieValue(value, path, parentNodes, receiptRoot); } - // parse block header - function parseBlockHeader(bytes rlpHeader) constant internal returns (BlockHeader) { + function parseBlockHeader(bytes rlpHeader) view internal returns (BlockHeader) { BlockHeader memory header; - var it = rlpHeader.toRLPItem().iterator(); + RLP.Iterator memory it = rlpHeader.toRLPItem().iterator(); uint idx; while (it.hasNext()) { @@ -112,24 +105,24 @@ contract PeaceRelay { return header; } - function getBlockNumber(bytes rlpHeader) constant internal returns (uint blockNumber) { + function getBlockNumber(bytes rlpHeader) view internal returns (uint blockNumber) { RLP.RLPItem[] memory rlpH = RLP.toList(RLP.toRLPItem(rlpHeader)); blockNumber = RLP.toUint(rlpH[8]); } - function getStateRoot(uint256 blockHash) constant returns (bytes32) { + function getStateRoot(uint256 blockHash) view public returns (bytes32) { return blocks[blockHash].stateRoot; } - function getTxRoot(uint256 blockHash) constant returns (bytes32) { + function getTxRoot(uint256 blockHash) view public returns (bytes32) { return blocks[blockHash].txRoot; } - function getReceiptRoot(uint256 blockHash) constant returns (bytes32) { + function getReceiptRoot(uint256 blockHash) view public returns (bytes32) { return blocks[blockHash].receiptRoot; } - function trieValue(bytes value, bytes encodedPath, bytes parentNodes, bytes32 root) constant internal returns (bool) { + function trieValue(bytes value, bytes encodedPath, bytes parentNodes, bytes32 root) view internal returns (bool) { return MerklePatriciaProof.verify(value, encodedPath, parentNodes, root); } diff --git a/contracts/SafeMath.sol b/contracts/SafeMath.sol index 6afeb69..56a12c5 100644 --- a/contracts/SafeMath.sol +++ b/contracts/SafeMath.sol @@ -1,31 +1,48 @@ -pragma solidity ^0.4.8; +pragma solidity ^0.4.23; + /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { - function mul(uint256 a, uint256 b) internal pure returns (uint256) { - uint256 c = a * b; - assert(a == 0 || c / a == b); + + /** + * @dev Multiplies two numbers, throws on overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0) { + return 0; + } + c = a * b; + assert(c / a == b); return c; } + /** + * @dev Integer division of two numbers, truncating the quotient. + */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 - uint256 c = a / b; + // uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold - return c; + return a / b; } + /** + * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). + */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } - - function add(uint256 a, uint256 b) internal pure returns (uint256) { - uint256 c = a + b; + + /** + * @dev Adds two numbers, throws on overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; assert(c >= a); return c; } -} +} \ No newline at end of file diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js deleted file mode 100644 index 17d65a2..0000000 --- a/migrations/2_deploy_contracts.js +++ /dev/null @@ -1,13 +0,0 @@ -const PeaceRelay = artifacts.require("./PeaceRelay.sol"); -const ETCToken = artifacts.require("./ETCToken.sol"); -const ETCLocking = artifacts.require("./ETCLocking.sol"); - -module.exports = function(deployer) { - return deployer.deploy(PeaceRelay, 0, "0x4d85606ad632cfac6ba1312a7abce4c82ecc667508ed3e0ffff98985b3a384b9",'0xf901cca00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a04798162224ddf6fd2d826932e48ce7bae0767540c49ca345e49e7df5e5baa6fda056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008080836691b780845a55501a008080').then(() => { - deployer.link(PeaceRelay, [ETCToken, ETCLocking]); - return deployer.deploy(ETCToken,PeaceRelay.address).then(() => { - deployer.link(ETCToken, [ETCLocking]) - return deployer.deploy(ETCLocking,PeaceRelay.address,ETCToken.address); - }) - }); -}; \ No newline at end of file diff --git a/src/components/Balances.js b/src/components/Balances.js index 90196ab..9579ebb 100644 --- a/src/components/Balances.js +++ b/src/components/Balances.js @@ -1,6 +1,6 @@ import React, { Component } from 'react' import { Button, Input } from 'reactstrap' -import { ETCToken } from './Constants.js'; +import { ETHToken } from './Constants.js'; export default class Balances extends Component { constructor(props) { @@ -25,7 +25,7 @@ export default class Balances extends Component { if (queryNetwork == 'kovan') { console.log('balanceOf() method not implemented in Smart Contract by design.') } else { - let balance = ETCToken.balanceOf(this.state.rinkebyAddress) + let balance = ETHToken.balanceOf(this.state.rinkebyAddress) balance = this.props.web3.fromWei(balance, 'ether').toNumber() if (balance != this.state.rinkebyBalance) { this.setState({rinkebyBalance: balance}) @@ -40,9 +40,9 @@ export default class Balances extends Component { render() { return (
-

ETC Tokens in Rinkeby

+

ETH Tokens in Rinkeby


-

{this.state.rinkebyBalance} ETC

+

{this.state.rinkebyBalance} ETH

diff --git a/src/components/BurnTxStatus.js b/src/components/BurnTxStatus.js index 65dd528..1a2300c 100644 --- a/src/components/BurnTxStatus.js +++ b/src/components/BurnTxStatus.js @@ -3,7 +3,7 @@ import { connect } from 'react-redux' import { Button } from 'reactstrap' import { newTxStatus, updateTxStatus, removeTxStatus } from '../actions/txStatusActions' import { MAX_ATTEMPTS, KOVAN_ETHERSCAN_LINK, InfuraRinkeby, InfuraKovan, - ETCLocking, ETC_TOKEN_ADDRESS, EPs, PeaceRelayKovan, PEACE_RELAY_ADDRESS_KOVAN} from './Constants.js' + ETHLocking, ETH_TOKEN_ADDRESS, EPs, PeaceRelayKovan, PEACE_RELAY_ADDRESS_KOVAN} from './Constants.js' var helper = require('../../utils/helpers.js'); var BN = require('bn.js'); @@ -14,7 +14,7 @@ const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); const mapStateToProps = (state) => ({ web3: state.web3Status.web3, currAccount: state.web3Status.currAccount, - ETCToken: state.contracts.ETCToken, + ETHToken: state.contracts.ETHToken, PeaceRelayRinkeby: state.contracts.PeaceRelayRinkeby, }) @@ -94,11 +94,11 @@ class BurnTxStatus extends Component { self = this if(chain == 'rinkeby') { - data = this.props.ETCToken.burn.getData(this.props.web3.toWei(amount),recipient); + data = this.props.ETHToken.burn.getData(this.props.web3.toWei(amount),recipient); await this.props.web3.eth.sendTransaction({ data: data, from: this.props.currAccount, - to: ETC_TOKEN_ADDRESS, + to: ETH_TOKEN_ADDRESS, gas: 100000}, async function(err, res) { @@ -152,7 +152,7 @@ class BurnTxStatus extends Component { async unlock(id, txProof, receiptProof, blockHash, destChain) { var data, res if(destChain == 'kovan') { - data = ETCLocking.unlock.getData(txProof.value, blockHash, txProof.path, txProof.parentNodes, + data = ETHLocking.unlock.getData(txProof.value, blockHash, txProof.path, txProof.parentNodes, receiptProof.value, receiptProof.path, receiptProof.parentNodes) var unlockHash = await signing.unlock(data) this.updateTxStatus(id,"Waiting for transaction to be mined."); diff --git a/src/components/Constants.js b/src/components/Constants.js index adc09b1..1aaf1ea 100644 --- a/src/components/Constants.js +++ b/src/components/Constants.js @@ -18,23 +18,23 @@ export const InfuraRinkeby = new Web3(new Web3.providers.HttpProvider("https://r export const InfuraKovan = new Web3(new Web3.providers.HttpProvider("https://kovan.infura.io/GuujZSIzbY0azOouyBPX")); export const PeaceRelayABI = require('../../build/contracts/PeaceRelay.json').abi; -export const ETCTokenABI = require('../../build/contracts/ETCToken.json').abi; -export const ETCLockingABI = require('../../build/contracts/ETCLocking.json').abi; +export const ETHTokenABI = require('../../build/contracts/ETHToken.json').abi; +export const ETHLockingABI = require('../../build/contracts/ETHLocking.json').abi; export const PEACE_RELAY_ADDRESS_RINKEBY = settings['rinkeby'].peaceRelayAddress export const PEACE_RELAY_ADDRESS_KOVAN = settings['kovan'].peaceRelayAddress -export const ETC_TOKEN_ADDRESS = settings['rinkeby'].etcTokenAddress -export const ETC_LOCKING_ADDRESS = settings['kovan'].etcLockingAddress +export const ETH_TOKEN_ADDRESS = settings['rinkeby'].ethTokenAddress +export const ETH_LOCKING_ADDRESS = settings['kovan'].ethLockingAddress var PeaceRelayRinkebyContract = InfuraRinkeby.eth.contract(PeaceRelayABI); var PeaceRelayKovanContract = InfuraKovan.eth.contract(PeaceRelayABI); -var ETCTokenContract = InfuraRinkeby.eth.contract(ETCTokenABI); -var ETCLockingContract = InfuraKovan.eth.contract(ETCLockingABI); +var ETHTokenContract = InfuraRinkeby.eth.contract(ETHTokenABI); +var ETHLockingContract = InfuraKovan.eth.contract(ETHLockingABI); export var PeaceRelayRinkeby = PeaceRelayRinkebyContract.at(PEACE_RELAY_ADDRESS_RINKEBY) export var PeaceRelayKovan = PeaceRelayKovanContract.at(PEACE_RELAY_ADDRESS_KOVAN) -export var ETCToken = ETCTokenContract.at(ETC_TOKEN_ADDRESS) -export var ETCLocking = ETCLockingContract.at(ETC_LOCKING_ADDRESS) +export var ETHToken = ETHTokenContract.at(ETH_TOKEN_ADDRESS) +export var ETHLocking = ETHLockingContract.at(ETH_LOCKING_ADDRESS) const EpRinkeby = new EP(new Web3.providers.HttpProvider("https://rinkeby.infura.io/GuujZSIzbY0azOouyBPX")); const EpKovan = new EP(new Web3.providers.HttpProvider("https://kovan.infura.io/GuujZSIzbY0azOouyBPX")); diff --git a/src/components/LockTxStatus.js b/src/components/LockTxStatus.js index 7f18abb..82e098a 100644 --- a/src/components/LockTxStatus.js +++ b/src/components/LockTxStatus.js @@ -2,8 +2,8 @@ import React, { Component } from 'react' import { connect } from 'react-redux' import { Button } from 'reactstrap' import { newTxStatus, updateTxStatus, removeTxStatus } from '../actions/txStatusActions' -import { MAX_ATTEMPTS, RINKEBY_ETHERSCAN_LINK, InfuraRinkeby, InfuraKovan, ETCToken, - EPs, PeaceRelayRinkeby, ETC_LOCKING_ADDRESS, PEACE_RELAY_ADDRESS_RINKEBY } from './Constants.js' +import { MAX_ATTEMPTS, RINKEBY_ETHERSCAN_LINK, InfuraRinkeby, InfuraKovan, ETHToken, + EPs, PeaceRelayRinkeby, ETH_LOCKING_ADDRESS, PEACE_RELAY_ADDRESS_RINKEBY } from './Constants.js' var helper = require('../../utils/helpers.js'); var BN = require('bn.js'); @@ -14,7 +14,7 @@ const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); const mapStateToProps = (state) => ({ web3: state.web3Status.web3, currAccount: state.web3Status.currAccount, - ETCLocking: state.contracts.ETCLocking, + ETHLocking: state.contracts.ETHLocking, PeaceRelayKovan: state.contracts.PeaceRelayKovan, }) @@ -48,8 +48,8 @@ class LockTxStatus extends Component { let id = new Date().getTime() /* To use this code when Infura allows event listening - ETCTokenMintEvent = ETCToken.Mint({to: this.props.recipient}) - ETCTokenMintEvent.watch(function(err,res){ + ETHTokenMintEvent = ETHToken.Mint({to: this.props.recipient}) + ETHTokenMintEvent.watch(function(err,res){ if(!err) { console.log(res) console.log("Tokens mined! =)") @@ -106,11 +106,11 @@ class LockTxStatus extends Component { self = this if(chain == 'kovan') { - data = this.props.ETCLocking.lock.getData(recipient); + data = this.props.ETHLocking.lock.getData(recipient); await this.props.web3.eth.sendTransaction({ data: data, from: this.props.currAccount, - to: ETC_LOCKING_ADDRESS, + to: ETH_LOCKING_ADDRESS, value: this.props.web3.toWei(amount), gas: 100000}, @@ -170,10 +170,10 @@ class LockTxStatus extends Component { console.log('Path:' + txProof.path) console.log('Nodes:' + txProof.parentNodes) - data = ETCToken.mint.getData(txProof.value, blockHash, + data = ETHToken.mint.getData(txProof.value, blockHash, txProof.path, txProof.parentNodes) var mintHash = await signing.mint(data) - this.updateTxStatus(id,"ETC Tokens will be credited after this transaction has been mined") + this.updateTxStatus(id,"ETH Tokens will be credited after this transaction has been mined") } else { this.updateTxStatus(id,"Wrong destination network.") } diff --git a/src/reducers/contractReducer.js b/src/reducers/contractReducer.js index b1a6ea9..44d157c 100644 --- a/src/reducers/contractReducer.js +++ b/src/reducers/contractReducer.js @@ -1,24 +1,24 @@ -import { PeaceRelayABI, ETCTokenABI, ETCLockingABI, - ETC_TOKEN_ADDRESS, PEACE_RELAY_ADDRESS_RINKEBY, PEACE_RELAY_ADDRESS_KOVAN, ETC_LOCKING_ADDRESS } from '../components/Constants' +import { PeaceRelayABI, ETHTokenABI, ETHLockingABI, + ETH_TOKEN_ADDRESS, PEACE_RELAY_ADDRESS_RINKEBY, PEACE_RELAY_ADDRESS_KOVAN, ETH_LOCKING_ADDRESS } from '../components/Constants' export default function reducer(state={ - ETCToken: '', - ETCLocking: '', + ETHToken: '', + ETHLocking: '', PeaceRelayKovan: '', PeaceRelayRinkeby: '' }, action) { switch (action.type) { case "WEB3_INJECTED": { let web3 = action.payload, - ETCToken = web3.eth.contract(ETCTokenABI).at(ETC_TOKEN_ADDRESS), - ETCLocking = web3.eth.contract(ETCLockingABI).at(ETC_LOCKING_ADDRESS), + ETHToken = web3.eth.contract(ETHTokenABI).at(ETH_TOKEN_ADDRESS), + ETHLocking = web3.eth.contract(ETHLockingABI).at(ETH_LOCKING_ADDRESS), PeaceRelayKovan = web3.eth.contract(PeaceRelayABI).at(PEACE_RELAY_ADDRESS_KOVAN), PeaceRelayRinkeby = web3.eth.contract(PeaceRelayABI).at(PEACE_RELAY_ADDRESS_RINKEBY) return { ...state, - ETCToken: ETCToken, - ETCLocking: ETCLocking, + ETHToken: ETHToken, + ETHLocking: ETHLocking, PeaceRelayKovan: PeaceRelayKovan, PeaceRelayRinkeby: PeaceRelayRinkeby } diff --git a/src/utils/signing.js b/src/utils/signing.js index d273dbb..41fa433 100644 --- a/src/utils/signing.js +++ b/src/utils/signing.js @@ -41,7 +41,7 @@ async function helper(data, chain, contractAddr, amount) { async function lock(data, amount) { try { - var hash = await helper(data, 'kovan', settings['kovan'].etcLockingAddress, amount); + var hash = await helper(data, 'kovan', settings['kovan'].ethLockingAddress, amount); return hash; } catch(err) { throw err; @@ -50,7 +50,7 @@ async function lock(data, amount) { async function unlock(data) { try { - var hash = await helper(data, 'kovan', settings['kovan'].etcLockingAddress, 0); + var hash = await helper(data, 'kovan', settings['kovan'].ethLockingAddress, 0); return hash; } catch(err) { throw err; @@ -59,7 +59,7 @@ async function unlock(data) { async function burn(data, amount) { try { - var hash = await helper(data, 'rinkeby', settings['rinkeby'].etcTokenAddress, amount); + var hash = await helper(data, 'rinkeby', settings['rinkeby'].ethTokenAddress, amount); return hash; } catch(err) { throw err; @@ -68,7 +68,7 @@ async function burn(data, amount) { async function mint(data) { try { - var hash = await helper(data, 'rinkeby', settings['rinkeby'].etcTokenAddress, 0); + var hash = await helper(data, 'rinkeby', settings['rinkeby'].ethTokenAddress, 0); return hash; } catch(err) { throw err; @@ -137,24 +137,4 @@ async function getTransactionReceipt(txHash, chain) { return result.body.result; } -// const Ropsten = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io")); -// const Kovan = new Web3(new Web3.providers.HttpProvider("https://kovan.infura.io")); - -// // TODO : Fix this(require undefined, because this is web-page) -// const PeacerelayABI = require('../../build/contracts/PeaceRelay.json').abi; -// const ETCTokenABI = require('../../build/contracts/ETCToken.json').abi; -// const ETCLockingABI = require('../../build/contracts/ETCLocking.json').abi; - -// var PeaceRelayRopsten = new Ropsten.eth.Contract(PeacerelayABI); -// var PeaceRelayKovan = new Kovan.eth.Contract(PeacerelayABI); -// var ETCToken = new Ropsten.eth.Contract(ETCTokenABI); -// var ETCLocking = new Kovan.eth.Contract(ETCLockingABI); - -// PeaceRelayRopsten.options.address = settings['ropsten'].peaceRelayAddress; -// PeaceRelayKovan.options.address = settings['kovan'].peaceRelayAddress; -// ETCToken.options.address = settings['ropsten'].etcTokenAddress; -// ETCLocking.options.address = settings['kovan'].etcLockingAddress; - -// module.exports = {ethCall, getBlockInfo, getTransactionReceipt, lock, unlock, mint, burn, PeaceRelayKovan, -// PeaceRelayRopsten, ETCToken, ETCLocking, EP}; module.exports = {ethCall, mint, unlock}; \ No newline at end of file