eth-erc20

ERC20 interface and example giftable token contract
Log | Files | Refs | LICENSE

commit 4da58e70c70c2dec8f0158a0444025c910e974b0
parent 00db79d6f593d8fd4794fce2585d389845aa5c3e
Author: nolash <dev@holbrook.no>
Date:   Sun,  2 May 2021 16:33:00 +0200

Update url

Diffstat:
A.gitignore | 6++++++
Mpython/MANIFEST.in | 2+-
Apython/giftable_erc20_token/data/__init__.py | 3+++
Mpython/giftable_erc20_token/runnable/deploy.py | 2+-
Mpython/requirements.txt | 5+++--
Mpython/setup.cfg | 14++++++++++----
Apython/test_requirements.txt | 3+++
Msolidity/GiftableToken.sol | 26++++++++++++++++++++++++++
8 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,6 @@ +__pycache__ +*.pyc +dist/ +build/ +gmon.out +*.egg-info diff --git a/python/MANIFEST.in b/python/MANIFEST.in @@ -1 +1 @@ -include **/data/GiftableToken.json **/data/GiftableToken.bin requirements.txt test_requirements.txt +include **/data/ERC20.json **/data/GiftableToken.json **/data/GiftableToken.bin requirements.txt test_requirements.txt diff --git a/python/giftable_erc20_token/data/__init__.py b/python/giftable_erc20_token/data/__init__.py @@ -0,0 +1,3 @@ +import os + +data_dir = os.path.realpath(os.path.dirname(__file__)) diff --git a/python/giftable_erc20_token/runnable/deploy.py b/python/giftable_erc20_token/runnable/deploy.py @@ -63,8 +63,8 @@ if args.vv: elif args.v: logg.setLevel(logging.INFO) -block_last = args.w block_all = args.ww +block_last = args.w or block_all passphrase_env = 'ETH_PASSPHRASE' if args.env_prefix != None: diff --git a/python/requirements.txt b/python/requirements.txt @@ -1,3 +1,4 @@ confini~=0.3.6rc3 -crypto-dev-signer~=0.4.14b2 -chainlib~=0.0.2a12 +crypto-dev-signer~=0.4.14b3 +chainlib~=0.0.3a1 +potaahto~=0.0.1a2 diff --git a/python/setup.cfg b/python/setup.cfg @@ -1,10 +1,10 @@ [metadata] -name = giftable-erc20-token -version = 0.0.8a9 -description = Simple ERC20 contract with deployment script that lets any address mint and gift itself tokens. +name = eth-erc20 +version = 0.0.9a1 +description = ERC20 interface and simple contract with deployment script that lets any address mint and gift itself tokens. author = Louis Holbrook author_email = dev@holbrook.no -url = https://gitlab.com/nolash/giftable-erc-token +url = https://gitlab.com/nolash/eth-erc20 keywords = ethereum classifiers = @@ -27,14 +27,20 @@ packages = giftable_erc20_token giftable_erc20_token.runnable giftable_erc20_token.data + eth_erc20 + eth_erc20.data + eth_erc20.runnable [options.package_data] * = data/GiftableToken.json data/GiftableToken.bin + data/ERC20.json [options.entry_points] console_scripts = giftable-token-deploy = giftable_erc20_token.runnable.deploy:main giftable-token-gift = giftable_erc20_token.runnable.gift:main giftable-token-minter = giftable_erc20_token.runnable.minter:main + erc20-transfer = eth_erc20.runnable.transfer:main + erc20-balance = eth_erc20.runnable.balance:main diff --git a/python/test_requirements.txt b/python/test_requirements.txt @@ -0,0 +1,3 @@ +eth_tester==0.5.0b3 +py-evm==0.3.0a20 +pytest==6.0.1 diff --git a/solidity/GiftableToken.sol b/solidity/GiftableToken.sol @@ -7,16 +7,23 @@ contract GiftableToken { address owner; mapping(address => bool) minters; + // Implements ERC20 string public name; + // Implements ERC20 string public symbol; + // Implements ERC20 uint8 public decimals; + // Implements ERC20 uint256 public totalSupply; + // Implements ERC20 mapping (address => uint256) public balanceOf; + // Implements ERC20 mapping (address => mapping (address => uint256)) public allowance; event Transfer(address indexed _from, address indexed _to, uint256 _value); event TransferFrom(address indexed _from, address indexed _to, address indexed _spender, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); + event Mint(address indexed _minter, address indexed _beneficiary, uint256 _value); constructor(string memory _name, string memory _symbol, uint8 _decimals) public { owner = msg.sender; @@ -32,6 +39,8 @@ contract GiftableToken { balanceOf[_to] += _value; totalSupply += _value; + emit Mint(msg.sender, _to, _value); + return true; } @@ -51,6 +60,7 @@ contract GiftableToken { return true; } + // Implements ERC20 function transfer(address _to, uint256 _value) public returns (bool) { require(balanceOf[msg.sender] >= _value); balanceOf[msg.sender] -= _value; @@ -59,6 +69,7 @@ contract GiftableToken { return true; } + // Implements ERC20 function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(allowance[_from][msg.sender] >= _value); require(balanceOf[_from] >= _value); @@ -69,9 +80,24 @@ contract GiftableToken { return true; } + // Implements ERC20 function approve(address _spender, uint256 _value) public returns (bool) { allowance[msg.sender][_spender] += _value; emit Approval(msg.sender, _spender, _value); return true; } + + // Implements EIP165 + function supportsInterface(bytes4 _sum) { + if (_sum == 0xc6bb4b70) { // ERC20 + return true; + } + if (_sum == 0x449a52f8) { // Minter + return true; + } + if (_sum == 0x01ffc9a7) { // EIP165 + return true; + } + return false; + } }