-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f3493f
commit e0d2798
Showing
5 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::Result; | ||
use clap::Parser; | ||
use serde_json_pythonic::to_string_pythonic; | ||
use starknet::core::types::contract::{legacy::LegacyContractClass, CompiledClass, SierraClass}; | ||
|
||
use crate::{path::ExpandedPathbufParser, utils::print_colored_json}; | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct Abi { | ||
#[clap( | ||
long, | ||
help = "Present the ABI as a flattened string in a Pythoic style" | ||
)] | ||
flatten: bool, | ||
#[clap( | ||
value_parser = ExpandedPathbufParser, | ||
help = "Path to contract artifact file" | ||
)] | ||
file: PathBuf, | ||
} | ||
|
||
impl Abi { | ||
pub fn run(self) -> Result<()> { | ||
// Working around a deserialization bug in `starknet-rs`: | ||
// https://github.com/xJonathanLEI/starknet-rs/issues/392 | ||
|
||
if let Ok(class) = | ||
serde_json::from_reader::<_, SierraClass>(std::fs::File::open(&self.file)?) | ||
{ | ||
let abi = class.abi; | ||
if self.flatten { | ||
println!("{}", to_string_pythonic(&abi)?); | ||
} else { | ||
print_colored_json(&abi)?; | ||
} | ||
} else if let Ok(class) = | ||
serde_json::from_reader::<_, LegacyContractClass>(std::fs::File::open(&self.file)?) | ||
{ | ||
let abi = class.abi; | ||
if self.flatten { | ||
println!("{}", to_string_pythonic(&abi)?); | ||
} else { | ||
print_colored_json(&abi)?; | ||
} | ||
} else if serde_json::from_reader::<_, CompiledClass>(std::fs::File::open(self.file)?) | ||
.is_ok() | ||
{ | ||
anyhow::bail!("cannot extract ABI from casm"); | ||
} else { | ||
anyhow::bail!("failed to parse contract artifact"); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
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