Version adapter

This commit is contained in:
Jordi Baylina 2017-08-04 10:32:33 +02:00
parent 8e46200213
commit 2b61f1c0fa
No known key found for this signature in database
GPG Key ID: 7480C80C1BE43112
3 changed files with 23 additions and 29 deletions

View File

@ -54,7 +54,7 @@ contract TokenController {
contract Controlled {
/// @notice The address of the controller is the only address that can call
/// a function with this modifier
modifier onlyController { if (msg.sender != controller) throw; _; }
modifier onlyController { require(msg.sender == controller); _; }
address public controller;
@ -168,7 +168,7 @@ contract MiniMeToken is Controlled {
/// @param _amount The amount of tokens to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _amount) returns (bool success) {
if (!transfersEnabled) throw;
require(transfersEnabled);
return doTransfer(msg.sender, _to, _amount);
}
@ -186,7 +186,7 @@ contract MiniMeToken is Controlled {
// controller of this contract, which in most situations should be
// another open source smart contract or 0x0
if (msg.sender != controller) {
if (!transfersEnabled) throw;
require(transfersEnabled);
// The standard ERC 20 transferFrom functionality
if (allowed[_from][msg.sender] < _amount) return false;
@ -208,10 +208,10 @@ contract MiniMeToken is Controlled {
return true;
}
if (parentSnapShotBlock >= block.number) throw;
require(parentSnapShotBlock < block.number);
// Do not allow transfer to 0x0 or the token contract itself
if ((_to == 0) || (_to == address(this))) throw;
require((_to != 0) && (_to != address(this)));
// If the amount being transfered is more than the balance of the
// account the transfer returns false
@ -222,8 +222,7 @@ contract MiniMeToken is Controlled {
// Alerts the token controller of the transfer
if (isContract(controller)) {
if (!TokenController(controller).onTransfer(_from, _to, _amount))
throw;
require(TokenController(controller).onTransfer(_from, _to, _amount));
}
// First update the balance array with the new value for the address
@ -233,7 +232,7 @@ contract MiniMeToken is Controlled {
// Then update the balance array with the new value for the address
// receiving the tokens
var previousBalanceTo = balanceOfAt(_to, block.number);
if (previousBalanceTo + _amount < previousBalanceTo) throw; // Check for overflow
require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow
updateValueAtNow(balances[_to], previousBalanceTo + _amount);
// An event to make the transfer easy to find on the blockchain
@ -255,18 +254,17 @@ contract MiniMeToken is Controlled {
/// @param _amount The amount of tokens to be approved for transfer
/// @return True if the approval was successful
function approve(address _spender, uint256 _amount) returns (bool success) {
if (!transfersEnabled) throw;
require(transfersEnabled);
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender,0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
if ((_amount!=0) && (allowed[msg.sender][_spender] !=0)) throw;
require((_amount == 0) || (allowed[msg.sender][_spender] == 0));
// Alerts the token controller of the approve function call
if (isContract(controller)) {
if (!TokenController(controller).onApprove(msg.sender, _spender, _amount))
throw;
require(TokenController(controller).onApprove(msg.sender, _spender, _amount));
}
allowed[msg.sender][_spender] = _amount;
@ -293,7 +291,7 @@ contract MiniMeToken is Controlled {
/// @return True if the function call was successful
function approveAndCall(address _spender, uint256 _amount, bytes _extraData
) returns (bool success) {
if (!approve(_spender, _amount)) throw;
require(approve(_spender, _amount));
ApproveAndCallFallBack(_spender).receiveApproval(
msg.sender,
@ -416,9 +414,9 @@ contract MiniMeToken is Controlled {
function generateTokens(address _owner, uint _amount
) onlyController returns (bool) {
uint curTotalSupply = totalSupply();
if (curTotalSupply + _amount < curTotalSupply) throw; // Check for overflow
require(curTotalSupply + _amount >= curTotalSupply); // Check for overflow
uint previousBalanceTo = balanceOf(_owner);
if (previousBalanceTo + _amount < previousBalanceTo) throw; // Check for overflow
require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow
updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount);
updateValueAtNow(balances[_owner], previousBalanceTo + _amount);
Transfer(0, _owner, _amount);
@ -433,9 +431,9 @@ contract MiniMeToken is Controlled {
function destroyTokens(address _owner, uint _amount
) onlyController returns (bool) {
uint curTotalSupply = totalSupply();
if (curTotalSupply < _amount) throw;
require(curTotalSupply >= _amount);
uint previousBalanceFrom = balanceOf(_owner);
if (previousBalanceFrom < _amount) throw;
require(previousBalanceFrom >= _amount);
updateValueAtNow(totalSupplyHistory, curTotalSupply - _amount);
updateValueAtNow(balances[_owner], previousBalanceFrom - _amount);
Transfer(_owner, 0, _amount);
@ -492,11 +490,11 @@ contract MiniMeToken is Controlled {
) internal {
if ((checkpoints.length == 0)
|| (checkpoints[checkpoints.length -1].fromBlock < block.number)) {
Checkpoint newCheckPoint = checkpoints[ checkpoints.length++ ];
Checkpoint storage newCheckPoint = checkpoints[ checkpoints.length++ ];
newCheckPoint.fromBlock = uint128(block.number);
newCheckPoint.value = uint128(_value);
} else {
Checkpoint oldCheckPoint = checkpoints[checkpoints.length-1];
Checkpoint storage oldCheckPoint = checkpoints[checkpoints.length-1];
oldCheckPoint.value = uint128(_value);
}
}
@ -522,12 +520,8 @@ contract MiniMeToken is Controlled {
/// set to 0, then the `proxyPayment` method is called which relays the
/// ether and creates tokens as described in the token controller contract
function () payable {
if (isContract(controller)) {
if (! TokenController(controller).proxyPayment.value(msg.value)(msg.sender))
throw;
} else {
throw;
}
require(isContract(controller));
require(TokenController(controller).proxyPayment.value(msg.value)(msg.sender));
}
//////////

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "minimetoken",
"version": "0.1.6",
"version": "0.1.7",
"description": "MiniMe contract",
"main": "dist/minimetoken.js",
"directories": {