mirror of
https://github.com/chaintool-py/eth-erc20.git
synced 2026-04-25 12:17:15 +02:00
Compare commits
3 Commits
v0.5.5
...
lash/appro
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cb8f744e8
|
||
|
|
edb35b3ead
|
||
|
|
fde30511de
|
@@ -7,7 +7,6 @@ from hexathon import (
|
|||||||
add_0x,
|
add_0x,
|
||||||
strip_0x,
|
strip_0x,
|
||||||
)
|
)
|
||||||
from crypto_dev_signer.eth.transaction import EIP155Transaction
|
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from chainlib.hash import (
|
from chainlib.hash import (
|
||||||
|
|||||||
99
python/eth_erc20/runnable/approve.py
Normal file
99
python/eth_erc20/runnable/approve.py
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#!python3
|
||||||
|
|
||||||
|
"""Token transfer script
|
||||||
|
|
||||||
|
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
||||||
|
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# standard imports
|
||||||
|
import os
|
||||||
|
import io
|
||||||
|
import json
|
||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# external imports
|
||||||
|
from hexathon import (
|
||||||
|
add_0x,
|
||||||
|
strip_0x,
|
||||||
|
)
|
||||||
|
from chainlib.eth.connection import EthHTTPConnection
|
||||||
|
from chainlib.chain import ChainSpec
|
||||||
|
from chainlib.eth.runnable.util import decode_for_puny_humans
|
||||||
|
from chainlib.eth.address import to_checksum_address
|
||||||
|
import chainlib.eth.cli
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from eth_erc20 import ERC20
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.WARNING)
|
||||||
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC | chainlib.eth.cli.Flag.WALLET
|
||||||
|
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||||
|
argparser.add_positional('amount', type=int, help='Token amount to send')
|
||||||
|
args = argparser.parse_args()
|
||||||
|
extra_args = {
|
||||||
|
'amount': None,
|
||||||
|
}
|
||||||
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=100000)
|
||||||
|
|
||||||
|
block_all = args.ww
|
||||||
|
block_last = args.w or block_all
|
||||||
|
|
||||||
|
wallet = chainlib.eth.cli.Wallet()
|
||||||
|
wallet.from_config(config)
|
||||||
|
|
||||||
|
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
|
||||||
|
conn = rpc.connect_by_config(config)
|
||||||
|
|
||||||
|
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
||||||
|
|
||||||
|
value = config.get('_AMOUNT')
|
||||||
|
|
||||||
|
send = config.true('_RPC_SEND')
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
signer = rpc.get_signer()
|
||||||
|
signer_address = rpc.get_sender_address()
|
||||||
|
|
||||||
|
gas_oracle = rpc.get_gas_oracle()
|
||||||
|
nonce_oracle = rpc.get_nonce_oracle()
|
||||||
|
|
||||||
|
g = ERC20(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
|
||||||
|
|
||||||
|
recipient = to_checksum_address(config.get('_RECIPIENT'))
|
||||||
|
if not config.true('_UNSAFE') and recipient != add_0x(config.get('_RECIPIENT')):
|
||||||
|
raise ValueError('invalid checksum address for recipient')
|
||||||
|
|
||||||
|
token_address = to_checksum_address(config.get('_EXEC_ADDRESS'))
|
||||||
|
if not config.true('_UNSAFE') and token_address != add_0x(config.get('_EXEC_ADDRESS')):
|
||||||
|
raise ValueError('invalid checksum address for contract')
|
||||||
|
|
||||||
|
(tx_hash_hex, o) = g.approve(token_address, signer_address, recipient, value, id_generator=rpc.id_generator)
|
||||||
|
|
||||||
|
if send:
|
||||||
|
conn.do(o)
|
||||||
|
if block_last:
|
||||||
|
r = conn.wait(tx_hash_hex)
|
||||||
|
if logg.isEnabledFor(logging.DEBUG):
|
||||||
|
sender_balance = balance(g, token_address, signer_address, id_generator=rpc.id_generator)
|
||||||
|
recipient_balance = balance(g, token_address, recipient, id_generator=rpc.id_generator)
|
||||||
|
logg.debug('sender {} balance after: {}'.format(signer_address, sender_balance))
|
||||||
|
logg.debug('recipient {} balance after: {}'.format(recipient, recipient_balance))
|
||||||
|
if r['status'] == 0:
|
||||||
|
logg.critical('VM revert. Wish I could tell you more')
|
||||||
|
sys.exit(1)
|
||||||
|
print(tx_hash_hex)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print(o['params'][0])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -24,7 +24,10 @@ from hexathon import (
|
|||||||
from chainlib.eth.connection import EthHTTPConnection
|
from chainlib.eth.connection import EthHTTPConnection
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from chainlib.eth.runnable.util import decode_for_puny_humans
|
from chainlib.eth.runnable.util import decode_for_puny_humans
|
||||||
from chainlib.eth.address import to_checksum_address
|
from chainlib.eth.address import (
|
||||||
|
to_checksum_address,
|
||||||
|
is_same_address,
|
||||||
|
)
|
||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
@@ -35,10 +38,12 @@ logg = logging.getLogger()
|
|||||||
|
|
||||||
arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC | chainlib.eth.cli.Flag.WALLET
|
arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC | chainlib.eth.cli.Flag.WALLET
|
||||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||||
|
argparser.add_argument('--from', type=str, help='Address to send on behalf of')
|
||||||
argparser.add_positional('amount', type=int, help='Token amount to send')
|
argparser.add_positional('amount', type=int, help='Token amount to send')
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
extra_args = {
|
extra_args = {
|
||||||
'amount': None,
|
'amount': None,
|
||||||
|
'from': None,
|
||||||
}
|
}
|
||||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=100000)
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=100000)
|
||||||
|
|
||||||
@@ -82,22 +87,37 @@ def main():
|
|||||||
if not config.true('_UNSAFE') and token_address != add_0x(config.get('_EXEC_ADDRESS')):
|
if not config.true('_UNSAFE') and token_address != add_0x(config.get('_EXEC_ADDRESS')):
|
||||||
raise ValueError('invalid checksum address for contract')
|
raise ValueError('invalid checksum address for contract')
|
||||||
|
|
||||||
|
transfer_from_address = None
|
||||||
|
if config.get('_FROM'):
|
||||||
|
transfer_from_address = to_checksum_address(config.get('_FROM'))
|
||||||
|
if not config.true('_UNSAFE') and transfer_from_address != add_0x(config.get('_FROM')):
|
||||||
|
raise ValueError('invalid checksum address for "from" argument')
|
||||||
|
|
||||||
|
check_balance_address = None
|
||||||
|
|
||||||
if logg.isEnabledFor(logging.DEBUG):
|
if logg.isEnabledFor(logging.DEBUG):
|
||||||
sender_balance = balance(g, token_address, signer_address, id_generator=rpc.id_generator)
|
if transfer_from_address:
|
||||||
|
check_balance_address = transfer_from_address
|
||||||
|
else:
|
||||||
|
check_balance_address = signer_address
|
||||||
|
sender_balance = balance(g, token_address, check_balance_address, id_generator=rpc.id_generator)
|
||||||
recipient_balance = balance(g, token_address, recipient, id_generator=rpc.id_generator)
|
recipient_balance = balance(g, token_address, recipient, id_generator=rpc.id_generator)
|
||||||
logg.debug('sender {} balance before: {}'.format(signer_address, sender_balance))
|
logg.debug('sender {} balance before: {}'.format(check_balance_address, sender_balance))
|
||||||
logg.debug('recipient {} balance before: {}'.format(recipient, recipient_balance))
|
logg.debug('recipient {} balance before: {}'.format(recipient, recipient_balance))
|
||||||
|
|
||||||
(tx_hash_hex, o) = g.transfer(token_address, signer_address, recipient, value, id_generator=rpc.id_generator)
|
if transfer_from_address and not is_same_address(transfer_from_address, signer_address):
|
||||||
|
(tx_hash_hex, o) = g.transfer_from(token_address, signer_address, transfer_from_address, recipient, value, id_generator=rpc.id_generator)
|
||||||
|
else:
|
||||||
|
(tx_hash_hex, o) = g.transfer(token_address, signer_address, recipient, value, id_generator=rpc.id_generator)
|
||||||
|
|
||||||
if send:
|
if send:
|
||||||
conn.do(o)
|
conn.do(o)
|
||||||
if block_last:
|
if block_last:
|
||||||
r = conn.wait(tx_hash_hex)
|
r = conn.wait(tx_hash_hex)
|
||||||
if logg.isEnabledFor(logging.DEBUG):
|
if logg.isEnabledFor(logging.DEBUG):
|
||||||
sender_balance = balance(g, token_address, signer_address, id_generator=rpc.id_generator)
|
sender_balance = balance(g, token_address, check_balance_address, id_generator=rpc.id_generator)
|
||||||
recipient_balance = balance(g, token_address, recipient, id_generator=rpc.id_generator)
|
recipient_balance = balance(g, token_address, recipient, id_generator=rpc.id_generator)
|
||||||
logg.debug('sender {} balance after: {}'.format(signer_address, sender_balance))
|
logg.debug('sender {} balance after: {}'.format(check_balance_address, sender_balance))
|
||||||
logg.debug('recipient {} balance after: {}'.format(recipient, recipient_balance))
|
logg.debug('recipient {} balance after: {}'.format(recipient, recipient_balance))
|
||||||
if r['status'] == 0:
|
if r['status'] == 0:
|
||||||
logg.critical('VM revert. Wish I could tell you more')
|
logg.critical('VM revert. Wish I could tell you more')
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
confini>=0.3.6rc3,<0.5.0
|
confini~=0.5.1
|
||||||
crypto-dev-signer>=0.4.15a1,<=0.4.15
|
chainlib-eth~=0.0.12
|
||||||
chainlib-eth>=0.0.9a9,<=0.1.0
|
potaahto~=0.1.0
|
||||||
potaahto~=0.0.1a2
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
default_pythonpath=$PYTHONPATH:.
|
||||||
|
export PYTHONPATH=${default_pythonpath:-.}
|
||||||
for f in `ls tests/*.py`; do
|
for f in `ls tests/*.py`; do
|
||||||
python $f
|
python $f
|
||||||
if [ $? -gt 0 ]; then
|
if [ $? -gt 0 ]; then
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = eth-erc20
|
name = eth-erc20
|
||||||
version = 0.1.2a3
|
version = 0.1.2
|
||||||
description = ERC20 interface and simple contract with deployment script that lets any address mint and gift itself tokens.
|
description = ERC20 interface and simple contract with deployment script that lets any address mint and gift itself tokens.
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ contract GiftableToken {
|
|||||||
event Transfer(address indexed _from, address indexed _to, uint256 _value);
|
event Transfer(address indexed _from, address indexed _to, uint256 _value);
|
||||||
event TransferFrom(address indexed _from, address indexed _to, address indexed _spender, 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 Approval(address indexed _owner, address indexed _spender, uint256 _value);
|
||||||
event Mint(address indexed _minter, address indexed _beneficiary, uint256 _value);
|
event Mint(address indexed _minter, address indexed _beneficiary, uint256 _value); // Minter
|
||||||
|
|
||||||
constructor(string memory _name, string memory _symbol, uint8 _decimals) public {
|
constructor(string memory _name, string memory _symbol, uint8 _decimals) public {
|
||||||
owner = msg.sender;
|
owner = msg.sender;
|
||||||
@@ -33,6 +33,7 @@ contract GiftableToken {
|
|||||||
minters[msg.sender] = true;
|
minters[msg.sender] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements Minter
|
||||||
function mintTo(address _to, uint256 _value) public returns (bool) {
|
function mintTo(address _to, uint256 _value) public returns (bool) {
|
||||||
require(minters[msg.sender]);
|
require(minters[msg.sender]);
|
||||||
|
|
||||||
@@ -52,6 +53,11 @@ contract GiftableToken {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements Writer
|
||||||
|
function addWriter(address _minter) public returns (bool) {
|
||||||
|
return addMinter(_minter);
|
||||||
|
}
|
||||||
|
|
||||||
function removeMinter(address _minter) public returns (bool) {
|
function removeMinter(address _minter) public returns (bool) {
|
||||||
require(msg.sender == owner || msg.sender == _minter);
|
require(msg.sender == owner || msg.sender == _minter);
|
||||||
|
|
||||||
@@ -60,6 +66,11 @@ contract GiftableToken {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements Writer
|
||||||
|
function deleteWriter(address _minter) public returns (bool) {
|
||||||
|
return removeMinter(_minter);
|
||||||
|
}
|
||||||
|
|
||||||
// Implements ERC20
|
// Implements ERC20
|
||||||
function transfer(address _to, uint256 _value) public returns (bool) {
|
function transfer(address _to, uint256 _value) public returns (bool) {
|
||||||
require(balanceOf[msg.sender] >= _value);
|
require(balanceOf[msg.sender] >= _value);
|
||||||
@@ -101,6 +112,9 @@ contract GiftableToken {
|
|||||||
if (_sum == 0x01ffc9a7) { // EIP165
|
if (_sum == 0x01ffc9a7) { // EIP165
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (_sum == 0x80c84bd6) { // Writer
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user