Skip to content

Commit

Permalink
Release 0.66.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC01 committed Aug 4, 2024
1 parent 5a6b54f commit 7a3287c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 74 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_**

Expand Down
4 changes: 2 additions & 2 deletions pysui/sui/sui_pgql/pgql_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions pysui/sui/sui_pgql/pgql_txn_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
9 changes: 1 addition & 8 deletions pysui/sui/sui_txn/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`",
Expand All @@ -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:
"""."""
Expand Down
84 changes: 31 additions & 53 deletions pysui/sui/sui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -57,7 +54,6 @@
from pysui.sui.sui_excepts import (
SuiException,
SuiMiisingBuildFolder,
SuiMiisingModuleByteCode,
SuiPackageBuildFail,
)
from pysui.sui.sui_txresults.single_tx import ObjectRead, ObjectReadData
Expand All @@ -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


Expand Down Expand Up @@ -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():
Expand All @@ -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"]),
Expand All @@ -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(
Expand All @@ -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")
Expand All @@ -222,24 +200,24 @@ 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"
)

# 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


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)
Expand All @@ -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


Expand Down
13 changes: 6 additions & 7 deletions pysui/sui_move/module/deserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
deserialize_friends,
)

from deprecated.sphinx import deprecated


class Deserialize(IntEnum):
"""Deserialize degree of deserialization invariants."""
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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.
Expand All @@ -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]:
Expand All @@ -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]:
Expand All @@ -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")

0 comments on commit 7a3287c

Please sign in to comment.