From 334c83cb36c7ad5a6ba4368895ee6b7749f5a01c Mon Sep 17 00:00:00 2001 From: mitchell Date: Sun, 25 Feb 2024 11:25:47 -0800 Subject: [PATCH] Add tracing to checking account example --- sample-dApps/checking_account/Cargo.toml | 1 + sample-dApps/checking_account/src/lib.rs | 3 +++ sample-dApps/checking_account/src/main.rs | 1 + src/smart_contract.rs | 13 +++++++++++-- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sample-dApps/checking_account/Cargo.toml b/sample-dApps/checking_account/Cargo.toml index 5d7ea89..4b62358 100644 --- a/sample-dApps/checking_account/Cargo.toml +++ b/sample-dApps/checking_account/Cargo.toml @@ -28,3 +28,4 @@ serde_json = "1.0" serde = { version = "1.0.143", features = ["derive"] } thiserror = "1.0.24" tokio = { version = "1.20.1", features = ["full"] } +tracing-subscriber = "0.3.18" diff --git a/sample-dApps/checking_account/src/lib.rs b/sample-dApps/checking_account/src/lib.rs index afe09e2..91c3a40 100644 --- a/sample-dApps/checking_account/src/lib.rs +++ b/sample-dApps/checking_account/src/lib.rs @@ -31,6 +31,7 @@ pub const SPEND_TOKEN_ASSET_NAME: &str = "SPEND TOKEN"; #[derive(Debug, Clone, Eq, PartialEq)] pub struct TimeLockedLogic; +#[derive(Debug)] pub enum CheckingAccountEndpoints { // Owner Endpoints /// Create a new checking account @@ -65,10 +66,12 @@ pub enum CheckingAccountEndpoints { }, } +#[derive(Debug)] pub enum CheckingAccountLookups { MyAccounts, } +#[derive(Debug)] pub enum CheckingAccountLookupResponses { MyAccounts(Vec), } diff --git a/sample-dApps/checking_account/src/main.rs b/sample-dApps/checking_account/src/main.rs index 4a7e342..6779b33 100644 --- a/sample-dApps/checking_account/src/main.rs +++ b/sample-dApps/checking_account/src/main.rs @@ -33,6 +33,7 @@ enum ActionParams { #[tokio::main] async fn main() -> Result<()> { + tracing_subscriber::fmt::init(); let args = Args::parse(); match args.action { ActionParams::Init { starting_ada } => init_checking_account_impl(starting_ada).await?, diff --git a/src/smart_contract.rs b/src/smart_contract.rs index 0081b98..c6242a9 100644 --- a/src/smart_contract.rs +++ b/src/smart_contract.rs @@ -3,7 +3,6 @@ use std::fmt::Debug; use crate::transaction::TxId; use crate::{error::Result, ledger_client::LedgerClient, logic::SCLogic}; -use crate::ledger_client::LedgerClientResult; /// Interface defining how to interact with your smart contract #[async_trait] @@ -65,6 +64,7 @@ where Logic: SCLogic + Eq + Debug + Send + Sync, Logic::Endpoints: Debug, Logic::Lookups: Debug, + Logic::LookupResponses: Debug, Record: LedgerClient + Send + Sync, { type Endpoint = Logic::Endpoints; @@ -89,6 +89,15 @@ where async fn lookup(&self, lookup: Self::Lookup) -> Result { tracing::info!("Looking up smart contract information: {:?}", &lookup); - Ok(Logic::lookup(lookup, &self.ledger_client).await?) + match Logic::lookup(lookup, &self.ledger_client).await { + Ok(res) => { + tracing::info!("Successfully queried information: {:?}", &res); + Ok(res) + } + Err(err) => { + tracing::error!("Failed to query information: {:?}", err); + Err(err.into()) + } + } } }