Controller interface change and fix in create clone

This commit is contained in:
Jordi Baylina 2016-12-11 19:45:19 +01:00
parent acbfd2056d
commit 3c48c46b01
2 changed files with 39 additions and 11 deletions

View File

@ -24,6 +24,13 @@ pragma solidity ^0.4.4;
/// @dev It is ERC20 compliant, but still needs to under go further testing.
// The controller must implement this interface
contract TokenController {
function proxyPayment(address _owner) payable returns(bool);
function onTransfer(address _from, address _to, uint _amount) returns(bool);
function onApprove(address _owner, address _spender, uint _amount) returns(bool);
}
contract Controlled {
/// @notice The address of the controller is the only address that can call
/// a function with this modifier
@ -40,12 +47,6 @@ contract Controlled {
}
}
// The controller should implement this interface if wants to receive the ether
// sent directly to the token contract.
contract Controller {
function proxyPayment(address _owner) payable returns(bool);
}
contract MiniMeToken is Controlled {
string public name; //The Token's name: e.g. DigixDAO Tokens
@ -180,6 +181,10 @@ contract MiniMeToken is Controlled {
return false;
}
if ((controller != 0)&&(isContract(controller))) {
if (!TokenController(controller).onTransfer(_from, _to, _amount)) throw;
}
// First update the balance array with the new value for the address
// sending the tokens
updateValueAtNow(balances[_from], previousBalanceFrom - _amount);
@ -214,6 +219,10 @@ contract MiniMeToken is Controlled {
// already 0 https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
if ((_amount!=0) && (allowed[msg.sender][_spender] !=0)) throw;
if ((controller != 0)&&(isContract(controller))) {
if (!TokenController(controller).onApprove(msg.sender, _spender, _amount)) throw;
}
allowed[msg.sender][_spender] = _amount;
Approval(msg.sender, _spender, _amount);
return true;
@ -359,6 +368,8 @@ contract MiniMeToken is Controlled {
_transfersEnabled
);
cloneToken.changeController(msg.sender);
// An event to make the token easy to find on the blockchain
NewCloneToken(address(cloneToken), _snapshotBlock);
return address(cloneToken);
@ -449,12 +460,27 @@ contract MiniMeToken is Controlled {
}
}
// Internal function to determine if an address is a cntract
function isContract(address _addr) constant internal returns(bool) {
uint size;
assembly {
size := extcodesize(_addr)
}
return size>0;
}
/// @notice The fallback function: If the contract's controller has not been
/// set to 0, the ether is sent to the controller (normally the token
/// creation contract) using the `proxyPayment` method.
function () payable {
if (controller == 0) throw;
if (! Controller(controller).proxyPayment.value(msg.value)(msg.sender)) {
if (isContract(controller)) {
if (! TokenController(controller).proxyPayment.value(msg.value)(msg.sender)) throw;
} else {
if (! controller.send(msg.value)) throw;
}
if (! TokenController(controller).proxyPayment.value(msg.value)(msg.sender)) {
throw;
}
}
@ -499,6 +525,8 @@ contract MiniMeTokenFactory {
_tokenSymbol,
_transfersEnabled
);
newToken.changeController(msg.sender);
return newToken;
}
}

View File

@ -33,7 +33,7 @@ describe('MiniMeToken test', function(){
var b = [];
before(function(done) {
ethConnector.init('testrpc' ,done);
ethConnector.init('testrpc' ,{gasLimit: 4000000}, done);
// ethConnector.init('rpc', done);
});
it('should deploy all the contracts ', function(done){
@ -332,7 +332,7 @@ describe('MiniMeToken test', function(){
true,
{
from: ethConnector.accounts[3],
gas: 4700000
gas: 4000000
},
function(err, res) {
assert.ifError(err);
@ -350,7 +350,7 @@ describe('MiniMeToken test', function(){
true,
{
from: ethConnector.accounts[3],
gas: 4700000
gas: 4000000
},
function(err, txHash) {
assert.ifError(err);
@ -422,7 +422,7 @@ describe('MiniMeToken test', function(){
function(cb) {
miniMeTokenClone.transfer(ethConnector.accounts[2], ethConnector.web3.toWei(4), {
from: ethConnector.accounts[1],
gas: 200000},
gas: 300000},
function(err) {
assert.ifError(err);
cb();