mirror of
https://github.com/chaintool-py/eth-erc20.git
synced 2026-04-27 21:01:04 +02:00
Add expire option
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -15,29 +15,33 @@ from chainlib.eth.contract import (
|
||||
|
||||
# local imports
|
||||
from giftable_erc20_token.data import data_dir
|
||||
from eth_erc20 import ERC20
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GiftableToken(TxFactory):
|
||||
class GiftableToken(ERC20):
|
||||
|
||||
__abi = None
|
||||
__bytecode = None
|
||||
|
||||
def constructor(self, sender_address, name, symbol, decimals, tx_format=TxFormat.JSONRPC, version=None):
|
||||
code = self.cargs(name, symbol, decimals)
|
||||
def constructor(self, sender_address, name, symbol, decimals, expire=0, tx_format=TxFormat.JSONRPC, version=None):
|
||||
code = self.cargs(name, symbol, decimals, expire=expire)
|
||||
tx = self.template(sender_address, None, use_nonce=True)
|
||||
tx = self.set_code(tx, code)
|
||||
return self.finalize(tx, tx_format)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def cargs(name, symbol, decimals, version=None):
|
||||
def cargs(name, symbol, decimals, expire=0, version=None):
|
||||
if expire == None:
|
||||
expire = 0
|
||||
code = GiftableToken.bytecode(version=version)
|
||||
enc = ABIContractEncoder()
|
||||
enc.string(name)
|
||||
enc.string(symbol)
|
||||
enc.uint256(decimals)
|
||||
enc.uint256(expire)
|
||||
code += enc.get()
|
||||
return code
|
||||
|
||||
@@ -108,12 +112,12 @@ def bytecode(**kwargs):
|
||||
|
||||
|
||||
def create(**kwargs):
|
||||
return GiftableToken.cargs(kwargs['name'], kwargs['symbol'], kwargs['decimals'], version=kwargs.get('version'))
|
||||
return GiftableToken.cargs(kwargs['name'], kwargs['symbol'], kwargs['decimals'], expire=kwargs.get('expire'), version=kwargs.get('version'))
|
||||
|
||||
|
||||
def args(v):
|
||||
if v == 'create':
|
||||
return (['name', 'symbol', 'decimals'], ['version'],)
|
||||
return (['name', 'symbol', 'decimals'], ['expire', 'version'],)
|
||||
elif v == 'default' or v == 'bytecode':
|
||||
return ([], ['version'],)
|
||||
raise ValueError('unknown command: ' + v)
|
||||
|
||||
@@ -45,6 +45,7 @@ def process_config_local(config, arg, args, flags):
|
||||
config.add(args.token_name, '_TOKEN_NAME', False)
|
||||
config.add(args.token_symbol, '_TOKEN_SYMBOL', False)
|
||||
config.add(args.token_decimals, '_TOKEN_DECIMALS', False)
|
||||
config.add(args.token_expire, '_TOKEN_EXPIRE', False)
|
||||
return config
|
||||
|
||||
|
||||
@@ -57,6 +58,7 @@ argparser = process_args(argparser, arg, flags)
|
||||
argparser.add_argument('--name', dest='token_name', required=True, type=str, help='Token name')
|
||||
argparser.add_argument('--symbol', dest='token_symbol', required=True, type=str, help='Token symbol')
|
||||
argparser.add_argument('--decimals', dest='token_decimals', default=18, type=int, help='Token decimals')
|
||||
argparser.add_argument('--expire', dest='token_expire', default=0, type=int, help='Token expiry timestamp (after which token cannot be traded)')
|
||||
args = argparser.parse_args()
|
||||
|
||||
logg = process_log(args, logg)
|
||||
@@ -87,6 +89,7 @@ def main():
|
||||
config.get('_TOKEN_NAME'),
|
||||
config.get('_TOKEN_SYMBOL'),
|
||||
config.get('_TOKEN_DECIMALS'),
|
||||
expire=config.get('_TOKEN_EXPIRE'),
|
||||
)
|
||||
if settings.get('RPC_SEND'):
|
||||
conn.do(o)
|
||||
1
python/giftable_erc20_token/unittest/__init__.py
Normal file
1
python/giftable_erc20_token/unittest/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .base import *
|
||||
51
python/giftable_erc20_token/unittest/base.py
Normal file
51
python/giftable_erc20_token/unittest/base.py
Normal file
@@ -0,0 +1,51 @@
|
||||
# standard imports
|
||||
import logging
|
||||
import time
|
||||
|
||||
# external imports
|
||||
from chainlib.eth.unittest.ethtester import EthTesterCase
|
||||
from chainlib.connection import RPCConnection
|
||||
from chainlib.eth.nonce import RPCNonceOracle
|
||||
from chainlib.eth.tx import receipt
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
|
||||
# local imports
|
||||
from giftable_erc20_token import GiftableToken
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestGiftableToken(EthTesterCase):
|
||||
|
||||
expire = 0
|
||||
|
||||
def setUp(self):
|
||||
super(TestGiftableToken, self).setUp()
|
||||
self.conn = RPCConnection.connect(self.chain_spec, 'default')
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
|
||||
c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
self.symbol = 'FOO'
|
||||
self.name = 'Foo Token'
|
||||
self.decimals = 16
|
||||
(tx_hash, o) = c.constructor(self.accounts[0], self.name, self.symbol, self.decimals, expire=self.expire)
|
||||
self.rpc.do(o)
|
||||
o = receipt(tx_hash)
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
self.address = to_checksum_address(r['contract_address'])
|
||||
logg.debug('published on address {} with hash {}'.format(self.address, tx_hash))
|
||||
|
||||
self.initial_supply = 1 << 40
|
||||
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[0], self.initial_supply)
|
||||
r = self.conn.do(o)
|
||||
o = receipt(tx_hash)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
|
||||
class TestGiftableExpireToken(TestGiftableToken):
|
||||
|
||||
expire = int(time.time()) + 100000
|
||||
|
||||
def setUp(self):
|
||||
super(TestGiftableExpireToken, self).setUp()
|
||||
Reference in New Issue
Block a user