From f24f1d08266c941764c20b94aab5de6efab3f2ee Mon Sep 17 00:00:00 2001 From: oho Date: Sun, 19 May 2019 14:43:10 +0200 Subject: [PATCH] splitter contract 1st draft; migrations changed; truffle_config.js changed --- contracts/Splitter.sol | 19 ++++++++----------- migrations/1_initial_migration.js | 7 +++++-- migrations/2_deploy_contracts.js | 5 +++++ truffle-config.js | 4 ++-- 4 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 migrations/2_deploy_contracts.js diff --git a/contracts/Splitter.sol b/contracts/Splitter.sol index abf6cf6..c3b5956 100644 --- a/contracts/Splitter.sol +++ b/contracts/Splitter.sol @@ -1,26 +1,23 @@ pragma solidity >=0.4.25 <0.6.0; -contract MetaCoin { - mapping (address => uint) balances; +contract Splitter { + mapping (address => uint) public balances; - event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Transfer(address indexed _from, address indexed _to1, address indexed _to2, uint256 _value); constructor() public { - balances[tx.origin] = 10000; + balances[msg.sender] = 10000; } - function sendCoin(address receiver, uint amount) public returns(bool sufficient) { + function sendSplitCoin(address receiver1, address receiver2, uint amount) public returns(bool sufficient) { if (balances[msg.sender] < amount) return false; balances[msg.sender] -= amount; - balances[receiver] += amount; - emit Transfer(msg.sender, receiver, amount); + balances[receiver1] += amount/2; + balances[receiver2] += amount/2; + emit Transfer(msg.sender, receiver1, receiver2, amount); return true; } - function getBalanceInEth(address addr) public view returns(uint){ - return ConvertLib.convert(getBalance(addr),2); - } - function getBalance(address addr) public view returns(uint) { return balances[addr]; } diff --git a/migrations/1_initial_migration.js b/migrations/1_initial_migration.js index ee2135d..5cfe349 100644 --- a/migrations/1_initial_migration.js +++ b/migrations/1_initial_migration.js @@ -1,5 +1,8 @@ const Migrations = artifacts.require("Migrations"); -module.exports = function(deployer) { +module.exports = function(deployer, network, accounts) { + console.log("network: ", network); + console.log("accounts: ", accounts); + deployer.deploy(Migrations); -}; +}; \ No newline at end of file diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js new file mode 100644 index 0000000..325690d --- /dev/null +++ b/migrations/2_deploy_contracts.js @@ -0,0 +1,5 @@ +const Splitter = artifacts.require("Splitter"); + +module.exports = function(deployer) { + deployer.deploy(Splitter); +}; diff --git a/truffle-config.js b/truffle-config.js index dfe3b8d..77d00f1 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -1,5 +1,5 @@ module.exports = { - /* + networks: { development: { // this one is optional and reduces "failing fast" dummerweise host: "127.0.0.1", @@ -22,5 +22,5 @@ module.exports = { network_id: "3" } } -*/ + };