-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat contract info: add impl for base64 xdr
- Loading branch information
Showing
11 changed files
with
294 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,55 @@ | ||
use std::{fmt::Debug, path::PathBuf}; | ||
use std::fmt::Debug; | ||
|
||
use crate::commands::contract::info::env_meta::Error::{NoEnvMetaPresent, NoSACEnvMeta}; | ||
use crate::commands::contract::info::shared; | ||
use crate::commands::contract::info::shared::fetch_wasm; | ||
use clap::{command, Parser}; | ||
use soroban_spec_tools::contract; | ||
use soroban_spec_tools::contract::Spec; | ||
|
||
use crate::commands::contract::InfoOutput; | ||
|
||
#[derive(Parser, Debug, Clone)] | ||
#[command(group( | ||
clap::ArgGroup::new("src") | ||
.required(true) | ||
.args(& ["wasm", "wasm_hash", "contract_id"]), | ||
))] | ||
#[group(skip)] | ||
pub struct Cmd { | ||
/// Wasm file to extract the meta from | ||
#[arg( | ||
long, | ||
conflicts_with = "wasm_hash", | ||
conflicts_with = "contract_id", | ||
group = "src" | ||
)] | ||
pub wasm: Option<PathBuf>, | ||
/// Wasm hash to get the meta for | ||
#[arg(long = "wasm-hash", group = "src")] | ||
pub wasm_hash: Option<String>, | ||
/// Contract ID to get the meta for | ||
#[arg(long = "id", env = "STELLAR_CONTRACT_ID", group = "src")] | ||
pub contract_id: Option<String>, | ||
/// Format of the output | ||
#[arg(long, default_value = "xdr-base64")] | ||
output: InfoOutput, | ||
#[command(flatten)] | ||
pub common: shared::Args, | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error {} | ||
pub enum Error { | ||
#[error(transparent)] | ||
Wasm(#[from] shared::Error), | ||
#[error(transparent)] | ||
Spec(#[from] contract::Error), | ||
#[error("Stellar asset contract doesn't contain meta information")] | ||
NoSACEnvMeta(), | ||
#[error("no meta present in provided WASM file")] | ||
NoEnvMetaPresent(), | ||
} | ||
|
||
impl Cmd { | ||
pub async fn run(&self) -> Result<String, Error> { | ||
Ok("env_meta".to_string()) // TODO | ||
let bytes = fetch_wasm(&self.common).await?; | ||
|
||
if bytes.is_none() { | ||
return Err(NoSACEnvMeta()); | ||
} | ||
let spec = Spec::new(&bytes.unwrap())?; | ||
|
||
if spec.env_meta_base64.is_none() { | ||
return Err(NoEnvMetaPresent()); | ||
} | ||
|
||
let res = match self.common.output { | ||
InfoOutput::XdrBase64 => spec.env_meta_base64.unwrap(), | ||
InfoOutput::Json => { | ||
unreachable!("TODO") | ||
} | ||
InfoOutput::JsonFormatted => { | ||
unreachable!("TODO") | ||
} | ||
}; | ||
|
||
Ok(res) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,58 @@ | ||
use std::fmt::Debug; | ||
use std::path::PathBuf; | ||
|
||
use crate::commands::contract::info::interface::Error::NoInterfacePresent; | ||
use crate::commands::contract::info::shared; | ||
use crate::commands::contract::info::shared::fetch_wasm; | ||
use clap::{command, Parser}; | ||
use soroban_spec_tools::contract; | ||
use soroban_spec_tools::contract::Spec; | ||
|
||
use crate::commands::contract::InfoOutput; | ||
|
||
#[derive(Parser, Debug, Clone)] | ||
#[command(group( | ||
clap::ArgGroup::new("src") | ||
.required(true) | ||
.args(& ["wasm", "wasm_hash", "contract_id"]), | ||
))] | ||
#[group(skip)] | ||
pub struct Cmd { | ||
/// Wasm file to extract the interface from | ||
#[arg( | ||
long, | ||
conflicts_with = "wasm_hash", | ||
conflicts_with = "contract_id", | ||
group = "src" | ||
)] | ||
pub wasm: Option<PathBuf>, | ||
/// Wasm hash to get the interface for | ||
#[arg(long = "wasm-hash", group = "src")] | ||
pub wasm_hash: Option<String>, | ||
/// Format of the output | ||
#[arg(long = "id", env = "STELLAR_CONTRACT_ID", group = "src")] | ||
pub contract_id: Option<String>, | ||
/// Format of the output | ||
#[arg(long, default_value = "xdr-base64")] | ||
output: InfoOutput, | ||
#[command(flatten)] | ||
pub common: shared::Args, | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error {} | ||
pub enum Error { | ||
#[error(transparent)] | ||
Wasm(#[from] shared::Error), | ||
#[error(transparent)] | ||
Spec(#[from] contract::Error), | ||
#[error("no interface present in provided WASM file")] | ||
NoInterfacePresent(), | ||
} | ||
|
||
impl Cmd { | ||
pub async fn run(&self) -> Result<String, Error> { | ||
Ok("interface".to_string()) // TODO | ||
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 | ||
} else { | ||
let spec = Spec::new(&bytes.unwrap())?; | ||
|
||
if spec.env_meta_base64.is_none() { | ||
return Err(NoInterfacePresent()); | ||
} | ||
|
||
spec.spec_base64.unwrap() | ||
}; | ||
|
||
let res = match self.common.output { | ||
InfoOutput::XdrBase64 => base64, | ||
InfoOutput::Json => { | ||
unreachable!("TODO") | ||
} | ||
InfoOutput::JsonFormatted => { | ||
unreachable!("TODO") | ||
} | ||
}; | ||
|
||
Ok(res) | ||
} | ||
} |
Oops, something went wrong.