mirror of
https://github.com/chaintool-py/eth-erc20.git
synced 2026-03-23 05:40:48 +01:00
Compare commits
17 Commits
lash/info-
...
v0.3.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48156eb7ba
|
||
|
|
70663293af
|
||
|
|
8f8d96dfef
|
||
|
|
1ed9da5a42
|
||
|
|
aed92e96d3
|
||
|
|
cda642253b | ||
|
|
d5a48282be
|
||
|
|
90d3088061
|
||
|
|
988858e3ae
|
||
|
|
8dbab82445
|
||
|
|
4f7a068164 | ||
|
|
e3bc539424 | ||
| 6da3f2108a | |||
| 5bf187612a | |||
| e811575c33 | |||
|
|
70972e2bf8
|
||
|
|
04cfd96dbb
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ build/
|
||||
gmon.out
|
||||
*.egg-info
|
||||
.venv/
|
||||
.idea
|
||||
@@ -1,26 +1,67 @@
|
||||
stages:
|
||||
- test
|
||||
- run-coverage
|
||||
- slither-analyzer
|
||||
|
||||
|
||||
variables:
|
||||
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .cache/pip
|
||||
- venv/
|
||||
|
||||
before_script:
|
||||
- python -V # Print out python version for debugging
|
||||
- pip install virtualenv
|
||||
- virtualenv venv
|
||||
- source venv/bin/activate
|
||||
|
||||
test:
|
||||
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-py-alpine:latest
|
||||
cache:
|
||||
- key:
|
||||
files:
|
||||
- requirements.txt
|
||||
- test_requirements.txt
|
||||
paths:
|
||||
- /root/.cache/pip
|
||||
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest
|
||||
script:
|
||||
# build abi
|
||||
- 'echo "Running Solc Version: $(solc --version)"'
|
||||
- cd solidity
|
||||
- solc --evm-version=byzantium GiftableToken.sol --abi | awk 'NR>3' > GiftableToken.abi.json
|
||||
# build bin
|
||||
- solc GiftableToken.sol --bin | awk 'NR>3' > GiftableToken.bin &&
|
||||
truncate -s "$((`stat -t -c "%s" GiftableToken.bin`-1))" GiftableToken.bin
|
||||
# install test dependencies
|
||||
- cd ../python
|
||||
- export PYTHONPATH=.
|
||||
- pip install --extra-index-url https://pip.grassrootseconomics.net
|
||||
--extra-index-url https://gitlab.com/api/v4/projects/27624814/packages/pypi/simple
|
||||
-r requirements.txt -r test_requirements.txt
|
||||
# run tests
|
||||
- bash run_tests.sh
|
||||
|
||||
run-coverage:
|
||||
stage: test
|
||||
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest
|
||||
script:
|
||||
- cd python
|
||||
- pip install --extra-index-url https://pip.grassrootseconomics.net:8433 -r test_requirements.txt
|
||||
- pip install --extra-index-url https://pip.grassrootseconomics.net:8433 -r test_requirements.txt
|
||||
- bash run_tests.sh
|
||||
- export PYTHONPATH=.
|
||||
- pip install --extra-index-url https://pip.grassrootseconomics.net
|
||||
--extra-index-url https://gitlab.com/api/v4/projects/27624814/packages/pypi/simple
|
||||
-r requirements.txt -r test_requirements.txt
|
||||
- pip install pytest pytest-cov
|
||||
- coverage run -m pytest
|
||||
- coverage html
|
||||
- coverage report --fail-under=90
|
||||
|
||||
coverage: '/^TOTAL.+?(\d+\%)$/'
|
||||
artifacts:
|
||||
reports:
|
||||
cobertura: python/htmlcov/index.html
|
||||
|
||||
|
||||
slither-analize:
|
||||
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-py-alpine:latest
|
||||
slither-analyzer:
|
||||
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest
|
||||
allow_failure: true
|
||||
script:
|
||||
- pip install slither-analyzer
|
||||
- slither solidity/
|
||||
- cd solidity
|
||||
- slither GiftableToken.sol
|
||||
- slither GiftableToken.sol --print human-summary
|
||||
|
||||
|
||||
|
||||
33
Dockerfile
33
Dockerfile
@@ -1,33 +0,0 @@
|
||||
FROM ethereum/solc:0.6.12
|
||||
|
||||
FROM python:3.8.6-alpine
|
||||
|
||||
COPY --from=0 /usr/bin/solc /usr/bin/solc
|
||||
|
||||
RUN apk update &&\
|
||||
apk add gcc bash musl-dev libffi-dev openssl-dev autoconf automake build-base \
|
||||
libtool pkgconfig python3-dev cargo
|
||||
|
||||
WORKDIR /usr/src
|
||||
|
||||
# Try to keep everything above here re-usable!
|
||||
|
||||
COPY ./solidity/ /usr/src/giftable_erc20_token/solidity/
|
||||
COPY ./python/ /usr/src/giftable_erc20_token/python/
|
||||
|
||||
RUN chmod +x ./python/run_tests.sh
|
||||
|
||||
RUN cd giftable_erc20_token/solidity && \
|
||||
solc GiftableToken.sol --abi | awk 'NR>3' > GiftableToken.abi.json
|
||||
|
||||
RUN cd giftable_erc20_token/solidity && \
|
||||
solc GiftableToken.sol --bin | awk 'NR>3' > GiftableToken.bin && \
|
||||
truncate -s "$((`stat -t -c "%s" GiftableToken.bin`-1))" GiftableToken.bin
|
||||
|
||||
RUN cd giftable_erc20_token/python && \
|
||||
pip install --extra-index-url https://pip.grassrootseconomics.net:8433 .
|
||||
|
||||
RUN pip install slither-analyzer
|
||||
|
||||
# To deploy:
|
||||
# giftable-token-deploy --contracts-dir giftable_erc20_token/solidity/ <amount>
|
||||
25
README.md
Normal file
25
README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# ETH-ERC20 Solidity Contract
|
||||
|
||||
|
||||
### solidity
|
||||
|
||||
To generate bytecode and tests install solc 8.x.x and run the solc bits below or execute the following:
|
||||
|
||||
```
|
||||
docker run -v `pwd`:/src registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest solc --evm-version=byzantium solidity/GiftableToken.sol --abi
|
||||
```
|
||||
|
||||
```
|
||||
docker run -v `pwd`:/src registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest solc GiftableToken.sol --bin | awk 'NR>3' > GiftableToken.bin
|
||||
```
|
||||
|
||||
### python unit tests
|
||||
|
||||
```
|
||||
pip install --extra-index-url https://gitlab.com/api/v4/projects/27624814/packages/pypi/simple \
|
||||
--extra-index-url https://pip.grassrootseconomics.net \
|
||||
-r requirements.txt -r test_requirements.txt
|
||||
|
||||
bash python/run_tests.sh
|
||||
|
||||
```
|
||||
BIN
python/.coverage
Normal file
BIN
python/.coverage
Normal file
Binary file not shown.
7
python/.coveragerc
Normal file
7
python/.coveragerc
Normal file
@@ -0,0 +1,7 @@
|
||||
[run]
|
||||
branch = True
|
||||
[report]
|
||||
omit = .venv/*
|
||||
**/runnable/*.py
|
||||
[html]
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
* 0.0.10-pending
|
||||
* 0.3.1
|
||||
- Upgrade chainlib to 0.2.0
|
||||
* 0.1.10
|
||||
- Apply transfer ownership protection in GiftableToken contract
|
||||
* 0.1.9
|
||||
- Add statictoken contract
|
||||
* 0.0.10
|
||||
- Upgrade chainlib dependency, providing customizable jsonrpc id
|
||||
- Move to chainlib-eth
|
||||
* 0.0.9-unreleased
|
||||
* 0.0.8-unreleased
|
||||
* 0.0.7-unreleased
|
||||
* 0.0.7
|
||||
- Implement keystore signing.
|
||||
- Change makefile to compile contract for Byzantium.
|
||||
- Change mint method name to mintTo
|
||||
|
||||
@@ -217,7 +217,6 @@ class ERC20(TxFactory):
|
||||
l = len(r)
|
||||
m = v[:l]
|
||||
if m != r:
|
||||
logg.error('method mismatch, expected {}, got {}'.format(r, m))
|
||||
raise RequestMismatchException(v)
|
||||
cursor += l
|
||||
|
||||
@@ -244,7 +243,6 @@ class ERC20(TxFactory):
|
||||
l = len(r)
|
||||
m = v[:l]
|
||||
if m != r:
|
||||
logg.error('method mismatch, expected {}, got {}'.format(r, m))
|
||||
raise RequestMismatchException(v)
|
||||
cursor += l
|
||||
|
||||
@@ -273,7 +271,6 @@ class ERC20(TxFactory):
|
||||
l = len(r)
|
||||
m = v[:l]
|
||||
if m != r:
|
||||
logg.error('method mismatch, expected {}, got {}'.format(r, m))
|
||||
raise RequestMismatchException(v)
|
||||
cursor += l
|
||||
|
||||
|
||||
110
python/eth_erc20/runnable/info.py
Normal file
110
python/eth_erc20/runnable/info.py
Normal file
@@ -0,0 +1,110 @@
|
||||
#!python3
|
||||
|
||||
"""Token balance query script
|
||||
|
||||
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
||||
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||
|
||||
"""
|
||||
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# standard imports
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
# external imports
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
strip_0x,
|
||||
even,
|
||||
)
|
||||
import sha3
|
||||
|
||||
# external imports
|
||||
import chainlib.eth.cli
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
from chainlib.eth.connection import EthHTTPConnection
|
||||
from chainlib.eth.gas import (
|
||||
OverrideGasOracle,
|
||||
balance,
|
||||
)
|
||||
from chainlib.chain import ChainSpec
|
||||
|
||||
# local imports
|
||||
from eth_erc20 import ERC20
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
|
||||
arg_flags = chainlib.eth.cli.argflag_std_read | chainlib.eth.cli.Flag.EXEC
|
||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||
argparser.add_positional('item', required=False)
|
||||
args = argparser.parse_args()
|
||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags)
|
||||
|
||||
rpc = chainlib.eth.cli.Rpc()
|
||||
conn = rpc.connect_by_config(config)
|
||||
|
||||
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
||||
|
||||
token_address = config.get('_EXEC_ADDRESS')
|
||||
|
||||
|
||||
def main():
|
||||
g = ERC20(chain_spec=chain_spec, gas_oracle=rpc.get_gas_oracle())
|
||||
|
||||
if not args.item or args.item == 'name':
|
||||
name_o = g.name(token_address)
|
||||
r = conn.do(name_o)
|
||||
token_name = g.parse_name(r)
|
||||
s = ''
|
||||
if not args.item or not args.raw:
|
||||
s = 'Name: '
|
||||
s += token_name
|
||||
print(s)
|
||||
if args.item == 'name':
|
||||
sys.exit(0)
|
||||
|
||||
if not args.item or args.item == 'symbol':
|
||||
symbol_o = g.symbol(token_address)
|
||||
r = conn.do(symbol_o)
|
||||
token_symbol = g.parse_symbol(r)
|
||||
s = ''
|
||||
if not args.item or not args.raw:
|
||||
s = 'Symbol: '
|
||||
s += token_symbol
|
||||
print(s)
|
||||
if args.item == 'symbol':
|
||||
sys.exit(0)
|
||||
|
||||
if not args.item or args.item == 'decimals':
|
||||
decimals_o = g.decimals(token_address)
|
||||
r = conn.do(decimals_o)
|
||||
decimals = int(strip_0x(r), 16)
|
||||
s = ''
|
||||
if not args.item or not args.raw:
|
||||
s = 'Decimals: '
|
||||
s += str(decimals)
|
||||
print(s)
|
||||
if args.item == 'decimals':
|
||||
sys.exit(0)
|
||||
|
||||
if not args.item or args.item == 'supply':
|
||||
supply_o = g.total_supply(token_address)
|
||||
r = conn.do(supply_o)
|
||||
supply = int(strip_0x(r), 16)
|
||||
s = ''
|
||||
if not args.item or not args.raw:
|
||||
s = 'Supply: '
|
||||
s += str(supply)
|
||||
print(s)
|
||||
if args.item == 'supply':
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
File diff suppressed because one or more lines are too long
@@ -95,3 +95,5 @@ class GiftableToken(TxFactory):
|
||||
tx = self.set_code(tx, data)
|
||||
tx = self.finalize(tx, tx_format)
|
||||
return tx
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
confini~=0.5.2
|
||||
chainlib-eth~=0.0.14
|
||||
potaahto==0.1.0
|
||||
confini>=0.5.7,<0.7.0
|
||||
chainlib-eth~=0.2.0
|
||||
potaahto~=0.1.1
|
||||
|
||||
0
python/run_tests.sh
Normal file → Executable file
0
python/run_tests.sh
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = eth-erc20
|
||||
version = 0.1.5
|
||||
version = 0.3.1
|
||||
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
|
||||
@@ -30,11 +30,14 @@ packages =
|
||||
eth_erc20
|
||||
eth_erc20.data
|
||||
eth_erc20.runnable
|
||||
static_token.data
|
||||
|
||||
[options.package_data]
|
||||
* =
|
||||
data/GiftableToken.json
|
||||
data/GiftableToken.bin
|
||||
data/StaticToken.json
|
||||
data/StaticToken.bin
|
||||
data/ERC20.json
|
||||
|
||||
[options.entry_points]
|
||||
@@ -44,3 +47,4 @@ console_scripts =
|
||||
giftable-token-minter = giftable_erc20_token.runnable.minter:main
|
||||
erc20-transfer = eth_erc20.runnable.transfer:main
|
||||
erc20-balance = eth_erc20.runnable.balance:main
|
||||
erc20-info = eth_erc20.runnable.info:main
|
||||
|
||||
1
python/static_token/data/StaticToken.bin
Normal file
1
python/static_token/data/StaticToken.bin
Normal file
File diff suppressed because one or more lines are too long
1
python/static_token/data/StaticToken.json
Normal file
1
python/static_token/data/StaticToken.json
Normal file
@@ -0,0 +1 @@
|
||||
[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"uint256","name":"_supply","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferFrom","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
||||
@@ -12,6 +12,7 @@ from chainlib.eth.tx import (
|
||||
receipt,
|
||||
)
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
from hexathon import strip_0x
|
||||
|
||||
# local imports
|
||||
from giftable_erc20_token import GiftableToken
|
||||
@@ -102,7 +103,7 @@ class TestToken(EthTesterCase):
|
||||
o = transaction(tx_hash)
|
||||
r = self.rpc.do(o)
|
||||
data = c.parse_transfer_request(r['data'])
|
||||
self.assertEqual(data[0], self.accounts[1])
|
||||
self.assertEqual(data[0], strip_0x(self.accounts[1]))
|
||||
self.assertEqual(data[1], 1000)
|
||||
|
||||
|
||||
@@ -124,7 +125,7 @@ class TestToken(EthTesterCase):
|
||||
o = transaction(tx_hash)
|
||||
r = self.rpc.do(o)
|
||||
data = c.parse_approve_request(r['data'])
|
||||
self.assertEqual(data[0], self.accounts[1])
|
||||
self.assertEqual(data[0], strip_0x(self.accounts[1]))
|
||||
self.assertEqual(data[1], 1000)
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[1], conn=self.conn)
|
||||
@@ -138,8 +139,8 @@ class TestToken(EthTesterCase):
|
||||
o = transaction(tx_hash)
|
||||
r = self.rpc.do(o)
|
||||
data = c.parse_transfer_from_request(r['data'])
|
||||
self.assertEqual(data[0], self.accounts[0])
|
||||
self.assertEqual(data[1], self.accounts[2])
|
||||
self.assertEqual(data[0], strip_0x(self.accounts[0]))
|
||||
self.assertEqual(data[1], strip_0x(self.accounts[2]))
|
||||
self.assertEqual(data[2], 1001)
|
||||
|
||||
(tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[0], self.accounts[2], 1000)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
||||
pragma solidity >0.6.11;
|
||||
pragma solidity >=0.6.11;
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// File-Version: 2
|
||||
@@ -93,6 +93,7 @@ contract GiftableToken {
|
||||
|
||||
// Implements EIP173
|
||||
function transferOwnership(address _newOwner) public returns (bool) {
|
||||
require(msg.sender == owner);
|
||||
owner = _newOwner;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,11 @@ all:
|
||||
$(SOLC) --bin GiftableToken.sol --evm-version byzantium | awk 'NR>3' > GiftableToken.bin
|
||||
truncate -s -1 GiftableToken.bin
|
||||
$(SOLC) --abi GiftableToken.sol --evm-version byzantium | awk 'NR>3' > GiftableToken.json
|
||||
$(SOLC) --bin StaticToken.sol --evm-version byzantium | awk 'NR>3' > StaticToken.bin
|
||||
truncate -s -1 StaticToken.bin
|
||||
$(SOLC) --abi StaticToken.sol --evm-version byzantium | awk 'NR>3' > StaticToken.json
|
||||
|
||||
install: all
|
||||
cp -v *{json,bin} ../python/giftable_erc20_token/data/
|
||||
cp -v Giftable*{json,bin} ../python/giftable_erc20_token/data/
|
||||
cp -v Static*{json,bin} ../python/static_token/data/
|
||||
|
||||
|
||||
1
solidity/StaticToken.bin
Normal file
1
solidity/StaticToken.bin
Normal file
File diff suppressed because one or more lines are too long
1
solidity/StaticToken.json
Normal file
1
solidity/StaticToken.json
Normal file
@@ -0,0 +1 @@
|
||||
[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"uint256","name":"_supply","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferFrom","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
||||
76
solidity/StaticToken.sol
Normal file
76
solidity/StaticToken.sol
Normal file
@@ -0,0 +1,76 @@
|
||||
pragma solidity >0.6.11;
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
contract StaticToken {
|
||||
|
||||
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);
|
||||
|
||||
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _supply) public {
|
||||
owner = msg.sender;
|
||||
name = _name;
|
||||
symbol = _symbol;
|
||||
decimals = _decimals;
|
||||
totalSupply = _supply;
|
||||
balanceOf[owner] = _supply;
|
||||
}
|
||||
|
||||
// Implements ERC20
|
||||
function transfer(address _to, uint256 _value) public returns (bool) {
|
||||
require(balanceOf[msg.sender] >= _value);
|
||||
balanceOf[msg.sender] -= _value;
|
||||
balanceOf[_to] += _value;
|
||||
emit Transfer(msg.sender, _to, _value);
|
||||
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);
|
||||
allowance[_from][msg.sender] = allowance[_from][msg.sender] - _value;
|
||||
balanceOf[_from] -= _value;
|
||||
balanceOf[_to] += _value;
|
||||
emit TransferFrom(_from, _to, msg.sender, _value);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Implements ERC20
|
||||
function approve(address _spender, uint256 _value) public returns (bool) {
|
||||
if (_value > 0) {
|
||||
require(allowance[msg.sender][_spender] == 0);
|
||||
}
|
||||
allowance[msg.sender][_spender] = _value;
|
||||
emit Approval(msg.sender, _spender, _value);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Implements EIP165
|
||||
function supportsInterface(bytes4 _sum) public returns (bool) {
|
||||
if (_sum == 0xc6bb4b70) { // ERC20
|
||||
return true;
|
||||
}
|
||||
if (_sum == 0x01ffc9a7) { // EIP165
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user