-
Notifications
You must be signed in to change notification settings - Fork 11.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JSONRPC] - Use a more structured dynamic field name instead of MoveValue::to_string #7318
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
8e8a54a
to
b07cab5
Compare
b2a0a62
to
65b3630
Compare
friendly nudge :) this PR need some reviews |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Things LGTM but I feel like someone more familiar with the crate might want to take a look at sui_serde changes.
Happy to stamp, just have a question about test coverage :)
public entry fun add_field_with_struct_name(o: &mut Object, v: Object) { | ||
sui::dynamic_field::add(&mut o.id, Name {name_str: std::string::utf8(b"Test Name")}, v); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add dynamic_object_field
tests for this case? The process to retrieve the inner name will be a tad different because of the wrapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure I will add tests for dynamic_object_field
ff3c02b
to
0762bd0
Compare
crates/sui-types/src/crypto.rs
Outdated
@@ -864,7 +865,7 @@ impl Signer<Signature> for Secp256k1KeyPair { | |||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Hash)] | |||
pub struct Secp256r1SuiSignature( | |||
#[schemars(with = "Base64")] | |||
#[serde_as(as = "Readable<Base64, Bytes>")] | |||
#[serde_as(as = "Readable<ToArray<Base64>, Bytes>")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this ToArray do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah i see... this is to use the sized array, why do we need it? (context is im probably going to replace this with a fastcrypto trait to do just this in a later PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya we need this because fast crypto's Base64
only support serde_as Vec<u8>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is used so I don't have to make changes in fast crypto 🙃, we can remove this once serde_as array is supported
0762bd0
to
1a49324
Compare
@@ -148,14 +149,14 @@ impl RpcReadApiServer for ReadApi { | |||
async fn get_dynamic_field_object( | |||
&self, | |||
parent_object_id: ObjectID, | |||
name: String, | |||
name: DynamicFieldName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to update https://github.com/MystenLabs/sui/blob/main/sdk/typescript/src/providers/json-rpc-provider.ts#L943 . I am happy to work on this by early next week
@patrickkuo any updates on this one? I believe it can be related to the #7668 implementation. |
I will update the TS SDK (this PR has been opened for too long, TS SDK support was added recently 🤣), will chase for approval after this. |
1a49324
to
2c6865c
Compare
2cb8d2b
to
2e7eef8
Compare
// Bincode does not like serde_json::Value, rocksdb will not insert the value without serializing value as string. | ||
#[schemars(with = "Value")] | ||
#[serde_as(as = "Readable<_, DisplayFromStr>")] | ||
pub value: Value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems a bit json-rpc specific to use a json::Value
here--someone looking at a DynamicFieldName
from inside Rust would presumably want to see a MoveStruct
or something else a bit more structured
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought MoveStruct is quite hard to construct in rust. Currently user can use the serde_json's macro json!{}
to construct the value, it is not structured but quite convenient. Maybe I can add something in the Rust SDK to accept more structured MoveValue input.
pub struct DynamicFieldName { | ||
#[schemars(with = "String")] | ||
#[serde_as(as = "Readable<DisplayFromStr, _>")] | ||
pub type_: TypeTag, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use a TypeTag
here, but a String
for object_type
above. Do we also want to change object_type
in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
object_type should use TypeTag
as well, I will change it now to make it consistent.
…f MoveValue::to_string
added serde adaptors to make fastcrypto's Hex, Base64 and Base58 work with array and TryFrom<Vec<u8>> types.
aabc0ac
to
2d6d9da
Compare
Current implementation of RPC dynamic field query use the
MoveValue::to_string
as name, which is quite ugly and hard to construct on client side to be used insui_getDynamicFieldObject
.Example name struct in move:
sui_getDynamicFields
response:This PR change the String name to
DynamicFieldName
, which is a struct of type and json value.The
name
field become more readable and easier to create on client side.Example response for primitive type name: