Skip to content

Commit

Permalink
Merge pull request #57 from ElrondNetwork/development
Browse files Browse the repository at this point in the history
Prepare version 1.0.21
  • Loading branch information
camilbancioiu authored Nov 1, 2021
2 parents bf2e978 + eeb885b commit 0ba55cc
Show file tree
Hide file tree
Showing 38 changed files with 2,840 additions and 542 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include erdpy/projects/*.txt
include erdpy/projects/*.json
include erdpy/wallet/*.txt

include erdpy/testnet/wallets/users/*.pem
include erdpy/testnet/wallets/users/*.json
Expand Down
7 changes: 7 additions & 0 deletions erdpy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [1.0.21] - 01.11.2021
- New command `erdpy wallet new`, which generates a new wallet mnemonic and optionally saves it to JSON or PEM
- Add support for Rust contract `meta` crates
- Update reference to the renamed VM repository (VM dependency is now named `vmtools`)
- Change `erdpy deps install all` to avoid installing / overwriting non-repository dependencies, e.g. Rust, LLVM, Go
- Update help strings and `CLI.md`

## [1.0.20] - 26.10.2021
- Bugfix by [phanletrunghieu](https://github.com/phanletrunghieu): use $PATH in `erdpy-up`
- Bugfix by [x2ocoder](https://github.com/x2ocoder): add missing `enable_epochs` configurations
Expand Down
673 changes: 347 additions & 326 deletions erdpy/CLI.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion erdpy/CLI.md.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ generate() {
group "Account" "account"
command "Account.Get" "account get"
command "Account.GetTransactions" "account get-transactions"

group "Wallet" "wallet"
command "Wallet.New" "wallet new"
command "Wallet.Derive" "wallet derive"
command "Wallet.Bech32" "wallet bech32"

Expand Down Expand Up @@ -117,3 +118,5 @@ generate() {
command "Data.Store" "data store"
command "Data.Load" "data load"
}

generate
2 changes: 1 addition & 1 deletion erdpy/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.20"
__version__ = "1.0.21"
16 changes: 8 additions & 8 deletions erdpy/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def generate_accounts(self, count):
self.generate_account(i)

def generate_account(self, name):
seed, pubkey = generate_pair()
secret_key, pubkey = generate_pair()
address = Address(pubkey).bech32()

pem_file = f"{name}_{address}.pem"
pem_file = path.join(self.folder, pem_file)
pem.write(pem_file, seed, pubkey, name=f"{name}:{address}")
pem.write(pem_file, secret_key, pubkey, name=f"{name}:{address}")

def get_all(self):
accounts = []
Expand All @@ -59,24 +59,24 @@ def __init__(self,
self.ledger = ledger

if self.pem_file:
seed, pubkey = pem.parse(self.pem_file, self.pem_index)
self.private_key_seed = seed.hex()
secret_key, pubkey = pem.parse(self.pem_file, self.pem_index)
self.secret_key = secret_key.hex()
self.address = Address(pubkey)
elif key_file and pass_file:
password = get_password(pass_file)
address_from_key_file, seed = load_from_key_file(key_file, password)
self.private_key_seed = seed.hex()
address_from_key_file, secret_key = load_from_key_file(key_file, password)
self.secret_key = secret_key.hex()
self.address = Address(address_from_key_file)

def sync_nonce(self, proxy: Any):
logger.info("Account.sync_nonce()")
self.nonce = proxy.get_account_nonce(self.address)
logger.info(f"Account.sync_nonce() done: {self.nonce}")

def get_seed(self) -> bytes:
def get_secret_key(self) -> bytes:
if self.ledger:
raise LedgerError("cannot get seed from a Ledger account")
return unhexlify(self.private_key_seed)
return unhexlify(self.secret_key)


class Address(IAddress):
Expand Down
51 changes: 46 additions & 5 deletions erdpy/cli_wallet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from erdpy.wallet.keyfile import save_to_key_file
from erdpy.wallet.core import generate_mnemonic
import logging
import getpass
from pathlib import Path
from typing import Any, List

from erdpy import cli_shared, wallet
from erdpy import cli_shared, wallet, utils
from erdpy.accounts import Account, Address
from erdpy.wallet import pem

Expand All @@ -12,10 +16,24 @@ def setup_parser(args: List[str], subparsers: Any) -> Any:
parser = cli_shared.add_group_subparser(
subparsers,
"wallet",
"Derive private key from mnemonic, bech32 address helpers etc."
"Create wallet, derive secret key from mnemonic, bech32 address helpers etc."
)
subparsers = parser.add_subparsers()

sub = cli_shared.add_command_subparser(
subparsers,
"wallet",
"new",
"Create a new wallet and print its mnemonic; optionally save as password-protected JSON (recommended) or PEM (not recommended)"
)
sub.add_argument("--json",
help="whether to create a json key file", action="store_true", default=False)
sub.add_argument("--pem",
help="whether to create a pem key file", action="store_true", default=False)
sub.add_argument("--output-path",
help="the output path and base file name for the generated wallet files (default: %(default)s)", type=str, default="./wallet")
sub.set_defaults(func=new_wallet)

sub = cli_shared.add_command_subparser(
subparsers,
"wallet",
Expand Down Expand Up @@ -69,19 +87,42 @@ def setup_parser(args: List[str], subparsers: Any) -> Any:
return subparsers


def new_wallet(args: Any):
mnemonic = generate_mnemonic()
print(f"Mnemonic: {mnemonic}")
secret_key, pubkey = wallet.derive_keys(mnemonic)
if args.pem:
pem_file = prepare_file(args.output_path, ".pem")
address = Address(pubkey)
pem.write(pem_file, secret_key, pubkey, name=address.bech32())
logger.info(f"Pem wallet generated: {pem_file}")
if args.json:
json_file = prepare_file(args.output_path, ".json")
password = getpass.getpass("Enter a new password:")
save_to_key_file(json_file, secret_key, pubkey, password)
logger.info(f"Json wallet generated: {json_file}")


def prepare_file(output_path: str, suffix: str) -> Path:
base_path = Path(output_path)
utils.ensure_folder(base_path.parent)
file_path = base_path.with_suffix(suffix)
return utils.uniquify(file_path)


def generate_pem(args: Any):
pem_file = args.pem
mnemonic = args.mnemonic
index = args.index

seed, pubkey = wallet.generate_pair()
secret_key, pubkey = wallet.generate_pair()
if mnemonic:
mnemonic = input("Enter mnemonic:\n")
mnemonic = mnemonic.strip()
seed, pubkey = wallet.derive_keys(mnemonic, index)
secret_key, pubkey = wallet.derive_keys(mnemonic, index)

address = Address(pubkey)
pem.write(pem_file, seed, pubkey, name=address.bech32())
pem.write(pem_file, secret_key, pubkey, name=address.bech32())
logger.info(f"Created PEM file [{pem_file}] for [{address.bech32()}]")


Expand Down
6 changes: 3 additions & 3 deletions erdpy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ def get_defaults() -> Dict[str, Any]:
"proxy": "https://testnet-gateway.elrond.com",
"chainID": "T",
"txVersion": "1",
"dependencies.arwentools.tag": "latest",
"dependencies.vmtools.tag": "latest",
"dependencies.elrond_wasm_rs.tag": "latest",
"dependencies.arwentools.urlTemplate.linux": "https://github.com/ElrondNetwork/arwen-wasm-vm/archive/{TAG}.tar.gz",
"dependencies.arwentools.urlTemplate.osx": "https://github.com/ElrondNetwork/arwen-wasm-vm/archive/{TAG}.tar.gz",
"dependencies.vmtools.urlTemplate.linux": "https://github.com/ElrondNetwork/wasm-vm/archive/{TAG}.tar.gz",
"dependencies.vmtools.urlTemplate.osx": "https://github.com/ElrondNetwork/wasm-vm/archive/{TAG}.tar.gz",
"dependencies.llvm.tag": "v9-19feb",
"dependencies.llvm.urlTemplate.linux": "https://ide.elrond.com/vendor-llvm/{TAG}/linux-amd64.tar.gz?t=19feb",
"dependencies.llvm.urlTemplate.osx": "https://ide.elrond.com/vendor-llvm/{TAG}/darwin-amd64.tar.gz?t=19feb",
Expand Down
4 changes: 2 additions & 2 deletions erdpy/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VM_TYPE_SYSTEM = "0001"
VM_TYPE_ARWEN = "0500"
VM_TYPE_WASM_VM = "0500"
SC_HEX_PUBKEY_PREFIX = "0" * 16
SC_HEX_PUBKEY_PREFIX_SYSTEM = SC_HEX_PUBKEY_PREFIX + VM_TYPE_SYSTEM + "0" * 30
SC_HEX_PUBKEY_PREFIX_ARWEN = SC_HEX_PUBKEY_PREFIX + VM_TYPE_ARWEN
SC_HEX_PUBKEY_PREFIX_WASM_VM = SC_HEX_PUBKEY_PREFIX + VM_TYPE_WASM_VM
2 changes: 1 addition & 1 deletion erdpy/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def deploy(self, owner: Account, arguments: List[Any], gas_price: int, gas_limit
return tx

def prepare_deploy_transaction_data(self, arguments: List[Any]):
tx_data = f"{self.bytecode}@{constants.VM_TYPE_ARWEN}@{self.metadata.to_hex()}"
tx_data = f"{self.bytecode}@{constants.VM_TYPE_WASM_VM}@{self.metadata.to_hex()}"

for arg in arguments:
tx_data += f"@{_prepare_argument(arg)}"
Expand Down
4 changes: 2 additions & 2 deletions erdpy/delegation/staking_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def prepare_args_for_add_nodes(args: Any):
# get validator
validator_pem = validator.get("pemFile")
validator_pem = path.join(path.dirname(args.validators_file), validator_pem)
seed, bls_key = parse_validator_pem(validator_pem)
signed_message = sign_message_with_bls_key(account.address.pubkey().hex(), seed.decode('ascii'))
secret_key_bytes, bls_key = parse_validator_pem(validator_pem)
signed_message = sign_message_with_bls_key(account.address.pubkey().hex(), secret_key_bytes.decode('ascii'))
add_nodes_data += f"@{bls_key}@{signed_message}"

args.receiver = args.delegation_contract
Expand Down
16 changes: 13 additions & 3 deletions erdpy/dependencies/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Dict, List

from erdpy import config, errors
from erdpy.dependencies.modules import (ArwenToolsModule, DependencyModule,
from erdpy.dependencies.modules import (VMToolsModule, DependencyModule,
GolangModule, MclSignerModule,
NodejsModule, Rust, StandaloneModule)

Expand All @@ -12,7 +12,7 @@

def install_module(key: str, tag: str = "", overwrite: bool = False):
if key == 'all':
modules = get_all_deps()
modules = get_all_deps_installable_via_cli()
else:
modules = [get_module_by_key(key)]

Expand Down Expand Up @@ -47,7 +47,7 @@ def get_deps_dict() -> Dict[str, DependencyModule]:
def get_all_deps() -> List[DependencyModule]:
return [
StandaloneModule(key="llvm", aliases=["clang", "cpp"]),
ArwenToolsModule(key="arwentools"),
VMToolsModule(key="vmtools"),
Rust(key="rust"),
NodejsModule(key="nodejs", aliases=[]),
StandaloneModule(key="elrond_go", repo_name="elrond-go", organisation="ElrondNetwork"),
Expand All @@ -57,6 +57,16 @@ def get_all_deps() -> List[DependencyModule]:
]


def get_all_deps_installable_via_cli() -> List[DependencyModule]:
return [
VMToolsModule(key="vmtools"),
StandaloneModule(key="elrond_go", repo_name="elrond-go", organisation="ElrondNetwork"),
StandaloneModule(key="elrond_proxy_go", repo_name="elrond-proxy-go", organisation="ElrondNetwork"),
MclSignerModule(key="mcl_signer")
]



def get_golang() -> GolangModule:
golang = get_module_by_key('golang')
assert isinstance(golang, GolangModule)
Expand Down
7 changes: 2 additions & 5 deletions erdpy/dependencies/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,19 @@ def _get_archive_path(self, tag: str) -> Path:
return archive


class ArwenToolsModule(StandaloneModule):
class VMToolsModule(StandaloneModule):
def __init__(self, key: str, aliases: List[str] = None):
if aliases is None:
aliases = list()

super().__init__(key, aliases)
self.repo_name = 'arwen-wasm-vm'
self.repo_name = 'wasm-vm'
self.organisation = 'ElrondNetwork'

def _post_install(self, tag: str):
dependencies.install_module('golang')

self.build_binary(tag, 'arwendebug')
self.build_binary(tag, 'test')

self.make_binary_symlink_in_parent_folder(tag, 'arwendebug', 'arwendebug')
self.make_binary_symlink_in_parent_folder(tag, 'test', 'mandos-test')
self.copy_libwasmer_in_parent_directory(tag)

Expand Down
22 changes: 11 additions & 11 deletions erdpy/ide/static/app/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var SmartContract = Backbone.Model.extend({

initialize: function () {
},

deploy: function (options) {
var payload = options.toJSON();
payload.id = this.id;
Expand All @@ -22,7 +22,7 @@ var SmartContract = Backbone.Model.extend({
app.talkToHead("queryWatchedVariables", payload);
},

addWatchedVariable: function(options) {
addWatchedVariable: function (options) {
this.getWatchedVariables(options.onTestnet).push({
Name: "alice's balance",
FunctionName: "do_balance",
Expand All @@ -32,7 +32,7 @@ var SmartContract = Backbone.Model.extend({
this.setWatchedVariables(options);
},

updateWatchedVariable: function(options) {
updateWatchedVariable: function (options) {
var index = options.index;
var variable = this.getWatchedVariables(options.onTestnet)[index];
variable.Name = options.name;
Expand All @@ -42,20 +42,20 @@ var SmartContract = Backbone.Model.extend({
this.setWatchedVariables(options);
},

deleteWatchedVariable: function(options) {
deleteWatchedVariable: function (options) {
var variables = this.getWatchedVariables(options.onTestnet);
variables.splice(options.index, 1);

this.setWatchedVariables(options);
},

getWatchedVariables: function(onTestnet) {
getWatchedVariables: function (onTestnet) {
var properties = onTestnet ? this.get("PropertiesOnTestnet") : this.get("PropertiesOnNodeDebug");
var variables = properties.WatchedVariables;
return variables;
},

setWatchedVariables: function(options) {
setWatchedVariables: function (options) {
var payload = options;
payload.id = this.id;
payload.variables = this.getWatchedVariables(options.onTestnet);
Expand All @@ -68,8 +68,8 @@ var SmartContract = Backbone.Model.extend({
var SmartContractDeployOptions = Backbone.Model.extend({
validate: function (attrs, options) {
if (attrs.onTestnet) {
if (!attrs.privateKey) {
return "When deploying on testnet, the private key is required.";
if (!attrs.secretKey) {
return "When deploying on testnet, the secret key is required.";
}
}
else {
Expand All @@ -87,8 +87,8 @@ var SmartContractRunOptions = Backbone.Model.extend({
}

if (attrs.onTestnet) {
if (!attrs.privateKey) {
return "When running on testnet, the private key is required.";
if (!attrs.secretKey) {
return "When running on testnet, the secret key is required.";
}
}
else {
Expand All @@ -101,4 +101,4 @@ var SmartContractRunOptions = Backbone.Model.extend({

var SmartContractsCollection = Backbone.Collection.extend({
model: SmartContract
});
});
Loading

0 comments on commit 0ba55cc

Please sign in to comment.