mirror of
https://github.com/chaintool-py/eth-erc20.git
synced 2024-11-26 19:56:48 +01:00
Add mint to method
This commit is contained in:
parent
9bece8494c
commit
d37657ceb7
79
python/giftable_erc20_token/factory.py
Normal file
79
python/giftable_erc20_token/factory.py
Normal file
@ -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
|
@ -21,7 +21,7 @@ from eth_keys import keys
|
|||||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
||||||
from crypto_dev_signer.keystore import DictKeystore
|
from crypto_dev_signer.keystore import DictKeystore
|
||||||
from crypto_dev_signer.eth.helper import EthTxExecutor
|
from crypto_dev_signer.eth.helper import EthTxExecutor
|
||||||
from chainlib.chain from ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = giftable-erc20-token
|
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.
|
description = Simple ERC20 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
|
||||||
|
Loading…
Reference in New Issue
Block a user