Skip to content

Commit

Permalink
Closes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC01 committed Nov 29, 2022
1 parent 70f6666 commit 7c0d5f4
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Was originally `0.1.2` but changed to `0.2.0` in line with semantic versioning,
- **SuiConfig** retains the fully qualified path to `client.yaml` used to initialize it
- SuiConfig adds property (read only) `configuration_path` to `client.yaml`
- SuiConfig adds property (read only) `environment` to the environment in use from client.yaml
- Support for `sui_getNormalizedMoveModule` in sui/sui_builders.py [change](https://github.com/FrankC01/pysui/issues/33)
- Support for `sui_getNormalizedMoveFunction` in sui/sui_builders.py [change](https://github.com/FrankC01/pysui/issues/33)
- Support for `sui_getNormalizedMoveStruct` in sui/sui_builders.py [change](https://github.com/FrankC01/pysui/issues/33)
- Support for `sui_getMoveFunctionArgTypes` in sui/sui_builders.py [change](https://github.com/FrankC01/pysui/issues/33)

### Fixed
- Object version result [closed](https://github.com/FrankC01/pysui/issues/29)
Expand Down
2 changes: 1 addition & 1 deletion DEVELOP.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# develop pysui

Python SUI client SDK for Sui - WIP and expect significant refactoring
SUI Python Client SDK for Sui

This document is for contributors or the curious developer

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pysui

Python SUI client SDK for Sui - WIP and expect significant refactoring
SUI Python Client SDK for Sui

- Repo Version: Unpublished **0.2.0**
- PyPi Version: **0.1.1**
Expand Down
4 changes: 4 additions & 0 deletions pysui/sui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
GetObject,
GetObjectsOwnedByObject,
GetPackage,
GetModule,
GetFunction,
GetFunctionArgs,
GetStructure,
GetRpcAPI,
GetCommittee,
GetEvents,
Expand Down
103 changes: 102 additions & 1 deletion pysui/sui/sui_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
CommitteeInfo,
EventID,
EventQueryEnvelope,
SuiMoveFunction,
SuiMoveFunctionArgumentTypes,
SuiMoveModule,
SuiMovePackage,
ObjectInfo,
ObjectRead,
ObjectID,
SuiBoolean,
SuiMoveStruct,
SuiString,
SuiInteger,
SuiTxBytes,
Expand Down Expand Up @@ -286,7 +290,7 @@ def _collect_parameters(self) -> list[ObjectInfo]:
class GetPackage(_NativeTransactionBuilder):
"""GetPackage When executed, return structured representations of all modules in the given package."""

def __init__(self, package: ObjectID = None) -> None:
def __init__(self, *, package: ObjectID) -> None:
"""__init__ Initialize GetPackage object.
:param package: ObjectID of package to query, defaults to None
Expand All @@ -307,6 +311,103 @@ def _collect_parameters(self) -> list[ObjectID]:
return [self.package]


class GetModule(_NativeTransactionBuilder):
"""GetModule When executed, returns the structural representation of a module.
Includes general Module informationn as well as structure and function definitions.
"""

def __init__(self, *, package: ObjectID, module_name: SuiString) -> None:
"""__init__ Initialize GetModule object.
:param package: ObjectID of package to query
:type package: ObjectID
:param module_name: Name of module from package to fetch
:type module_name: SuiString
"""
super().__init__("sui_getNormalizedMoveModule", handler_cls=SuiMoveModule, handler_func="ingest_data")
self.package: ObjectID = sui_utils.as_object_id(package)
self.module_name: SuiString = module_name

def _collect_parameters(self) -> list[ObjectID]:
"""Collect the call parameters."""
return [self.package, self.module_name]


class GetFunction(_NativeTransactionBuilder):
"""GetFunction When executed, returns the structural representation of a module's function.
Includes general function arguments and return type definitions.
"""

def __init__(self, *, package: ObjectID, module_name: SuiString, function_name: SuiString) -> None:
"""__init__ Initialize GetModule object.
:param package: ObjectID of package to query
:type package: ObjectID
:param module_name: Name of module from package containing function_name to fetch
:type module_name: SuiString
:param function_name: Name of module from package to fetch
:type function_name: SuiString
"""
super().__init__("sui_getNormalizedMoveFunction", handler_cls=SuiMoveFunction, handler_func="ingest_data")
self.package: ObjectID = sui_utils.as_object_id(package)
self.module_name: SuiString = module_name
self.function_name: SuiString = function_name

def _collect_parameters(self) -> list[ObjectID]:
"""Collect the call parameters."""
return [self.package, self.module_name, self.function_name]


class GetFunctionArgs(_NativeTransactionBuilder):
"""GetFunction When executed, returns the argument types of a Move function."""

def __init__(self, *, package: ObjectID, module: SuiString, function: SuiString) -> None:
"""__init__ Initialize GetModule object.
:param package: ObjectID of package to query
:type package: ObjectID
:param module: Name of module from package containing function_name to fetch
:type module: SuiString
:param function: Name of module's function to fetch arguments for
:type function: SuiString
"""
super().__init__(
"sui_getMoveFunctionArgTypes", handler_cls=SuiMoveFunctionArgumentTypes, handler_func="ingest_data"
)
self.package: ObjectID = sui_utils.as_object_id(package)
self.module: SuiString = module
self.function: SuiString = function

def _collect_parameters(self) -> list[ObjectID]:
"""Collect the call parameters."""
return [self.package, self.module, self.function]


class GetStructure(_NativeTransactionBuilder):
"""GetStructure When executed, returns a module's structure representation."""

def __init__(self, *, package: ObjectID, module_name: SuiString, structure_name: SuiString) -> None:
"""__init__ Initialize GetModule object.
:param package: ObjectID of package to query
:type package: ObjectID
:param module_name: Name of module from package containing function_name to fetch
:type module_name: SuiString
:param structure_name: Name of structure from structure to fetch
:type structure_name: SuiString
"""
super().__init__("sui_getNormalizedMoveStruct", handler_cls=SuiMoveStruct, handler_func="ingest_data")
self.package: ObjectID = sui_utils.as_object_id(package)
self.module_name: SuiString = module_name
self.structure_name: SuiString = structure_name

def _collect_parameters(self) -> list[ObjectID]:
"""Collect the call parameters."""
return [self.package, self.module_name, self.structure_name]


class GetRpcAPI(_NativeTransactionBuilder):
"""GetRpcAPI When executed, returns full list of SUI node RPC API supported."""

Expand Down
4 changes: 2 additions & 2 deletions pysui/sui/sui_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def get_package(self, package_id: ObjectID) -> Union[SuiRpcResult, Exception]:
:returns: The package detail data
:rtype: SuiRpcResult
"""
result = self.execute(GetPackage(package_id))
result = self.execute(GetPackage(package=package_id))
return result

def get_events(self, *, query: SuiMap, cursor: str, limit: int, descending_order: bool) -> SuiRpcResult:
Expand Down Expand Up @@ -831,7 +831,7 @@ async def get_package(self, package_id: ObjectID) -> Union[SuiRpcResult, Excepti
:returns: The package detail data
:rtype: SuiRpcResult
"""
result = await self.execute(GetPackage(package_id))
result = await self.execute(GetPackage(package=package_id))
return result

async def get_events(self, *, query: SuiMap, cursor: str, limit: int, descending_order: bool) -> SuiRpcResult:
Expand Down
113 changes: 100 additions & 13 deletions pysui/sui/sui_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@

# -*- coding: utf-8 -*-


"""Sui Types."""


from abc import ABC

import re

# import json
Expand All @@ -38,39 +35,78 @@
def valid_sui_address(instr: str) -> bool:
"""Verify Sui address string."""
inlen = len(instr)
if instr == "0x2":
return True
if instr == "Immutable":
return True
if inlen > SUI_HEX_ADDRESS_STRING_LEN or inlen < SUI_ADDRESS_STRING_LEN:
return False
# _kp = keypair_from_keystring(instr)
if inlen == SUI_HEX_ADDRESS_STRING_LEN and __fullstring_pattern.findall(instr):
return True
return __partstring_pattern.findall(instr)
match instr:
case "0x2" | "Immutable":
return True
case _:
if inlen > SUI_HEX_ADDRESS_STRING_LEN or inlen < SUI_ADDRESS_STRING_LEN:
return False
# _kp = keypair_from_keystring(instr)
if inlen == SUI_HEX_ADDRESS_STRING_LEN and __fullstring_pattern.findall(instr):
return True
return __partstring_pattern.findall(instr)


class SuiBaseType(AbstractType):
"""Base most SUI object type."""

def __init__(self, identifier: Any) -> None:
"""__init__ Native string initializing SuiString.
:param identifier: A native python type
:type identifier: Any
"""
super().__init__(identifier)


class SuiScalarType(SuiBaseType):
"""Base most SUI scalar type."""

def __init__(self, identifier: Any) -> None:
"""__init__ Native string initializing SuiString.
:param identifier: A native python type
:type identifier: Any
"""
super().__init__(identifier)


class SuiString(SuiScalarType):
"""Sui String type."""

def __init__(self, identifier: str) -> None:
"""__init__ Native string initializing SuiString.
:param identifier: A python str
:type identifier: str
"""
super().__init__(identifier)

@property
def function(self) -> str:
"""Alias for transactions."""
return self.value

@property
def function_name(self) -> str:
"""Alias for transactions."""
return self.value

@property
def module(self) -> str:
"""Alias for transactions."""
return self.value

@property
def module_name(self) -> str:
"""Alias for transactions."""
return self.value

@property
def struct_name(self) -> str:
"""Alias for transactions."""
return self.value

@property
def arguments(self) -> str:
"""Alias for transactions."""
Expand Down Expand Up @@ -1296,6 +1332,17 @@ class SuiMoveStruct(DataClassJsonMixin):
def __post_init__(self):
"""Post init processing for type parameters."""

@classmethod
def ingest_data(cls, indata: dict) -> "SuiMoveStruct":
"""ingest_data Ingest results of direct call to `sui_getNormalizedMoveStruct`.
:param indata: Dictionary containing structure defintion
:type indata: dict
:return: Instance of SuiMoveStruct
:rtype: SuiMoveFunction
"""
return SuiMoveStruct.from_dict(indata)


@dataclass
class SuiMoveVector(DataClassJsonMixin):
Expand Down Expand Up @@ -1341,6 +1388,24 @@ def __post_init__(self):
self.reference_to = SuiMoveType.resolve(self.reference_to)


@dataclass
class SuiMoveFunctionArgumentTypes(DataClassJsonMixin):
"""From getNormalized."""

arg_list: list[Union[str, dict[str, str]]]

@classmethod
def ingest_data(cls, indata: list) -> "SuiMoveFunctionArgumentTypes":
"""ingest_data Ingest results of calling `sui_getMoveFunctionArgTypes`.
:param indata: list containing function argument types
:type indata: list
:return: Instance of SuiMoveFunctionArgumentTypes
:rtype: SuiMoveFunctionArgumentTypes
"""
return SuiMoveFunctionArgumentTypes.from_dict({"arg_list": indata})


@dataclass
class SuiMoveFunction(DataClassJsonMixin):
"""From getNormalized."""
Expand Down Expand Up @@ -1370,6 +1435,17 @@ def __post_init__(self):
new_rets.append(parm)
self.returns = new_rets

@classmethod
def ingest_data(cls, indata: dict) -> "SuiMoveFunction":
"""ingest_data Ingest results of calling `sui_getNormalizedMoveFunction`.
:param indata: Dictionary containing function defintion
:type indata: dict
:return: Instance of SuiMoveFunction
:rtype: SuiMoveFunction
"""
return SuiMoveFunction.from_dict(indata)


# Module module information type
@dataclass
Expand Down Expand Up @@ -1397,6 +1473,17 @@ class SuiMoveModule(DataClassJsonMixin):
def __post_init__(self):
"""Post init processing for parameters."""

@classmethod
def ingest_data(cls, indata: dict) -> "SuiMoveModule":
"""ingest_data Ingest results of calling `sui_getNormalizedMoveModule`.
:param indata: Dictionary containing module defintion
:type indata: dict
:return: Instance of SuiMoveModule
:rtype: SuiMoveModule
"""
return SuiMoveModule.from_dict(indata)


@dataclass
class SuiMovePackage(DataClassJsonMixin):
Expand Down

0 comments on commit 7c0d5f4

Please sign in to comment.