remove delegationOf from abstract/interface

This commit is contained in:
Ricardo Guilherme Schmidt 2019-03-25 05:15:23 -03:00
parent 5ab38c899a
commit 8128736580
No known key found for this signature in database
GPG Key ID: BFB3F5C8ED618A94
4 changed files with 42 additions and 71 deletions

View File

@ -18,10 +18,7 @@ interface Delegation {
* @param _who What address to lookup. * @param _who What address to lookup.
* @return The address `_who` choosen delegate to. * @return The address `_who` choosen delegate to.
*/ */
function delegatedTo(address _who) function delegatedTo(address _who) external view returns (address);
external
view
returns (address directDelegate);
/** /**
* @notice Reads `_who` configured delegation at block number `_block` or * @notice Reads `_who` configured delegation at block number `_block` or
@ -30,36 +27,6 @@ interface Delegation {
* @param _block Block number of what height in history. * @param _block Block number of what height in history.
* @return The address `_who` choosen delegate to. * @return The address `_who` choosen delegate to.
*/ */
function delegatedToAt( function delegatedToAt(address _who, uint _block) external view returns (address);
address _who,
uint _block
)
external
view
returns (address directDelegate);
/**
* @notice Reads the final delegate of `_who` at block number `_block`.
* @param _who Address to lookup.
* @return Final delegate address.
*/
function delegationOf(address _who)
external
view
returns(address finalDelegate);
/**
* @notice Reads the final delegate of `_who` at block number `_block`.
* @param _who Address to lookup.
* @param _block From what block.
* @return Final delegate address.
*/
function delegationOfAt(
address _who,
uint _block
)
external
view
returns(address finalDelegate);
} }

View File

@ -105,23 +105,4 @@ contract DelegationAbstract is InstanceAbstract, Delegation {
return _who; return _who;
} }
} }
/**
* @notice Reads the final delegate of `_who` at block number `_block`.
* @param _who Address to lookup.
* @param _block From what block.
* @return Final delegate address.
*/
function findDelegationOfAt(
address _who,
uint _block
)
internal
view
returns(address finalDelegate)
{
finalDelegate = findDelegatedToAt(_who, _block);
if (finalDelegate != _who) { //_who is delegating to someone?
finalDelegate = findDelegationOfAt(finalDelegate, _block); //yes, load the delegation of _who delegation
}
}
} }

View File

@ -40,19 +40,6 @@ contract DelegationBase is DelegationAbstract {
return findDelegatedToAt(_who, block.number); return findDelegatedToAt(_who, block.number);
} }
/**
* @notice Reads the final delegate of `_who` at block number `_block`.
* @param _who Address to lookup.
* @return Final delegate address.
*/
function delegationOf(address _who)
external
view
returns(address)
{
return findDelegationOfAt(_who, block.number);
}
/** /**
* @notice Reads `_who` configured delegation at block number `_block` in this level, * @notice Reads `_who` configured delegation at block number `_block` in this level,
* or from parent level if `_who` never defined/defined to parent address. * or from parent level if `_who` never defined/defined to parent address.
@ -71,6 +58,19 @@ contract DelegationBase is DelegationAbstract {
return findDelegatedToAt(_who, _block); return findDelegatedToAt(_who, _block);
} }
/**
* @notice Reads the final delegate of `_who` at block number `_block`.
* @param _who Address to lookup.
* @return Final delegate address.
*/
function delegationOf(address _who)
external
view
returns(address)
{
return findDelegationOfAt(_who, block.number);
}
/** /**
* @notice Reads the final delegate of `_who` at block number `_block`. * @notice Reads the final delegate of `_who` at block number `_block`.
* @param _who Address to lookup. * @param _who Address to lookup.
@ -88,4 +88,27 @@ contract DelegationBase is DelegationAbstract {
return findDelegationOfAt(_who, _block); return findDelegationOfAt(_who, _block);
} }
/**
* @notice Reads the final delegate of `_who` at block number `_block`.
* @param _who Address to lookup.
* @param _block From what block.
* @return Final delegate address.
*/
function findDelegationOfAt(
address _who,
uint _block
)
internal
view
returns(address finalDelegate)
{
finalDelegate = _who;
address last;
do {
last = finalDelegate;
finalDelegate = findDelegatedToAt(last, _block);
} while (finalDelegate != last);
}
} }

View File

@ -2,7 +2,7 @@ const utils = require("../utils/testUtils")
const DefaultDelegation = require('Embark/contracts/DefaultDelegation'); const DefaultDelegation = require('Embark/contracts/DefaultDelegation');
const DelegationFactory = require('Embark/contracts/DelegationFactory'); const DelegationFactory = require('Embark/contracts/DelegationFactory');
const Delegation = require('Embark/contracts/Delegation'); const DelegationBase = require('Embark/contracts/DelegationBase');
config({ config({
contracts: { contracts: {
@ -58,7 +58,7 @@ contract("DelegationBase", function() {
it("creates headless delegation", async function () { it("creates headless delegation", async function () {
let result = await DelegationFactory.methods.createDelegation(utils.zeroAddress).send(); let result = await DelegationFactory.methods.createDelegation(utils.zeroAddress).send();
var NoDefaultDelegation = new web3.eth.Contract(Delegation._jsonInterface, result.events.InstanceCreated.returnValues[0]); var NoDefaultDelegation = new web3.eth.Contract(DelegationBase._jsonInterface, result.events.InstanceCreated.returnValues[0]);
result = await NoDefaultDelegation.methods.delegatedTo(accounts[0]).call() result = await NoDefaultDelegation.methods.delegatedTo(accounts[0]).call()
assert.equal(result, accounts[0]) assert.equal(result, accounts[0])
result = await NoDefaultDelegation.methods.delegationOf(accounts[0]).call() result = await NoDefaultDelegation.methods.delegationOf(accounts[0]).call()
@ -67,7 +67,7 @@ contract("DelegationBase", function() {
it("creates root delegation", async function () { it("creates root delegation", async function () {
let result = await DelegationFactory.methods.createDelegation(DefaultDelegation._address).send(); let result = await DelegationFactory.methods.createDelegation(DefaultDelegation._address).send();
RootDelegation = new web3.eth.Contract(Delegation._jsonInterface, result.events.InstanceCreated.returnValues[0]); RootDelegation = new web3.eth.Contract(DelegationBase._jsonInterface, result.events.InstanceCreated.returnValues[0]);
defaultDelegate = await DefaultDelegation.methods.defaultDelegate().call(); defaultDelegate = await DefaultDelegation.methods.defaultDelegate().call();
}) })
@ -132,7 +132,7 @@ contract("DelegationBase", function() {
it("creates child delegation", async function () { it("creates child delegation", async function () {
let result = await DelegationFactory.methods.createDelegation(RootDelegation._address).send(); let result = await DelegationFactory.methods.createDelegation(RootDelegation._address).send();
ChildDelegation = new web3.eth.Contract(Delegation._jsonInterface, result.events.InstanceCreated.returnValues[0]); ChildDelegation = new web3.eth.Contract(DelegationBase._jsonInterface, result.events.InstanceCreated.returnValues[0]);
}) })
it("Child Delegate to Default", async function () { it("Child Delegate to Default", async function () {