Skip to content

Make Minime ERC223 compatible #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
35 changes: 32 additions & 3 deletions contracts/MiniMeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ contract Controlled {
}
}

contract ERC223Fallback {
function tokenFallback(address _from, uint _value, bytes _data);
}

/// @dev The actual token contract, the default controller is the msg.sender
/// that deploys the contract, so usually this token will be deployed by a
/// token controller contract, which Giveth will call a "Campaign"
Expand Down Expand Up @@ -165,7 +169,7 @@ contract MiniMeToken is Controlled {
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _amount) returns (bool success) {
if (!transfersEnabled) throw;
return doTransfer(msg.sender, _to, _amount);
return doTransfer(msg.sender, _to, _amount, "");
}

/// @notice Send `_amount` tokens to `_to` from `_from` on the condition it
Expand All @@ -188,16 +192,17 @@ contract MiniMeToken is Controlled {
if (allowed[_from][msg.sender] < _amount) return false;
allowed[_from][msg.sender] -= _amount;
}
return doTransfer(_from, _to, _amount);
return doTransfer(_from, _to, _amount, "");
}

/// @dev This is the actual transfer function in the token contract, it can
/// only be called by other functions in this contract.
/// @param _from The address holding the tokens being transferred
/// @param _to The address of the recipient
/// @param _amount The amount of tokens to be transferred
/// @doTransfer _data Extra data to be added in each transfer
/// @return True if the transfer was successful
function doTransfer(address _from, address _to, uint _amount
function doTransfer(address _from, address _to, uint _amount, bytes _data
) internal returns(bool) {

if (_amount == 0) {
Expand Down Expand Up @@ -229,8 +234,15 @@ contract MiniMeToken is Controlled {
var previousBalanceTo = balanceOfAt(_to, block.number);
updateValueAtNow(balances[_to], previousBalanceTo + _amount);

if (isContract(_to)) {
ERC223Fallback(_to).tokenFallback(_from, _amount, _data);
}

// An event to make the transfer easy to find on the blockchain

// We call two transfers, one for ERC20 and other for ERC223 compatibility
Transfer(_from, _to, _amount);
Transfer(_from, _to, _amount, _data);

return true;
}
Expand Down Expand Up @@ -312,6 +324,21 @@ contract MiniMeToken is Controlled {
return totalSupplyAt(block.number);
}

///////////////
// ERC223 Compatible token
///////////////

/// @notice Send `_amount` tokens to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _amount The amount of tokens to be transferred
/// @param _data Extra data to be stored with the transfer
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _amount, bytes _data) returns (bool success) {
if (!transfersEnabled) throw;
return doTransfer(msg.sender, _to, _amount, _data);
}



////////////////
// Query balance and totalSupply in History
Expand Down Expand Up @@ -540,6 +567,7 @@ contract MiniMeToken is Controlled {
// Events
////////////////
event Transfer(address indexed _from, address indexed _to, uint256 _amount);
event Transfer(address indexed _from, address indexed _to, uint256 _amount, bytes _data);
event NewCloneToken(address indexed _cloneToken, uint _snapshotBlock);
event Approval(
address indexed _owner,
Expand Down Expand Up @@ -591,3 +619,4 @@ contract MiniMeTokenFactory {
return newToken;
}
}