Skip to content

Commit

Permalink
[sui-json-rpc] Use more efficient parser (#4306)
Browse files Browse the repository at this point in the history
* [sui-json-rpc] Use more efficient parser

- Use the newer parser for Moves type tags

* fixup! [sui-json-rpc] Use more efficient parser
  • Loading branch information
tnowacki authored Aug 29, 2022
1 parent 84c4f78 commit 5ad8a9c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions crates/sui-json-rpc-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ use move_binary_format::normalized::{
use move_bytecode_utils::module_cache::GetModule;
use move_core_types::identifier::Identifier;
use move_core_types::language_storage::{StructTag, TypeTag};
use move_core_types::parser::{parse_struct_tag, parse_type_tag};
use move_core_types::value::{MoveStruct, MoveStructLayout, MoveValue};
use schemars::JsonSchema;
use serde::ser::Error;
use serde::Deserialize;
use serde::Serialize;
use serde_json::Value;
use serde_with::serde_as;
use sui_types::{parse_sui_struct_tag, parse_sui_type_tag};
use tracing::warn;

use sui_json::SuiJsonValue;
Expand Down Expand Up @@ -477,7 +477,7 @@ impl TryInto<Object> for SuiObject<SuiRawData> {
fn try_into(self) -> Result<Object, Self::Error> {
let data = match self.data {
SuiRawData::MoveObject(o) => {
let struct_tag = parse_struct_tag(o.type_())?;
let struct_tag = parse_sui_struct_tag(o.type_())?;
Data::Move(unsafe {
MoveObject::new_from_execution(
struct_tag,
Expand Down Expand Up @@ -2091,7 +2091,7 @@ pub struct SuiTypeTag(String);
impl TryInto<TypeTag> for SuiTypeTag {
type Error = anyhow::Error;
fn try_into(self) -> Result<TypeTag, Self::Error> {
parse_type_tag(&self.0)
parse_sui_type_tag(&self.0)
}
}

Expand Down Expand Up @@ -2155,8 +2155,8 @@ impl TryInto<EventFilter> for SuiEventFilter {
Package(id) => EventFilter::Package(id),
Module(module) => EventFilter::Module(Identifier::new(module)?),
MoveEventType(event_type) => {
// parse_struct_tag converts StructTag string e.g. `0x2::devnet_nft::MintNFTEvent` to StructTag object
EventFilter::MoveEventType(parse_struct_tag(&event_type)?)
// parse_sui_struct_tag converts StructTag string e.g. `0x2::devnet_nft::MintNFTEvent` to StructTag object
EventFilter::MoveEventType(parse_sui_struct_tag(&event_type)?)
}
MoveEventField { path, value } => EventFilter::MoveEventField { path, value },
SenderAddress(address) => EventFilter::SenderAddress(address),
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev = "8d090

move-binary-format = { git = "https://github.com/move-language/move", rev = "70b34a66473c34ad30d101290b249f2db3c847a2" }
move-bytecode-utils = { git = "https://github.com/move-language/move", rev = "70b34a66473c34ad30d101290b249f2db3c847a2" }
move-command-line-common = { git = "https://github.com/move-language/move", rev = "70b34a66473c34ad30d101290b249f2db3c847a2" }
move-core-types = { git = "https://github.com/move-language/move", rev = "70b34a66473c34ad30d101290b249f2db3c847a2", features = ["address20"] }
move-disassembler = { git = "https://github.com/move-language/move", rev = "70b34a66473c34ad30d101290b249f2db3c847a2" }
move-ir-types = { git = "https://github.com/move-language/move", rev = "70b34a66473c34ad30d101290b249f2db3c847a2" }
Expand All @@ -57,4 +58,3 @@ workspace-hack = { path = "../workspace-hack"}

[dev-dependencies]
bincode = "1.3.3"

23 changes: 22 additions & 1 deletion crates/sui-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
)]

use base_types::ObjectID;
use move_core_types::account_address::AccountAddress;
use move_core_types::{
account_address::AccountAddress,
language_storage::{StructTag, TypeTag},
};

#[macro_use]
pub mod error;
Expand Down Expand Up @@ -59,3 +62,21 @@ const fn get_hex_address_two() -> AccountAddress {
pub fn sui_framework_address_concat_string(suffix: &str) -> String {
format!("{}{suffix}", SUI_FRAMEWORK_ADDRESS.to_hex_literal())
}

pub fn parse_sui_struct_tag(s: &str) -> anyhow::Result<StructTag> {
use move_command_line_common::types::ParsedStructType;
ParsedStructType::parse(s)?.into_struct_tag(&resolve_address)
}

pub fn parse_sui_type_tag(s: &str) -> anyhow::Result<TypeTag> {
use move_command_line_common::types::ParsedType;
ParsedType::parse(s)?.into_type_tag(&resolve_address)
}

fn resolve_address(addr: &str) -> Option<AccountAddress> {
match addr {
"std" => Some(MOVE_STDLIB_ADDRESS),
"sui" => Some(SUI_FRAMEWORK_ADDRESS),
_ => None,
}
}
6 changes: 3 additions & 3 deletions crates/sui/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
use anyhow::anyhow;
use clap::*;
use colored::Colorize;
use move_core_types::{language_storage::TypeTag, parser::parse_type_tag};
use move_core_types::language_storage::TypeTag;
use move_package::BuildConfig;
use serde::Serialize;
use serde_json::json;
Expand All @@ -33,7 +33,7 @@ use sui_types::{
messages::ExecuteTransactionRequestType,
messages::Transaction,
object::Owner,
SUI_FRAMEWORK_ADDRESS,
parse_sui_type_tag, SUI_FRAMEWORK_ADDRESS,
};
use tracing::info;

Expand Down Expand Up @@ -117,7 +117,7 @@ pub enum SuiClientCommands {
/// Function name in module
#[clap(
long,
parse(try_from_str = parse_type_tag),
parse(try_from_str = parse_sui_type_tag),
multiple_occurrences = false,
multiple_values = true
)]
Expand Down

0 comments on commit 5ad8a9c

Please sign in to comment.