Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 9 additions & 55 deletions crates/sncast/src/response/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ use crate::response::cast_message::SncastMessage;
use anyhow::Error;
use camino::Utf8PathBuf;
use conversions::string::IntoHexStr;
use conversions::{padded_felt::PaddedFelt, serde::serialize::CairoSerialize};
use conversions::{IntoConv, padded_felt::PaddedFelt, serde::serialize::CairoSerialize};
use foundry_ui::Message;
use foundry_ui::styling;
use indoc::formatdoc;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_json::json;
use starknet::core::types::contract::{AbiConstructor, AbiEntry};
use starknet_types_core::felt::Felt;
use std::fmt::Write;

#[derive(Clone, Serialize, Deserialize, CairoSerialize, Debug, PartialEq)]
pub struct DeclareTransactionResponse {
pub class_hash: PaddedFelt,
Expand Down Expand Up @@ -53,31 +55,6 @@ pub struct AlreadyDeclaredResponse {
pub class_hash: PaddedFelt,
}

impl CommandResponse for AlreadyDeclaredResponse {}

impl Message for SncastMessage<AlreadyDeclaredResponse> {
fn text(&self) -> String {
styling::OutputBuilder::new()
.success_message("Contract class already declared")
.blank_line()
.field(
"Class Hash",
&self.command_response.class_hash.into_hex_string(),
)
.build()
}

fn json(&self) -> Value {
serde_json::to_value(&self.command_response).unwrap_or_else(|err| {
json!({
"error": "Failed to serialize response",
"command": self.command,
"details": err.to_string()
})
})
}
}

#[derive(Clone, Serialize, Deserialize, CairoSerialize, Debug, PartialEq)]
#[serde(tag = "status")]
pub enum DeclareResponse {
Expand All @@ -86,37 +63,14 @@ pub enum DeclareResponse {
Success(DeclareTransactionResponse),
}

impl CommandResponse for DeclareResponse {}

impl Message for SncastMessage<DeclareResponse> {
fn text(&self) -> String {
match &self.command_response {
DeclareResponse::AlreadyDeclared(response) => styling::OutputBuilder::new()
.success_message("Contract class already declared")
.blank_line()
.field("Class Hash", &response.class_hash.into_hex_string())
.build(),
DeclareResponse::Success(response) => styling::OutputBuilder::new()
.success_message("Declaration completed")
.blank_line()
.field("Class Hash", &response.class_hash.into_hex_string())
.field(
"Transaction Hash",
&response.transaction_hash.into_hex_string(),
)
.build(),
impl DeclareResponse {
#[must_use]
pub fn class_hash(&self) -> Felt {
match self {
DeclareResponse::AlreadyDeclared(response) => response.class_hash.into_(),
DeclareResponse::Success(response) => response.class_hash.into_(),
}
}

fn json(&self) -> Value {
serde_json::to_value(&self.command_response).unwrap_or_else(|err| {
json!({
"error": "Failed to serialize response",
"command": self.command,
"details": err.to_string()
})
})
}
}

impl OutputLink for DeclareTransactionResponse {
Expand Down
Loading