Merge pull request #14 from Giveth/KeepParentHistory

Keep the parent history when you clone a token
This commit is contained in:
Jordi Baylina 2017-05-03 15:24:30 +02:00 committed by GitHub
commit 878b412664
5 changed files with 30 additions and 37 deletions

View File

@ -321,20 +321,15 @@ contract MiniMeToken is Controlled {
function balanceOfAt(address _owner, uint _blockNumber) constant
returns (uint) {
// If the `_blockNumber` requested is before the genesis block for the
// the token being queried, the value returned is 0
if (_blockNumber < creationBlock) {
return 0;
// These next few lines are used when the balance of the token is
// requested before a check point was ever created for this token, it
// requires that the `parentToken.balanceOfAt` be queried at the
// genesis block for that token as this contains initial balance of
// this token
} else if ((balances[_owner].length == 0)
if ((balances[_owner].length == 0)
|| (balances[_owner][0].fromBlock > _blockNumber)) {
if (address(parentToken) != 0) {
return parentToken.balanceOfAt(_owner, parentSnapShotBlock);
return parentToken.balanceOfAt(_owner, min(_blockNumber, parentSnapShotBlock));
} else {
// Has no parent
return 0;
@ -344,7 +339,6 @@ contract MiniMeToken is Controlled {
} else {
return getValueAt(balances[_owner], _blockNumber);
}
}
/// @notice Total amount of tokens at a specific `_blockNumber`.
@ -352,20 +346,15 @@ contract MiniMeToken is Controlled {
/// @return The total amount of tokens at `_blockNumber`
function totalSupplyAt(uint _blockNumber) constant returns(uint) {
// If the `_blockNumber` requested is before the genesis block for the
// the token being queried, the value returned is 0
if (_blockNumber < creationBlock) {
return 0;
// These next few lines are used when the totalSupply of the token is
// requested before a check point was ever created for this token, it
// requires that the `parentToken.totalSupplyAt` be queried at the
// genesis block for this token as that contains totalSupply of this
// token at this block number.
} else if ((totalSupplyHistory.length == 0)
if ((totalSupplyHistory.length == 0)
|| (totalSupplyHistory[0].fromBlock > _blockNumber)) {
if (address(parentToken) != 0) {
return parentToken.totalSupplyAt(parentSnapShotBlock);
return parentToken.totalSupplyAt(min(_blockNumber, parentSnapShotBlock));
} else {
return 0;
}
@ -522,6 +511,11 @@ contract MiniMeToken is Controlled {
return size>0;
}
/// @dev Helper function to return a min betwen the two uints
function min(uint a, uint b) internal returns (uint) {
return a < b ? a : b;
}
/// @notice The fallback function: If the contract's controller has not been
/// set to 0, then the `proxyPayment` method is called which relays the
/// ether and creates tokens as described in the token controller contract

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
import ethConnector from "ethconnector";
import path from "path";
const ethConnector = require("ethconnector");
const path = require("path");
ethConnector.compile(
path.join(__dirname, "../contracts/MiniMeToken.sol"),
@ -11,5 +11,4 @@ ethConnector.compile(
} else {
process.exit(0);
}
},
);
});

View File

@ -1,14 +1,14 @@
import async from "async";
import BigNumber from "bignumber.js";
import { deploy, sendContractTx, asyncfunc } from "runethtx";
import {
const async = require("async");
const BigNumber = require("bignumber.js");
const { deploy, sendContractTx, asyncfunc } = require("runethtx");
const {
MiniMeTokenAbi,
MiniMeTokenByteCode,
MiniMeTokenFactoryAbi,
MiniMeTokenFactoryByteCode,
} from "../contracts/MiniMeToken.sol.js";
} = require("../contracts/MiniMeToken.sol.js");
export default class MiniMeToken {
module.exports = class MiniMeToken {
constructor(web3, address) {
this.web3 = web3;

View File

@ -1,8 +1,8 @@
import ethConnector from "ethconnector";
import assert from "assert"; // node.js core module
import async from "async";
const ethConnector = require("ethconnector");
const assert = require("assert"); // node.js core module
const async = require("async");
import MiniMeToken from "../js/minimetoken";
const MiniMeToken = require("../js/minimetoken");
const verbose = false;
@ -298,7 +298,7 @@ describe("MiniMeToken test", () => {
(cb) => {
miniMeTokenClone.contract.totalSupplyAt(b[ 4 ], (err, _balance) => {
assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 0);
assert.equal(ethConnector.web3.fromWei(_balance), 7);
cb();
});
},
@ -306,7 +306,7 @@ describe("MiniMeToken test", () => {
miniMeTokenClone.contract.balanceOfAt(ethConnector.accounts[ 2 ], b[ 4 ],
(err, _balance) => {
assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 0);
assert.equal(ethConnector.web3.fromWei(_balance), 1);
cb();
});
},
@ -374,7 +374,7 @@ describe("MiniMeToken test", () => {
miniMeTokenClone.contract.balanceOfAt(ethConnector.accounts[ 1 ], b[ 4 ],
(err, _balance) => {
assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 0);
assert.equal(ethConnector.web3.fromWei(_balance), 6);
cb();
});
},
@ -382,7 +382,7 @@ describe("MiniMeToken test", () => {
miniMeTokenClone.contract.balanceOfAt(ethConnector.accounts[ 2 ], b[ 4 ],
(err, _balance) => {
assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 0);
assert.equal(ethConnector.web3.fromWei(_balance), 1);
cb();
});
},
@ -398,7 +398,7 @@ describe("MiniMeToken test", () => {
miniMeTokenClone.contract.totalSupplyAt(b[ 4 ],
(err, _totalSupply) => {
assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_totalSupply), 0);
assert.equal(ethConnector.web3.fromWei(_totalSupply), 7);
cb();
});
},