From 7a3287c638ed98b21db7a2ec322cd4ed9acbac70 Mon Sep 17 00:00:00 2001 From: "Frank V. Castellucci" Date: Sun, 4 Aug 2024 04:36:00 -0400 Subject: [PATCH] Release 0.66.0 --- CHANGELOG.md | 3 +- README.md | 2 +- pysui/sui/sui_pgql/pgql_schema.py | 4 +- pysui/sui/sui_pgql/pgql_txn_base.py | 3 +- pysui/sui/sui_txn/transaction.py | 9 +-- pysui/sui/sui_utils.py | 84 ++++++++++------------------ pysui/sui_move/module/deserialize.py | 13 ++--- 7 files changed, 44 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 212573e..b93f708 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.66.0] - Unpublished +## [0.66.0] - 2024-08-04 ### Added @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Coin deserialization failed when previousTransactionBlock has been pruned - Validate GraphQL schema existence before adding to available list +- [bug](https://github.com/FrankC01/pysui/issues/222) Fixed publish that broke with enums ### Changed diff --git a/README.md b/README.md index 88adf06..473fb39 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ See [CHANGELOG](https://github.com/FrankC01/pysui/blob/main/CHANGELOG.md) ## PyPi current -**Release-0.65.0 - Released 2024-07-18** +**Release-0.66.0 - Released 2024-08-04** **_BREAKING CHANGES to GraphQL support_** diff --git a/pysui/sui/sui_pgql/pgql_schema.py b/pysui/sui/sui_pgql/pgql_schema.py index e92eda7..a72d08b 100644 --- a/pysui/sui/sui_pgql/pgql_schema.py +++ b/pysui/sui/sui_pgql/pgql_schema.py @@ -95,7 +95,7 @@ def load_schema_cache( """.""" schema_mgr: Schema = None # TODO: Temporary Sui devnet bug workaround - if genv != "devnet": + if not genv.startswith("devnet"): _furl = gurl + "/" + default_version if default_version else gurl else: _furl = gurl @@ -131,7 +131,7 @@ def load_schema_cache( _url, _init_client, _base_version, _long_version, _schema, _rpc_config ) - if genv == "devnet": + if genv.startswith("devnet"): return schema_mgr while schema_mgr._present_schemas: diff --git a/pysui/sui/sui_pgql/pgql_txn_base.py b/pysui/sui/sui_pgql/pgql_txn_base.py index 583f428..24f118f 100644 --- a/pysui/sui/sui_pgql/pgql_txn_base.py +++ b/pysui/sui/sui_pgql/pgql_txn_base.py @@ -235,13 +235,12 @@ def _compile_source( src_path, args_list, ) - modules = list(map(self._to_bytes_from_str, compiled_package.compiled_modules)) dependencies = [ bcs.Address.from_str(x if isinstance(x, str) else x.value) for x in compiled_package.dependencies ] digest = bcs.Digest.from_bytes(compiled_package.package_digest) - return modules, dependencies, digest + return compiled_package.compiled_modules, dependencies, digest if __name__ == "__main__": diff --git a/pysui/sui/sui_txn/transaction.py b/pysui/sui/sui_txn/transaction.py index e1979f2..ee2a54f 100644 --- a/pysui/sui/sui_txn/transaction.py +++ b/pysui/sui/sui_txn/transaction.py @@ -389,12 +389,6 @@ def _resolve_item( case _: raise ValueError(f"Uknown class type handler {clz_name}") - def _to_bytes_from_str(self, inbound: Union[str, SuiString]) -> list[int]: - """Utility to convert base64 string to bytes then as list of u8.""" - return list( - base64.b64decode(inbound if isinstance(inbound, str) else inbound.value) - ) - @versionchanged( version="0.50.0", reason="Removed with_unpublished_dependencies and skip_fetch_latest_git_deps replace with `args_list`", @@ -411,13 +405,12 @@ def _compile_source( src_path, args_list, ) - modules = list(map(self._to_bytes_from_str, compiled_package.compiled_modules)) dependencies = [ bcs.Address.from_str(x if isinstance(x, str) else x.value) for x in compiled_package.dependencies ] digest = bcs.Digest.from_bytes(compiled_package.package_digest) - return modules, dependencies, digest + return compiled_package.compiled_modules, dependencies, digest def _receiving_parm(self, parm) -> bool: """.""" diff --git a/pysui/sui/sui_utils.py b/pysui/sui/sui_utils.py index 8672157..46244f2 100644 --- a/pysui/sui/sui_utils.py +++ b/pysui/sui/sui_utils.py @@ -39,9 +39,6 @@ DEFAULT_SUI_BINARY_PATH, ) -import pysui.sui_move.module.deserialize as deser -from pysui.sui_move.bin_reader.module_reader import ModuleReader - from pysui.sui.sui_types.scalars import ( SuiString, ObjectID, @@ -57,7 +54,6 @@ from pysui.sui.sui_excepts import ( SuiException, SuiMiisingBuildFolder, - SuiMiisingModuleByteCode, SuiPackageBuildFail, ) from pysui.sui.sui_txresults.single_tx import ObjectRead, ObjectReadData @@ -71,18 +67,18 @@ @dataclass -@versionchanged( - version="0.17.0", - reason="Added the package digest that matches chain digest.", +@versionadded( + version="0.66.0", + reason="Uses raw bytes from modules.", ) -class CompiledPackage: +class CompiledPackageRaw: """Ease of compilation information dataclass.""" project_name: str project_id: str project_source_digest: bytes dependencies: list[str] - compiled_modules: list[SuiString] = None + compiled_modules: list[bytes] = None package_digest: bytes = None @@ -132,24 +128,7 @@ def _compile_projectg( raise SuiPackageBuildFail(result.stdout) -def _module_bytes(module: Path) -> Union[ModuleReader, OSError]: - """Fetch the module reader for this module.""" - return deser.reader_from_file(str(module)) - - -def _modules_bytes( - module_path: Path, -) -> Union[list[ModuleReader], SuiMiisingModuleByteCode, OSError]: - """.""" - mod_list = list(module_path.glob("*.mv")) - if not mod_list: - raise SuiMiisingModuleByteCode(f"{module_path} is empty") - # Open and get the bytes representation of same - result_list: list[ModuleReader] = [_module_bytes(module) for module in mod_list] - return result_list - - -def _build_dep_info(build_path: str) -> Union[CompiledPackage, Exception]: +def _build_dep_info(build_path: str) -> Union[CompiledPackageRaw, Exception]: """Fetch details about build.""" build_info = Path(build_path).joinpath("BuildInfo.yaml") if build_info.exists(): @@ -163,7 +142,7 @@ def _build_dep_info(build_path: str) -> Union[CompiledPackage, Exception]: for key, value in inner_dep.items(): if key != pname: dep_ids.append(f"0x{value}") - return CompiledPackage( + return CompiledPackageRaw( pname, pindent, binascii.unhexlify(build_info_dict["source_digest"]), @@ -172,30 +151,29 @@ def _build_dep_info(build_path: str) -> Union[CompiledPackage, Exception]: raise ValueError("Corrupt publish build information") -@versionadded( - version="0.20.0", - reason="Sui move build introduced hashing the modules first.", -) -def _package_digest(package: CompiledPackage, readers: list[ModuleReader]) -> None: - """Converts compiled module bytes for publishing and digest calculation.""" - mod_strs: list = [] - all_bytes: list = [] - # Get the bytes for digest and string for publishing - for mod_bytes in readers: - mr_bytes = mod_bytes.reader.getvalue() +def _package_digestg(package: CompiledPackageRaw, module_path: Path) -> None: + """Captures compiled module bytes for publishing and digest calculation.""" + + mod_bytes: list[bytes] = [] + all_digests: list[bytes] = [] + + mod_list = list(module_path.glob("*.mv")) + if not mod_list: + raise ValueError(f"{module_path} is empty") + for mmod in mod_list: + binfile = mmod.read_bytes() hasher = hashlib.blake2b(digest_size=32) - hasher.update(mr_bytes) - all_bytes.append(hasher.digest()) - mod_strs.append(SuiString(base64.b64encode(mr_bytes).decode())) + hasher.update(binfile) + all_digests.append(hasher.digest()) + mod_bytes.append(list(binfile)) for dep_str in package.dependencies: - all_bytes.append(binascii.unhexlify(dep_str[2:])) - - all_bytes.sort() + all_digests.append(binascii.unhexlify(dep_str[2:])) + all_digests.sort() hasher = hashlib.blake2b(digest_size=32) - for bblock in all_bytes: + for bblock in all_digests: hasher.update(bblock) package.package_digest = hasher.digest() - package.compiled_modules = mod_strs + package.compiled_modules = mod_bytes @versionchanged( @@ -205,7 +183,7 @@ def _package_digest(package: CompiledPackage, readers: list[ModuleReader]) -> No def publish_build( path_to_package: Path, args_list: list[str], -) -> Union[CompiledPackage, Exception]: +) -> Union[CompiledPackageRaw, Exception]: """Build and collect module base64 strings and dependencies ObjectIDs.""" if os.environ[PYSUI_EXEC_ENV] == EMPEHMERAL_PATH: raise ValueError(f"Configuration does not support publishing") @@ -222,8 +200,8 @@ def publish_build( if len(build_subdir) > 1: raise SuiMiisingBuildFolder(f"No build folder found in {path_to_package}") # Finally, get the module(s) bytecode folder - byte_modules = Path(build_subdir[0]).joinpath("bytecode_modules") - if not byte_modules.exists(): + move_modules = Path(build_subdir[0]).joinpath("bytecode_modules") + if not move_modules.exists(): raise SuiMiisingBuildFolder( f"No bytecode_modules folder found for {path_to_package}/build" ) @@ -231,7 +209,7 @@ def publish_build( # Construct initial package cpackage = _build_dep_info(build_subdir[0].path) # Set module bytes as base64 strings and generate package digest - _package_digest(cpackage, _modules_bytes(byte_modules)) + _package_digestg(cpackage, move_modules) return cpackage @@ -239,7 +217,7 @@ def publish_buildg( sui_bin_path_str: str, path_to_package: Path, args_list: list[str], -) -> Union[CompiledPackage, Exception]: +) -> Union[CompiledPackageRaw, Exception]: """Build and collect module base64 strings and dependencies ObjectIDs.""" # Compile the package path_to_package = _compile_projectg(sui_bin_path_str, path_to_package, args_list) @@ -263,7 +241,7 @@ def publish_buildg( # Construct initial package cpackage = _build_dep_info(build_subdir[0].path) # Set module bytes as base64 strings and generate package digest - _package_digest(cpackage, _modules_bytes(byte_modules)) + _package_digestg(cpackage, byte_modules) return cpackage diff --git a/pysui/sui_move/module/deserialize.py b/pysui/sui_move/module/deserialize.py index 8717a34..03c723a 100644 --- a/pysui/sui_move/module/deserialize.py +++ b/pysui/sui_move/module/deserialize.py @@ -51,6 +51,8 @@ deserialize_friends, ) +from deprecated.sphinx import deprecated + class Deserialize(IntEnum): """Deserialize degree of deserialization invariants.""" @@ -195,6 +197,7 @@ def _deserialize_raw_type( raise ValueError(f"Uknown table type key {table_type.name}") +@deprecated(version="0.66.0", reason="Module utilities not supported.") def deserialize( reader: ModuleReader, form: Deserialize ) -> Union[RawModuleContent, Exception]: @@ -232,6 +235,7 @@ def deserialize( raise ValueError("No module byte code defined in file") +@deprecated(version="0.66.0", reason="Module utilities not supported.") def reader_from_file(module: str) -> Union[ModuleReader, Exception]: """reader_from_file Returns a module reader for module. @@ -243,6 +247,7 @@ def reader_from_file(module: str) -> Union[ModuleReader, Exception]: return ModuleReader.read_from_file(module) +@deprecated(version="0.66.0", reason="Module utilities not supported.") def from_file( module: str, form: Deserialize = Deserialize.ALL ) -> Union[RawModuleContent, Exception]: @@ -258,6 +263,7 @@ def from_file( return deserialize(ModuleReader.read_from_file(module), form) +@deprecated(version="0.66.0", reason="Module utilities not supported.") def from_base64( in_base64: str, form: Deserialize = Deserialize.ALL ) -> Union[RawModuleContent, Exception]: @@ -271,10 +277,3 @@ def from_base64( :rtype: Union[RawModuleContent, Exception] """ return deserialize(ModuleReader.read_from_base64(in_base64), form) - - -if __name__ == "__main__": - deser_track = from_file( - "~/frankc01/sui-track/build/SuiTrack/bytecode_modules/base.mv" - ) - # print("Success")