Skip to content
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

[sui-json-rpc] Use more efficient parser #4306

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[sui-json-rpc] Use more efficient parser
- Use the newer parser for Moves type tags
  • Loading branch information
tnowacki committed Aug 25, 2022
commit 249117bee5ae1310ec79bc28bc57fa147b256977
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.

1 change: 1 addition & 0 deletions crates/sui-json-rpc-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bcs = "0.1.3"
move-binary-format = { git = "https://github.com/move-language/move", rev = "70b34a66473c34ad30d101290b249f2db3c847a2" }
move-core-types = { git = "https://github.com/move-language/move", rev = "70b34a66473c34ad30d101290b249f2db3c847a2", features = ["address20"] }
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" }

sui-types = { path = "../sui-types" }
sui-json = { path = "../sui-json" }
Expand Down
21 changes: 20 additions & 1 deletion crates/sui-json-rpc-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ use move_binary_format::normalized::{
Struct as NormalizedStruct, Type as NormalizedType,
};
use move_bytecode_utils::module_cache::GetModule;
use move_core_types::account_address::AccountAddress;
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::{MOVE_STDLIB_ADDRESS, SUI_FRAMEWORK_ADDRESS};
use tracing::warn;

use sui_json::SuiJsonValue;
Expand Down Expand Up @@ -2209,3 +2210,21 @@ impl TransactionBytes {
TransactionData::from_signable_bytes(&self.tx_bytes.to_vec()?)
}
}

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

fn parse_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.into()),
"sui" => Some(SUI_FRAMEWORK_ADDRESS.into()),
_ => None,
}
}