Skip to content

Commit

Permalink
Fixed logic related to class hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
integraledelebesgue committed Aug 27, 2024
1 parent 85f478e commit b11b1bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
26 changes: 19 additions & 7 deletions crates/sncast/src/helpers/scarb_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use scarb_api::{
use scarb_ui::args::PackagesFilter;
use shared::{command::CommandExt, print::print_as_warning};
use starknet::{
core::types::{contract::SierraClass, BlockId, FlattenedSierraClass},
core::types::{
contract::{CompiledClass, SierraClass},
BlockId, FlattenedSierraClass,
},
providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider, ProviderError},
};
use starknet_crypto::FieldElement;
Expand Down Expand Up @@ -202,27 +205,36 @@ pub fn read_manifest_and_build_artifacts(

pub struct CompiledContract {
pub class: FlattenedSierraClass,
pub class_hash: FieldElement,
pub sierra_class_hash: FieldElement,
pub casm_class_hash: FieldElement,
}

impl TryFrom<&StarknetContractArtifacts> for CompiledContract {
type Error = anyhow::Error;

fn try_from(artifacts: &StarknetContractArtifacts) -> Result<Self, Self::Error> {
let class = serde_json::from_str::<SierraClass>(&artifacts.sierra)
.context("Failed to parse sierra artifact")?
let sierra_class = serde_json::from_str::<SierraClass>(&artifacts.sierra)
.context("Failed to parse Sierra artifact")?
.flatten()?;

let class_hash = class.class_hash();
let compiled_class = serde_json::from_str::<CompiledClass>(&artifacts.casm)
.context("Failed to parse CASM artifact")?;

Ok(Self { class, class_hash })
let sierra_class_hash = sierra_class.class_hash();
let casm_class_hash = compiled_class.class_hash()?;

Ok(Self {
class: sierra_class,
sierra_class_hash,
casm_class_hash,
})
}
}

impl CompiledContract {
pub async fn is_declared(&self, provider: &JsonRpcClient<HttpTransport>) -> Result<bool> {
let block_id = BlockId::Tag(starknet::core::types::BlockTag::Pending);
let class_hash = self.class_hash;
let class_hash = self.sierra_class_hash;

let response = provider.get_class(block_id, class_hash).await;

Expand Down
6 changes: 5 additions & 1 deletion crates/sncast/src/starknet_commands/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ pub async fn declare_compiled(
.try_into_fee_settings(account.provider(), account.block_id())
.await?;

let CompiledContract { class, class_hash } = contract;
let CompiledContract {
class,
casm_class_hash: class_hash,
..
} = contract;

let result = match fee_settings {
FeeSettings::Eth { max_fee } => {
Expand Down

0 comments on commit b11b1bc

Please sign in to comment.