ChainMovers / suibase

Sui development environment and cookbook.
https://suibase.io
Apache License 2.0
35 stars 6 forks source link

Add Maturin UniFFI Bindings to Suibase #27

Closed mario4tier closed 1 year ago

mario4tier commented 1 year ago

Proposing the UX to be:

Took the idea from ( https://pyo3.rs/v0.18.3/ )

This method keeps the python package in-sync with the local suibase version.

mario4tier commented 1 year ago

The script basically do in the pip environment:

cd ~/suibase/rust/helper-uniffi
pip install maturin
maturin develop                   <-- This build + install/update the suibase python helper
mario4tier commented 1 year ago

commit 8568174b4f17295bda43e0e5381e7e59902b2d3f match the UniFFI strategy to favor portability/safety over performance.

In Rust terms: interior mutability achieve with Arc/Mutex to remain Sync+Send.

The API is now validated (at compile time) by the suibase.udl (a WebIDL-like language).

References: https://www.ralfj.de/projects/rust-101/part15.html https://mozilla.github.io/uniffi-rs/udl/interfaces.html#concurrent-access

mario4tier commented 1 year ago

This is now fully working. The documentation is still lacking though.

This is a demo after doing '~/suibase/pip-install':

(env) ~/suibase/rust/helper-uniffi$ python3
Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import suibase;
>>> helper=suibase.Helper();
>>> helper.is_installed()
True
>>> helper.select_workdir("active")
>>> helper.workdir()
'localnet'
>>> helper.client_address("active")
'0xf7ae71f84fabc58662bd4209a8893f462c60f247095bb35b19ff659ad0081462'
>>> helper.rpc_url()
'http://0.0.0.0:9000'
>>> helper.ws_url()
'ws://0.0.0.0:9000'
>>> helper.package_id("demo")
'0x794fc1d80f18a02eb0b7094d2f5a9f9f40bcf653996291f7a7086404689a19b5'
>>> helper.published_new_objects("demo::Counter::Counter")
['0xef876238524a33124a924aba5a141f2b317f1e61b12032e78fed5c6aba650093']