Skip to content
This repository was archived by the owner on Aug 12, 2024. It is now read-only.

Commit 7dc3a2f

Browse files
authored
Merge pull request #147 from aeternity/release/3.0.0
Release/3.0.0
2 parents 1dca16f + c7e59ac commit 7dc3a2f

30 files changed

+1276
-603
lines changed

.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# this is used by docker-compose.yml to for the node image tag
2-
TAG=v2.0.0
2+
NODE_TAG=v2.1.0
3+
COMPILER_TAG=v2.1.0
34

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ build
1010
coverage.xml
1111
docker-compose.override.yml
1212
test-results.xml
13+
.coverage

CHANGELOG.md

Lines changed: 375 additions & 207 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ publish:
4343
publish-test:
4444
@echo publish on test.pypi.org
4545
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
46-
@echo done
46+
@echo done
47+
48+
changelog:
49+
@echo build changelog
50+
gitolog -t keepachangelog -s angular . -o CHANGELOG.md
51+
@echo done

aeternity/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
__version__ = '2.0.0'
1+
__version__ = '3.0.0'
22

3-
__compatibility__ = dict(
4-
from_version=">=1.4.0",
5-
to_version="<3.0.0"
6-
)
3+
__node_compatibility__ = (">=1.4.0", "<3.0.0")

aeternity/__main__.py

Lines changed: 111 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
from aeternity import __version__
1010

1111
from aeternity.node import NodeClient, Config
12-
from aeternity.transactions import TxSigner
13-
# from aeternity.oracle import Oracle, OracleQuery, NoOracleResponse
12+
from aeternity.transactions import TxSigner, TxBuilder
13+
from aeternity.identifiers import NETWORK_ID_MAINNET
1414
from . import utils, signing, aens, defaults, exceptions
15-
from aeternity.contract import Contract
15+
from aeternity.contract import CompilerClient
1616

1717
from datetime import datetime, timezone
1818

@@ -164,7 +164,7 @@ def _print_error(err, title="error", exit_code=0):
164164
]
165165

166166
_sign_options = [
167-
click.option('--network-id', default=None, help="The network id to use when signing a transaction")
167+
click.option('--network-id', default=NETWORK_ID_MAINNET, help="The network id to use when signing a transaction", show_default=True)
168168
]
169169

