mirror of https://github.com/vacp2p/minime.git
Merge pull request #14 from Giveth/KeepParentHistory
Keep the parent history when you clone a token
This commit is contained in:
commit
878b412664
|
@ -321,20 +321,15 @@ contract MiniMeToken is Controlled {
|
||||||
function balanceOfAt(address _owner, uint _blockNumber) constant
|
function balanceOfAt(address _owner, uint _blockNumber) constant
|
||||||
returns (uint) {
|
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
|
// 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
|
// requested before a check point was ever created for this token, it
|
||||||
// requires that the `parentToken.balanceOfAt` be queried at the
|
// requires that the `parentToken.balanceOfAt` be queried at the
|
||||||
// genesis block for that token as this contains initial balance of
|
// genesis block for that token as this contains initial balance of
|
||||||
// this token
|
// this token
|
||||||
} else if ((balances[_owner].length == 0)
|
if ((balances[_owner].length == 0)
|
||||||
|| (balances[_owner][0].fromBlock > _blockNumber)) {
|
|| (balances[_owner][0].fromBlock > _blockNumber)) {
|
||||||
if (address(parentToken) != 0) {
|
if (address(parentToken) != 0) {
|
||||||
return parentToken.balanceOfAt(_owner, parentSnapShotBlock);
|
return parentToken.balanceOfAt(_owner, min(_blockNumber, parentSnapShotBlock));
|
||||||
} else {
|
} else {
|
||||||
// Has no parent
|
// Has no parent
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -344,7 +339,6 @@ contract MiniMeToken is Controlled {
|
||||||
} else {
|
} else {
|
||||||
return getValueAt(balances[_owner], _blockNumber);
|
return getValueAt(balances[_owner], _blockNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice Total amount of tokens at a specific `_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`
|
/// @return The total amount of tokens at `_blockNumber`
|
||||||
function totalSupplyAt(uint _blockNumber) constant returns(uint) {
|
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
|
// 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
|
// requested before a check point was ever created for this token, it
|
||||||
// requires that the `parentToken.totalSupplyAt` be queried at the
|
// requires that the `parentToken.totalSupplyAt` be queried at the
|
||||||
// genesis block for this token as that contains totalSupply of this
|
// genesis block for this token as that contains totalSupply of this
|
||||||
// token at this block number.
|
// token at this block number.
|
||||||
} else if ((totalSupplyHistory.length == 0)
|
if ((totalSupplyHistory.length == 0)
|
||||||
|| (totalSupplyHistory[0].fromBlock > _blockNumber)) {
|
|| (totalSupplyHistory[0].fromBlock > _blockNumber)) {
|
||||||
if (address(parentToken) != 0) {
|
if (address(parentToken) != 0) {
|
||||||
return parentToken.totalSupplyAt(parentSnapShotBlock);
|
return parentToken.totalSupplyAt(min(_blockNumber, parentSnapShotBlock));
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -522,6 +511,11 @@ contract MiniMeToken is Controlled {
|
||||||
return size>0;
|
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
|
/// @notice The fallback function: If the contract's controller has not been
|
||||||
/// set to 0, then the `proxyPayment` method is called which relays the
|
/// set to 0, then the `proxyPayment` method is called which relays the
|
||||||
/// ether and creates tokens as described in the token controller contract
|
/// ether and creates tokens as described in the token controller contract
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,5 @@
|
||||||
import ethConnector from "ethconnector";
|
const ethConnector = require("ethconnector");
|
||||||
import path from "path";
|
const path = require("path");
|
||||||
|
|
||||||
ethConnector.compile(
|
ethConnector.compile(
|
||||||
path.join(__dirname, "../contracts/MiniMeToken.sol"),
|
path.join(__dirname, "../contracts/MiniMeToken.sol"),
|
||||||
|
@ -11,5 +11,4 @@ ethConnector.compile(
|
||||||
} else {
|
} else {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import async from "async";
|
const async = require("async");
|
||||||
import BigNumber from "bignumber.js";
|
const BigNumber = require("bignumber.js");
|
||||||
import { deploy, sendContractTx, asyncfunc } from "runethtx";
|
const { deploy, sendContractTx, asyncfunc } = require("runethtx");
|
||||||
import {
|
const {
|
||||||
MiniMeTokenAbi,
|
MiniMeTokenAbi,
|
||||||
MiniMeTokenByteCode,
|
MiniMeTokenByteCode,
|
||||||
MiniMeTokenFactoryAbi,
|
MiniMeTokenFactoryAbi,
|
||||||
MiniMeTokenFactoryByteCode,
|
MiniMeTokenFactoryByteCode,
|
||||||
} from "../contracts/MiniMeToken.sol.js";
|
} = require("../contracts/MiniMeToken.sol.js");
|
||||||
|
|
||||||
export default class MiniMeToken {
|
module.exports = class MiniMeToken {
|
||||||
|
|
||||||
constructor(web3, address) {
|
constructor(web3, address) {
|
||||||
this.web3 = web3;
|
this.web3 = web3;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import ethConnector from "ethconnector";
|
const ethConnector = require("ethconnector");
|
||||||
import assert from "assert"; // node.js core module
|
const assert = require("assert"); // node.js core module
|
||||||
import async from "async";
|
const async = require("async");
|
||||||
|
|
||||||
import MiniMeToken from "../js/minimetoken";
|
const MiniMeToken = require("../js/minimetoken");
|
||||||
|
|
||||||
const verbose = false;
|
const verbose = false;
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ describe("MiniMeToken test", () => {
|
||||||
(cb) => {
|
(cb) => {
|
||||||
miniMeTokenClone.contract.totalSupplyAt(b[ 4 ], (err, _balance) => {
|
miniMeTokenClone.contract.totalSupplyAt(b[ 4 ], (err, _balance) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(ethConnector.web3.fromWei(_balance), 0);
|
assert.equal(ethConnector.web3.fromWei(_balance), 7);
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -306,7 +306,7 @@ describe("MiniMeToken test", () => {
|
||||||
miniMeTokenClone.contract.balanceOfAt(ethConnector.accounts[ 2 ], b[ 4 ],
|
miniMeTokenClone.contract.balanceOfAt(ethConnector.accounts[ 2 ], b[ 4 ],
|
||||||
(err, _balance) => {
|
(err, _balance) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(ethConnector.web3.fromWei(_balance), 0);
|
assert.equal(ethConnector.web3.fromWei(_balance), 1);
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -374,7 +374,7 @@ describe("MiniMeToken test", () => {
|
||||||
miniMeTokenClone.contract.balanceOfAt(ethConnector.accounts[ 1 ], b[ 4 ],
|
miniMeTokenClone.contract.balanceOfAt(ethConnector.accounts[ 1 ], b[ 4 ],
|
||||||
(err, _balance) => {
|
(err, _balance) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(ethConnector.web3.fromWei(_balance), 0);
|
assert.equal(ethConnector.web3.fromWei(_balance), 6);
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -382,7 +382,7 @@ describe("MiniMeToken test", () => {
|
||||||
miniMeTokenClone.contract.balanceOfAt(ethConnector.accounts[ 2 ], b[ 4 ],
|
miniMeTokenClone.contract.balanceOfAt(ethConnector.accounts[ 2 ], b[ 4 ],
|
||||||
(err, _balance) => {
|
(err, _balance) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(ethConnector.web3.fromWei(_balance), 0);
|
assert.equal(ethConnector.web3.fromWei(_balance), 1);
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -398,7 +398,7 @@ describe("MiniMeToken test", () => {
|
||||||
miniMeTokenClone.contract.totalSupplyAt(b[ 4 ],
|
miniMeTokenClone.contract.totalSupplyAt(b[ 4 ],
|
||||||
(err, _totalSupply) => {
|
(err, _totalSupply) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(ethConnector.web3.fromWei(_totalSupply), 0);
|
assert.equal(ethConnector.web3.fromWei(_totalSupply), 7);
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue