add default fee control and events

This commit is contained in:
Ricardo Guilherme Schmidt 2018-12-19 15:22:03 -02:00
parent 91b88f6a35
commit a0209cdaca
No known key found for this signature in database
GPG Key ID: 5A2518EA28136E2B

View File

@ -1,4 +1,7 @@
pragma solidity >=0.5.0 <0.6.0;
import "../common/Controlled.sol";
/**
* @title MessageTribute
* @author Richard Ramos (Status Research & Development GmbH)
@ -9,23 +12,31 @@ pragma solidity >=0.5.0 <0.6.0;
token is deposited, and transferred from stakeholders to recipients upon receiving
a reply from the recipient.
*/
contract MessageTribute {
uint256 defaultValue;
contract MessageTribute is Controlled {
event DefaultFee(uint256 _value);
event CustomFee(address indexed _user, uint256 _value);
event ResetFee(address indexed _user);
struct Fee {
bool custom;
uint128 value;
}
uint256 public defaultValue;
mapping(address => Fee) public feeCatalog;
constructor(uint256 _defaultValue) public {
defaultValue = _defaultValue;
emit DefaultFee(_defaultValue);
}
/**
* @notice Set tribute for accounts or everyone
* @param _value Required tribute value (using token from constructor)
*/
function setRequiredTribute(uint256 _value) external {
feeCatalog[msg.sender] = Fee(true, uint128(_value));
emit CustomFee(msg.sender, _value);
}
/**
@ -33,8 +44,18 @@ contract MessageTribute {
*/
function reset() external {
delete feeCatalog[msg.sender];
emit ResetFee(msg.sender);
}
/** @notice controller can configure default fee
* @param _defaultValue fee for unset or reseted users.
*/
function setDefaultValue(uint256 _defaultValue) external onlyController {
defaultValue = _defaultValue;
emit DefaultFee(_defaultValue);
}
/**
* @notice Obtain required fee to talk with `_to`
* @param _to Account `msg.sender` wishes to talk to