Skip to content

Commit

Permalink
fix: add ProviderError in Error for FCall
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Dec 15, 2023
1 parent 8bba7d3 commit ae688eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions crates/cairo-serde/src/call.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! This file must be in the proc_macro2 crate that must be reworked.
use crate::{CairoSerde, Error, Result as CairoResult};
use starknet::core::types::{BlockId, BlockTag, FunctionCall};
use std::marker::PhantomData;

use crate::{CairoSerde, Error, Result as CairoResult};

#[derive(Debug)]
pub struct FCall<'p, P, T> {
pub call_raw: FunctionCall,
Expand Down Expand Up @@ -39,7 +40,7 @@ where
.provider
.call(self.call_raw, self.block_id)
.await
.map_err(|err| Error::Deserialize(format!("Deserialization error {}", err)))?;
.map_err(Error::Provider)?;

T::cairo_deserialize(&r, 0)
}
Expand Down
5 changes: 4 additions & 1 deletion crates/cairo-serde/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
use super::CairoSerde;

use starknet::core::types::FieldElement;
use starknet::providers::ProviderError;

/// Cairo types result.
pub type Result<T> = core::result::Result<T, Error>;

/// A cairo type error.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Invalid type found {0:?}.")]
InvalidTypeString(String),
#[error("Error during serialization {0:?}.")]
Serialize(String),
#[error("Error during deserialization {0:?}.")]
Deserialize(String),
#[error("Provider errror {0:?}.")]
Provider(#[from] ProviderError),
}

impl CairoSerde for Error {
Expand Down
6 changes: 3 additions & 3 deletions crates/rs/src/expand/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ impl CairoContract {
pub struct #reader<P: #snrs_providers::Provider + Sync> {
pub address: #snrs_types::FieldElement,
pub provider: P,
pub block_id: Option<#snrs_types::BlockId>,
pub block_id: #snrs_types::BlockId,
}

impl<P: #snrs_providers::Provider + Sync> #reader<P> {
pub fn new(
address: #snrs_types::FieldElement,
provider: P,
) -> Self {
Self { address, provider, block_id: None }
Self { address, provider, block_id: #snrs_types::BlockId::Tag(#snrs_types::BlockTag::Pending) }
}

pub fn set_contract_address(mut self, address: #snrs_types::FieldElement) {
Expand All @@ -60,7 +60,7 @@ impl CairoContract {
}

pub fn with_block(self, block_id: #snrs_types::BlockId) -> Self {
Self { block_id: Some(block_id), ..self }
Self { block_id, ..self }
}
}
};
Expand Down

0 comments on commit ae688eb

Please sign in to comment.