I'm still pretty new to ethereum but I have a decent understanding of how it works and I've written a couple different contracts.
What I am trying to figure out is if it is possible to have n different coin types in a single contract.
So for example if I took the example coin code from the go-ethereum github
contract token {
mapping (address => uint) public coinBalanceOf;
event CoinTransfer(address sender, address receiver, uint amount);
/* Initializes contract with initial supply tokens to the creator of the contract */
function token(uint supply) {
coinBalanceOf[msg.sender] = supply;
}
/* Very simple trade function */
function sendCoin(address receiver, uint amount) returns(bool sufficient) {
if (coinBalanceOf[msg.sender] < amount) return false;
coinBalanceOf[msg.sender] -= amount;
coinBalanceOf[receiver] += amount;
CoinTransfer(msg.sender, receiver, amount);
return true;
}
}
and instead of just having the one coin type I wanted to have three different coin types, coin1, coin2, and coin3, what would be the best way to implement this in my contract?
My initial thought was to have an array of all of the different coin types and then each element in the array would contain another array that contains the address and balance information but I'm not exactly sure how I would write that.