-
Notifications
You must be signed in to change notification settings - Fork 21
ExternalLocking4Rep : add registrar #562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,20 +10,24 @@ import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; | |
|
|
||
| contract ExternalLocking4Reputation is Locking4Reputation, Ownable { | ||
|
|
||
| event Register(address indexed _beneficiary); | ||
|
|
||
| address public externalLockingContract; | ||
| string public getBalanceFuncSignature; | ||
|
|
||
| // locker -> bool | ||
| mapping(address => bool) public externalLockers; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the code would be more clear if this were called "claimers".
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even better: "claimants". |
||
| // beneficiary -> bool | ||
| mapping(address => bool) public registrar; | ||
|
|
||
| /** | ||
| * @dev initialize | ||
| * @param _avatar the avatar to mint reputation from | ||
| * @param _reputationReward the total reputation this contract will reward | ||
| * for the token locking | ||
| * @param _lockingStartTime locking starting period time. | ||
| * @param _lockingEndTime the locking end time. | ||
| * locking is disable after this time. | ||
| * @param _claimingStartTime claiming starting period time. | ||
| * @param _claimingEndTime the claiming end time. | ||
| * claiming is disable after this time. | ||
| * @param _redeemEnableTime redeem enable time . | ||
| * redeem reputation can be done after this time. | ||
| * @param _externalLockingContract the contract which lock the token. | ||
|
|
@@ -33,36 +37,45 @@ contract ExternalLocking4Reputation is Locking4Reputation, Ownable { | |
| function initialize( | ||
| Avatar _avatar, | ||
| uint _reputationReward, | ||
| uint _lockingStartTime, | ||
| uint _lockingEndTime, | ||
| uint _claimingStartTime, | ||
| uint _claimingEndTime, | ||
| uint _redeemEnableTime, | ||
| address _externalLockingContract, | ||
| string _getBalanceFuncSignature) | ||
| external | ||
| onlyOwner | ||
| { | ||
| require(_lockingEndTime > _lockingStartTime, "_lockingEndTime should be greater than _lockingStartTime"); | ||
| require(_claimingEndTime > _claimingStartTime, "_claimingEndTime should be greater than _claimingStartTime"); | ||
| externalLockingContract = _externalLockingContract; | ||
| getBalanceFuncSignature = _getBalanceFuncSignature; | ||
| super._initialize( | ||
| _avatar, | ||
| _reputationReward, | ||
| _lockingStartTime, | ||
| _lockingEndTime, | ||
| _claimingStartTime, | ||
| _claimingEndTime, | ||
| _redeemEnableTime, | ||
| 1); | ||
| } | ||
|
|
||
| /** | ||
| * @dev lock function | ||
| * @return lockingId | ||
| * @dev claim function | ||
| * @param _beneficiary the beneficiary address to claim for | ||
| * if _beneficiary == 0 the claim will be for the msg.sender. | ||
| * @return claimId | ||
| */ | ||
| function lock() public returns(bytes32) { | ||
| function claim(address _beneficiary) public returns(bytes32) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we call "_beneficiary" "_claimer"?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it is not the claimer, as one can claim for someone else, who was registered.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @leviadam I view this as a person having "authorized" anyone else to claim the tokens for them. The word "claimant" would be better here than "claimer". So I might rename the function "Register" to something else. A legal term is "Release" (to release the exclusive right to do something). Maybe "Authorize", though one is not authorizing any particular account to do the claim. Mainly I think we're being inconsistent inside the contract with the sense of "locking" and "claiming", and that is the primary source of confusion. Further, frankly I'm not wild about "claim" either. My understanding of the Magnolia contract is that what this "claim" method is doing is simply placing the claimant's tokens into a mapping from which the tokens can eventually be "unlocked" (placed in another mapping), then withdrawn (placed in another mapping) that finally allows the owner of the tokens to have control over the tokens. So what "claim" is doing is not in fact claiming anything, as the Magnolia contract currently stands (in Kovan, at 0x4eDc383aDEa781762b74E7082C03F423523e61Bb). Unless the contract is changing, "Lock" seems appropriate here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. msg.sender in this case is claiming on behalf of the claimant (here
|
||
| require(avatar != Avatar(0), "should initialize first"); | ||
| require(externalLockers[msg.sender] == false, "locking twice is not allowed"); | ||
| externalLockers[msg.sender] = true; | ||
| address beneficiary; | ||
| if (_beneficiary == address(0)) { | ||
| beneficiary = msg.sender; | ||
| } else { | ||
| require(registrar[_beneficiary],"beneficiary should be register"); | ||
| beneficiary = _beneficiary; | ||
| } | ||
| require(externalLockers[beneficiary] == false, "claiming twice is not allowed"); | ||
| externalLockers[beneficiary] = true; | ||
| // solium-disable-next-line security/no-low-level-calls | ||
| bool result = externalLockingContract.call(abi.encodeWithSignature(getBalanceFuncSignature, msg.sender)); | ||
| bool result = externalLockingContract.call(abi.encodeWithSignature(getBalanceFuncSignature, beneficiary)); | ||
| uint lockedAmount; | ||
| // solium-disable-next-line security/no-inline-assembly | ||
| assembly { | ||
|
|
@@ -73,6 +86,15 @@ contract ExternalLocking4Reputation is Locking4Reputation, Ownable { | |
| default { lockedAmount := mload(0) } | ||
| } | ||
|
|
||
| return super._lock(lockedAmount, 1, msg.sender); | ||
| return super._lock(lockedAmount, 1, beneficiary); | ||
| } | ||
|
|
||
| /** | ||
| * @dev register function | ||
| * register for external locking claim | ||
| */ | ||
| function register() public { | ||
| registrar[msg.sender] = true; | ||
| emit Register(msg.sender); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would refer to this everywhere as "Authorizing" rather than "Registering"