mirror of https://github.com/vacp2p/minime.git
Controller interface change and fix in create clone
This commit is contained in:
parent
acbfd2056d
commit
3c48c46b01
|
@ -24,6 +24,13 @@ pragma solidity ^0.4.4;
|
||||||
/// @dev It is ERC20 compliant, but still needs to under go further testing.
|
/// @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 {
|
contract Controlled {
|
||||||
/// @notice The address of the controller is the only address that can call
|
/// @notice The address of the controller is the only address that can call
|
||||||
/// a function with this modifier
|
/// 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 {
|
contract MiniMeToken is Controlled {
|
||||||
|
|
||||||
string public name; //The Token's name: e.g. DigixDAO Tokens
|
string public name; //The Token's name: e.g. DigixDAO Tokens
|
||||||
|
@ -180,6 +181,10 @@ contract MiniMeToken is Controlled {
|
||||||
return false;
|
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
|
// First update the balance array with the new value for the address
|
||||||
// sending the tokens
|
// sending the tokens
|
||||||
updateValueAtNow(balances[_from], previousBalanceFrom - _amount);
|
updateValueAtNow(balances[_from], previousBalanceFrom - _amount);
|
||||||
|
@ -214,6 +219,10 @@ contract MiniMeToken is Controlled {
|
||||||
// already 0 https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
|
// already 0 https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
|
||||||
if ((_amount!=0) && (allowed[msg.sender][_spender] !=0)) throw;
|
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;
|
allowed[msg.sender][_spender] = _amount;
|
||||||
Approval(msg.sender, _spender, _amount);
|
Approval(msg.sender, _spender, _amount);
|
||||||
return true;
|
return true;
|
||||||
|
@ -359,6 +368,8 @@ contract MiniMeToken is Controlled {
|
||||||
_transfersEnabled
|
_transfersEnabled
|
||||||
);
|
);
|
||||||
|
|
||||||
|
cloneToken.changeController(msg.sender);
|
||||||
|
|
||||||
// An event to make the token easy to find on the blockchain
|
// An event to make the token easy to find on the blockchain
|
||||||
NewCloneToken(address(cloneToken), _snapshotBlock);
|
NewCloneToken(address(cloneToken), _snapshotBlock);
|
||||||
return address(cloneToken);
|
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
|
/// @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
|
/// set to 0, the ether is sent to the controller (normally the token
|
||||||
/// creation contract) using the `proxyPayment` method.
|
/// creation contract) using the `proxyPayment` method.
|
||||||
function () payable {
|
function () payable {
|
||||||
if (controller == 0) throw;
|
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;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -499,6 +525,8 @@ contract MiniMeTokenFactory {
|
||||||
_tokenSymbol,
|
_tokenSymbol,
|
||||||
_transfersEnabled
|
_transfersEnabled
|
||||||
);
|
);
|
||||||
|
|
||||||
|
newToken.changeController(msg.sender);
|
||||||
return newToken;
|
return newToken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ describe('MiniMeToken test', function(){
|
||||||
var b = [];
|
var b = [];
|
||||||
|
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
ethConnector.init('testrpc' ,done);
|
ethConnector.init('testrpc' ,{gasLimit: 4000000}, done);
|
||||||
// ethConnector.init('rpc', done);
|
// ethConnector.init('rpc', done);
|
||||||
});
|
});
|
||||||
it('should deploy all the contracts ', function(done){
|
it('should deploy all the contracts ', function(done){
|
||||||
|
@ -332,7 +332,7 @@ describe('MiniMeToken test', function(){
|
||||||
true,
|
true,
|
||||||
{
|
{
|
||||||
from: ethConnector.accounts[3],
|
from: ethConnector.accounts[3],
|
||||||
gas: 4700000
|
gas: 4000000
|
||||||
},
|
},
|
||||||
function(err, res) {
|
function(err, res) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
@ -350,7 +350,7 @@ describe('MiniMeToken test', function(){
|
||||||
true,
|
true,
|
||||||
{
|
{
|
||||||
from: ethConnector.accounts[3],
|
from: ethConnector.accounts[3],
|
||||||
gas: 4700000
|
gas: 4000000
|
||||||
},
|
},
|
||||||
function(err, txHash) {
|
function(err, txHash) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
@ -422,7 +422,7 @@ describe('MiniMeToken test', function(){
|
||||||
function(cb) {
|
function(cb) {
|
||||||
miniMeTokenClone.transfer(ethConnector.accounts[2], ethConnector.web3.toWei(4), {
|
miniMeTokenClone.transfer(ethConnector.accounts[2], ethConnector.web3.toWei(4), {
|
||||||
from: ethConnector.accounts[1],
|
from: ethConnector.accounts[1],
|
||||||
gas: 200000},
|
gas: 300000},
|
||||||
function(err) {
|
function(err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
cb();
|
cb();
|
||||||
|
|
Loading…
Reference in New Issue