Skip to content

Commit

Permalink
Merge pull request #195 from multiversx/remove-erdjs-snippets
Browse files Browse the repository at this point in the history
Do not handle erdjs-snippets anymore, since they have been removed from mx-sdk-rs's templates folder
  • Loading branch information
andreibancioiu authored Jan 19, 2023
2 parents 851669a + c63ac36 commit 7342e62
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 42 deletions.
2 changes: 1 addition & 1 deletion multiversx_sdk_cli/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "5.0.1"
__version__ = "5.1.0"
41 changes: 5 additions & 36 deletions multiversx_sdk_cli/projects/templates.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import json
import logging
import os
from pathlib import Path
import shutil
from pathlib import Path
from typing import Any, List, Tuple

from multiversx_sdk_cli import errors, utils
from multiversx_sdk_cli.projects import shared
from multiversx_sdk_cli.projects.project_rust import CargoFile
from multiversx_sdk_cli.projects.templates_config import get_templates_repositories
from multiversx_sdk_cli.projects.templates_repository import TemplatesRepository
from multiversx_sdk_cli.projects.templates_config import \
get_templates_repositories
from multiversx_sdk_cli.projects.templates_repository import \
TemplatesRepository

logger = logging.getLogger("projects.templates")
ERDJS_SNIPPETS_FOLDER_NAME = "erdjs-snippets"


def list_project_templates():
Expand Down Expand Up @@ -70,42 +70,11 @@ def _copy_template(template: str, destination_path: Path, project_name: str):
if repo.has_template(template):
source_path = repo.get_template_folder(template)
shutil.copytree(source_path, destination_path)
_copy_erdjs_snippets(template, repo.get_payload_folder(), destination_path, project_name)
return

raise errors.TemplateMissingError(template)


def _copy_erdjs_snippets(template: str, templates_payload_folder: Path, destination_path: Path, project_name: str):
source_erdjs_snippets_folder = templates_payload_folder / ERDJS_SNIPPETS_FOLDER_NAME
source_erdjs_snippets_subfolder = source_erdjs_snippets_folder / template
destination_erdjs_snippets_folder = destination_path.parent / ERDJS_SNIPPETS_FOLDER_NAME
no_snippets = not source_erdjs_snippets_subfolder.is_dir()

logger.info(f"_copy_erdjs_snippets, source_erdjs_snippets_subfolder: {source_erdjs_snippets_subfolder}")
logger.info(f"_copy_erdjs_snippets, destination_erdjs_snippets_folder: {destination_erdjs_snippets_folder}")

if no_snippets:
logger.info(f"_copy_erdjs_snippets: no snippets in template {template}")
return

utils.ensure_folder(destination_erdjs_snippets_folder)

# Copy snippets to destination
# First, copy the subfolder associated with the template
shutil.copytree(source_erdjs_snippets_subfolder, destination_erdjs_snippets_folder / project_name)

# After that, copy the remaining files from the source folder - not recursively (on purpose).
for file in os.listdir(source_erdjs_snippets_folder):
source_file = source_erdjs_snippets_folder / file
destination_file = destination_erdjs_snippets_folder / file
should_copy = source_file.is_file() and not destination_file.exists()

if should_copy:
logger.info(f"_copy_erdjs_snippets, file: {file}")
shutil.copy(source_file, destination_file)


def _load_as_template(directory: Path):
if shared.is_source_clang(directory):
return TemplateClang(directory)
Expand Down
9 changes: 5 additions & 4 deletions multiversx_sdk_cli/wallet/keyfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import base64
import os
from binascii import b2a_base64, hexlify, unhexlify
from json import dump, load
from pathlib import Path
from typing import Any
import multiversx_sdk_cli.accounts as accounts
from json import load, dump
from uuid import uuid4

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, hmac
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives.kdf.scrypt import Scrypt

import multiversx_sdk_cli.accounts as accounts
from multiversx_sdk_cli import errors


Expand Down Expand Up @@ -102,8 +103,8 @@ def make_cyphertext(backend: Any, key: bytes, iv: bytes, secret_key: str):
return encryptor.update(secret_key) + encryptor.finalize()


# erdjs implementation:
# https://github.com/multiversx/mx-sdk-erdjs-walletcore/blob/main/src/userWallet.ts
# sdk-js implementation:
# https://github.com/multiversx/mx-sdk-js-wallet/blob/main/src/userWallet.ts
def format_key_json(uid: str, pubkey: str, iv: bytes, ciphertext: bytes, salt: bytes, mac: bytes) -> Any:
address = accounts.Address(pubkey)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import setuptools

VERSION = "5.0.1"
VERSION = "5.1.0"

try:
with open('./multiversx_sdk_cli/_version.py', 'wt') as versionfile:
Expand Down

0 comments on commit 7342e62

Please sign in to comment.