Skip to content

Commit f8d307c

Browse files
[Feature]boostraped move (#12)
* feat: boostraped move * feat: dependancy graph * feat: grpc only support * fix: align Sui dependency sources --------- Signed-off-by: David <70471875+davidrotari19@users.noreply.github.com>
1 parent 2795cbe commit f8d307c

48 files changed

Lines changed: 870 additions & 1436 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ The format is based on [Keep a Changelog], and this project adheres to
1010
### Added
1111

1212
- Add `sui-move`: core Move-shaped type layer (traits, abilities, decoding).
13-
- Add Move framework primitives under `sui_move::primitives` (e.g. `coin`, `balance`, `vec_map`) with BCS-accurate tags/layouts.
13+
- Keep Move framework declarations out of the `sui-move` core so generated package bindings define
14+
`UID`, `Coin<T>`, `Balance<T>`, containers, and other framework shapes.
1415
- Add `sui-move-derive` and the `sui-move` `derive` feature for defining Move-shaped structs via macros.
1516
- Add `sui-move-call`: typed Move call descriptions (`CallSpec`) plus typed wrappers for Sui `Input` kinds (pure, immutable/owned, shared, receiving).
1617
- Add `sui-move-ptb`: minimal PTB builder that consumes `CallSpec` and produces `ProgrammableTransaction`.

‎Cargo.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ serde = { version = "1.0", features = ["derive"] }
1919
serde_json = "1.0"
2020
thiserror = "1.0"
2121
bcs = "0.1.6"
22-
sui-sdk-types = { version = "0.3.1", git = "https://github.com/mystenlabs/sui-rust-sdk", features = ["serde"] }
23-
sui-rpc = { version = "0.3.1", git = "https://github.com/mystenlabs/sui-rust-sdk" }
24-
sui-crypto = { version = "0.3.0", git = "https://github.com/mystenlabs/sui-rust-sdk" }
22+
sui-sdk-types = { version = "0.3.1", features = ["serde"] }
23+
sui-rpc = { version = "0.3.1" }
24+
sui-crypto = { version = "0.3.0" }
2525
proc-macro2 = "1"
2626
quote = "1"
2727
syn = { version = "2", features = ["full"] }

‎MODEL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Execution and checkpoint inclusion are distinct:
7373
- a transaction can be **executed** (effects exist),
7474
- later it can be **checkpointed** (indexes are updated; “read-your-writes” on that node).
7575

76-
RPC calls may time out waiting for checkpoint inclusion even though execution succeeded. A correct
76+
gRPC calls may time out waiting for checkpoint inclusion even though execution succeeded. A correct
7777
client abstraction must preserve recovery information (digest/effects when available) and represent
7878
finality explicitly rather than as a boolean.
7979

‎sui-move-call/README.md‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,14 @@ use sui_move::prelude::*;
7373
use sui_move_call::{CallSpec, MoveObject};
7474
use sui_sdk_types::{Address, Digest, ObjectReference, TypeTag};
7575

76+
#[sui_move::move_struct(address = "0x2", module = "object", abilities = "store")]
77+
pub struct UID {
78+
pub id: u64,
79+
}
80+
7681
#[sui_move::move_struct(address = "0x1", module = "vault", abilities = "key")]
7782
pub struct Vault {
78-
pub id: sui_move::types::UID,
83+
pub id: UID,
7984
}
8085

8186
pub fn withdraw(vault: &MoveObject<Vault>, amount: u64) -> CallSpec {
@@ -112,9 +117,14 @@ use std::str::FromStr;
112117
use sui_move_call::{CallArg, CallSpec, ReceivingMoveObject, SharedMoveObject};
113118
use sui_sdk_types::{Address, Digest, ObjectReference};
114119

120+
#[sui_move::move_struct(address = "0x2", module = "object", abilities = "store")]
121+
struct UID {
122+
id: u64,
123+
}
124+
115125
#[sui_move::move_struct(address = "0x1", module = "demo", abilities = "key")]
116126
struct Thing {
117-
id: sui_move::types::UID,
127+
id: UID,
118128
}
119129

120130
let package = Address::from_str("0x1").unwrap();
@@ -134,5 +144,5 @@ assert!(matches!(spec.arguments[1], CallArg::Receiving(_)));
134144
## Non-goals
135145

136146
- No transaction building: this crate does not produce `ProgrammableTransaction`.
137-
- No execution/runtime: this crate does not talk to RPC or submit transactions.
147+
- No execution/runtime: this crate does not talk to a network client or submit transactions.
138148
- No object fetching: object contents are not loaded or decoded here.

‎sui-move-call/src/lib.rs‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ pub use sui_sdk_types::Input as CallArg;
3131
/// use sui_move_call::MoveObject;
3232
/// use sui_sdk_types::{Address, Digest, ObjectReference};
3333
///
34+
/// # #[sui_move::move_struct(address = "0x2", module = "object", abilities = "store")]
35+
/// # struct UID { id: u64 }
36+
/// #
3437
/// #[sui_move::move_struct(address = "0x1", module = "demo", abilities = "key")]
3538
/// struct Demo {
36-
/// id: sui_move::types::UID,
39+
/// id: UID,
3740
/// }
3841
///
3942
/// let id = Address::from_str("0x1").unwrap();
@@ -82,9 +85,12 @@ impl<T: MoveStruct + HasKey> MoveObject<T> {
8285
/// use sui_move_call::SharedMoveObject;
8386
/// use sui_sdk_types::Address;
8487
///
88+
/// # #[sui_move::move_struct(address = "0x2", module = "object", abilities = "store")]
89+
/// # struct UID { id: u64 }
90+
/// #
8591
/// #[sui_move::move_struct(address = "0x1", module = "demo", abilities = "key")]
8692
/// struct SharedThing {
87-
/// id: sui_move::types::UID,
93+
/// id: UID,
8894
/// }
8995
///
9096
/// let object_id = Address::from_str("0x1").unwrap();
@@ -168,9 +174,12 @@ impl<T: MoveStruct + HasKey> SharedMoveObject<T> {
168174
/// use sui_move_call::ReceivingMoveObject;
169175
/// use sui_sdk_types::{Address, Digest, ObjectReference};
170176
///
177+
/// # #[sui_move::move_struct(address = "0x2", module = "object", abilities = "store")]
178+
/// # struct UID { id: u64 }
179+
/// #
171180
/// #[sui_move::move_struct(address = "0x1", module = "demo", abilities = "key")]
172181
/// struct ReceivingThing {
173-
/// id: sui_move::types::UID,
182+
/// id: UID,
174183
/// }
175184
///
176185
/// let id = Address::from_str("0x1").unwrap();
@@ -369,9 +378,12 @@ pub enum CallSpecError {
369378
/// use sui_move_call::{CallSpec, MoveObject};
370379
/// use sui_sdk_types::{Address, Digest, ObjectReference, TypeTag};
371380
///
381+
/// # #[sui_move::move_struct(address = "0x2", module = "object", abilities = "store")]
382+
/// # struct UID { id: u64 }
383+
/// #
372384
/// #[sui_move::move_struct(address = "0x1", module = "vault", abilities = "key")]
373385
/// struct Vault {
374-
/// id: sui_move::types::UID,
386+
/// id: UID,
375387
/// }
376388
///
377389
/// let package = Address::from_str("0x1").unwrap();

‎sui-move-call/tests/basic.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@ use sui_move_call::{
66
};
77
use sui_sdk_types::{Address, Digest, FundsWithdrawal, ObjectReference, TypeTag, WithdrawFrom};
88

9+
#[sui_move::move_struct(address = "0x2", module = "object", abilities = "copy, store")]
10+
struct ID {
11+
bytes: Address,
12+
}
13+
14+
#[sui_move::move_struct(address = "0x2", module = "object", abilities = "store")]
15+
struct UID {
16+
id: ID,
17+
}
18+
919
#[sui_move::move_struct(address = "0x1", module = "demo", abilities = "key")]
1020
struct Demo {
11-
id: sui_move::types::UID,
21+
id: UID,
1222
}
1323

1424
#[test]

‎sui-move-codegen/README.md‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,11 @@ assert!(code.contains("spec.push_type_arg::<T0>();"));
325325
## Example: fetch over gRPC
326326

327327
```rust,no_run
328-
use sui_move_codegen::fetch_package;
329-
use sui_rpc::Client;
328+
use sui_move_codegen::{fetch_package, GrpcClient};
330329
use sui_sdk_types::Address;
331330
332331
# async fn demo() -> Result<(), Box<dyn std::error::Error>> {
333-
let mut client = Client::new(Client::MAINNET_FULLNODE)?;
332+
let mut client = GrpcClient::new(GrpcClient::MAINNET_FULLNODE)?;
334333
let package_id: Address = "0x2".parse()?;
335334
336335
let pkg = fetch_package(&mut client, package_id).await?;
@@ -349,6 +348,35 @@ To keep builds deterministic, fetch metadata once and commit it (JSON), then ren
349348

350349
This avoids putting network access in CI/build scripts.
351350

351+
## Cross-package type resolution
352+
353+
The renderer only treats primitive Move types and datatypes from the package being rendered as
354+
intrinsic. Framework and dependency types are still ordinary package declarations, so register their
355+
generated Rust bindings explicitly:
356+
357+
```rust,no_run
358+
use sui_move_codegen::fetch_package;
359+
use sui_move_codegen::render::{render_package, RenderOptions};
360+
use sui_move_codegen::GrpcClient;
361+
use sui_sdk_types::Address;
362+
363+
# async fn demo() -> Result<(), Box<dyn std::error::Error>> {
364+
let mut client = GrpcClient::new(GrpcClient::MAINNET_FULLNODE)?;
365+
366+
let framework = fetch_package(&mut client, "0x2".parse::<Address>()?).await?;
367+
let app = fetch_package(&mut client, "0x123".parse::<Address>()?).await?;
368+
369+
let opts = RenderOptions::default().with_external_package(&framework, "sui_framework");
370+
let code = render_package(&app, &opts);
371+
# let _ = code;
372+
# Ok(())
373+
# }
374+
```
375+
376+
Without an external binding, an external datatype renders as a `compile_error!`. That keeps missing
377+
dependency bindings explicit instead of silently reintroducing handwritten framework mirrors into
378+
`sui-move`.
379+
352380
## Using the generated code
353381

354382
The rendered Rust is meant to live in its own crate or module. At minimum, the generated code

‎sui-move-codegen/src/lib.rs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ pub mod render;
1313

1414
pub use crate::source::fetch_package;
1515

16+
/// Sui gRPC client used by package metadata fetching.
17+
pub type GrpcClient = sui_rpc::Client;
18+
1619
/// Errors from sourcing or normalizing package metadata.
1720
#[derive(thiserror::Error, Debug)]
1821
pub enum Error {
19-
/// RPC request failed.
20-
#[error("rpc: {0}")]
21-
Rpc(String),
22+
/// gRPC request failed.
23+
#[error("grpc: {0}")]
24+
Grpc(String),
2225

2326
/// Package missing from response.
2427
#[error("package missing from response")]
Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
//! Mapping for common Sui framework types.
1+
//! Mapping for irreducible built-in Move types.
2+
//!
3+
//! Sui framework types such as `0x2::object::UID`, `0x2::coin::Coin`, and
4+
//! `0x1::option::Option` are deliberately not mapped here. They are package-defined datatypes and
5+
//! must be generated from package metadata like any other Move package.
26
37
use proc_macro2::TokenStream;
4-
use quote::quote;
58

69
use crate::ir::TypeName;
710

@@ -15,55 +18,6 @@ pub(crate) struct BuiltinDatatype {
1518
}
1619

1720
pub(crate) fn map_builtin(type_name: &TypeName, use_aliases: bool) -> Option<BuiltinDatatype> {
18-
let address = type_name.address.as_str();
19-
let module = type_name.module.as_str();
20-
let name = type_name.name.as_str();
21-
22-
let (path, is_key) = match (address, module, name) {
23-
("0x2", "object", "UID") => (sm(use_aliases, quote! { types::UID }), false),
24-
("0x2", "object", "ID") => (sm(use_aliases, quote! { types::ID }), false),
25-
("0x2", "sui", "SUI") => (sm(use_aliases, quote! { sui::SUI }), false),
26-
("0x2", "bag", "Bag") => (sm(use_aliases, quote! { bag::Bag }), true),
27-
("0x2", "balance", "Balance") => (sm(use_aliases, quote! { balance::Balance }), false),
28-
("0x2", "coin", "Coin") => (sm(use_aliases, quote! { coin::Coin }), true),
29-
("0x2", "clock", "Clock") => (sm(use_aliases, quote! { clock::Clock }), true),
30-
("0x2", "tx_context", "TxContext") => {
31-
(sm(use_aliases, quote! { tx_context::TxContext }), false)
32-
}
33-
("0x1", "type_name", "TypeName") => {
34-
(sm(use_aliases, quote! { type_name::TypeName }), false)
35-
}
36-
("0x1", "ascii", "String") => (sm(use_aliases, quote! { ascii::String }), false),
37-
("0x2", "vec_map", "VecMap") => (sm(use_aliases, quote! { vec_map::VecMap }), false),
38-
("0x2", "vec_set", "VecSet") => (sm(use_aliases, quote! { vec_set::VecSet }), false),
39-
("0x2", "object_bag", "ObjectBag") => {
40-
(sm(use_aliases, quote! { object_bag::ObjectBag }), true)
41-
}
42-
("0x2", "linked_table", "LinkedTable") => {
43-
(sm(use_aliases, quote! { linked_table::LinkedTable }), false)
44-
}
45-
("0x2", "object_table", "ObjectTable") => {
46-
(sm(use_aliases, quote! { object_table::ObjectTable }), false)
47-
}
48-
("0x1", "option", "Option") => (sm(use_aliases, quote! { containers::MoveOption }), false),
49-
("0x2", "table", "Table") => (sm(use_aliases, quote! { containers::Table }), false),
50-
("0x2", "dynamic_field", "Field") => {
51-
(sm(use_aliases, quote! { containers::DynamicField }), false)
52-
}
53-
("0x2", "dynamic_object_field", "DynamicField") => (
54-
sm(use_aliases, quote! { containers::DynamicObjectField }),
55-
false,
56-
),
57-
_ => return None,
58-
};
59-
60-
Some(BuiltinDatatype { path, is_key })
61-
}
62-
63-
fn sm(use_aliases: bool, path: TokenStream) -> TokenStream {
64-
if use_aliases {
65-
quote! { sm::#path }
66-
} else {
67-
quote! { sui_move::#path }
68-
}
21+
let _ = (type_name, use_aliases);
22+
None
6923
}

‎sui-move-codegen/src/render/calls.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ fn is_object_type(
167167
if let Some(builtin) = builtins::map_builtin(type_name, opts.use_aliases) {
168168
return builtin.is_key;
169169
}
170+
if let Some(external) = opts.external_types.get(type_name) {
171+
return external.is_key;
172+
}
170173
pkg.modules
171174
.get(&type_name.module)
172175
.and_then(|m| {

0 commit comments

Comments
 (0)