Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

return uint128 at reputation functions. #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions contracts/Reputation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract Reputation is Ownable {

/// @dev This function makes it easy to get the total number of reputation
/// @return The total number of reputation
function totalSupply() public view returns (uint256) {
function totalSupply() public view returns (uint128) {
return totalSupplyAt(block.number);
}

Expand All @@ -59,7 +59,7 @@ contract Reputation is Ownable {
* @dev return the reputation amount of a given owner
* @param _owner an address of the owner which we want to get his reputation
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
function balanceOf(address _owner) public view returns (uint128 balance) {
return balanceOfAt(_owner, block.number);
}

Expand All @@ -68,7 +68,7 @@ contract Reputation is Ownable {
/// @param _blockNumber The block number when the balance is queried
/// @return The balance at `_blockNumber`
function balanceOfAt(address _owner, uint256 _blockNumber)
public view returns (uint256)
public view returns (uint128)
{
if ((balances[_owner].length == 0) || (balances[_owner][0].fromBlock > _blockNumber)) {
return 0;
Expand All @@ -81,7 +81,7 @@ contract Reputation is Ownable {
/// @notice Total amount of reputation at a specific `_blockNumber`.
/// @param _blockNumber The block number when the totalSupply is queried
/// @return The total amount of reputation at `_blockNumber`
function totalSupplyAt(uint256 _blockNumber) public view returns(uint256) {
function totalSupplyAt(uint256 _blockNumber) public view returns(uint128) {
if ((totalSupplyHistory.length == 0) || (totalSupplyHistory[0].fromBlock > _blockNumber)) {
return 0;
// This will return the expected totalSupply during normal situations
Expand Down Expand Up @@ -130,7 +130,7 @@ contract Reputation is Ownable {
/// @param checkpoints The history of values being queried
/// @param _block The block number to retrieve the value at
/// @return The number of reputation being queried
function getValueAt(Checkpoint[] storage checkpoints, uint256 _block) internal view returns (uint256) {
function getValueAt(Checkpoint[] storage checkpoints, uint256 _block) internal view returns (uint128) {
if (checkpoints.length == 0) {
return 0;
}
Expand All @@ -147,7 +147,9 @@ contract Reputation is Ownable {
uint256 min = 0;
uint256 max = checkpoints.length-1;
while (max > min) {
uint256 mid = (max + min + 1) / 2;
uint256 mid = (max + min + 1);
require(mid > max);
mid = mid / 2;
if (checkpoints[mid].fromBlock<=_block) {
min = mid;
} else {
Expand All @@ -162,7 +164,7 @@ contract Reputation is Ownable {
/// @param checkpoints The history of data being updated
/// @param _value The new number of reputation
function updateValueAtNow(Checkpoint[] storage checkpoints, uint256 _value) internal {
require(uint128(_value) == _value); //check value is in the 128 bits bounderies
require(uint128(_value) == _value); //check value is in the 128 bits boundaries
if ((checkpoints.length == 0) || (checkpoints[checkpoints.length - 1].fromBlock < block.number)) {
Checkpoint storage newCheckPoint = checkpoints[checkpoints.length++];
newCheckPoint.fromBlock = uint128(block.number);
Expand Down
4 changes: 0 additions & 4 deletions test/reputation.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,11 @@ contract('Reputation', accounts => {
await reputation.mint(accounts[1], rep1, { from: accounts[0] });
var tx = await reputation.mint(accounts[1], rep1, { from: accounts[0] });
await reputation.mint(accounts[3], rep1, { from: accounts[0] });


assert.equal (await reputation.totalSupply(),rep1+rep1+rep1);

assert.equal (await reputation.totalSupplyAt(tx.receipt.blockNumber),rep1+rep1);
assert.equal (await reputation.totalSupplyAt(tx.receipt.blockNumber-1),rep1);
assert.equal (await reputation.balanceOfAt(accounts[1],tx.receipt.blockNumber),rep1+rep1);
assert.equal (await reputation.balanceOfAt(accounts[1],tx.receipt.blockNumber-1),rep1);

assert.equal (await reputation.balanceOfAt(accounts[3],tx.receipt.blockNumber),0);

});
Expand Down