Skip to content

Commit

Permalink
Release 0.58.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC01 committed Apr 23, 2024
1 parent 7687cd8 commit 987ae2d
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 49 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@ 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.58.0] - Unpublished
## [0.58.0] - - 2024-04-22

### Added

- build_and_sign() to GraphQL SuiTransaction
- `merge_some` and `split_1_half` examples transactions in pgql_s_example.py

### Fixed

- [PR](https://github.com/FrankC01/pysui/pull/197) - Documentation
- [PR](https://github.com/FrankC01/pysui/pull/198) - Documentation


### Changed

- Bump support to Sui 1.24.0
- SuiCoinObjectGQL now supports various owner types (AddressOwner, Immutable, Shared, Parent)


### Removed

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.57.0 - Released 2024-04-15**
**Release-0.58.0 - Released 2024-04-22**

- Supports _SUI 1.24.x RPC API_
- Backwards compatable to _Sui 1.18.x RPC API_
Expand Down
54 changes: 45 additions & 9 deletions pgql_s_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,10 @@ def do_dry_run_new(client: SuiGQLClient):
This uses the new SuiTransaction (GraphQL RPC based)
"""
txer = SuiTransaction(client=client)
lres = txer.move_call(
target="0x2::address::length", arguments=[], type_arguments=[]
scres = txer.split_coin(coin=txer.gas, amounts=[1000000000])
txer.transfer_objects(
transfers=scres, recipient=client.config.active_address.address
)
# scres = txer.split_coin(coin=txer.gas, amounts=[1000000000])
# txer.transfer_objects(
# transfers=scres, recipient=client.config.active_address.address
# )

tx_b64 = base64.b64encode(txer.transaction_data().serialize()).decode()
print(tx_b64)
Expand Down Expand Up @@ -571,6 +568,44 @@ def do_execute_new(client: SuiGQLClient):
)


def merge_some(client: SuiGQLClient):
"""Merge all coins in wallet."""

result = client.execute_query_node(
with_node=qn.GetCoins(owner=client.config.active_address.address)
)
if result.is_ok() and len(result.result_data.data) > 1:
txer: SuiTransaction = SuiTransaction(client=client)
txer.merge_coins(merge_to=txer.gas, merge_from=result.result_data.data[1:])
tx_b64, sig_array = txer.build_and_sign()
handle_result(
client.execute_query_node(
with_node=qn.ExecuteTransaction(tx_bytestr=tx_b64, sig_array=sig_array)
)
)


def split_1_half(client: SuiGQLClient):
"""Merge all coins in wallet."""

result = client.execute_query_node(
with_node=qn.GetCoins(owner=client.config.active_address.address)
)
if result.is_ok() and len(result.result_data.data) == 1:
amount = int(int(result.result_data.data[0].balance) / 2)
txer: SuiTransaction = SuiTransaction(client=client)
scres = txer.split_coin(coin=txer.gas, amounts=[amount])
txer.transfer_objects(
transfers=scres, recipient=client.config.active_address.address
)
tx_b64, sig_array = txer.build_and_sign()
handle_result(
client.execute_query_node(
with_node=qn.ExecuteTransaction(tx_bytestr=tx_b64, sig_array=sig_array)
)
)


if __name__ == "__main__":

cfg = SuiConfig.default_config()
Expand All @@ -583,7 +618,7 @@ def do_execute_new(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 @@ -614,12 +649,13 @@ def do_execute_new(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)
# do_execute_new(client_init)

# merge_some(client_init)
# split_1_half(client_init)
## Config
# do_chain_id(client_init)
# do_configs(client_init)
Expand Down
31 changes: 29 additions & 2 deletions pysui/sui/sui_pgql/pgql_fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,39 @@ def fragment(self, schema: DSLSchema) -> DSLFragment:
previous_transaction=schema.TransactionBlock.digest
),
schema.Coin.owner.select(
# DSLInlineFragment()
# .on(schema.AddressOwner)
# .select(
# schema.AddressOwner.owner.select(
# coin_owner=schema.Owner.address
# )
# ),
DSLInlineFragment()
.on(schema.AddressOwner)
.select(
schema.AddressOwner.owner.select(
coin_owner=schema.Owner.address
)
address_id=schema.Owner.address
),
obj_owner_kind=DSLMetaField("__typename"),
),
DSLInlineFragment()
.on(schema.Shared)
.select(
initial_version=schema.Shared.initialSharedVersion,
obj_owner_kind=DSLMetaField("__typename"),
),
DSLInlineFragment()
.on(schema.Immutable)
.select(
obj_owner_kind=DSLMetaField("__typename"),
),
DSLInlineFragment()
.on(schema.Parent)
.select(
schema.Parent.parent.select(
parent_id=schema.Object.address
),
obj_owner_kind=DSLMetaField("__typename"),
),
),
schema.Coin.contents.select(
Expand Down
94 changes: 58 additions & 36 deletions pysui/sui/sui_pgql/pgql_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,41 @@ class ObjectReadDeletedGQL:
object_kind: str


@dataclasses_json.dataclass_json(letter_case=dataclasses_json.LetterCase.CAMEL)
@dataclasses.dataclass
class SuiObjectOwnedShared:
"""Collection of coin data objects."""

obj_owner_kind: str
initial_version: int


@dataclasses_json.dataclass_json(letter_case=dataclasses_json.LetterCase.CAMEL)
@dataclasses.dataclass
class SuiObjectOwnedAddress:
"""Collection of coin data objects."""

obj_owner_kind: str
address_id: str


@dataclasses_json.dataclass_json(letter_case=dataclasses_json.LetterCase.CAMEL)
@dataclasses.dataclass
class SuiObjectOwnedParent:
"""Collection of coin data objects."""

obj_owner_kind: str
parent_id: str


@dataclasses_json.dataclass_json(letter_case=dataclasses_json.LetterCase.CAMEL)
@dataclasses.dataclass
class SuiObjectOwnedImmutable:
"""Collection of coin data objects."""

obj_owner_kind: str


@dataclasses_json.dataclass_json(letter_case=dataclasses_json.LetterCase.CAMEL)
@dataclasses.dataclass
class SuiCoinObjectGQL(PGQL_Type):
Expand All @@ -91,9 +126,15 @@ class SuiCoinObjectGQL(PGQL_Type):
object_digest: str
balance: str
previous_transaction: str
coin_owner: str
# coin_owner: str
has_public_transfer: bool
coin_object_id: str
object_owner: Union[
SuiObjectOwnedAddress,
SuiObjectOwnedParent,
SuiObjectOwnedShared,
SuiObjectOwnedImmutable,
]

@property
def object_id(self) -> str:
Expand All @@ -104,7 +145,23 @@ def object_id(self) -> str:
def from_query(clz, in_data: dict) -> "SuiCoinObjectGQL":
"""From raw GraphQL result data."""
ser_dict: dict[str, Union[str, int]] = {}
owner = in_data.pop("owner")
owner_kind = owner["obj_owner_kind"]
_fast_flat(in_data, ser_dict)
match owner_kind:
case "AddressOwner":
ser_dict["object_owner"] = SuiObjectOwnedAddress(
owner_kind, owner["owner"]["address_id"]
)
case "Shared":
ser_dict["object_owner"] = SuiObjectOwnedShared.from_dict(owner)
case "Parent":
ser_dict["object_owner"] = SuiObjectOwnedParent(
owner_kind, owner["owner"]["parent_id"]
)
case "Immutable":
ser_dict["object_owner"] = SuiObjectOwnedImmutable(owner_kind)
# ser_dict = ser_dict | res_dict
return clz.from_dict(ser_dict)


Expand Down Expand Up @@ -157,41 +214,6 @@ def from_query(clz, in_data: dict) -> "SuiCoinObjectsGQL":
return SuiCoinObjectsGQL(dlist, ncurs)


@dataclasses_json.dataclass_json(letter_case=dataclasses_json.LetterCase.CAMEL)
@dataclasses.dataclass
class SuiObjectOwnedShared:
"""Collection of coin data objects."""

obj_owner_kind: str
initial_version: int


@dataclasses_json.dataclass_json(letter_case=dataclasses_json.LetterCase.CAMEL)
@dataclasses.dataclass
class SuiObjectOwnedAddress:
"""Collection of coin data objects."""

obj_owner_kind: str
address_id: str


@dataclasses_json.dataclass_json(letter_case=dataclasses_json.LetterCase.CAMEL)
@dataclasses.dataclass
class SuiObjectOwnedParent:
"""Collection of coin data objects."""

obj_owner_kind: str
parent_id: str


@dataclasses_json.dataclass_json(letter_case=dataclasses_json.LetterCase.CAMEL)
@dataclasses.dataclass
class SuiObjectOwnedImmutable:
"""Collection of coin data objects."""

obj_owner_kind: str


@dataclasses_json.dataclass_json(letter_case=dataclasses_json.LetterCase.CAMEL)
@dataclasses.dataclass
class SuiStakedCoinGQL:
Expand Down

0 comments on commit 987ae2d

Please sign in to comment.