mirror of
https://github.com/status-im/contracts.git
synced 2025-02-23 20:18:42 +00:00
remove values from registry
This commit is contained in:
parent
e5cadba3b8
commit
46743c27aa
@ -4,97 +4,51 @@ import "../common/Controlled.sol";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @title MessageTribute
|
* @title MessageTribute
|
||||||
* @author Richard Ramos (Status Research & Development GmbH)
|
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)* @
|
||||||
* Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
* @notice User registry of Tribute to Talk manifests
|
||||||
* @dev Inspired by one of Satoshi Nakamoto’s original suggested use cases for Bitcoin,
|
|
||||||
we will be introducing an economics-based anti-spam filter, in our case for
|
|
||||||
receiving messages and “cold” contact requests from users.
|
|
||||||
token is deposited, and transferred from stakeholders to recipients upon receiving
|
|
||||||
a reply from the recipient.
|
|
||||||
*/
|
*/
|
||||||
contract MessageTribute is Controlled {
|
contract MessageTribute is Controlled {
|
||||||
event DefaultFee(uint256 value);
|
event Manifest(address indexed user, bytes manifest);
|
||||||
event CustomFee(address indexed user, uint256 value);
|
|
||||||
event PublicMessage(address indexed user, bytes message);
|
|
||||||
event ResetFee(address indexed user);
|
|
||||||
event Stopped(bool stop);
|
event Stopped(bool stop);
|
||||||
|
|
||||||
struct Fee {
|
|
||||||
bool custom;
|
|
||||||
uint128 value;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool public stopped;
|
bool public stopped;
|
||||||
uint256 public defaultValue;
|
mapping(address => bytes) private manifests;
|
||||||
mapping(address => Fee) public feeCatalog;
|
|
||||||
mapping(address => bytes) contenthash;
|
|
||||||
|
|
||||||
modifier notStopped {
|
modifier notStopped {
|
||||||
require(!stopped, "Contract disabled.");
|
require(!stopped, "Contract disabled.");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(uint256 _defaultValue) public {
|
|
||||||
defaultValue = _defaultValue;
|
|
||||||
emit DefaultFee(_defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice Set tribute for everyone
|
* @param _defaultManifest contenthash manifest returned for unset/reset users
|
||||||
* @param _value Required tribute value
|
|
||||||
*/
|
*/
|
||||||
function setRequiredTribute(uint256 _value) external notStopped {
|
constructor(bytes memory _defaultManifest) public {
|
||||||
feeCatalog[msg.sender] = Fee(true, uint128(_value));
|
updateManifest(address(0), _defaultManifest);
|
||||||
emit CustomFee(msg.sender, _value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notice Set tribute for everyone and public message
|
|
||||||
* @param _value Required tribute value
|
|
||||||
* @param _contenthash Contenthash of Public Message
|
|
||||||
*/
|
|
||||||
function setRequiredTribute(uint256 _value, bytes calldata _contenthash) external notStopped {
|
|
||||||
feeCatalog[msg.sender] = Fee(true, uint128(_value));
|
|
||||||
emit CustomFee(msg.sender, _value);
|
|
||||||
contenthash[msg.sender] = _contenthash;
|
|
||||||
emit PublicMessage(msg.sender, _contenthash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice Set public message
|
* @notice Set public message
|
||||||
* @param _contenthash Contenthash of Public Message
|
* @param _manifest contenthash manifest of Tribute to Talk
|
||||||
*/
|
*/
|
||||||
function updateMessage(bytes calldata _contenthash) external notStopped {
|
function setManifest(bytes calldata _manifest) external notStopped {
|
||||||
contenthash[msg.sender] = _contenthash;
|
updateManifest(msg.sender, _manifest);
|
||||||
emit PublicMessage(msg.sender, _contenthash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice Resets account params
|
* @notice Resets account to default manifest
|
||||||
*/
|
*/
|
||||||
function reset(bool value, bool message) external notStopped {
|
function resetManifest() external notStopped {
|
||||||
if(value){
|
delete manifests[msg.sender];
|
||||||
delete feeCatalog[msg.sender];
|
emit Manifest(msg.sender, new bytes(0));
|
||||||
emit ResetFee(msg.sender);
|
|
||||||
}
|
|
||||||
if(message) {
|
|
||||||
delete contenthash[msg.sender];
|
|
||||||
emit PublicMessage(msg.sender, new bytes(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice controller can configure default fee
|
* @notice controller can configure default fee
|
||||||
* @param _defaultValue fee for unset or reseted users.
|
* @param _defaultManifest contenthash manifest returned for unset/reset users
|
||||||
*/
|
*/
|
||||||
function setDefaultValue(uint256 _defaultValue) external onlyController {
|
function setDefaultManifest(bytes calldata _defaultManifest) external onlyController {
|
||||||
defaultValue = _defaultValue;
|
updateManifest(address(0), _defaultManifest);
|
||||||
emit DefaultFee(_defaultValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice controller can stop the contract
|
* @notice controller can stop the contract
|
||||||
* @param _stop true disables alterting the contract
|
* @param _stop true disables alterting the contract
|
||||||
@ -104,25 +58,26 @@ contract MessageTribute is Controlled {
|
|||||||
emit Stopped(_stop);
|
emit Stopped(_stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @notice Obtain required fee to talk with `_to`
|
|
||||||
* @param _to Account `msg.sender` wishes to talk to
|
|
||||||
* @return Fee
|
|
||||||
*/
|
|
||||||
function getFee(address _to) public view
|
|
||||||
returns (uint256)
|
|
||||||
{
|
|
||||||
Fee storage fee = feeCatalog[_to];
|
|
||||||
return fee.custom ? uint256(fee.value) : defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice Obtain public message content hash
|
* @notice Obtain public message content hash
|
||||||
* @param _who Account reading the message from.
|
* @param _who Account reading the message from.
|
||||||
* @return contenthash
|
* @return contenthash of user custom manifest, or if unset, default manifest
|
||||||
*/
|
*/
|
||||||
function getContenthash(address _who) external view returns(bytes memory) {
|
function getManifest(address _who) external view returns(bytes memory manifest) {
|
||||||
return contenthash[_who];
|
manifest = manifests[_who];
|
||||||
|
if(manifest.length == 0) {
|
||||||
|
manifest = manifests[address(0)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev changes storage and fires event
|
||||||
|
* @param account account being changed, use address(0) for default manifest
|
||||||
|
* @param manifest contenthash format data.
|
||||||
|
*/
|
||||||
|
function updateManifest(address account, bytes memory manifest) internal {
|
||||||
|
manifests[account] = manifest;
|
||||||
|
emit Manifest(account, manifest);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user