Skip to content

Commit

Permalink
stellar info: add json support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifropc committed Aug 6, 2024
1 parent 92d21c0 commit c123022
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
10 changes: 4 additions & 6 deletions cmd/soroban-cli/src/commands/contract/info/env_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub enum Error {
NoSACEnvMeta(),
#[error("no meta present in provided WASM file")]
NoEnvMetaPresent(),
#[error(transparent)]
Json(#[from] serde_json::Error),
}

impl Cmd {
Expand All @@ -42,12 +44,8 @@ impl Cmd {

let res = match self.common.output {
InfoOutput::XdrBase64 => spec.env_meta_base64.unwrap(),
InfoOutput::Json => {
unreachable!("TODO")
}
InfoOutput::JsonFormatted => {
unreachable!("TODO")
}
InfoOutput::Json => serde_json::to_string(&spec.env_meta)?,
InfoOutput::JsonFormatted => serde_json::to_string_pretty(&spec.env_meta)?,
};

Ok(res)
Expand Down
18 changes: 7 additions & 11 deletions cmd/soroban-cli/src/commands/contract/info/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,30 @@ pub enum Error {
Spec(#[from] contract::Error),
#[error("no interface present in provided WASM file")]
NoInterfacePresent(),
#[error(transparent)]
Json(#[from] serde_json::Error),
}

impl Cmd {
pub async fn run(&self) -> Result<String, Error> {
let bytes = fetch_wasm(&self.common).await?;

let base64 = if bytes.is_none() {
let res = Spec::spec_to_base64(&soroban_sdk::token::StellarAssetSpec::spec_xdr())?;

res.0
let (base64, spec) = if bytes.is_none() {
Spec::spec_to_base64(&soroban_sdk::token::StellarAssetSpec::spec_xdr())?
} else {
let spec = Spec::new(&bytes.unwrap())?;

if spec.env_meta_base64.is_none() {
return Err(NoInterfacePresent());
}

spec.spec_base64.unwrap()
(spec.spec_base64.unwrap(), spec.spec)
};

let res = match self.common.output {
InfoOutput::XdrBase64 => base64,
InfoOutput::Json => {
unreachable!("TODO")
}
InfoOutput::JsonFormatted => {
unreachable!("TODO")
}
InfoOutput::Json => serde_json::to_string(&spec)?,
InfoOutput::JsonFormatted => serde_json::to_string_pretty(&spec)?,
};

Ok(res)
Expand Down
10 changes: 4 additions & 6 deletions cmd/soroban-cli/src/commands/contract/info/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub enum Error {
NoSACMeta(),
#[error("no meta present in provided WASM file")]
NoMetaPresent(),
#[error(transparent)]
Json(#[from] serde_json::Error),
}

impl Cmd {
Expand All @@ -43,12 +45,8 @@ impl Cmd {

let res = match self.common.output {
InfoOutput::XdrBase64 => spec.meta_base64.unwrap(),
InfoOutput::Json => {
unreachable!("TODO")
}
InfoOutput::JsonFormatted => {
unreachable!("TODO")
}
InfoOutput::Json => serde_json::to_string(&spec.meta)?,
InfoOutput::JsonFormatted => serde_json::to_string_pretty(&spec.meta)?,
};

Ok(res)
Expand Down

0 comments on commit c123022

Please sign in to comment.