Add publish cli

This commit is contained in:
lash 2023-05-31 16:28:38 +01:00
parent 88546a88a2
commit 92216df990
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
10 changed files with 161 additions and 30 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ __pycache__
build/
solidity/*.bin
solidity/*.json
python/dist/

View File

@ -1 +1 @@
include **/data/ERC20.json **/data/GiftableToken.json **/data/GiftableToken.bin *requirements.txt CHANGELOG LICENSE WAIVER WAIVER.asc **/data/.chainlib
include **/data/*.json **/data/*.json **/data/*.bin *requirements.txt CHANGELOG LICENSE WAIVER WAIVER.asc **/data/.chainlib

View File

@ -1,12 +1,48 @@
# standard imports
import os
import logging
# external imports
from giftable_erc20_token import GiftableToken
from chainlib.eth.tx import (
TxFactory,
TxFormat,
)
from chainlib.eth.contract import (
ABIContractEncoder,
ABIContractType,
)
# local imports
from ge_capped_token.data import data_dir
logg = logging.getLogger(__name__)
class CappedToken(GiftableToken):
__abi = None
__bytecode = None
def constructor(self, sender_address, name, symbol, decimals, tx_format=TxFormat.JSONRPC, version=None):
code = self.cargs(name, symbol, decimals)
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):
code = CappedToken.bytecode(version=version)
enc = ABIContractEncoder()
enc.string(name)
enc.string(symbol)
enc.uint256(decimals)
args = enc.get()
code += args
logg.debug('constructor code: ' + args)
return code
@staticmethod
def abi():
if CappedToken.__abi == None:

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,109 @@
#!python3
"""Deploys capped token
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
"""
# SPDX-License-Identifier: GPL-3.0-or-later
# standard imports
import sys
import os
import json
import argparse
import logging
import time
from enum import Enum
# external imports
import chainlib.eth.cli
from chainlib.eth.tx import receipt
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
from ge_capped_token import CappedToken
logg = logging.getLogger()
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)
return config
arg_flags = ArgFlag()
arg = Arg(arg_flags)
flags = arg_flags.STD_WRITE | arg_flags.WALLET
argparser = chainlib.eth.cli.ArgumentParser()
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')
args = argparser.parse_args()
logg = process_log(args, logg)
config = Config()
config = process_config(config, arg, args, flags)
config = process_config_local(config, arg, args, flags)
logg.debug('config loaded:\n{}'.format(config))
settings = ChainSettings()
settings = process_settings(settings, config)
logg.debug('settings loaded:\n{}'.format(settings))
def main():
signer_address = settings.get('SENDER_ADDRESS')
conn = settings.get('CONN')
c = CappedToken(
settings.get('CHAIN_SPEC'),
signer=settings.get('SIGNER'),
gas_oracle=settings.get('GAS_ORACLE'),
nonce_oracle=settings.get('NONCE_ORACLE'),
)
(tx_hash_hex, o) = c.constructor(
signer_address,
config.get('_TOKEN_NAME'),
config.get('_TOKEN_SYMBOL'),
config.get('_TOKEN_DECIMALS'),
)
if settings.get('RPC_SEND'):
conn.do(o)
if settings.get('WAIT'):
r = conn.wait(tx_hash_hex)
if r['status'] == 0:
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
sys.exit(1)
# TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
address = r['contractAddress']
print(address)
else:
print(tx_hash_hex)
else:
print(o)
if __name__ == '__main__':
main()

View File

@ -17,8 +17,6 @@ logg = logging.getLogger(__name__)
class TestCappedToken(EthTesterCase):
expire = 0
def setUp(self):
super(TestCappedToken, self).setUp()
self.conn = RPCConnection.connect(self.chain_spec, 'default')
@ -27,7 +25,7 @@ class TestCappedToken(EthTesterCase):
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)
(tx_hash, o) = c.constructor(self.accounts[0], self.name, self.symbol, self.decimals)
self.rpc.do(o)
o = receipt(tx_hash)
r = self.rpc.do(o)
@ -37,15 +35,7 @@ class TestCappedToken(EthTesterCase):
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)
self.conn.do(o)
o = receipt(tx_hash)
r = self.conn.do(o)
self.assertEqual(r['status'], 1)
class TestCappedExpireToken(TestCappedToken):
expire = int(time.time()) + 100000
def setUp(self):
super(TestCappedExpireToken, self).setUp()

View File

@ -1,6 +1,6 @@
[metadata]
name = ge-capped-token
version = 0.0.1
version = 0.1.0
description = ERC20 token that can be minted, capped and expired.
author = Louis Holbrook
author_email = dev@holbrook.no
@ -29,14 +29,10 @@ licence_files =
include_package_data = True
python_requires = >= 3.8
packages =
giftable_erc20_token
giftable_erc20_token.runnable
giftable_erc20_token.unittest
giftable_erc20_token.data
eth_erc20
eth_erc20.data
eth_erc20.runnable
static_token.data
ge_capped_token
ge_capped_token.runnable
ge_capped_token.unittest
ge_capped_token.data
[options.package_data]
* =
@ -48,4 +44,4 @@ packages =
[options.entry_points]
console_scripts =
capped-token-publish = giftable_erc20_token.runnable.publish:main
ge-capped-token-publish = ge_capped_token.runnable.publish:main

View File

@ -71,12 +71,11 @@ contract CappedToken {
uint8 constant EXPIRY_STATE = 4;
uint256 constant public maxSealState = 15;
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _expireTimestamp) {
constructor(string memory _name, string memory _symbol, uint8 _decimals) {
owner = msg.sender;
name = _name;
symbol = _symbol;
decimals = _decimals;
expires = _expireTimestamp;
}
// Change max token supply.
@ -122,8 +121,8 @@ contract CappedToken {
// Implements Minter
function mintTo(address _to, uint256 _value) public returns (bool) {
require(writers[msg.sender] || msg.sender == owner);
require(applyExpiry() == 0);
require(writers[msg.sender] || msg.sender == owner, "ERR_AXX");
require(applyExpiry() == 0, "ERR_EXPIRE");
if (maxSupply > 0) {
require(totalSupply() + _value <= maxSupply);
}