Skip to content

Instantly share code, notes, and snippets.

@wadealexc
Created November 8, 2018 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wadealexc/d1d9715637dc2f730d166e11bd136a24 to your computer and use it in GitHub Desktop.
Save wadealexc/d1d9715637dc2f730d166e11bd136a24 to your computer and use it in GitHub Desktop.
Sample Account Registry utility
pragma solidity ^0.4.24;
contract ERC20_Utility {
function transfer(address _sender, address _to, uint _amt) external returns (bool);
}
contract RegisterAccount {
// Maps addresses to registry status
mapping (address => bool) public registered;
/**
* @dev Meta-ERC20-Transfer function. Requires that _to is a registered address
* @param _token The ERC20_Utility compatible token in which the transfer is being performed
* @param _to The intended recipient of the token transfer
* @param _amt The amount of tokens to transfer
* @return bool Whether the transfer was successful
*/
function transferERC20(address _token, address _to, uint _amt) external returns (bool) {
// Ensure the destination is registered
require(registered[_to], "Destination not registered!");
// Register the sender, if they are not registered already
if (!registered[msg.sender]) {
registered[msg.sender] = true;
}
// Perform the transfer, ensure it returns 'true'
require(ERC20_Utility(_token).transfer(msg.sender, _to, _amt));
return true;
}
/**
* @dev Allows an account to register themselves
*/
function registerAccount() external {
require(!registered[msg.sender]);
registered[msg.sender] = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment