Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions contracts/MeshStandardToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
This Token Contract implements the standard token functionality (https://github.com/ethereum/EIPs/issues/20) as well as the following OPTIONAL extras intended for use by mesh organizations.

In other words. This is intended for deployment in something like a Token Factory or Mist wallet, and then used by humans performing within mesh organizations.
Imagine coins, currencies, shares, voting weight, etc.
Machine-based, rapid creation of many tokens would not necessarily need these extra features or will be minted in other manners.

1) Initial Finite Supply (upon creation one specifies how much is minted).
2) In the absence of a token registry: Optional Decimal, Symbol & Name.
3) Optional approveAndCall() functionality to notify a contract if an approval() has occurred.

.*/
pragma solidity ^0.4.4;

import "./StandardToken.sol";

contract MeshStandardToken is StandardToken {

function () {
//if ether is sent to this address, send it back.
throw;
}

/* Public variables of the token */

/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; //fancy name: eg Simon Bucks
uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
string public symbol; //An identifier: eg SBX
string public version = 'M0.1'; //mesh 0.1 standard. Just an arbitrary versioning scheme.

function MeshStandardToken(
uint256 _initialAmount,
string _tokenName,
uint8 _decimalUnits,
string _tokenSymbol
) {
balances[msg.sender] = _initialAmount; // Give the creator all initial tokens
totalSupply = _initialAmount; // Update total supply
name = _tokenName; // Set the name for display purposes
decimals = _decimalUnits; // Amount of decimals for display purposes
symbol = _tokenSymbol; // Set the symbol for display purposes
}

/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);

//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
}
23 changes: 23 additions & 0 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
23 changes: 23 additions & 0 deletions contracts/test/SampleRecipientSuccess.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
This is an example contract that helps test the functionality of the approveAndCall() functionality of HumanStandardToken.sol.
This one assumes successful receival of approval.
*/
pragma solidity ^0.4.8;

contract SampleRecipientSuccess {
/* A Generic receiving function for contracts that accept tokens */
address public from;
uint256 public value;
address public tokenContract;
bytes public extraData;

event ReceivedApproval(uint256 _value);

function receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData) {
from = _from;
value = _value;
tokenContract = _tokenContract;
extraData = _extraData;
ReceivedApproval(_value);
}
}
11 changes: 11 additions & 0 deletions contracts/test/SampleRecipientThrow.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
This is an example contract that helps test the functionality of the approveAndCall() functionality of HumanStandardToken.sol.
This one will throw and thus needs to propagate the error up.
*/
pragma solidity ^0.4.8;

contract SampleRecipientThrow {
function () {
throw;
}
}
5 changes: 5 additions & 0 deletions migrations/1_initial_migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var Migrations = artifacts.require("./Migrations.sol");

module.exports = function(deployer) {
deployer.deploy(Migrations);
};
7 changes: 7 additions & 0 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var MeshStandardToken = artifacts.require("./MeshStandardToken.sol");
var HumanStandardToken = artifacts.require("./HumanStandardToken.sol");

module.exports = function(deployer) {
deployer.deploy(MeshStandardToken);
deployer.deploy(HumanStandardToken);
};
Loading