170170
_transaction_options = [
@@ -338,19 +338,20 @@ def account_balance(keystore_name, password, force, wait, json_):
338338
@click.argument('keystore_name', required=True)
339339
@click.argument('recipient_id', required=True)
340340
@click.argument('amount', required=True, type=int)
341+
@click.option('--payload', default="", help="Spend transaction payload")
341342
@global_options
342343
@account_options
343344
@online_options
344345
@transaction_options
345346
@sign_options
346-
def account_spend(keystore_name, recipient_id, amount, fee, ttl, nonce, password, network_id, force, wait, json_):
347+
def account_spend(keystore_name, recipient_id, amount, payload, fee, ttl, nonce, password, network_id, force, wait, json_):
347348
try:
348349
set_global_options(json_, force, wait)
349350
account, keystore_path = _account(keystore_name, password=password)
350351
account.nonce = nonce
351352
if not utils.is_valid_hash(recipient_id, prefix="ak"):
352353
raise ValueError("Invalid recipient address")
353-
tx = _node_cli(network_id=network_id).spend(account, recipient_id, amount, tx_ttl=ttl, fee=fee)
354+
tx = _node_cli(network_id=network_id).spend(account, recipient_id, amount, tx_ttl=ttl, fee=fee, payload=payload)
354355
_print_object(tx, title='spend transaction')
355356
except Exception as e:
356357
_print_error(e, exit_code=1)
@@ -420,8 +421,7 @@ def tx_broadcast(signed_transaction, force, wait, json_):
420421
def tx_spend(sender_id, recipient_id, amount, ttl, fee, nonce, payload, json_):
421422
try:
422423
set_global_options(json_)
423-
cli = _node_cli()
424-
tx = cli.tx_builder.tx_spend(sender_id, recipient_id, amount, payload, fee, ttl, nonce)
424+
tx = TxBuilder().tx_spend(sender_id, recipient_id, amount, payload, fee, ttl, nonce)
425425
# print the results
426426
_print_object(tx, title='spend tx')
427427
except Exception as e:
@@ -584,34 +584,101 @@ def name_transfer(keystore_name, domain, address, ttl, fee, nonce, password, net
584584
#
585585
#
586586

587-
@click.group('contract', help='Deploy and execute contracts on the chain')
588-
def contract():
587+
@cli.group(help="Interact with Æternity smart contract compiler")
588+
def compiler():
589589
pass
590590

591591

592-
@contract.command(help="Compile a contract")
592+
@compiler.command('compile', help="Compile a contract")
593+
@click.option('--compiler-url', '-c', default='http://localhost:3080', envvar='COMPILER_URL', help='Aeternity compiler url', metavar='URL')
593594
@click.argument("contract_file")
594-
def contract_compile(contract_file):
595+
@global_options
596+
def contract_compile(contract_file, compiler_url, json_):
595597
try:
598+
set_global_options(json_, False, False)
596599
with open(contract_file) as fp:
597600
code = fp.read()
598-
c = _node_cli().Contract(Contract.SOPHIA)
601+
c = CompilerClient(compiler_url)
599602
result = c.compile(code)
600-
_print_object({"bytecode", result}, title="contract")
603+
if click.confirm(f'Save contract bytecode to file ({contract_file}.bin) ?', default=True, show_default=True):
604+
with open(f"{contract_file}.bin", "w") as fp:
605+
fp.write(result.bytecode)
606+
_print_object(result, title="contract")
607+
except Exception as e:
608+
_print_error(e, exit_code=1)
609+
610+
611+
@compiler.command('aci', help="Get the aci of a contract")
612+
@click.option('--compiler-url', '-c', default='http://localhost:3080', envvar='COMPILER_URL', help='Aeternity compiler url', metavar='URL')
613+
@click.argument("contract_file")
614+
@global_options
615+
def contract_aci(contract_file, compiler_url, json_):
616+
try:
617+
set_global_options(json_, False, False)
618+
with open(contract_file) as fp:
619+
code = fp.read()
620+
c = CompilerClient(compiler_url)
621+
result = c.aci(code)
622+
_print_object(result, title="contract")
623+
except Exception as e:
624+
_print_error(e, exit_code=1)
625+
626+
627+
@compiler.command('encode-calldata', help="Enocode the calldata to invoke a contract")
628+
@click.option('--compiler-url', '-c', default='http://localhost:3080', envvar='COMPILER_URL', help='Aeternity compiler url', metavar='URL')
629+
@click.argument("contract_file")
630+
@click.argument("function_name")
631+
@click.option("--arguments", default=None, help="Argument of the function if any, comma separated")
632+
@global_options
633+
def contract_encode_calldata(contract_file, function_name, arguments, compiler_url, json_):
634+
try:
635+
set_global_options(json_, False, False)
636+
with open(contract_file) as fp:
637+
code = fp.read()
638+
c = CompilerClient(compiler_url)
639+
arguments = [] if arguments is None else arguments.split(",")
640+
result = c.encode_calldata(code, function_name, arguments=arguments)
641+
_print_object(result, title="contract")
642+
# except Exception as e:
643+
# _print_error(e, exit_code=1)
644+
finally:
645+
pass
646+
647+
648+
@compiler.command('decode-data', help="Decode the data retrieve from a contract")
649+
@click.option('--compiler-url', '-c', default='http://localhost:3080', envvar='COMPILER_URL', help='Aeternity compiler url', metavar='URL')
650+
@click.argument("sophia_type")
651+
@click.argument("encoded_data")
652+
@global_options
653+
def contract_decode_data(contract_file, encoded_data, sophia_type, compiler_url, json_):
654+
try:
655+
set_global_options(json_, False, False)
656+
c = CompilerClient(compiler_url)
657+
result = c.decode_data(sophia_type, encoded_data)
658+
_print_object(result, title="contract")
601659
except Exception as e:
602660
_print_error(e, exit_code=1)
603661

604662

605-
@contract.command('deploy', help='Deploy a contract on the chain')
663+
@cli.group(help='Deploy and execute contracts on the chain')
664+
def contracts():
665+
pass
666+
667+
668+
@contracts.command('deploy', help='Deploy a contract on the chain')
606669
@click.argument('keystore_name', required=True)
607-
@click.argument("contract_file", required=True)
670+
@click.argument("bytecode_file", required=True)
671+
@click.option("--init-calldata", default=defaults.CONTRACT_INIT_CALLDATA, help="The calldata for the init function", show_default=True)
608672
@click.option("--gas", default=defaults.CONTRACT_GAS, help='Amount of gas to deploy the contract', show_default=True)
673+
@click.option("--amount", default=defaults.CONTRACT_AMOUNT, help='Amount of tokens to transfer to the contract', show_default=True)
674+
@click.option("--gas-price", default=defaults.CONTRACT_GAS_PRICE, help='The gas price used to execute the contract init function', show_default=True)
675+
@click.option("--deposit", default=defaults.CONTRACT_AMOUNT, help='A initial deposit to the contract', show_default=True)
609676
@global_options
610677
@account_options
611678
@online_options
612679
@transaction_options
613680
@sign_options
614-
def contract_deploy(keystore_name, contract_file, gas, password, network_id, force, wait, json_):
681+
def contract_deploy(keystore_name, bytecode_file, init_calldata, gas, gas_price, amount, deposit, password, ttl, fee, nonce, network_id, force, wait, json_):
615682
"""
616683
Deploy a contract to the chain and create a deploy descriptor
617684
with the contract informations that can be use to invoke the contract
@@ -621,36 +688,22 @@ def contract_deploy(keystore_name, contract_file, gas, password, network_id, for
621688
source file. Multiple deploy of the same contract file will generate different
622689
deploy descriptor
623690
"""
691+
print("Not yet implemented")
692+
return
624693
try:
625-
with open(contract_file) as fp:
694+
with open(bytecode_file) as fp:
626695
set_global_options(json_, force, wait)
627696
account, _ = _account(keystore_name, password=password)
628-
code = fp.read()
629-
contract = _node_cli(network_id=network_id).Contract(code)
630-
tx = contract.tx_create(account, gas=gas)
631-
# save the contract data
632-
contract_data = {
633-
'source': contract.source_code,
634-
'bytecode': contract.bytecode,
635-
'id': contract.id,
636-
'transaction': tx.tx_hash,
637-
'owner': account.get_address(),
638-
'created_at': datetime.now().isoformat('T')
639-
}
640-
# write the contract data to a file
641-
deploy_descriptor = f"{contract_file}.deploy.{contract.id[3:]}.json"
642-
with open(deploy_descriptor, 'w') as fw:
643-
json.dump(contract_data, fw, indent=2)
644-
_print_object({
645-
"Contract id": contract.id,
646-
"Transaction hash": tx.tx_hash,
647-
"Deploy descriptor": deploy_descriptor,
648-
}, title="contract")
697+
bytecode = fp.read()
698+
contract = _node_cli(network_id=network_id).Contract()
699+
tx = contract.create(account, bytecode, init_calldata=init_calldata, gas=gas, amount=amount,
700+
gas_price=gas_price, deposit=deposit, tx_ttl=ttl, fee=fee)
701+
_print_object(tx, title="contract create")
649702
except Exception as e:
650703
_print_error(e, exit_code=1)
651704

652705

653-
@contract.command('call', help='Execute a function of the contract')
706+
@contracts.command('call', help='Execute a function of the contract')
654707
@click.argument('keystore_name', required=True)
655708
@click.argument("deploy_descriptor", required=True)
656709
@click.argument("function", required=True)
@@ -663,6 +716,8 @@ def contract_deploy(keystore_name, contract_file, gas, password, network_id, for
663716
@transaction_options
664717
@sign_options
665718
def contract_call(keystore_name, deploy_descriptor, function, params, return_type, gas, password, network_id, force, wait, json_):
719+
print("Not yet implemented")
720+
return
666721
try:
667722
with open(deploy_descriptor) as fp:
668723
contract = json.load(fp)
@@ -674,16 +729,23 @@ def contract_call(keystore_name, deploy_descriptor, function, params, return_typ
674729
account, _ = _account(keystore_name, password=password)
675730

676731
contract = _node_cli(network_id=network_id).Contract(source, bytecode=bytecode, address=address)
677-
tx, result = contract.tx_call(account, function, params, gas=gas)
732+
tx = contract.tx_call(account, function, params, gas=gas)
678733
_print_object(tx, "contract call")
679-
if result.return_type == 'ok':
680-
value, remote_type = contract.decode_data(result.return_value, return_type)
681-
_print_object({
682-
'Return value': value,
683-
'Return remote type': remote_type,
684-
})
685-
686-
pass
734+
except Exception as e:
735+
_print_error(e, exit_code=1)
736+
737+
738+
@contracts.command('call-info', help='Retrieve the result of a contract call if any')
739+
@click.argument('tx_hash', required=True)
740+
@global_options
741+
@online_options
742+
def contract_call_info(tx_hash, force, wait, json_):
743+
print("Not yet implemented")
744+
return
745+
try:
746+
contract = _node_cli().Contract()
747+
call_object = contract.get_call_object(tx_hash)
748+
_print_object(call_object, "contract call object")
687749
except Exception as e:
688750
_print_error(e, exit_code=1)
689751

aeternity/aens.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,12 @@ def claim(self, account, name_salt, preclaim_tx_hash, fee=defaults.FEE, tx_ttl=d
167167
safe_height = self.preclaimed_block_height + self.client.config.key_block_confirmation_num
168168
if current_height < safe_height:
169169
raise NameTooEarlyClaim(f"It is not safe to execute the name claim before height {safe_height}, current height: {current_height}")
170-
# name encode name
171-
name = hashing.name_id(self.domain)
172170
# get the transaction builder
173171
txb = self.client.tx_builder
174172
# get the account nonce and ttl
175173
nonce, ttl = self.client._get_nonce_ttl(account.get_address(), tx_ttl)
176174
# create transaction
177-
tx = txb.tx_name_claim(account.get_address(), name, self.preclaim_salt, fee, ttl, nonce)
175+
tx = txb.tx_name_claim(account.get_address(), self.domain, self.preclaim_salt, fee, ttl, nonce)
178176
# sign the transaction
179177
tx_signed = self.client.sign_transaction(account, tx.tx)
180178
# post the transaction to the chain

0 commit comments

Comments
 (0)