From 1d827eaefcfdd9706a980de81ceddece26185393 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 20 Aug 2017 18:57:15 -0700 Subject: [PATCH] first commit --- build/contracts/Migrations.json | 73 ++++++++++ build/contracts/Remittance.json | 222 ++++++++++++++++++++++++++++++ build/contracts/Splitter.json | 197 ++++++++++++++++++++++++++ contracts/Migrations.sol | 23 ++++ contracts/Remittance.sol | 67 +++++++++ contracts/Splitter.sol | 48 +++++++ migrations/1_initial_migration.js | 5 + migrations/2_deploy_contracts.js | 7 + test/TestMetacoin.sol | 25 ++++ test/metacoin.js | 63 +++++++++ truffle.js | 19 +++ 11 files changed, 749 insertions(+) create mode 100644 build/contracts/Migrations.json create mode 100644 build/contracts/Remittance.json create mode 100644 build/contracts/Splitter.json create mode 100644 contracts/Migrations.sol create mode 100644 contracts/Remittance.sol create mode 100644 contracts/Splitter.sol create mode 100644 migrations/1_initial_migration.js create mode 100644 migrations/2_deploy_contracts.js create mode 100644 test/TestMetacoin.sol create mode 100644 test/metacoin.js create mode 100644 truffle.js diff --git a/build/contracts/Migrations.json b/build/contracts/Migrations.json new file mode 100644 index 0000000..9c555c7 --- /dev/null +++ b/build/contracts/Migrations.json @@ -0,0 +1,73 @@ +{ + "contract_name": "Migrations", + "abi": [ + { + "constant": false, + "inputs": [ + { + "name": "new_address", + "type": "address" + } + ], + "name": "upgrade", + "outputs": [], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "last_completed_migration", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "completed", + "type": "uint256" + } + ], + "name": "setCompleted", + "outputs": [], + "payable": false, + "type": "function" + }, + { + "inputs": [], + "payable": false, + "type": "constructor" + } + ], + "unlinked_binary": "0x6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b6101b38061003c6000396000f300606060405263ffffffff60e060020a6000350416630900f0108114610045578063445df0ac146100665780638da5cb5b1461008b578063fdacd576146100ba575b600080fd5b341561005057600080fd5b610064600160a060020a03600435166100d2565b005b341561007157600080fd5b610079610150565b60405190815260200160405180910390f35b341561009657600080fd5b61009e610156565b604051600160a060020a03909116815260200160405180910390f35b34156100c557600080fd5b610064600435610165565b005b6000805433600160a060020a039081169116141561014a5781905080600160a060020a031663fdacd57660015460405160e060020a63ffffffff84160281526004810191909152602401600060405180830381600087803b151561013557600080fd5b6102c65a03f1151561014657600080fd5b5050505b5b5b5050565b60015481565b600054600160a060020a031681565b60005433600160a060020a03908116911614156101825760018190555b5b5b505600a165627a7a72305820d1b9769e1da046b91ec97e60e238273c882e80a1d7044e7e671701d6ffedc8710029", + "networks": { + "1503280387528": { + "events": {}, + "links": {}, + "address": "0x474a770dbfe19e9ec158f9cfca0dab5f863345d3", + "updated_at": 1503280595635 + } + }, + "schema_version": "0.0.5", + "updated_at": 1503280595635 +} \ No newline at end of file diff --git a/build/contracts/Remittance.json b/build/contracts/Remittance.json new file mode 100644 index 0000000..bfa7bcb --- /dev/null +++ b/build/contracts/Remittance.json @@ -0,0 +1,222 @@ +{ + "contract_name": "Remittance", + "abi": [ + { + "constant": true, + "inputs": [], + "name": "deadline", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "inputHash1", + "type": "bytes32" + }, + { + "name": "inputHash2", + "type": "bytes32" + } + ], + "name": "enterHashCodes", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "killMe", + "outputs": [], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "duration", + "type": "uint256" + }, + { + "name": "recieverAdd", + "type": "address" + } + ], + "name": "exchangeShop", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": true, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "verifyhash1", + "type": "bytes32" + }, + { + "name": "verifyhash2", + "type": "bytes32" + }, + { + "name": "contractOwner", + "type": "address" + } + ], + "name": "verifyFunds", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "fee", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "", + "type": "address" + } + ], + "name": "exchangeShopDetails", + "outputs": [ + { + "name": "recieverAddress", + "type": "address" + }, + { + "name": "recieverAmount", + "type": "uint256" + }, + { + "name": "deadline", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "contractAddress", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "type": "function" + }, + { + "inputs": [], + "payable": false, + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "msgSender", + "type": "address" + }, + { + "indexed": false, + "name": "recieverAddress", + "type": "address" + }, + { + "indexed": false, + "name": "contractAmount", + "type": "uint256" + } + ], + "name": "LogExchange", + "type": "event" + } + ], + "unlinked_binary": "0x6060604052341561000f57600080fd5b5b60008054600160a060020a03338116600160a060020a0319928316179092556501176592e0006003556001805430909316929091169190911790555b5b6105228061005c6000396000f3006060604052361561007d5763ffffffff60e060020a60003504166329dcb0cf81146100825780634844efaf146100a75780638da5cb5b146100d4578063b603cd8014610103578063cb6f6f1a14610118578063d4a0601214610143578063ddca3f431461017c578063ec666944146101a1578063f6b4dfb4146101f6575b600080fd5b341561008d57600080fd5b610095610225565b60405190815260200160405180910390f35b34156100b257600080fd5b6100c060043560243561022b565b604051901515815260200160405180910390f35b34156100df57600080fd5b6100e7610286565b604051600160a060020a03909116815260200160405180910390f35b341561010e57600080fd5b610116610295565b005b6100c0600435600160a060020a03602435166102bd565b604051901515815260200160405180910390f35b341561014e57600080fd5b6100c0600435602435600160a060020a0360443516610389565b604051901515815260200160405180910390f35b341561018757600080fd5b610095610459565b60405190815260200160405180910390f35b34156101ac57600080fd5b6101c0600160a060020a036004351661045f565b6040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390f35b341561020157600080fd5b6100e761048a565b604051600160a060020a03909116815260200160405180910390f35b60025481565b6000610235610499565b83836040519182526020820152604090810190519081900390208152600480546001810161026383826104ab565b916000526020600020900160005b508290815190555060019250505b5092915050565b600054600160a060020a031681565b60005433600160a060020a039081169116146102ad57fe5b600054600160a060020a0316ff5b565b60003415156102cb57600080fd5b33600160a060020a0390811660009081526005602052604090208054600160a060020a0319169184169190911790556002345b33600160a060020a038116600090815260056020526040908190209390920460018401554386016002909301929092557fbc2674b1c231352f5fe99c10d8db7182a2c0c857f496f1157968bdcbdb52bf3d91908490349051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15060015b92915050565b600083836040519182526020820152604090810190519081900390206004805460009081106103b457fe5b906000526020600020900160005b5054146103ce57600080fd5b600160a060020a0380831660009081526005602052604090819020805460019091015492169180156108fc029151600060405180830381858888f19350505050151561041957600080fd5b81600160a060020a03166108fc6003549081150290604051600060405180830381858888f19350505050151561044e57600080fd5b5060015b9392505050565b60035481565b600560205260009081526040902080546001820154600290920154600160a060020a03909116919083565b600154600160a060020a031681565b60206040519081016040526000815290565b8154818355818115116104cf576000838152602090206104cf9181019083016104d5565b5b505050565b6104f391905b808211156104ef57600081556001016104db565b5090565b905600a165627a7a723058206f4f8a8cfb441f8df103ead89f1550d76f0e6174f58d8ff82d0cc483d2628d740029", + "networks": { + "1503280387528": { + "events": { + "0xbc2674b1c231352f5fe99c10d8db7182a2c0c857f496f1157968bdcbdb52bf3d": { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "msgSender", + "type": "address" + }, + { + "indexed": false, + "name": "recieverAddress", + "type": "address" + }, + { + "indexed": false, + "name": "contractAmount", + "type": "uint256" + } + ], + "name": "LogExchange", + "type": "event" + } + }, + "links": {}, + "address": "0x44b09bd8d0b52486ad5484dca914661db7625fc1", + "updated_at": 1503280595620 + } + }, + "schema_version": "0.0.5", + "updated_at": 1503280595620 +} \ No newline at end of file diff --git a/build/contracts/Splitter.json b/build/contracts/Splitter.json new file mode 100644 index 0000000..e336684 --- /dev/null +++ b/build/contracts/Splitter.json @@ -0,0 +1,197 @@ +{ + "contract_name": "Splitter", + "abi": [ + { + "constant": true, + "inputs": [], + "name": "getBalance", + "outputs": [ + { + "name": "amount", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "getAliceBalance", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "getCarolBalance", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "sendWei", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": true, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "carol", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "killMe", + "outputs": [], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "bob", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "getBobBalance", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "alice", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "type": "function" + }, + { + "inputs": [ + { + "name": "_bob", + "type": "address" + }, + { + "name": "_carol", + "type": "address" + } + ], + "payable": false, + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "name": "receiver1", + "type": "address" + }, + { + "indexed": false, + "name": "receiver2", + "type": "address" + } + ], + "name": "LogSplitAmount", + "type": "event" + } + ], + "unlinked_binary": "0x6060604052341561000f57600080fd5b60405160408061042483398101604052808051919060200180519150505b60008054600160a060020a03338116600160a060020a0319928316179092556001805485841690831617905560028054928416929091169190911790555b50505b6103a78061007d6000396000f3006060604052361561007d5763ffffffff60e060020a60003504166312065fe0811461008257806325c4dc3c146100a757806357903b0b146100cc57806357bce8b0146100f15780638b930f151461010d578063b603cd801461013c578063c09cec7714610151578063f1a16f6814610180578063fb47e3a2146101a5575b600080fd5b341561008d57600080fd5b6100956101d4565b60405190815260200160405180910390f35b34156100b257600080fd5b6100956101e3565b60405190815260200160405180910390f35b34156100d757600080fd5b6100956101f4565b60405190815260200160405180910390f35b6100f9610205565b604051901515815260200160405180910390f35b341561011857600080fd5b610120610315565b604051600160a060020a03909116815260200160405180910390f35b341561014757600080fd5b61014f610324565b005b341561015c57600080fd5b61012061034c565b604051600160a060020a03909116815260200160405180910390f35b341561018b57600080fd5b61009561035b565b60405190815260200160405180910390f35b34156101b057600080fd5b61012061036c565b604051600160a060020a03909116815260200160405180910390f35b600160a060020a033016315b90565b600054600160a060020a0316315b90565b600254600160a060020a0316315b90565b6000805433600160a060020a0390811691161461022157600080fd5b34151561022d57600080fd5b600154600160a060020a03166108fc6002345b049081150290604051600060405180830381858888f19350505050151561026657600080fd5b60028054600160a060020a0316906108fc90345b049081150290604051600060405180830381858888f1935050505015156102a057600080fd5b6001546002547f06db731693593acc083dff79ce1fcec079345d6a9523bc1b715f844092cb0d579134913391600160a060020a039081169116604051938452600160a060020a039283166020850152908216604080850191909152911660608301526080909101905180910390a15060015b90565b600254600160a060020a031681565b60005433600160a060020a0390811691161461033c57fe5b600054600160a060020a0316ff5b565b600154600160a060020a031681565b600154600160a060020a0316315b90565b600054600160a060020a0316815600a165627a7a723058205a91733220fa530c5d9de13d01854e67283899d4298203be5b4fe6ae6ad061680029", + "networks": { + "1503280387528": { + "events": { + "0x06db731693593acc083dff79ce1fcec079345d6a9523bc1b715f844092cb0d57": { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "name": "receiver1", + "type": "address" + }, + { + "indexed": false, + "name": "receiver2", + "type": "address" + } + ], + "name": "LogSplitAmount", + "type": "event" + } + }, + "links": {}, + "address": "0x4b3d07016fa6dda112547ff73a08e8fbc054fc49", + "updated_at": 1503280595630 + } + }, + "schema_version": "0.0.5", + "updated_at": 1503280595630 +} \ No newline at end of file diff --git a/contracts/Migrations.sol b/contracts/Migrations.sol new file mode 100644 index 0000000..7e7fe8d --- /dev/null +++ b/contracts/Migrations.sol @@ -0,0 +1,23 @@ +pragma solidity ^0.4.4; + +contract Migrations { + address public owner; + uint public last_completed_migration; + + modifier restricted() { + if (msg.sender == owner) _; + } + + function Migrations() { + owner = msg.sender; + } + + function setCompleted(uint completed) restricted { + last_completed_migration = completed; + } + + function upgrade(address new_address) restricted { + Migrations upgraded = Migrations(new_address); + upgraded.setCompleted(last_completed_migration); + } +} diff --git a/contracts/Remittance.sol b/contracts/Remittance.sol new file mode 100644 index 0000000..f15f141 --- /dev/null +++ b/contracts/Remittance.sol @@ -0,0 +1,67 @@ +pragma solidity ^0.4.6; + +contract Remittance { + address public owner; + address public contractAddress; + uint public deadline; + uint public fee; + + event LogExchange(address msgSender, address recieverAddress, uint contractAmount); + + struct ExchangeShopDetails { + address recieverAddress; + uint recieverAmount; + uint deadline; + } + + struct HashCodes { + bytes32 theHash; + } + + HashCodes[] private hashCodes; + + mapping(address=>ExchangeShopDetails) public exchangeShopDetails; + + function Remittance(){ + owner = msg.sender; + fee = 300000 * 4000000 ; //Fee (gas*gasPrice) + contractAddress = this; + + } + + function enterHashCodes(bytes32 inputHash1,bytes32 inputHash2) public returns (bool success) { + + HashCodes memory newCodes; + newCodes.theHash = keccak256(inputHash1,inputHash2); + hashCodes.push(newCodes); + return true; + } + + function exchangeShop(uint duration, address recieverAdd) public payable returns (bool success) { + + if(msg.value== 0) revert(); + + exchangeShopDetails[msg.sender].recieverAddress = recieverAdd; + exchangeShopDetails[msg.sender].recieverAmount = msg.value/2; //Local Currency + exchangeShopDetails[msg.sender].deadline = block.number+duration; + + LogExchange(msg.sender, recieverAdd, msg.value ); + + return true; + } + + function verifyFunds(bytes32 verifyhash1, bytes32 verifyhash2, address contractOwner) public returns (bool success) { + + require(hashCodes[0].theHash == keccak256(verifyhash1,verifyhash2)); + exchangeShopDetails[contractOwner].recieverAddress.transfer(exchangeShopDetails[contractOwner].recieverAmount); + contractOwner.transfer(fee); + return true; + } + + + function killMe() { + assert(msg.sender==owner); + suicide(owner); + } + +} diff --git a/contracts/Splitter.sol b/contracts/Splitter.sol new file mode 100644 index 0000000..a232b0d --- /dev/null +++ b/contracts/Splitter.sol @@ -0,0 +1,48 @@ +pragma solidity ^0.4.4; + +contract Splitter { + + address public alice; + address public bob; + address public carol; + + event LogSplitAmount(uint amount,address sender,address receiver1,address receiver2); + + function Splitter(address _bob, address _carol) { + alice = msg.sender; + bob = _bob; + carol = _carol; + } + + function getBalance() public constant returns (uint amount){ + return this.balance; + } + + function sendWei() public payable returns (bool success) { + + if(msg.sender != alice) revert(); + if(msg.value == 0) revert(); + bob.transfer(msg.value / 2); + carol.transfer(msg.value / 2); + LogSplitAmount(msg.value,msg.sender,bob,carol); + return true; + } + + function getAliceBalance() public returns (uint) { + return alice.balance; + } + + function getBobBalance() public returns (uint) { + return bob.balance; + } + + function getCarolBalance() public returns (uint) { + return carol.balance; + } + + function killMe() { + assert(msg.sender==alice); + suicide(alice); + } + +} diff --git a/migrations/1_initial_migration.js b/migrations/1_initial_migration.js new file mode 100644 index 0000000..4d5f3f9 --- /dev/null +++ b/migrations/1_initial_migration.js @@ -0,0 +1,5 @@ +var Migrations = artifacts.require("./Migrations.sol"); + +module.exports = function(deployer) { + deployer.deploy(Migrations); +}; diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js new file mode 100644 index 0000000..022b0d7 --- /dev/null +++ b/migrations/2_deploy_contracts.js @@ -0,0 +1,7 @@ +var Remittance = artifacts.require("./Remittance.sol"); +var Splitter = artifacts.require("./Splitter.sol"); + +module.exports = function(deployer) { + deployer.deploy(Remittance); + deployer.deploy(Splitter); +}; diff --git a/test/TestMetacoin.sol b/test/TestMetacoin.sol new file mode 100644 index 0000000..96ccc1e --- /dev/null +++ b/test/TestMetacoin.sol @@ -0,0 +1,25 @@ +pragma solidity ^0.4.2; + +import "truffle/Assert.sol"; +import "truffle/DeployedAddresses.sol"; +import "../contracts/MetaCoin.sol"; + +contract TestMetacoin { + + function testInitialBalanceUsingDeployedContract() { + MetaCoin meta = MetaCoin(DeployedAddresses.MetaCoin()); + + uint expected = 10000; + + Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially"); + } + + function testInitialBalanceWithNewMetaCoin() { + MetaCoin meta = new MetaCoin(); + + uint expected = 10000; + + Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially"); + } + +} diff --git a/test/metacoin.js b/test/metacoin.js new file mode 100644 index 0000000..c61c093 --- /dev/null +++ b/test/metacoin.js @@ -0,0 +1,63 @@ +var MetaCoin = artifacts.require("./MetaCoin.sol"); + +contract('MetaCoin', function(accounts) { + it("should put 10000 MetaCoin in the first account", function() { + return MetaCoin.deployed().then(function(instance) { + return instance.getBalance.call(accounts[0]); + }).then(function(balance) { + assert.equal(balance.valueOf(), 10000, "10000 wasn't in the first account"); + }); + }); + it("should call a function that depends on a linked library", function() { + var meta; + var metaCoinBalance; + var metaCoinEthBalance; + + return MetaCoin.deployed().then(function(instance) { + meta = instance; + return meta.getBalance.call(accounts[0]); + }).then(function(outCoinBalance) { + metaCoinBalance = outCoinBalance.toNumber(); + return meta.getBalanceInEth.call(accounts[0]); + }).then(function(outCoinBalanceEth) { + metaCoinEthBalance = outCoinBalanceEth.toNumber(); + }).then(function() { + assert.equal(metaCoinEthBalance, 2 * metaCoinBalance, "Library function returned unexpected function, linkage may be broken"); + }); + }); + it("should send coin correctly", function() { + var meta; + + // Get initial balances of first and second account. + var account_one = accounts[0]; + var account_two = accounts[1]; + + var account_one_starting_balance; + var account_two_starting_balance; + var account_one_ending_balance; + var account_two_ending_balance; + + var amount = 10; + + return MetaCoin.deployed().then(function(instance) { + meta = instance; + return meta.getBalance.call(account_one); + }).then(function(balance) { + account_one_starting_balance = balance.toNumber(); + return meta.getBalance.call(account_two); + }).then(function(balance) { + account_two_starting_balance = balance.toNumber(); + return meta.sendCoin(account_two, amount, {from: account_one}); + }).then(function() { + return meta.getBalance.call(account_one); + }).then(function(balance) { + account_one_ending_balance = balance.toNumber(); + return meta.getBalance.call(account_two); + }).then(function(balance) { + account_two_ending_balance = balance.toNumber(); + + assert.equal(account_one_ending_balance, account_one_starting_balance - amount, "Amount wasn't correctly taken from the sender"); + assert.equal(account_two_ending_balance, account_two_starting_balance + amount, "Amount wasn't correctly sent to the receiver"); + }); + }); +}); diff --git a/truffle.js b/truffle.js new file mode 100644 index 0000000..90ca667 --- /dev/null +++ b/truffle.js @@ -0,0 +1,19 @@ +module.exports = { + networks: { + development: { // This one is optional and reduces the scope for failing fast + host: "localhost", + port: 8545, + network_id: "*" // Match any network id + }, + "net42": { + host: "localhost", + port: 8545, + network_id: 42 + }, + "ropsten": { + host: "localhost", + port: 8545, + network_id: 3 + } + } +};