remove payment processing

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

View File

@ -1,8 +1,4 @@
pragma solidity >=0.5.0 <0.6.0; pragma solidity >=0.5.0 <0.6.0;
import "../token/ERC20Token.sol";
/** /**
* @title MessageTribute * @title MessageTribute
* @author Richard Ramos (Status Research & Development GmbH) * @author Richard Ramos (Status Research & Development GmbH)
@ -14,52 +10,41 @@ import "../token/ERC20Token.sol";
a reply from the recipient. a reply from the recipient.
*/ */
contract MessageTribute { contract MessageTribute {
event AudienceGranted(address indexed from, address to);
mapping(address => mapping(address => uint256)) public feeCatalog;
ERC20Token public token; uint256 defaultValue;
/** struct Fee {
* @notice Contructor of MessageTribute bool custom;
* @param _token Address of Status Network Token (or any ERC20 compatible token) uint128 value;
**/
constructor(ERC20Token _token) public {
token = _token;
} }
mapping(address => Fee) public feeCatalog;
/** /**
* @notice Set tribute for accounts or everyone * @notice Set tribute for accounts or everyone
* @param _to Address to set the tribute. If address(0), applies to everyone * @param _value Required tribute value (using token from constructor)
* @param _amount Required tribute amount (using token from constructor)
*/ */
function setRequiredTribute(address _to, uint _amount) external { function setRequiredTribute(uint256 _value) external {
feeCatalog[msg.sender][_to] = _amount; feeCatalog[msg.sender] = Fee(true, uint128(_value));
}
/**
* @notice Pay tribute to talk
*/
function payTribute(address _to) external {
address requester = msg.sender;
uint256 amount = getFee(_to, requester);
delete feeCatalog[_to][requester];
require(token.transferFrom(requester, _to, amount), "Transfer fail");
emit AudienceGranted(_to, requester);
} }
/** /**
* @notice Obtain required fee to talk with `_from` * @notice Reset to default value
* @param _from Account `msg.sender` wishes to talk to */
function reset() external {
delete feeCatalog[msg.sender];
}
/**
* @notice Obtain required fee to talk with `_to`
* @param _to Account `msg.sender` wishes to talk to
* @return Fee * @return Fee
*/ */
function getFee(address _from, address _to) public view function getFee(address _to) public view
returns (uint256) returns (uint256)
{ {
uint256 specificFee = feeCatalog[_from][_to]; Fee storage fee = feeCatalog[_to];
uint256 generalFee = feeCatalog[_from][address(0)]; return fee.custom ? uint256(fee.value) : defaultValue;
return specificFee > 0 ? specificFee : generalFee;
} }
} }