From 3befedfc7fc6472c80464ad67a4c92c15227076f Mon Sep 17 00:00:00 2001 From: Artem Pikulin Date: Fri, 28 Dec 2018 17:47:00 +0700 Subject: [PATCH] Remove helpers. Update Readme. --- README.md | 22 +++++-------- helpers/alice/aliceClaimsPayment.js | 45 --------------------------- helpers/alice/approveToken.js | 36 ---------------------- helpers/alice/bobClaimsPayment.js | 45 --------------------------- helpers/alice/deploy.js | 42 ------------------------- helpers/alice/initErc20Deal.js | 44 -------------------------- helpers/alice/initEthDeal.js | 41 ------------------------ helpers/bob/aliceClaimsDeposit.js | 44 -------------------------- helpers/bob/aliceClaimsPayment.js | 44 -------------------------- helpers/bob/approveToken.js | 36 ---------------------- helpers/bob/bobClaimsDeposit.js | 44 -------------------------- helpers/bob/bobClaimsPayment.js | 44 -------------------------- helpers/bob/bobMakesErc20Deposit.js | 48 ----------------------------- helpers/bob/bobMakesErc20Payment.js | 48 ----------------------------- helpers/bob/bobMakesEthDeposit.js | 41 ------------------------ helpers/bob/bobMakesEthPayment.js | 41 ------------------------ helpers/bob/deploy.js | 42 ------------------------- helpers/config.js | 23 -------------- helpers/deployToken.js | 41 ------------------------ helpers/getSecretAndHash.js | 15 --------- 20 files changed, 8 insertions(+), 778 deletions(-) delete mode 100644 helpers/alice/aliceClaimsPayment.js delete mode 100644 helpers/alice/approveToken.js delete mode 100644 helpers/alice/bobClaimsPayment.js delete mode 100644 helpers/alice/deploy.js delete mode 100644 helpers/alice/initErc20Deal.js delete mode 100644 helpers/alice/initEthDeal.js delete mode 100644 helpers/bob/aliceClaimsDeposit.js delete mode 100644 helpers/bob/aliceClaimsPayment.js delete mode 100644 helpers/bob/approveToken.js delete mode 100644 helpers/bob/bobClaimsDeposit.js delete mode 100644 helpers/bob/bobClaimsPayment.js delete mode 100644 helpers/bob/bobMakesErc20Deposit.js delete mode 100644 helpers/bob/bobMakesErc20Payment.js delete mode 100644 helpers/bob/bobMakesEthDeposit.js delete mode 100644 helpers/bob/bobMakesEthPayment.js delete mode 100644 helpers/bob/deploy.js delete mode 100644 helpers/config.js delete mode 100644 helpers/deployToken.js delete mode 100644 helpers/getSecretAndHash.js diff --git a/README.md b/README.md index 65d96d2..72516ed 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,22 @@ # Etomic Swap Smart Contracts for BarterDex platform. [![Build Status](https://travis-ci.org/artemii235/etomic-swap.svg?branch=master)](https://travis-ci.org/artemii235/etomic-swap) -Etomic swap Smart Contracts are implemented to support ETH and ERC20 atomic swaps on BarterDex platform. +Etomic swap Smart Contract is implemented to support ETH and ERC20 atomic swaps on BarterDex platform. Please note that this project is not production ready yet! ## Swap workflow -Smart Contracts follow BarterDex Atomic swap protocol https://github.com/SuperNETorg/komodo/wiki/barterDEX-Whitepaper-v2#atomic-swaps -Despite example shows swap of ETH/ERC20 this approach will work also for ETH/ERC20 swaps to any currency supporting HTLC and multisigs. +Smart Contracts follow standard symmetric Atomic swap protocol. +Despite example shows swap of ETH/ERC20 this approach will work also for ETH/ERC20 swaps to any currency supporting HTLC (https://en.bitcoin.it/wiki/Hashed_Timelock_Contracts). 1. Bob wants to change his 1 ETH to Alice 1 ERC20 token. -1. Alice and Bob generate temporary Private/Public key pairs required to execute the swap. -1. Alice sends dexfee (handled externally by client side) -1. Bob sends deposit locked with his hash of BsecretN. He will need to reveal BsecretN to claim it back. Alice can claim deposit without knowing a secret after 4 hours. -1. Alice sends payment locked with 2 hashes: AsecretM and BsecretN. -1. Bob sends payment locked with hash of AsecretM. Bob can claim payment back after 2 hours without knowing AsecretM. -1. Alice claims Bob payment revealing AsecretM. -1. Bob claims Alice payment using AsecretM. -1. Bob claims his deposit back. +1. Alice sends dexfee (handled externally by client side). +1. Bob sends payment locked with hash of the Secret. He can refund the payment in 4 hours. +1. Alice sends payment locked with Bob Secret hash. She can refund her payment in 2 hours. +1. Bob spends Alice payment by revealing the secret. +1. Alice spends Bob payment using revealed secret. ## Project structure 1. `contracts` - Smart Contracts source code. -1. `helpers` - NodeJS command line scripts helping to deploy/interact with Smart Contracts. 1. `test` - Smart contracts unit tests. ## How to setup dev environment? @@ -31,12 +27,10 @@ Despite example shows swap of ETH/ERC20 this approach will work also for ETH/ERC 1. Start containers `docker-compose up -d`. 1. Install project dependencies: `docker-compose exec workspace yarn`. 1. To run tests: `docker-compose exec workspace truffle test`. -1. To run helper scripts set `ALICE_PK`, `BOB_PK` in .env file. These variables should contain valid Ethereum private keys - these keys stay at your local machine, however it's not recommended to put keys having access to real money. ## Related links 1. Komodo platform - https://www.komodoplatform.com -1. BarterDex - https://www.komodoplatform.com/en/technology/barterdex ## Useful links for smart contracts development diff --git a/helpers/alice/aliceClaimsPayment.js b/helpers/alice/aliceClaimsPayment.js deleted file mode 100644 index e74041f..0000000 --- a/helpers/alice/aliceClaimsPayment.js +++ /dev/null @@ -1,45 +0,0 @@ -const Web3 = require('web3'); -const web3 = new Web3(process.env.ETH_RPC_URL); -const config = require('../config'); - -async function method() { - const contract = new web3.eth.Contract(config.alice.abi, config.alice.address); - const method = contract.methods.aliceClaimsPayment( - process.argv[2], - web3.utils.toWei('1'), - process.argv[3], - config.deal.bob, - process.argv[4], - process.argv[5] - ); - - const txInput = { - to: config.alice.address, - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.ALICE_PK) - .then(transaction => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', transactionHash => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('got receipt'); - console.log(receipt); - process.exit(); - }); - }); -} - -method(); diff --git a/helpers/alice/approveToken.js b/helpers/alice/approveToken.js deleted file mode 100644 index 7218e1d..0000000 --- a/helpers/alice/approveToken.js +++ /dev/null @@ -1,36 +0,0 @@ -const Web3 = require('web3'); -const web3 = new Web3(process.env.ETH_RPC_URL); -const config = require('../config'); - -async function approveToken() { - const contract = new web3.eth.Contract(config.tokenContract.abi, config.tokenContract.address); - const method = contract.methods.approve(config.alice.address, web3.utils.toWei('1')); - - const txInput = { - to: config.tokenContract.address, - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.ALICE_PK) - .then((transaction) => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', (transactionHash) => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - }) - .catch((error) => { - console.log(error); - }) - .then((receipt) => { - console.log('token allowance approved'); - console.log(receipt); - process.exit(); - }); - }); -} - -approveToken(); \ No newline at end of file diff --git a/helpers/alice/bobClaimsPayment.js b/helpers/alice/bobClaimsPayment.js deleted file mode 100644 index ca24ae6..0000000 --- a/helpers/alice/bobClaimsPayment.js +++ /dev/null @@ -1,45 +0,0 @@ -const Web3 = require('web3'); -const web3 = new Web3(process.env.ETH_RPC_URL); -const config = require('../config'); - -async function claimPayment() { - const contract = new web3.eth.Contract(config.alice.abi, config.alice.address); - const method = contract.methods.bobClaimsPayment( - process.argv[2], - web3.utils.toWei('1'), - process.argv[3], - config.deal.alice, - process.argv[4], - process.argv[5] - ); - - const txInput = { - to: config.alice.address, - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.BOB_PK) - .then(transaction => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', transactionHash => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('transaction confirmed'); - console.log(receipt); - process.exit(); - }); - }); -} - -claimPayment(); diff --git a/helpers/alice/deploy.js b/helpers/alice/deploy.js deleted file mode 100644 index 3fa5332..0000000 --- a/helpers/alice/deploy.js +++ /dev/null @@ -1,42 +0,0 @@ -const config = require('../config'); -const Web3 = require('web3'); -const web3 = new Web3(process.env.ETH_RPC_URL); - -async function deploy() { - const contract = new web3.eth.Contract(config.alice.abi); - - const deploy = contract.deploy({ - data: config.alice.byteCode, - arguments: [] - }); - - const txInput = { - to: null, - gas: (await deploy.estimateGas()) + 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: deploy.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.ALICE_PK) - .then((transaction) => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', transactionHash => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('swap contract deployed'); - console.log(receipt); - process.exit(); - }); - }); -} - -deploy(); \ No newline at end of file diff --git a/helpers/alice/initErc20Deal.js b/helpers/alice/initErc20Deal.js deleted file mode 100644 index 0e66116..0000000 --- a/helpers/alice/initErc20Deal.js +++ /dev/null @@ -1,44 +0,0 @@ -const Web3 = require('web3'); -const web3 = new Web3(process.env.ETH_RPC_URL); -const config = require('../config'); - -async function initErc20Deal() { - const contract = new web3.eth.Contract(config.alice.abi, config.alice.address); - const method = contract.methods.initErc20Deal( - process.argv[2], - web3.utils.toWei('1'), - config.deal.bob, - process.argv[3], - process.argv[4], - config.tokenContract.address - ); - - const txInput = { - to: config.alice.address, - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.ALICE_PK).then(transaction => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', transactionHash => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('deal initialized'); - console.log(receipt); - process.exit(); - }); - }); -} - -initErc20Deal(); diff --git a/helpers/alice/initEthDeal.js b/helpers/alice/initEthDeal.js deleted file mode 100644 index b5890ca..0000000 --- a/helpers/alice/initEthDeal.js +++ /dev/null @@ -1,41 +0,0 @@ -const Web3 = require('web3'); -const config = require('../config'); - -const web3 = new Web3(process.env.ETH_RPC_URL); - -function initEthDeal() { - const contract = new web3.eth.Contract(config.alice.abi, config.alice.address); - // get deal id and hashes from command line - const method = contract.methods.initEthDeal(process.argv[2], config.deal.bob, process.argv[3], process.argv[4]); - - const txInput = { - to: config.alice.address, - value: web3.utils.toWei('1'), - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.ALICE_PK) - .then((transaction) => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', (transactionHash) => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('deal initialized'); - console.log(receipt); - process.exit(); - }); - }); -} - -initEthDeal(); \ No newline at end of file diff --git a/helpers/bob/aliceClaimsDeposit.js b/helpers/bob/aliceClaimsDeposit.js deleted file mode 100644 index 09a3524..0000000 --- a/helpers/bob/aliceClaimsDeposit.js +++ /dev/null @@ -1,44 +0,0 @@ -const Web3 = require('web3'); -const web3 = new Web3(process.env.ETH_RPC_URL); -const config = require('../config'); - -async function method() { - const contract = new web3.eth.Contract(config.bob.abi, config.bob.address); - const method = contract.methods.aliceClaimsDeposit( - process.argv[2], - web3.utils.toWei('1'), - config.deal.bob, - process.argv[3], - process.argv[4] - ); - - const txInput = { - to: config.bob.address, - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.ALICE_PK) - .then(transaction => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', transactionHash => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('got receipt'); - console.log(receipt); - process.exit(); - }); - }); -} - -method(); diff --git a/helpers/bob/aliceClaimsPayment.js b/helpers/bob/aliceClaimsPayment.js deleted file mode 100644 index bb24e2a..0000000 --- a/helpers/bob/aliceClaimsPayment.js +++ /dev/null @@ -1,44 +0,0 @@ -const Web3 = require('web3'); -const web3 = new Web3(process.env.ETH_RPC_URL); -const config = require('../config'); - -async function method() { - const contract = new web3.eth.Contract(config.bob.abi, config.bob.address); - const method = contract.methods.aliceClaimsPayment( - process.argv[2], - web3.utils.toWei('1'), - process.argv[3], - config.deal.bob, - process.argv[4] - ); - - const txInput = { - to: config.bob.address, - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.ALICE_PK) - .then(transaction => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', transactionHash => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('got receipt'); - console.log(receipt); - process.exit(); - }); - }); -} - -method(); diff --git a/helpers/bob/approveToken.js b/helpers/bob/approveToken.js deleted file mode 100644 index 98bb0a3..0000000 --- a/helpers/bob/approveToken.js +++ /dev/null @@ -1,36 +0,0 @@ -const Web3 = require('web3'); -const web3 = new Web3(process.env.ETH_RPC_URL); -const config = require('../config'); - -async function approveToken() { - const contract = new web3.eth.Contract(config.tokenContract.abi, config.tokenContract.address); - const method = contract.methods.approve(config.bob.address, web3.utils.toWei('100')); - - const txInput = { - to: config.tokenContract.address, - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.BOB_PK) - .then((transaction) => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', (transactionHash) => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - }) - .catch((error) => { - console.log(error); - }) - .then((receipt) => { - console.log('token allowance approved'); - console.log(receipt); - process.exit(); - }); - }); -} - -approveToken(); \ No newline at end of file diff --git a/helpers/bob/bobClaimsDeposit.js b/helpers/bob/bobClaimsDeposit.js deleted file mode 100644 index 48a9faf..0000000 --- a/helpers/bob/bobClaimsDeposit.js +++ /dev/null @@ -1,44 +0,0 @@ -const Web3 = require('web3'); -const web3 = new Web3(process.env.ETH_RPC_URL); -const config = require('../config'); - -async function method() { - const contract = new web3.eth.Contract(config.bob.abi, config.bob.address); - const method = contract.methods.bobClaimsDeposit( - process.argv[2], - web3.utils.toWei('1'), - process.argv[3], - config.deal.alice, - process.argv[4] - ); - - const txInput = { - to: config.bob.address, - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.BOB_PK) - .then(transaction => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', transactionHash => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('got receipt'); - console.log(receipt); - process.exit(); - }); - }); -} - -method(); diff --git a/helpers/bob/bobClaimsPayment.js b/helpers/bob/bobClaimsPayment.js deleted file mode 100644 index a6adf17..0000000 --- a/helpers/bob/bobClaimsPayment.js +++ /dev/null @@ -1,44 +0,0 @@ -const Web3 = require('web3'); -const web3 = new Web3(process.env.ETH_RPC_URL); -const config = require('../config'); - -async function claimPayment() { - const contract = new web3.eth.Contract(config.bob.abi, config.bob.address); - const method = contract.methods.bobClaimsPayment( - process.argv[2], - web3.utils.toWei('1'), - config.deal.alice, - process.argv[3], - process.argv[4] - ); - - const txInput = { - to: config.bob.address, - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.BOB_PK) - .then(transaction => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', transactionHash => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('transaction confirmed'); - console.log(receipt); - process.exit(); - }); - }); -} - -claimPayment(); diff --git a/helpers/bob/bobMakesErc20Deposit.js b/helpers/bob/bobMakesErc20Deposit.js deleted file mode 100644 index 202d0d1..0000000 --- a/helpers/bob/bobMakesErc20Deposit.js +++ /dev/null @@ -1,48 +0,0 @@ -const Web3 = require('web3'); -const config = require('../config'); - -const web3 = new Web3(process.env.ETH_RPC_URL); - -function initEthDeal() { - const contract = new web3.eth.Contract(config.bob.abi, config.bob.address); - // get deal id and hashes from command line - const method = contract.methods.bobMakesErc20Deposit( - process.argv[2], - web3.utils.toWei('1'), - config.deal.alice, - process.argv[3], - config.tokenContract.address, - Math.floor(Date.now() / 1000) + 720 - ); - - const txInput = { - to: config.bob.address, - value: 0, - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.BOB_PK) - .then((transaction) => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', (transactionHash) => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('deposit made'); - console.log(receipt); - process.exit(); - }); - }); -} - -initEthDeal(); \ No newline at end of file diff --git a/helpers/bob/bobMakesErc20Payment.js b/helpers/bob/bobMakesErc20Payment.js deleted file mode 100644 index 92bad99..0000000 --- a/helpers/bob/bobMakesErc20Payment.js +++ /dev/null @@ -1,48 +0,0 @@ -const Web3 = require('web3'); -const config = require('../config'); - -const web3 = new Web3(process.env.ETH_RPC_URL); - -function initEthDeal() { - const contract = new web3.eth.Contract(config.bob.abi, config.bob.address); - // get deal id and hashes from command line - const method = contract.methods.bobMakesErc20Payment( - process.argv[2], - web3.utils.toWei('1'), - config.deal.alice, - process.argv[3], - config.tokenContract.address, - Math.floor(Date.now() / 1000) + 720 - ); - - const txInput = { - to: config.bob.address, - value: 0, - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.BOB_PK) - .then((transaction) => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', (transactionHash) => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('deposit made'); - console.log(receipt); - process.exit(); - }); - }); -} - -initEthDeal(); \ No newline at end of file diff --git a/helpers/bob/bobMakesEthDeposit.js b/helpers/bob/bobMakesEthDeposit.js deleted file mode 100644 index e4b1bf4..0000000 --- a/helpers/bob/bobMakesEthDeposit.js +++ /dev/null @@ -1,41 +0,0 @@ -const Web3 = require('web3'); -const config = require('../config'); - -const web3 = new Web3(process.env.ETH_RPC_URL); - -function initEthDeal() { - const contract = new web3.eth.Contract(config.bob.abi, config.bob.address); - // get deal id and hashes from command line - const method = contract.methods.bobMakesEthDeposit(process.argv[2], config.deal.alice, process.argv[3], Math.floor(Date.now() / 1000) + Number(process.argv[4])); - - const txInput = { - to: config.bob.address, - value: web3.utils.toWei('1'), - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.BOB_PK) - .then((transaction) => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', (transactionHash) => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('deposit made'); - console.log(receipt); - process.exit(); - }); - }); -} - -initEthDeal(); \ No newline at end of file diff --git a/helpers/bob/bobMakesEthPayment.js b/helpers/bob/bobMakesEthPayment.js deleted file mode 100644 index e0b4749..0000000 --- a/helpers/bob/bobMakesEthPayment.js +++ /dev/null @@ -1,41 +0,0 @@ -const Web3 = require('web3'); -const config = require('../config'); - -const web3 = new Web3(process.env.ETH_RPC_URL); - -function initEthDeal() { - const contract = new web3.eth.Contract(config.bob.abi, config.bob.address); - // get deal id and hashes from command line - const method = contract.methods.bobMakesEthPayment(process.argv[2], config.deal.alice, process.argv[3], Math.floor(Date.now() / 1000) + Number(process.argv[4])); - - const txInput = { - to: config.bob.address, - value: web3.utils.toWei('1'), - gas: 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: method.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.BOB_PK) - .then((transaction) => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', (transactionHash) => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('payment made'); - console.log(receipt); - process.exit(); - }); - }); -} - -initEthDeal(); \ No newline at end of file diff --git a/helpers/bob/deploy.js b/helpers/bob/deploy.js deleted file mode 100644 index 2d81b96..0000000 --- a/helpers/bob/deploy.js +++ /dev/null @@ -1,42 +0,0 @@ -const config = require('../config'); -const Web3 = require('web3'); -const web3 = new Web3(process.env.ETH_RPC_URL); - -async function deploy() { - const contract = new web3.eth.Contract(config.bob.abi); - - const deploy = contract.deploy({ - data: config.bob.byteCode, - arguments: [] - }); - - const txInput = { - to: null, - gas: (await deploy.estimateGas()) + 300000, - gasPrice: web3.utils.toWei('100', 'gwei'), - data: deploy.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.ALICE_PK) - .then((transaction) => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', transactionHash => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('Bob contract deployed'); - console.log(receipt); - process.exit(); - }); - }); -} - -deploy(); diff --git a/helpers/config.js b/helpers/config.js deleted file mode 100644 index 5ab2aa6..0000000 --- a/helpers/config.js +++ /dev/null @@ -1,23 +0,0 @@ -const config = { - alice: { - abi: [{"constant":false,"inputs":[{"name":"_dealId","type":"bytes32"},{"name":"_amount","type":"uint256"},{"name":"_bob","type":"address"},{"name":"_aliceHash","type":"bytes20"},{"name":"_bobHash","type":"bytes20"},{"name":"_tokenAddress","type":"address"}],"name":"initErc20Deal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_dealId","type":"bytes32"},{"name":"_amount","type":"uint256"},{"name":"_tokenAddress","type":"address"},{"name":"_alice","type":"address"},{"name":"_bobHash","type":"bytes20"},{"name":"_aliceSecret","type":"bytes"}],"name":"bobClaimsPayment","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_dealId","type":"bytes32"},{"name":"_bob","type":"address"},{"name":"_aliceHash","type":"bytes20"},{"name":"_bobHash","type":"bytes20"}],"name":"initEthDeal","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"deals","outputs":[{"name":"dealHash","type":"bytes20"},{"name":"state","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_dealId","type":"bytes32"},{"name":"_amount","type":"uint256"},{"name":"_tokenAddress","type":"address"},{"name":"_bob","type":"address"},{"name":"_aliceHash","type":"bytes20"},{"name":"_bobSecret","type":"bytes"}],"name":"aliceClaimsPayment","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}], - address: '0xe1D4236C5774D35Dc47dcc2E5E0CcFc463A3289c', - byteCode: '0x6060604052341561000f57600080fd5b6109d88061001e6000396000f3006060604052600436106100535763ffffffff60e060020a600035041663184db3bf8114610058578063392ec66b146100a057806347c7b6e2146100ee57806381cd872a1461011d5780638b9a167a1461016d575b600080fd5b341561006357600080fd5b61009e600435602435600160a060020a036044358116906bffffffffffffffffffffffff196064358116916084359091169060a435166101bb565b005b34156100ab57600080fd5b61009e60048035906024803591600160a060020a03604435811692606435909116916bffffffffffffffffffffffff19608435169160a4359081019101356103df565b61009e600435600160a060020a03602435166bffffffffffffffffffffffff1960443581169060643516610660565b341561012857600080fd5b6101336004356107db565b6040516bffffffffffffffffffffffff19831681526020810182600381111561015857fe5b60ff1681526020019250505060405180910390f35b341561017857600080fd5b61009e60048035906024803591600160a060020a03604435811692606435909116916bffffffffffffffffffffffff19608435169160a4359081019101356107ff565b600080600160a060020a038616158015906101de5750600160a060020a03831615155b80156101ea5750600087115b801561021857506000808981526020819052604090205460a060020a900460ff16600381111561021657fe5b145b151561022357600080fd5b6003338688878b88600060405160200152604051606060020a600160a060020a03978816810282526bffffffffffffffffffffffff1996871660148301529487168502602882015292909416603c830152605082015291909216909102607082015260840160206040518083038160008661646e5a03f115156102a557600080fd5b505060405151606060020a029150604080519081016040526bffffffffffffffffffffffff1983168152602081016001905260008981526020819052604090208151815473ffffffffffffffffffffffffffffffffffffffff1916606060020a90910417815560208201518154829074ff0000000000000000000000000000000000000000191660a060020a83600381111561033d57fe5b021790555090505082905080600160a060020a03166323b872dd33308a60006040516020015260405160e060020a63ffffffff8616028152600160a060020a0393841660048201529190921660248201526044810191909152606401602060405180830381600087803b15156103b257600080fd5b6102c65a03f115156103c357600080fd5b5050506040518051905015156103d557fe5b5050505050505050565b600080600160008a81526020819052604090205460a060020a900460ff16600381111561040857fe5b1461041257600080fd5b6003866003600287876000604051602001526040518083838082843782019150509250505060206040518083038160008661646e5a03f1151561045457600080fd5b5050604051805190506000604051602001526040519081526020908101906040518083038160008661646e5a03f1151561048d57600080fd5b505060405151606060020a0233888c8c600060405160200152604051606060020a600160a060020a03978816810282526bffffffffffffffffffffffff1996871660148301529487168502602882015292909416603c830152605082015291909216909102607082015260840160206040518083038160008661646e5a03f1151561051757600080fd5b50506040515160008a815260208190526040902054606060020a9182029350026bffffffffffffffffffffffff199081169083161461055557600080fd5b600089815260208190526040902080546002919074ff0000000000000000000000000000000000000000191660a060020a835b0217905550600160a060020a03871615156105d357600160a060020a03331688156108fc0289604051600060405180830381858888f1935050505015156105ce57600080fd5b610655565b5085600160a060020a03811663a9059cbb338a60006040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b151561063257600080fd5b6102c65a03f1151561064357600080fd5b50505060405180519050151561065557fe5b505050505050505050565b6000600160a060020a0384161580159061067a5750600034115b80156106a857506000808681526020819052604090205460a060020a900460ff1660038111156106a657fe5b145b15156106b357600080fd5b6003338486853460008060405160200152604051606060020a600160a060020a03978816810282526bffffffffffffffffffffffff1996871660148301529487168502602882015292909416603c830152605082015291909216909102607082015260840160206040518083038160008661646e5a03f1151561073557600080fd5b505060405151606060020a029050604080519081016040526bffffffffffffffffffffffff1982168152602081016001905260008681526020819052604090208151815473ffffffffffffffffffffffffffffffffffffffff1916606060020a90910417815560208201518154829074ff0000000000000000000000000000000000000000191660a060020a8360038111156107cd57fe5b021790555050505050505050565b600060208190529081526040902054606060020a81029060a060020a900460ff1682565b600080600160008a81526020819052604090205460a060020a900460ff16600381111561082857fe5b1461083257600080fd5b60033386886003600289896000604051602001526040518083838082843782019150509250505060206040518083038160008661646e5a03f1151561087657600080fd5b5050604051805190506000604051602001526040519081526020908101906040518083038160008661646e5a03f115156108af57600080fd5b505060405151606060020a028c8c600060405160200152604051606060020a600160a060020a03978816810282526bffffffffffffffffffffffff1996871660148301529487168502602882015292909416603c830152605082015291909216909102607082015260840160206040518083038160008661646e5a03f1151561093757600080fd5b50506040515160008a815260208190526040902054606060020a9182029350026bffffffffffffffffffffffff199081169083161461097557600080fd5b600089815260208190526040902080546003919074ff0000000000000000000000000000000000000000191660a060020a836105885600a165627a7a72305820666f591e9ae8ec3b5bd29796bd16ed66fd1c2cfa02229e016b5825f2ffd5fa040029', - }, - tokenContract: { - abi: [{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_subtractedValue","type":"uint256"}],"name":"decreaseApproval","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_addedValue","type":"uint256"}],"name":"increaseApproval","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}], - address: '0xc0eb7AeD740E1796992A08962c15661bDEB58003', - byteCode: '0x6060604052341561000f57600080fd5b683635c9adc5dea00000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550683635c9adc5dea000006000819055506111d48061007b6000396000f3006060604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100b4578063095ea7b31461014257806318160ddd1461019c57806323b872dd146101c5578063313ce5671461023e578063661884631461026d57806370a08231146102c757806395d89b4114610314578063a9059cbb146103a2578063d73dd623146103fc578063dd62ed3e14610456575b600080fd5b34156100bf57600080fd5b6100c76104c2565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101075780820151818401526020810190506100ec565b50505050905090810190601f1680156101345780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561014d57600080fd5b610182600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506104fb565b604051808215151515815260200191505060405180910390f35b34156101a757600080fd5b6101af6105ed565b6040518082815260200191505060405180910390f35b34156101d057600080fd5b610224600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506105f3565b604051808215151515815260200191505060405180910390f35b341561024957600080fd5b6102516109b2565b604051808260ff1660ff16815260200191505060405180910390f35b341561027857600080fd5b6102ad600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506109b7565b604051808215151515815260200191505060405180910390f35b34156102d257600080fd5b6102fe600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610c48565b6040518082815260200191505060405180910390f35b341561031f57600080fd5b610327610c91565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561036757808201518184015260208101905061034c565b50505050905090810190601f1680156103945780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156103ad57600080fd5b6103e2600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610cca565b604051808215151515815260200191505060405180910390f35b341561040757600080fd5b61043c600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610eee565b604051808215151515815260200191505060405180910390f35b341561046157600080fd5b6104ac600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506110ea565b6040518082815260200191505060405180910390f35b6040805190810160405280600a81526020017f4a75737420546f6b656e0000000000000000000000000000000000000000000081525081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60005481565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415151561063057600080fd5b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561067e57600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561070957600080fd5b61075b82600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461117190919063ffffffff16565b600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506107f082600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461118a90919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506108c282600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461117190919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b601281565b600080600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115610ac8576000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610b5c565b610adb838261117190919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6040805190810160405280600381526020017f4a5354000000000000000000000000000000000000000000000000000000000081525081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515610d0757600080fd5b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610d5557600080fd5b610da782600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461117190919063ffffffff16565b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e3c82600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461118a90919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000610f7f82600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461118a90919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600082821115151561117f57fe5b818303905092915050565b600080828401905083811015151561119e57fe5b80915050929150505600a165627a7a723058204fa5a47919ba4010e83d5c6ab7397081e1a7cf16c527ee08c7c292aa3445bf8a0029' - }, - bob: { - abi: [{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"payments","outputs":[{"name":"paymentHash","type":"bytes20"},{"name":"lockTime","type":"uint64"},{"name":"state","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_txId","type":"bytes32"},{"name":"_amount","type":"uint256"},{"name":"_secret","type":"bytes32"},{"name":"_bob","type":"address"},{"name":"_tokenAddress","type":"address"}],"name":"aliceClaimsPayment","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_txId","type":"bytes32"},{"name":"_amount","type":"uint256"},{"name":"_secret","type":"bytes32"},{"name":"_alice","type":"address"},{"name":"_tokenAddress","type":"address"}],"name":"bobClaimsDeposit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"deposits","outputs":[{"name":"depositHash","type":"bytes20"},{"name":"lockTime","type":"uint64"},{"name":"state","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_txId","type":"bytes32"},{"name":"_amount","type":"uint256"},{"name":"_bob","type":"address"},{"name":"_tokenAddress","type":"address"},{"name":"_secretHash","type":"bytes20"}],"name":"aliceClaimsDeposit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_txId","type":"bytes32"},{"name":"_alice","type":"address"},{"name":"_secretHash","type":"bytes20"},{"name":"_lockTime","type":"uint64"}],"name":"bobMakesEthPayment","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"_txId","type":"bytes32"},{"name":"_amount","type":"uint256"},{"name":"_alice","type":"address"},{"name":"_secretHash","type":"bytes20"},{"name":"_tokenAddress","type":"address"},{"name":"_lockTime","type":"uint64"}],"name":"bobMakesErc20Deposit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_txId","type":"bytes32"},{"name":"_amount","type":"uint256"},{"name":"_alice","type":"address"},{"name":"_secretHash","type":"bytes20"},{"name":"_tokenAddress","type":"address"},{"name":"_lockTime","type":"uint64"}],"name":"bobMakesErc20Payment","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_txId","type":"bytes32"},{"name":"_alice","type":"address"},{"name":"_secretHash","type":"bytes20"},{"name":"_lockTime","type":"uint64"}],"name":"bobMakesEthDeposit","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"_txId","type":"bytes32"},{"name":"_amount","type":"uint256"},{"name":"_alice","type":"address"},{"name":"_tokenAddress","type":"address"},{"name":"_secretHash","type":"bytes20"}],"name":"bobClaimsPayment","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}], - address: '0x2a8e4F9aE69c86e277602c6802085fEbC4BD5986', - byteCode: '0x6060604052341561000f57600080fd5b6110c08061001e6000396000f30060606040526004361061008a5763ffffffff60e060020a6000350416630716326d811461008f578063113ee583146100eb5780631f7a72f71461011b5780633d4dff7b146101495780634b915a681461015f5780635ab30d95146101975780635d567259146101c8578063b8a15b1d1461020e578063dd23795f14610254578063e45ef4ad14610285575b600080fd5b341561009a57600080fd5b6100a56004356102bd565b6040516001606060020a03198416815267ffffffffffffffff83166020820152604081018260038111156100d557fe5b60ff168152602001935050505060405180910390f35b34156100f657600080fd5b610119600435602435604435600160a060020a03606435811690608435166102f3565b005b341561012657600080fd5b610119600435602435604435600160a060020a0360643581169060843516610545565b341561015457600080fd5b6100a56004356106cc565b341561016a57600080fd5b610119600435602435600160a060020a03604435811690606435166001606060020a031960843516610702565b610119600435600160a060020a03602435166001606060020a03196044351667ffffffffffffffff606435166108c3565b34156101d357600080fd5b610119600435602435600160a060020a036044358116906001606060020a031960643516906084351667ffffffffffffffff60a43516610a60565b341561021957600080fd5b610119600435602435600160a060020a036044358116906001606060020a031960643516906084351667ffffffffffffffff60a43516610c33565b610119600435600160a060020a03602435166001606060020a03196044351667ffffffffffffffff60643516610dd6565b341561029057600080fd5b610119600435602435600160a060020a03604435811690606435166001606060020a031960843516610f65565b600160205260009081526040902054606060020a81029060a060020a810467ffffffffffffffff169060e060020a900460ff1683565b600080600160008881526001602052604090205460e060020a900460ff16600381111561031c57fe5b1461032657600080fd5b600333856003600289604051908152602090810190604051808303816000865af1151561035257600080fd5b505060405180519050604051908152602090810190604051808303816000865af1151561037e57600080fd5b505060405151606060020a02868a604051606060020a600160a060020a0396871681028252948616850260148201526001606060020a031990931660288401529316909102603c82015260508101919091526070016020604051808303816000865af115156103ec57600080fd5b505060405151600088815260016020526040902054606060020a91909102925060a060020a900467ffffffffffffffff164210801561044c57506000878152600160205260409020546001606060020a0319838116606060020a90920216145b151561045757600080fd5b600087815260016020526040902080546002919060e060020a60ff02191660e060020a835b0217905550600160a060020a03831615156104c757600160a060020a03331686156108fc0287604051600060405180830381858888f1935050505015156104c257600080fd5b61053c565b5081600160a060020a03811663a9059cbb338860405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b151561051d57600080fd5b5af1151561052a57600080fd5b50505060405180519050151561053c57fe5b50505050505050565b600080600160008881526020819052604090205460e060020a900460ff16600381111561056e57fe5b1461057857600080fd5b600384336003600289604051908152602090810190604051808303816000865af115156105a457600080fd5b505060405180519050604051908152602090810190604051808303816000865af115156105d057600080fd5b505060405151606060020a02868a604051606060020a600160a060020a0396871681028252948616850260148201526001606060020a031990931660288401529316909102603c82015260508101919091526070016020604051808303816000865af1151561063e57600080fd5b505060405151600088815260208190526040902054606060020a9182029350026001606060020a0319908116908316148015610698575060008781526020819052604090205460a060020a900467ffffffffffffffff1642105b15156106a357600080fd5b600087815260208190526040902080546003919060e060020a60ff02191660e060020a8361047c565b600060208190529081526040902054606060020a81029060a060020a810467ffffffffffffffff169060e060020a900460ff1683565b600080600160008881526020819052604090205460e060020a900460ff16600381111561072b57fe5b1461073557600080fd5b6003338685878a604051606060020a600160a060020a0396871681028252948616850260148201526001606060020a031990931660288401529316909102603c82015260508101919091526070016020604051808303816000865af1151561079c57600080fd5b505060405151600088815260208190526040902054606060020a9182029350026001606060020a03199081169083161480156107f7575060008781526020819052604090205460a060020a900467ffffffffffffffff164210155b151561080257600080fd5b600087815260208190526040902080546002919060e060020a60ff02191660e060020a835b0217905550600160a060020a038416151561086d57600160a060020a03331686156108fc0287604051600060405180830381858888f1935050505015156104c257600080fd5b5082600160a060020a03811663a9059cbb338860405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b151561051d57600080fd5b6000600160a060020a038416158015906108dd5750600034115b801561090b57506000808681526001602052604090205460e060020a900460ff16600381111561090957fe5b145b151561091657600080fd5b6003843385600034604051606060020a600160a060020a0396871681028252948616850260148201526001606060020a031990931660288401529316909102603c82015260508101919091526070016020604051808303816000865af1151561097e57600080fd5b505060405151606060020a029050606060405190810160409081526001606060020a03198316825267ffffffffffffffff8416602083015281016001905260008681526001602052604090208151815473ffffffffffffffffffffffffffffffffffffffff1916606060020a9091041781556020820151815467ffffffffffffffff9190911660a060020a027bffffffffffffffff00000000000000000000000000000000000000001990911617815560408201518154829060e060020a60ff02191660e060020a836003811115610a5257fe5b021790555050505050505050565b6000806003863387878b604051606060020a600160a060020a0396871681028252948616850260148201526001606060020a031990931660288401529316909102603c82015260508101919091526070016020604051808303816000865af11515610aca57600080fd5b505060405151606060020a029150606060405190810160409081526001606060020a03198416825267ffffffffffffffff8516602083015281016001905260008981526020819052604090208151815473ffffffffffffffffffffffffffffffffffffffff1916606060020a9091041781556020820151815467ffffffffffffffff9190911660a060020a027bffffffffffffffff00000000000000000000000000000000000000001990911617815560408201518154829060e060020a60ff02191660e060020a836003811115610b9e57fe5b021790555090505083905080600160a060020a03166323b872dd33308a60405160e060020a63ffffffff8616028152600160a060020a0393841660048201529190921660248201526044810191909152606401602060405180830381600087803b1515610c0a57600080fd5b5af11515610c1757600080fd5b505050604051805190501515610c2957fe5b5050505050505050565b600080600160a060020a03861615801590610c4e5750600087115b8015610c7c57506000808981526001602052604090205460e060020a900460ff166003811115610c7a57fe5b145b8015610c905750600160a060020a03841615155b1515610c9b57600080fd5b6003863387878b604051606060020a600160a060020a0396871681028252948616850260148201526001606060020a031990931660288401529316909102603c82015260508101919091526070016020604051808303816000865af11515610d0257600080fd5b505060405151606060020a029150606060405190810160409081526001606060020a03198416825267ffffffffffffffff8516602083015281016001905260008981526001602052604090208151815473ffffffffffffffffffffffffffffffffffffffff1916606060020a9091041781556020820151815467ffffffffffffffff9190911660a060020a027bffffffffffffffff00000000000000000000000000000000000000001990911617815560408201518154829060e060020a60ff02191660e060020a836003811115610b9e57fe5b6000600160a060020a03841615801590610df05750600034115b8015610e1e57506000808681526020819052604090205460e060020a900460ff166003811115610e1c57fe5b145b1515610e2957600080fd5b6003843385600034604051606060020a600160a060020a0396871681028252948616850260148201526001606060020a031990931660288401529316909102603c82015260508101919091526070016020604051808303816000865af11515610e9157600080fd5b505060405151606060020a029050606060405190810160409081526001606060020a03198316825267ffffffffffffffff8416602083015281016001905260008681526020819052604090208151815473ffffffffffffffffffffffffffffffffffffffff1916606060020a9091041781556020820151815467ffffffffffffffff9190911660a060020a027bffffffffffffffff00000000000000000000000000000000000000001990911617815560408201518154829060e060020a60ff02191660e060020a836003811115610a5257fe5b600080600160008881526001602052604090205460e060020a900460ff166003811115610f8e57fe5b14610f9857600080fd5b6003853385878a604051606060020a600160a060020a0396871681028252948616850260148201526001606060020a031990931660288401529316909102603c82015260508101919091526070016020604051808303816000865af11515610fff57600080fd5b505060405151600088815260016020526040902054606060020a91909102925060a060020a900467ffffffffffffffff16421080159061106057506000878152600160205260409020546001606060020a0319838116606060020a90920216145b151561106b57600080fd5b600087815260016020526040902080546003919060e060020a60ff02191660e060020a836108275600a165627a7a72305820a4c5ca3f359d962bbd845809ba6d9416b2d47f125f108722acbeb1d907264bcd0029' - }, - deal: { - alice: '0x485d2cc2d13a9e12E4b53D606DB1c8adc884fB8a', - bob: '0xA7EF3f65714AE266414C9E58bB4bAa4E6FB82B41' - } -}; - -module.exports = config; diff --git a/helpers/deployToken.js b/helpers/deployToken.js deleted file mode 100644 index b1f948f..0000000 --- a/helpers/deployToken.js +++ /dev/null @@ -1,41 +0,0 @@ -const Web3 = require('web3'); -const web3 = new Web3(process.env.ETH_RPC_URL); -const config = require('./config'); - -async function deploy() { - const contract = new web3.eth.Contract(config.tokenContract.abi); - - const deploy = contract.deploy({ - data: config.tokenContract.byteCode - }); - - const txInput = { - to: null, - amount: '0', - gas: (await deploy.estimateGas()) + 300000, - gasPrice: web3.utils.toWei('4', 'gwei'), - data: deploy.encodeABI() - }; - - web3.eth.accounts.signTransaction(txInput, process.env.ALICE_PK).then(transaction => { - web3.eth.sendSignedTransaction(transaction.rawTransaction) - .on('transactionHash', transactionHash => { - console.log(`txHash: ${ transactionHash }`); - }) - .on('error', (error) => { - console.log(error); - process.exit(); - }) - .catch((error) => { - console.log(error); - process.exit(); - }) - .then((receipt) => { - console.log('token contract deployed'); - console.log(receipt); - process.exit(); - }); - }); -} - -deploy(); \ No newline at end of file diff --git a/helpers/getSecretAndHash.js b/helpers/getSecretAndHash.js deleted file mode 100644 index c13ea6a..0000000 --- a/helpers/getSecretAndHash.js +++ /dev/null @@ -1,15 +0,0 @@ -const crypto = require('crypto'); -const RIPEMD160 = require('ripemd160'); - -const secret1 = new Buffer('42d928cb29f2b9c09076a7888427b8c9d401b95fb1bfcea5d83d9912528f4f73', 'hex'); -const hash1 = '0x' + new RIPEMD160().update(crypto.createHash('sha256').update(secret1).digest()).digest('hex'); -const hash256 = '0x' + crypto.createHash('sha256').update(secret1).digest('hex'); -const secret2 = crypto.randomBytes(32); -const hash2 = '0x' + new RIPEMD160().update(crypto.createHash('sha256').update(secret2).digest()).digest('hex'); - -console.log(`secret1: ${ '0x' + secret1.toString('hex') }`); -console.log(`hash1: ${ hash1 }`); -console.log(`hash256: ${ hash256 }`); -console.log(`secret2: ${ '0x' + secret2.toString('hex') }`); -console.log(`hash2: ${ hash2 }`); -console.log(`dealId: ${ '0x' + crypto.randomBytes(32).toString('hex') }`);