mirror of
https://github.com/saymrwulf/splitter.git
synced 2026-11-18 08:56:04 +00:00
splitter contract 1st draft; migrations changed; truffle_config.js changed
This commit is contained in:
parent
1d64613d7b
commit
f24f1d0826
4 changed files with 20 additions and 15 deletions
|
|
@ -1,26 +1,23 @@
|
||||||
pragma solidity >=0.4.25 <0.6.0;
|
pragma solidity >=0.4.25 <0.6.0;
|
||||||
|
|
||||||
contract MetaCoin {
|
contract Splitter {
|
||||||
mapping (address => uint) balances;
|
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 {
|
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;
|
if (balances[msg.sender] < amount) return false;
|
||||||
balances[msg.sender] -= amount;
|
balances[msg.sender] -= amount;
|
||||||
balances[receiver] += amount;
|
balances[receiver1] += amount/2;
|
||||||
emit Transfer(msg.sender, receiver, amount);
|
balances[receiver2] += amount/2;
|
||||||
|
emit Transfer(msg.sender, receiver1, receiver2, amount);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBalanceInEth(address addr) public view returns(uint){
|
|
||||||
return ConvertLib.convert(getBalance(addr),2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBalance(address addr) public view returns(uint) {
|
function getBalance(address addr) public view returns(uint) {
|
||||||
return balances[addr];
|
return balances[addr];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
const Migrations = artifacts.require("Migrations");
|
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);
|
deployer.deploy(Migrations);
|
||||||
};
|
};
|
||||||
5
migrations/2_deploy_contracts.js
Normal file
5
migrations/2_deploy_contracts.js
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
const Splitter = artifacts.require("Splitter");
|
||||||
|
|
||||||
|
module.exports = function(deployer) {
|
||||||
|
deployer.deploy(Splitter);
|
||||||
|
};
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/*
|
|
||||||
networks: {
|
networks: {
|
||||||
development: { // this one is optional and reduces "failing fast" dummerweise
|
development: { // this one is optional and reduces "failing fast" dummerweise
|
||||||
host: "127.0.0.1",
|
host: "127.0.0.1",
|
||||||
|
|
@ -22,5 +22,5 @@ module.exports = {
|
||||||
network_id: "3"
|
network_id: "3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue