Skip to content
This repository was archived by the owner on Aug 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
14651fb
Update compatiblity check with node v2.0.0 (minerva)
noandrea Feb 17, 2019
1dde681
Fix property retrieval for generation
noandrea Feb 17, 2019
3c1d32f
Add contract create/call support for minerva
noandrea Feb 20, 2019
540a1b0
Add function to calculate fees for a transaction
noandrea Feb 20, 2019
8fb6424
Better tests instrumentation using fixtures (WIP)
noandrea Feb 21, 2019
de939f1
Add automatic fee calculation (WIP)
noandrea Feb 21, 2019
23d9ace
Fix transaction generation for aens (WIP)
noandrea Feb 21, 2019
9b13e52
Update transaction generation for contracts
noandrea Feb 24, 2019
6763b37
Update transaction generation for oracles
noandrea Feb 24, 2019
7d7a2d4
Fix test fixture calls
noandrea Feb 24, 2019
4df98d2
Fix native oracle respond transaction
noandrea Feb 24, 2019
7889b32
Fix tests using fixtures
noandrea Feb 24, 2019
503b9ed
Update test for debug / native scenarios
noandrea Feb 24, 2019
0696ca3
Fix test fixtures
noandrea Feb 25, 2019
af1f10f
Use master tag for docker testing
noandrea Feb 26, 2019
056f17c
Fix lint error, remove legacy field
noandrea Feb 26, 2019
3d3693b
Set node version to minerva
noandrea Feb 26, 2019
495cab1
Force image pull before builds
noandrea Feb 26, 2019
863664e
Debug jenkins build
noandrea Feb 26, 2019
10e5af3
Debugging jenkins
noandrea Feb 26, 2019
a483b19
Debugging jenkins - update pytest to the latest version
noandrea Feb 27, 2019
a9db54b
Fix node version in .env
noandrea Feb 27, 2019
4d8683f
Use custom account.json for genesis accounts
noandrea Feb 27, 2019
6308e78
Fix typo in parameter name
noandrea Feb 27, 2019
fbdd91b
Add reminder for contracts fee calculation
noandrea Feb 27, 2019
035e2a1
Fix lint error
noandrea Feb 27, 2019
a23412c
Update fee calculation using 8 bytes as fee field size
noandrea Feb 27, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# this is used by docker-compose.yml to for the node image tag
TAG=v1.4.0
TAG=v2.0.0


Coordinate the developmnet of the sdks (features, release schedule, development policies)
Coordinate with the core team to keep all the aepps working on the 3 environments
Maintain the aepps so they keep working
Maintain a 2 way communication between core team and aepps team
Operate 3 environments (mainnet, testnet, unstable) that are used by the aepps and the public
Operate all the aepps-dev in the 3 environments + other stuff (like hackmd)
Design and mediate the feature/user experience for developer tools with the teams
Keep track of the security issues and


6 changes: 1 addition & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pipeline {

environment {
DOCKER_COMPOSE = "docker-compose -p ${env.BUILD_TAG} -H 127.0.0.1:2376"
SCANNER_HOME = tool 'default-sonarqube-scanner'
}

stages {
Expand All @@ -21,12 +20,9 @@ pipeline {
withCredentials([usernamePassword(credentialsId: 'genesis-wallet',
usernameVariable: 'WALLET_PUB',
passwordVariable: 'WALLET_PRIV')]) {
sh "${env.DOCKER_COMPOSE} pull node"
sh "${env.DOCKER_COMPOSE} run sdk flake8"
sh "${env.DOCKER_COMPOSE} run sdk make test"
// run sonar?
// withSonarQubeEnv('default-sonarqube-server') {
// sh "${env.SCANNER_HOME}/bin/sonar-scanner -X"
// }
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions aeternity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__version__ = '1.1.2'
__version__ = '2.0.0a1'

__compatibility__ = dict(
from_version=">=1.0.0",
to_version="<2.0.0"
from_version=">=1.4.0",
to_version="<3.0.0"
)
2 changes: 1 addition & 1 deletion aeternity/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ def chain_play(height, limit, force, wait, json_):
limit -= 1
if limit <= 0:
break
g = cli.get_generation_by_hash(hash=g.key_block.get("prev_key_hash"))
g = cli.get_generation_by_hash(hash=g.key_block.prev_key_hash)
except Exception as e:
print(e)
g = None
Expand Down
14 changes: 4 additions & 10 deletions aeternity/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import requests
import sys
import semver
from collections import MutableSequence
from . import __compatibility__

# vm version specification
# https://github.com/aeternity/protocol/blob/master/contracts/contract_vms.md#virtual-machines-on-the-%C3%A6ternity-blockchain
AEVM_NO_VM = 0
# fee calculation
GAS_PER_BYTE = 20
BASE_GAS = 15000
Expand All @@ -17,13 +13,13 @@
NAME_CLIENT_TTL = 60000
DEFAULT_NAME_TTL = 500
# default relative ttl in number of blocks for executing transaction on the chain
MAX_TX_TTL = sys.maxsize
MAX_TX_TTL = 256
DEFAULT_TX_TTL = 0
# default fee for posting transaction
DEFAULT_FEE = 20000
DEFAULT_FEE = 0
# contracts
CONTRACT_DEFAULT_GAS = 170000
CONTRACT_DEFAULT_GAS_PRICE = 1
CONTRACT_DEFAULT_GAS = 100000
CONTRACT_DEFAULT_GAS_PRICE = 1000000000
CONTRACT_DEFAULT_DEPOSIT = 0
CONTRACT_DEFAULT_VM_VERSION = 1
CONTRACT_DEFAULT_AMOUNT = 0
Expand All @@ -35,8 +31,6 @@
ORACLE_DEFAULT_TTL_VALUE = 500
ORACLE_DEFAULT_QUERY_TTL_VALUE = 10
ORACLE_DEFAULT_RESPONSE_TTL_VALUE = 10
ORACLE_DEFAULT_VM_VERSION = AEVM_NO_VM


# network id
DEFAULT_NETWORK_ID = "ae_mainnet"
Expand Down
38 changes: 31 additions & 7 deletions aeternity/contract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from aeternity.openapi import OpenAPIClientException
from aeternity.openapi import OpenAPIClientException, UnsupportedEpochVersion
from aeternity import utils, config
from aeternity.identifiers import CONTRACT_ID
from aeternity.identifiers import CONTRACT_ID, CONTRACT_ROMA_VM, CONTRACT_ROMA_ABI, CONTRACT_MINERVA_VM, CONTRACT_MINERVA_ABI
import semver


class ContractError(Exception):
Expand Down Expand Up @@ -42,22 +43,29 @@ def tx_call(self, account, function, arg,
gas=config.CONTRACT_DEFAULT_GAS,
gas_price=config.CONTRACT_DEFAULT_GAS_PRICE,
fee=config.DEFAULT_FEE,
vm_version=config.CONTRACT_DEFAULT_VM_VERSION,
vm_version=None,
abi_version=None,
tx_ttl=config.DEFAULT_TX_TTL):
"""Call a sophia contract"""

if not utils.is_valid_hash(self.address, prefix=CONTRACT_ID):
raise ValueError("Missing contract id")

try:
# retrieve the correct vm/abi version
vm, abi = self._get_vm_abi_versions()
vm_version = vm if vm_version is None else vm_version
abi_version = abi if abi_version is None else abi_version
# prepare the call data
call_data = self.encode_calldata(function, arg)
# get the transaction builder
txb = self.client.tx_builder
# get the account nonce and ttl
nonce, ttl = self.client._get_nonce_ttl(account.get_address(), tx_ttl)
# build the transaction
tx = txb.tx_contract_call(account.get_address(), self.address, call_data, function, arg, amount, gas, gas_price, vm_version, fee, ttl, nonce)
tx = txb.tx_contract_call(account.get_address(), self.address, call_data, function, arg,
amount, gas, gas_price, abi_version,
fee, ttl, nonce)
# sign the transaction
tx_signed, sg, tx_hash = self.client.sign_transaction(account, tx)
# post the transaction to the chain
Expand All @@ -76,21 +84,27 @@ def tx_create(self,
gas=config.CONTRACT_DEFAULT_GAS,
gas_price=config.CONTRACT_DEFAULT_GAS_PRICE,
fee=config.DEFAULT_FEE,
vm_version=config.CONTRACT_DEFAULT_VM_VERSION,
vm_version=None,
abi_version=None,
tx_ttl=config.DEFAULT_TX_TTL):
"""
Create a contract and deploy it to the chain
:return: address
"""
try:
# retrieve the correct vm/abi version
vm, abi = self._get_vm_abi_versions()
vm_version = vm if vm_version is None else vm_version
abi_version = abi if abi_version is None else abi_version
# encode the call data
call_data = self.encode_calldata("init", init_state)

# get the transaction builder
txb = self.client.tx_builder
# get the account nonce and ttl
nonce, ttl = self.client._get_nonce_ttl(account.get_address(), tx_ttl)
# build the transaction
tx, contract_id = txb.tx_contract_create(account.get_address(), self.bytecode, call_data, amount, deposit, gas, gas_price, vm_version,
tx, contract_id = txb.tx_contract_create(account.get_address(), self.bytecode, call_data,
amount, deposit, gas, gas_price, vm_version, abi_version,
fee, ttl, nonce)
# sign the transaction
tx_signed, sg, tx_hash = self.client.sign_transaction(account, tx)
Expand Down Expand Up @@ -167,3 +181,13 @@ def decode_data(self, data, sophia_type):
return reply.data.value, reply.data.type
except OpenAPIClientException as e:
raise ContractError(e)

def _get_vm_abi_versions(self):
"""
Check the version of the node and retrieve the correct values for abi and vm version
"""
if semver.match(self.client.api_version, "<=1.4.0"):
return CONTRACT_ROMA_VM, CONTRACT_ROMA_ABI
if semver.match(self.client.api_version, "<3.0.0"):
return CONTRACT_MINERVA_VM, CONTRACT_MINERVA_ABI
raise UnsupportedEpochVersion(f"Version {self.client.api_version} is not supported")
20 changes: 11 additions & 9 deletions aeternity/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def encode_rlp(prefix, data):
:param data: the array that has to be encoded in rlp
"""
if not isinstance(data, list):
raise ValueError("data to be encoded to rlp must be an array")
raise ValueError("data to be encoded to rlp must be a list")
payload = rlp.encode(data)
return encode(prefix, payload)

Expand Down Expand Up @@ -132,13 +132,17 @@ def namehash_encode(prefix, name):
return encode(prefix, namehash(name))


def _int(val: int) -> bytes:
def _int(val: int, byte_length: int = None) -> bytes:
"""
Encode and int to a big endian byte array
:param val: the value to encode
:param byte_length: number of bytes that should be used to encoded the number, by default is the minimum
"""
if val == 0:
return val.to_bytes(1, byteorder='big')
return val.to_bytes((val.bit_length() + 7) // 8, byteorder='big')
size = 1 if byte_length is None else byte_length
return val.to_bytes(size, byteorder='big')
size = (val.bit_length() + 7) // 8 if byte_length is None else byte_length
return val.to_bytes(size, byteorder='big')


def _binary(val):
Expand Down Expand Up @@ -168,15 +172,15 @@ def contract_id(owner_id, nonce):
:param owner_id: the account creating the conctract
:param nonce: the nonce of the contract creation transaction
"""
return hash_encode("ct", decode(owner_id) + _int(nonce))
return hash_encode(identifiers.CONTRACT_ID, decode(owner_id) + _int(nonce))


def oracle_id(account_id):
"""
Compute the oracle id of a oracle registration
:parm account_id: the account registering the oracle
"""
return f"ok_{account_id[3:]}"
return f"{identifiers.ORACLE_ID}_{account_id[3:]}"


def oracle_query_id(sender_id, nonce, oracle_id):
Expand All @@ -186,9 +190,7 @@ def oracle_query_id(sender_id, nonce, oracle_id):
:param nonce: the nonce of the query transaction
:param oracle_id: the oracle id
"""
def _int32(val):
return val.to_bytes(32, byteorder='big')
return hash_encode("oq", decode(sender_id) + _int32(nonce) + decode(oracle_id))
return hash_encode(identifiers.ORACLE_QUERY_ID, decode(sender_id) + _int(nonce, byte_length=32) + decode(oracle_id))


def randint(upper_bound=2**64):
Expand Down
23 changes: 23 additions & 0 deletions aeternity/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,26 @@
OBJECT_TAG_POI = 60
OBJECT_TAG_MICRO_BODY = 101
OBJECT_TAG_LIGHT_MICRO_BLOCK = 102


# VM Identifiers
# vm version specification
# https://github.com/aeternity/protocol/blob/master/contracts/contract_vms.md#virtual-machines-on-the-%C3%A6ternity-blockchain
NO_VM = 0
VM_SOPHIA = 1
VM_SOLIDITY = 2
VM_SOPHIA_IMPROVEMENTS = 3
# abi
NO_ABI = 0
ABI_SOPHIA = 1
ABI_SOLIDITY = 2
# Contracts identifiers
# For Roma
CONTRACT_ROMA_VM = 0 # this is to maintain retrocompatibility
CONTRACT_ROMA_ABI = 1
# For Minerva: 196609 # that is int.from_bytes(int(3).to_bytes(2, "big") + int(1).to_bytes(2, "big"), "big")
CONTRACT_MINERVA_VM = 3
CONTRACT_MINERVA_ABI = 1

# Oracles
ORACLE_DEFAULT_VM_VERSION = NO_VM
10 changes: 5 additions & 5 deletions aeternity/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ def __init__(self, url, url_internal=None, debug=False, force_compatibility=Fals
try:
# load the openapi json file from the node
self.api_def = requests.get(f"{url}/api").json()
api_version = self.api_def.get("info", {}).get("version", "unknown")
self.api_version = self.api_def.get("info", {}).get("version", "unknown")
# retrieve the version of the node we are connecting to
match_min = semver.match(api_version, __compatibility__.get("from_version"))
match_max = semver.match(api_version, __compatibility__.get("to_version"))
match_min = semver.match(self.api_version, __compatibility__.get("from_version"))
match_max = semver.match(self.api_version, __compatibility__.get("to_version"))
if (not match_min or not match_max) and not force_compatibility:
f, t = __compatibility__.get('from_version'), __compatibility__.get('to_version')
raise UnsupportedEpochVersion(
f"unsupported epoch version {api_version}, supported version are {f} and {t}")
f"unsupported node version {self.api_version}, supported version are {f} and {t}")
except requests.exceptions.ConnectionError as e:
raise ConfigException(f"Error connecting to the epoch node at {self.api_url}, connection unavailable")
raise ConfigException(f"Error connecting to the node at {self.api_url}, connection unavailable")
except Exception as e:
raise UnsupportedEpochVersion(f"Unable to connect to the node: {e}")

Expand Down
4 changes: 2 additions & 2 deletions aeternity/oracles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from aeternity import config, hashing
from aeternity.identifiers import ORACLE_ID
from aeternity.identifiers import ORACLE_ID, ORACLE_DEFAULT_VM_VERSION

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -66,7 +66,7 @@ def register(self, account, query_format, response_format,
query_fee=config.ORACLE_DEFAULT_QUERY_FEE,
ttl_type=config.ORACLE_DEFAULT_TTL_TYPE_DELTA,
ttl_value=config.ORACLE_DEFAULT_TTL_VALUE,
vm_version=config.ORACLE_DEFAULT_VM_VERSION,
vm_version=ORACLE_DEFAULT_VM_VERSION,
fee=config.DEFAULT_FEE,
tx_ttl=config.DEFAULT_TX_TTL):
"""
Expand Down
Loading