From d37657ceb74415f8d4df63d830143e794ea97005 Mon Sep 17 00:00:00 2001 From: nolash Date: Fri, 19 Mar 2021 20:15:50 +0100 Subject: [PATCH] Add mint to method --- python/giftable_erc20_token/factory.py | 79 ++++++++++++++++++++ python/giftable_erc20_token/runnable/gift.py | 2 +- python/setup.cfg | 2 +- 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 python/giftable_erc20_token/factory.py diff --git a/python/giftable_erc20_token/factory.py b/python/giftable_erc20_token/factory.py new file mode 100644 index 0000000..06f8153 --- /dev/null +++ b/python/giftable_erc20_token/factory.py @@ -0,0 +1,79 @@ +# standard imports +import os +import logging + +# external imports +from chainlib.eth.tx import ( + TxFactory, + TxFormat, + ) +from chainlib.eth.encoding import abi_encode_hex +from chainlib.hash import keccak256_string_to_hex +from chainlib.eth.contract import ( + ABIContractEncoder, + ABIContractType, + ) + + +# local imports +from giftable_erc20_token.data import data_dir + +logg = logging.getLogger(__name__) + + +class GiftableToken(TxFactory): + + __abi = None + __bytecode = None + + def constructor(self, sender_address, name, symbol, decimals): + code = GiftableToken.bytecode() + + tx = self.template(sender_address, '0x', use_nonce=True) + code += abi_encode_hex('(string,string,uint8)', [name, symbol, decimals]) + tx = self.set_code(tx, code) + return self.build(tx) + + + @staticmethod + def abi(): + if GiftableToken.__abi == None: + f = open(os.path.join(data_dir, 'GiftableToken.json'), 'r') + GiftableToken.__abi = json.load(f) + f.close() + return GiftableToken.__abi + + + @staticmethod + def bytecode(): + if GiftableToken.__bytecode == None: + f = open(os.path.join(data_dir, 'GiftableToken.bin')) + GiftableToken.__bytecode = f.read() + f.close() + return GiftableToken.__bytecode + + + def add_minter(self, contract_address, sender_address, address): + enc = ABIContractEncoder() + enc.method('mintTo') + enc.typ(ABIContractType.ADDRESS) + enc.address(address) + data = enc.get() + tx = self.template(sender_address, contract_address, use_nonce=True) + tx = self.set_code(tx, data) + tx = self.finalize(tx, tx_format) + return tx + + + def mint_to(self, contract_address, sender_address, address, value, tx_format=TxFormat.JSONRPC): + enc = ABIContractEncoder() + enc.method('mintTo') + enc.typ(ABIContractType.ADDRESS) + enc.typ(ABIContractType.UINT256) + enc.address(address) + enc.uint256(value) + data = enc.get() + tx = self.template(sender_address, contract_address, use_nonce=True) + tx = self.set_code(tx, data) + tx = self.finalize(tx, tx_format) + return tx diff --git a/python/giftable_erc20_token/runnable/gift.py b/python/giftable_erc20_token/runnable/gift.py index 8dc7523..8ac71cf 100644 --- a/python/giftable_erc20_token/runnable/gift.py +++ b/python/giftable_erc20_token/runnable/gift.py @@ -21,7 +21,7 @@ from eth_keys import keys from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer from crypto_dev_signer.keystore import DictKeystore from crypto_dev_signer.eth.helper import EthTxExecutor -from chainlib.chain from ChainSpec +from chainlib.chain import ChainSpec logging.basicConfig(level=logging.WARNING) logg = logging.getLogger() diff --git a/python/setup.cfg b/python/setup.cfg index 6734c30..f96739c 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = giftable-erc20-token -version = 0.0.7b11 +version = 0.0.7b13 description = Simple ERC20 contract with deployment script that lets any address mint and gift itself tokens. author = Louis Holbrook author_email = dev@holbrook.no