Created
December 20, 2018 08:43
-
-
Save lyhistory/08646fc88d96ecf11680272f098b8924 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.0+commit.1d4f565a.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
contract metaCoin { | |
mapping (address => uint) public balances; | |
constructor() public{ | |
balances[msg.sender] = 10000; | |
} | |
function balancesOf(address addr) public returns(uint){ | |
return balances[addr]; | |
} | |
function sendToken(address receiver, uint amount) public returns(bool successful){ | |
if (balances[msg.sender] < amount) return false; | |
balances[msg.sender] -= amount; | |
balances[receiver] += amount; | |
return false; | |
} | |
} | |
contract coinCaller{ | |
struct transfer{ | |
metaCoin coinContract; | |
uint amount; | |
address recipient; | |
bool successful; | |
uint balance; | |
} | |
mapping(uint => transfer) transfers; | |
uint numTransfers; | |
function sendCoin(address coinContractAddress, address receiver, uint amount) public{ | |
transfer memory t = transfers[numTransfers]; //Creates a reference t | |
t.coinContract = metaCoin(coinContractAddress); | |
t.amount = amount; | |
t.recipient = receiver; | |
t.successful = t.coinContract.sendToken(receiver, amount); | |
t.balance = t.coinContract.balances(address(this)); | |
numTransfers++; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
contract metaCoin { | |
mapping (address => uint) public balances; | |
constructor(uint initialBalance) public{ | |
balances[tx.origin] = initialBalance; | |
} | |
function sendToken(address receiver, uint amount) public returns(bool){ | |
if (balances[msg.sender] < amount) return false; | |
balances[msg.sender] -= amount; | |
balances[receiver] += amount; | |
return false; | |
} | |
} | |
contract coinSpawn{ | |
mapping(uint => metaCoin) deployedContracts; | |
uint numContracts; | |
function createCoin(uint initialBalance) public returns(address){ | |
deployedContracts[numContracts] = new metaCoin(initialBalance); | |
numContracts++; | |
return address(deployedContracts[numContracts-1]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment