Skip to content

Commit

Permalink
[Wallet CLI UX] - wallet-cli move call string args no longer need quo…
Browse files Browse the repository at this point in the history
…te escape (MystenLabs#1996)

* * move call string args no longer need quote escape
* SuiJsonValue debug print fix
* split coin merge coin result output style fix

* fixup after rebase
  • Loading branch information
patrickkuo authored May 17, 2022
1 parent 16c8173 commit 9c160b2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 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.

1 change: 1 addition & 0 deletions sui_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ multiaddr = "0.14.0"
mysten-network = { git = "https://github.com/MystenLabs/mysten-infra", rev = "7c247967e5a5abd59ecaa75bc62b05bcdf4503fe" }
prometheus_exporter = "0.8.4"
once_cell = "1.10.0"
colored = "2.0.0"

sui-adapter = { path = "../crates/sui-adapter" }
sui-framework = { path = "../sui_programmability/framework" }
Expand Down
15 changes: 8 additions & 7 deletions sui_core/src/gateway_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use serde::Deserialize;
use serde::Serialize;
use serde_json::Value;

use colored::Colorize;
use sui_types::base_types::{
ObjectDigest, ObjectID, ObjectRef, SequenceNumber, SuiAddress, TransactionDigest,
};
Expand Down Expand Up @@ -99,9 +100,9 @@ pub struct SplitCoinResponse {
impl Display for SplitCoinResponse {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut writer = String::new();
writeln!(writer, "----- Certificate ----")?;
writeln!(writer, "{}", "----- Certificate ----".bold())?;
write!(writer, "{}", self.certificate)?;
writeln!(writer, "----- Split Coin Results ----")?;
writeln!(writer, "{}", "----- Split Coin Results ----".bold())?;

let coin = GasCoin::try_from(&self.updated_coin).map_err(fmt::Error::custom)?;
writeln!(writer, "Updated Coin : {}", coin)?;
Expand Down Expand Up @@ -135,9 +136,9 @@ pub struct MergeCoinResponse {
impl Display for MergeCoinResponse {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut writer = String::new();
writeln!(writer, "----- Certificate ----")?;
writeln!(writer, "{}", "----- Certificate ----".bold())?;
write!(writer, "{}", self.certificate)?;
writeln!(writer, "----- Merge Coin Results ----")?;
writeln!(writer, "{}", "----- Merge Coin Results ----".bold())?;

let coin = GasCoin::try_from(&self.updated_coin).map_err(fmt::Error::custom)?;
writeln!(writer, "Updated Coin : {}", coin)?;
Expand Down Expand Up @@ -638,14 +639,14 @@ impl Display for SuiTransactionKind {
writeln!(writer, "Recipient : {}", t.recipient)?;
writeln!(writer, "Object ID : {}", t.object_ref.object_id)?;
writeln!(writer, "Version : {:?}", t.object_ref.version)?;
writeln!(
write!(
writer,
"Object Digest : {}",
Base64::encode(t.object_ref.digest)
)?;
}
Self::Publish(_p) => {
writeln!(writer, "Transaction Kind : Publish")?;
write!(writer, "Transaction Kind : Publish")?;
}
Self::Call(c) => {
writeln!(writer, "Transaction Kind : Call")?;
Expand All @@ -657,7 +658,7 @@ impl Display for SuiTransactionKind {
writeln!(writer, "Module : {}", c.module)?;
writeln!(writer, "Function : {}", c.function)?;
writeln!(writer, "Arguments : {:?}", c.arguments)?;
writeln!(writer, "Type Arguments : {:?}", c.type_arguments)?;
write!(writer, "Type Arguments : {:?}", c.type_arguments)?;
}
}
write!(f, "{}", writer)
Expand Down
19 changes: 10 additions & 9 deletions sui_core/src/sui_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use std::collections::VecDeque;
use std::fmt::{Debug, Formatter};

use anyhow::{anyhow, bail};
// Alias the type names for clarity
Expand All @@ -16,7 +17,7 @@ use move_core_types::{
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::{Number, Value as JsonValue};
use serde_json::{json, Number, Value as JsonValue};

use sui_types::base_types::{decode_bytes_hex, ObjectID, SuiAddress};
use sui_types::move_package::MovePackage;
Expand All @@ -35,7 +36,7 @@ pub enum SuiJsonCallArg {
Pure(Vec<u8>),
}

#[derive(Eq, PartialEq, Debug, Clone, Deserialize, Serialize, JsonSchema)]
#[derive(Eq, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
pub struct SuiJsonValue(JsonValue);
impl SuiJsonValue {
pub fn new(json_value: JsonValue) -> Result<SuiJsonValue, anyhow::Error> {
Expand Down Expand Up @@ -141,6 +142,12 @@ impl SuiJsonValue {
}
}

impl Debug for SuiJsonValue {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}

fn try_from_bcs_bytes(bytes: &[u8]) -> Result<JsonValue, anyhow::Error> {
// Try to deserialize data
if let Ok(v) = bcs::from_bytes::<String>(bytes) {
Expand Down Expand Up @@ -175,13 +182,7 @@ fn try_from_bcs_bytes(bytes: &[u8]) -> Result<JsonValue, anyhow::Error> {
impl std::str::FromStr for SuiJsonValue {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, anyhow::Error> {
// Add quotes for hex value start with 0x if it's missing
let s = if s.starts_with(HEX_PREFIX) {
serde_json::from_str(&format!("\"{}\"", s))
} else {
serde_json::from_str(s)
}?;
SuiJsonValue::new(s)
SuiJsonValue::new(serde_json::from_value(json!(s))?)
}
}

Expand Down

0 comments on commit 9c160b2

Please sign in to comment.