Skip to content

Commit

Permalink
Release 0.59.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC01 committed May 2, 2024
1 parent 72c6b52 commit e797b54
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 94 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ 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.59.0] - Unpublished
## [0.59.0] - 2024-05-02

### Added

### Fixed

- [bug](https://github.com/FrankC01/pysui/issues/201) - Parameter passing fix for JSON RPC
- [bug](https://github.com/FrankC01/pysui/issues/200) - Typo in cursor reference in sample code

### Changed

- GetTx querynode includes richer object changes effects content.

### Removed

- `split_coin_and_return` from GraphQL SuiTransaction. Less costly to just split and transfer
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.58.0 - Released 2024-04-22**
**Release-0.59.0 - Released 2024-05-02**

- Supports _SUI 1.24.x RPC API_
- Backwards compatable to _Sui 1.18.x RPC API_
Expand Down
6 changes: 3 additions & 3 deletions pgql_s_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def do_tx(client: SuiGQLClient):

handle_result(
client.execute_query_node(
with_node=qn.GetTx(digest="7ZP8jboeNPu6vKx6pnx9CxmvDsXV9CKu48sv2LLCAuUj")
with_node=qn.GetTx(digest="BJYyvkTgZBuMgBx8MmgcGtBTYqYZwpFQcc2YHZq4A6Z8")
)
)

Expand Down Expand Up @@ -626,7 +626,7 @@ def split_1_half(client: SuiGQLClient):
## QueryNodes (fetch)
# do_coin_meta(client_init)
# do_coins_for_type(client_init)
# do_gas(client_init)
do_gas(client_init)
# do_all_gas(client_init)
# do_gas_ids(client_init)
# do_sysstate(client_init)
Expand Down Expand Up @@ -657,7 +657,7 @@ def split_1_half(client: SuiGQLClient):
# do_module(client_init)
# do_package(client_init)
# do_dry_run(client_init)
do_dry_run_new(client_init)
# do_dry_run_new(client_init)
# do_dry_run_kind_new(client_init)
# do_dry_run_kind(client_init)
# do_execute(client_init)
Expand Down
68 changes: 23 additions & 45 deletions pysui/sui/sui_builders/base_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from enum import IntEnum
from typing import Type, Union, get_args
import typing_utils
from pysui import SuiAddress
from deprecated.sphinx import versionchanged
from pysui.abstracts.client_types import SuiBaseType
from pysui.abstracts.client_rpc import Builder
Expand Down Expand Up @@ -123,30 +124,28 @@ def __init__(
self._handler_cls: Type[SuiBaseType] = handler_cls
self._handler_func: str = handler_func

@versionchanged(
version="0.24.0", reason="Moved from list to dict for RPC params"
)
@versionchanged(version="0.24.0", reason="Moved from list to dict for RPC params")
def _pull_vars(self) -> dict:
"""Filter out private/protected var elements."""
var_map = vars(self)
outparms = {}
vparms = []
for key, value in var_map.items():
if key[0] != "_":
outparms[key] = value
return outparms

@versionchanged(
version="0.24.0", reason="Moved from list to dict for RPC params"
)
vparms.append(value)
return vparms
# outparms = {}
# for key, value in var_map.items():
# if key[0] != "_":
# outparms[key] = value
# return outparms

@versionchanged(version="0.24.0", reason="Moved from list to dict for RPC params")
def _collect_parameters(self) -> dict:
"""Collect the call parameters."""
# TODO: Merge with `params` method when refactored or just remove abstract decl
return self._pull_vars()

@property
@versionchanged(
version="0.24.0", reason="Moved from list to dict for RPC params"
)
@versionchanged(version="0.24.0", reason="Moved from list to dict for RPC params")
def params(self) -> dict:
"""Return parameters list."""
return self._pull_vars()
Expand Down Expand Up @@ -217,23 +216,17 @@ def value_type_validator(
has_type in COERCION_FROM_TO_SETS
and ctype_value in COERCION_FROM_TO_SETS[has_type]
):
result_dict[ctype_key] = COERCION_FN_MAP[ctype_value](
args[ctype_key]
)
result_dict[ctype_key] = COERCION_FN_MAP[ctype_value](args[ctype_key])
# If no value in argument but type supports Optional
elif not args[ctype_key]:
if has_type in COERCION_FN_MAP:
result_dict[ctype_key] = COERCION_FN_MAP[has_type](
ctype_key
)
result_dict[ctype_key] = COERCION_FN_MAP[has_type](ctype_key)
else:
raise TypeError(
f"{ctype_key} has no value and no coercion function. In {has_type}"
)
elif has_type in COERCION_TO_FROM_SETS:
result_dict[ctype_key] = COERCION_FN_MAP[has_type](
args[ctype_key]
)
result_dict[ctype_key] = COERCION_FN_MAP[has_type](args[ctype_key])
else:
# We get here if we can't coerce type
raise ValueError(
Expand Down Expand Up @@ -289,10 +282,7 @@ def sui_true_type(anno) -> object:
:return: True type as object
:rtype: object
"""
if (
"_name" in anno.__dict__
and anno.__dict__["_name"] == "Optional"
):
if "_name" in anno.__dict__ and anno.__dict__["_name"] == "Optional":
return get_args(anno)[0]
return anno

Expand Down Expand Up @@ -322,42 +312,32 @@ def wrapper(self, *args, **kwargs) -> None:
# handle default values
if spec.defaults:
# if defaults:
for attr, val in zip(
reversed(spec.args), reversed(spec.defaults)
):
for attr, val in zip(reversed(spec.args), reversed(spec.defaults)):
if sieve(attr):
__var_map[attr] = val
__var_type_map[attr] = sui_true_type(
spec.annotations[attr]
)
__var_type_map[attr] = sui_true_type(spec.annotations[attr])
# # handle positional arguments
positional_attrs = spec.args[1:]
for attr, val in zip(positional_attrs, args):
if sieve(attr):
__var_map[attr] = val
__var_type_map[attr] = sui_true_type(
spec.annotations[attr]
)
__var_type_map[attr] = sui_true_type(spec.annotations[attr])
# __var_type_map[attr] = spec.annotations[attr]

# handle keyword args
if kwargs:
for attr, val in kwargs.items():
if sieve(attr):
__var_map[attr] = val
__var_type_map[attr] = sui_true_type(
spec.annotations[attr]
)
__var_type_map[attr] = sui_true_type(spec.annotations[attr])
# __var_type_map[attr] = spec.annotations[attr]

# handle keywords with defaults:
if spec.kwonlydefaults:
for attr, val in spec.kwonlydefaults.items():
if not __var_map[attr] and sieve(attr):
__var_map[attr] = val
__var_type_map[attr] = sui_true_type(
spec.annotations[attr]
)
__var_type_map[attr] = sui_true_type(spec.annotations[attr])
# __var_type_map[attr] = spec.annotations[attr]

def my_set_lambda(name, coerce, self, val):
Expand Down Expand Up @@ -394,9 +374,7 @@ def my_get_lambda(name, self):
# Setup the properties (getter, setter)
myclass = self.__class__
for _new_key, _new_val in _instance_dict.items():
coercer = COERCION_FN_MAP.get(
__var_type_map[_new_key], lambda x: x
)
coercer = COERCION_FN_MAP.get(__var_type_map[_new_key], lambda x: x)
setattr(
myclass,
_new_key,
Expand Down
10 changes: 6 additions & 4 deletions pysui/sui/sui_builders/get_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,9 @@ def __init__(self, cp_id: SuiString):
@property
def params(self) -> dict:
"""."""
res = super().params
return {"id": res["cp_id"]}
return super().params
# res = super().params
# return {"id": res["cp_id"]}


@versionchanged(
Expand All @@ -890,8 +891,9 @@ def __init__(self, cp_seq: SuiString):
@property
def params(self) -> dict:
"""."""
res = super().params
return {"id": res["cp_seq"]}
return super().params
# res = super().params
# return {"id": res["cp_seq"]}


@deprecated(version="0.52.0", reason="Use QueryNode equivalent")
Expand Down
4 changes: 3 additions & 1 deletion pysui/sui/sui_clients/sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ def is_synchronous(self) -> bool:
def _execute(self, builder: SuiBaseBuilder) -> Union[SuiRpcResult, Exception]:
"""Execute the builder construct."""
# Validate builder and send request
vres = self._validate_builder(builder)
# print(vres)
try:
result = self._client.post(
self.config.rpc_url,
headers=builder.header,
json=self._validate_builder(builder),
json=vres,
)
return SuiRpcResult(
True,
Expand Down
3 changes: 2 additions & 1 deletion pysui/sui/sui_pgql/pgql_fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ class StandardTxEffects(PGQL_Fragment):
@cache
def fragment(self, schema: DSLSchema) -> DSLFragment:
"""."""
base_obj = BaseObject().fragment(schema)
# base_obj = BaseObject().fragment(schema)
base_obj = StandardObject().fragment(schema)
gas_cost = GasCost().fragment(schema)

return (
Expand Down
2 changes: 2 additions & 0 deletions pysui/sui/sui_pgql/pgql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ def as_document_node(self, schema: DSLSchema) -> DocumentNode:
"""
std_txn = frag.StandardTransaction().fragment(schema)
tx_effects = frag.StandardTxEffects().fragment(schema)
std_object = frag.StandardObject().fragment(schema)
base_object = frag.BaseObject().fragment(schema)
gas_cost = frag.GasCost().fragment(schema)
qres = schema.Query.transactionBlock(digest=self.digest)
Expand All @@ -629,6 +630,7 @@ def as_document_node(self, schema: DSLSchema) -> DocumentNode:
std_txn,
tx_effects,
base_object,
std_object,
gas_cost,
DSLQuery(qres),
)
Expand Down
60 changes: 45 additions & 15 deletions pysui/sui/sui_txn_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def __parm_array_list(in_array: Any, api_parm_name: str) -> list[Any]:


@versionchanged(version="0.24.0", reason="Moved from list to dict for RPC params")
def __validate_parameter(build_parm: Any, api_parm: SuiApiParam) -> Union[str, SuiRpcApiInvalidParameter]:
def __validate_parameter(
build_parm: Any, api_parm: SuiApiParam
) -> Union[str, SuiRpcApiInvalidParameter]:
"""Validate the specific parameter."""
att = getattr(build_parm, api_parm.name)
match api_parm.schema.type:
Expand All @@ -69,33 +71,61 @@ def __validate_parameter(build_parm: Any, api_parm: SuiApiParam) -> Union[str, S

# print(f"att {api_parm.name} = {att}")
if att is None and api_parm.required:
raise SuiRpcApiInvalidParameter(f"builder {build_parm} does not have attribute {api_parm.name}")
raise SuiRpcApiInvalidParameter(
f"builder {build_parm} does not have attribute {api_parm.name}"
)
return att


# def _parameter_check(api_method: SuiApi, builder: Builder) -> Union[tuple[str, str], SuiRpcApiInvalidParameter]:
# """Perform parameter validations."""
# # All calls take at least 1 parameter
# build_parms = builder.params
# if len(build_parms) != len(api_method.params):
# raise SuiRpcApiInvalidParameter(
# f"API Expected {len(api_method.params)} parameters for {builder.method} but found {len(build_parms)}"
# )

# results = {}
# index = 0
# for bkey, bvalue in build_parms.items():
# api_def = api_method.params[index]
# if bkey == api_def.name:
# vres = __validate_parameter(bvalue, api_def)
# results[bkey] = vres
# index += 1
# else:
# raise SuiRpcApiInvalidParameter(f"Expected {api_method.name} found {bkey}")
# return results


@versionchanged(version="0.24.0", reason="Moved from list to dict for RPC params")
def _parameter_check(api_method: SuiApi, builder: Builder) -> Union[tuple[str, str], SuiRpcApiInvalidParameter]:
@versionchanged(
version="0.59.0", reason="Sui stopped supporting JSON dicts, reverting back to list"
)
def _parameter_check(
api_method: SuiApi, builder: Builder
) -> Union[tuple[str, str], SuiRpcApiInvalidParameter]:
"""Perform parameter validations."""
# All calls take at least 1 parameter
parmlen = len(api_method.params)
build_parms = builder.params
if len(build_parms) != len(api_method.params):
if len(build_parms) != parmlen:
raise SuiRpcApiInvalidParameter(
f"API Expected {len(api_method.params)} parameters for {builder.method} but found {len(build_parms)}"
f"API Expected {parmlen} parameters for {builder.method} but found {len(build_parms)}"
)

results = {}
results = []
index = 0
for bkey, bvalue in build_parms.items():
api_def = api_method.params[index]
if bkey == api_def.name:
vres = __validate_parameter(bvalue, api_def)
results[bkey] = vres
index += 1
else:
raise SuiRpcApiInvalidParameter(f"Expected {api_method.name} found {bkey}")
while index < parmlen:
vres = __validate_parameter(build_parms[index], api_method.params[index])
results.append(vres)
index = index + 1
return results


def validate_api(api_method: SuiApi, builder: Builder) -> Union[tuple[str, str], SuiRpcApiInvalidParameter]:
def validate_api(
api_method: SuiApi, builder: Builder
) -> Union[tuple[str, str], SuiRpcApiInvalidParameter]:
"""Validate the API parameters and arguments."""
return _parameter_check(api_method, builder)
Loading

0 comments on commit e797b54

Please sign in to comment.