mirror of
https://github.com/chaintool-py/eth-erc20.git
synced 2026-04-26 04:27:13 +02:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7183e01b72
|
||
| 5e7e539bb9 | |||
|
|
a87fbb13bc
|
@@ -9,12 +9,14 @@ from chainlib.eth.contract import (
|
|||||||
ABIContractType,
|
ABIContractType,
|
||||||
abi_decode_single,
|
abi_decode_single,
|
||||||
)
|
)
|
||||||
|
from chainlib.eth.jsonrpc import to_blockheight_param
|
||||||
from chainlib.eth.error import RequestMismatchException
|
from chainlib.eth.error import RequestMismatchException
|
||||||
from chainlib.eth.tx import (
|
from chainlib.eth.tx import (
|
||||||
TxFactory,
|
TxFactory,
|
||||||
TxFormat,
|
TxFormat,
|
||||||
)
|
)
|
||||||
from chainlib.jsonrpc import JSONRPCRequest
|
from chainlib.jsonrpc import JSONRPCRequest
|
||||||
|
from chainlib.block import BlockSpec
|
||||||
from hexathon import (
|
from hexathon import (
|
||||||
add_0x,
|
add_0x,
|
||||||
strip_0x,
|
strip_0x,
|
||||||
@@ -26,7 +28,7 @@ logg = logging.getLogger()
|
|||||||
class ERC20(TxFactory):
|
class ERC20(TxFactory):
|
||||||
|
|
||||||
|
|
||||||
def balance_of(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None):
|
def balance_of(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None, height=BlockSpec.LATEST):
|
||||||
j = JSONRPCRequest(id_generator)
|
j = JSONRPCRequest(id_generator)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
o['method'] = 'eth_call'
|
o['method'] = 'eth_call'
|
||||||
@@ -38,7 +40,8 @@ class ERC20(TxFactory):
|
|||||||
tx = self.template(sender_address, contract_address)
|
tx = self.template(sender_address, contract_address)
|
||||||
tx = self.set_code(tx, data)
|
tx = self.set_code(tx, data)
|
||||||
o['params'].append(self.normalize(tx))
|
o['params'].append(self.normalize(tx))
|
||||||
o['params'].append('latest')
|
height = to_blockheight_param(height)
|
||||||
|
o['params'].append(height)
|
||||||
o = j.finalize(o)
|
o = j.finalize(o)
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ logg.debug('settings loaded:\n{}'.format(settings))
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
signer_address = settings.get('SENDER_ADDRESS')
|
signer_address = settings.get('SENDER_ADDRESS')
|
||||||
|
conn = settings.get('CONN')
|
||||||
|
|
||||||
c = GiftableToken(
|
c = GiftableToken(
|
||||||
settings.get('CHAIN_SPEC'),
|
settings.get('CHAIN_SPEC'),
|
||||||
|
|||||||
@@ -25,62 +25,80 @@ from hexathon import (
|
|||||||
strip_0x,
|
strip_0x,
|
||||||
add_0x,
|
add_0x,
|
||||||
)
|
)
|
||||||
|
from chainlib.settings import ChainSettings
|
||||||
|
from chainlib.eth.cli.log import process_log
|
||||||
|
from chainlib.eth.settings import process_settings
|
||||||
|
from chainlib.eth.cli.arg import (
|
||||||
|
Arg,
|
||||||
|
ArgFlag,
|
||||||
|
process_args,
|
||||||
|
)
|
||||||
|
from chainlib.eth.cli.config import (
|
||||||
|
Config,
|
||||||
|
process_config,
|
||||||
|
)
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from giftable_erc20_token import GiftableToken
|
from giftable_erc20_token import GiftableToken
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
|
||||||
logg = logging.getLogger()
|
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)
|
def process_config_local(config, arg, args, flags):
|
||||||
argparser.add_positional('amount', type=int, help='Token amount to gift')
|
config.add(config.get('_POSARG'), '_VALUE', False)
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
arg_flags = ArgFlag()
|
||||||
|
arg = Arg(arg_flags)
|
||||||
|
flags = arg_flags.STD_WRITE | arg_flags.WALLET | arg_flags.EXEC
|
||||||
|
|
||||||
|
argparser = chainlib.eth.cli.ArgumentParser()
|
||||||
|
argparser = process_args(argparser, arg, flags)
|
||||||
|
argparser.add_argument('value', type=str, help='Token value to send')
|
||||||
args = argparser.parse_args()
|
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=GiftableToken.gas())
|
|
||||||
|
|
||||||
wallet = chainlib.eth.cli.Wallet()
|
logg = process_log(args, logg)
|
||||||
wallet.from_config(config)
|
|
||||||
|
|
||||||
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
|
config = Config()
|
||||||
conn = rpc.connect_by_config(config)
|
config = process_config(config, arg, args, flags, positional_name='value')
|
||||||
|
config = process_config_local(config, arg, args, flags)
|
||||||
|
logg.debug('config loaded:\n{}'.format(config))
|
||||||
|
|
||||||
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
settings = ChainSettings()
|
||||||
|
settings = process_settings(settings, config)
|
||||||
|
logg.debug('settings loaded:\n{}'.format(settings))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
signer = rpc.get_signer()
|
token_address = settings.get('EXEC')
|
||||||
signer_address = rpc.get_sender_address()
|
signer_address = settings.get('SENDER_ADDRESS')
|
||||||
|
recipient = settings.get('RECIPIENT')
|
||||||
|
value = settings.get('VALUE')
|
||||||
|
conn = settings.get('CONN')
|
||||||
|
|
||||||
gas_oracle = rpc.get_gas_oracle()
|
c = GiftableToken(
|
||||||
nonce_oracle = rpc.get_nonce_oracle()
|
settings.get('CHAIN_SPEC'),
|
||||||
|
signer=settings.get('SIGNER'),
|
||||||
|
gas_oracle=settings.get('GAS_ORACLE'),
|
||||||
|
nonce_oracle=settings.get('NONCE_ORACLE'),
|
||||||
|
)
|
||||||
|
|
||||||
recipient_address_input = config.get('_RECIPIENT')
|
(tx_hash_hex, o) = c.mint_to(
|
||||||
if recipient_address_input == None:
|
token_address,
|
||||||
recipient_address_input = signer_address
|
signer_address,
|
||||||
|
recipient,
|
||||||
recipient_address = add_0x(to_checksum_address(recipient_address_input))
|
value,
|
||||||
if not config.true('_UNSAFE') and recipient_address != add_0x(recipient_address_input):
|
)
|
||||||
raise ValueError('invalid checksum address for recipient')
|
if settings.get('RPC_SEND'):
|
||||||
|
|
||||||
token_address = add_0x(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')
|
|
||||||
|
|
||||||
token_value = config.get('_AMOUNT')
|
|
||||||
c = GiftableToken(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
|
|
||||||
(tx_hash_hex, o) = c.mint_to(token_address, signer_address, recipient_address, token_value)
|
|
||||||
if config.get('_RPC_SEND'):
|
|
||||||
conn.do(o)
|
conn.do(o)
|
||||||
if config.get('_WAIT'):
|
if settings.get('WAIT'):
|
||||||
r = conn.wait(tx_hash_hex)
|
r = conn.wait(tx_hash_hex)
|
||||||
if r['status'] == 0:
|
if r['status'] == 0:
|
||||||
sys.stderr.write('EVM revert. Wish I had more to tell you')
|
sys.stderr.write('EVM revert. Wish I had more to tell you')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
logg.info('mint to {} tx {}'.format(recipient_address, tx_hash_hex))
|
logg.info('mint to {} tx {}'.format(recipient, tx_hash_hex))
|
||||||
|
|
||||||
print(tx_hash_hex)
|
print(tx_hash_hex)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -72,7 +72,9 @@ logg.debug('settings loaded:\n{}'.format(settings))
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
token_address = settings.get('EXEC')
|
||||||
signer_address = settings.get('SENDER_ADDRESS')
|
signer_address = settings.get('SENDER_ADDRESS')
|
||||||
|
conn = settings.get('CONN')
|
||||||
|
|
||||||
recipient_address_input = settings.get('RECIPIENT')
|
recipient_address_input = settings.get('RECIPIENT')
|
||||||
if recipient_address_input == None:
|
if recipient_address_input == None:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = eth-erc20
|
name = eth-erc20
|
||||||
version = 0.5.1
|
version = 0.5.3
|
||||||
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
|
||||||
@@ -20,7 +20,7 @@ classifiers =
|
|||||||
License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
|
License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
|
||||||
Topic :: Internet
|
Topic :: Internet
|
||||||
#Topic :: Blockchain :: EVM
|
#Topic :: Blockchain :: EVM
|
||||||
license = OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
|
license = AGPLv3+
|
||||||
licence_files =
|
licence_files =
|
||||||
LICENSE
|
LICENSE
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user