use delegate(address(0)) to reset to parent

This commit is contained in:
Ricardo Guilherme Schmidt 2019-03-20 22:05:03 -03:00
parent 3eb48a9b65
commit 0e6c159188
No known key found for this signature in database
GPG Key ID: BFB3F5C8ED618A94
2 changed files with 32 additions and 27 deletions

View File

@ -5,16 +5,16 @@ interface Delegation {
event Delegate(address who, address to);
/**
* @notice Changes the delegation of `msg.sender` to `_to`. if _to 0x00: delegate to self.
* In case of having a parent proxy, if never defined, fall back to parent proxy.
* If once defined and want to delegate to parent proxy, set `_to` as parent address.
* @param _to To what address the caller address will delegate to.
* @notice Set `msg.sender` delegate.
* `_to == address(0)` resets to parent delegation
* `_to == msg.sender` ends delegate chain.
* @param _to Address the caller will delegate to.
*/
function delegate(address _to) external;
/**
* @notice Reads `_who` configured delegation in this level,
* or from parent level if `_who` never defined/defined to parent address.
* @notice Reads `_who` configured delegation in this level or
* from parent level if `_who` never defined/reset.
* @param _who What address to lookup.
* @return The address `_who` choosen delegate to.
*/
@ -24,18 +24,8 @@ interface Delegation {
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 `_who` configured delegation at block number `_block` in this level,
* or from parent level if `_who` never defined/defined to parent address.
* @notice Reads `_who` configured delegation at block number `_block` or
* from parent level if `_who` never defined/reset.
* @param _who What address to lookup.
* @param _block Block number of what height in history.
* @return The address `_who` choosen delegate to.
@ -48,6 +38,16 @@ interface Delegation {
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.

View File

@ -24,9 +24,9 @@ contract DelegationAbstract is InstanceAbstract, Delegation {
}
/**
* @dev Changes the delegation of `_from` to `_to`. if _to 0x00: delegate to self.
* In case of having a parent proxy, if never defined, fall back to parent proxy.
* If once defined and want to delegate to parent proxy, set `_to` as parent address.
* @dev Changes the delegation of `_from` to `_to`.
* If `_to` is set to 0x00, fall to parent proxy.
* If `_to == _from` removes delegation.
* @param _from Address delegating.
* @param _to Address delegated.
*/
@ -94,9 +94,14 @@ contract DelegationAbstract is InstanceAbstract, Delegation {
}
}
DelegateSet memory d = getMemoryAt(checkpoints, _block);
// Case user set delegate to parentDelegation address
if (d.to == address(parentDelegation)) {
return Delegation(parentDelegation).delegatedToAt(_who, _block);
// Case user unset delegation
if (d.to == address(0)) {
if (address(parentDelegation) != address(0)) {
return Delegation(parentDelegation).delegatedToAt(_who, _block);
} else {
return _who;
}
}
return d.to;
}
@ -116,10 +121,10 @@ contract DelegationAbstract is InstanceAbstract, Delegation {
returns(address finalDelegate)
{
finalDelegate = findDelegatedToAt(_who, _block);
if (finalDelegate != _who) { //_who is delegating?
return findDelegationOfAt(finalDelegate, _block); //load the delegation of _who delegation
if (finalDelegate == _who) { //_who is delegating to someone?
return _who; //no, reached the endpoint of delegation
} else {
return _who; //reached the endpoint of delegation
return findDelegationOfAt(finalDelegate, _block); //yes, load the delegation of _who delegation
}
}