Skip to content

Commit

Permalink
Add tracing to checking account example
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchTurner committed Feb 25, 2024
1 parent f3c4752 commit 334c83c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions sample-dApps/checking_account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions sample-dApps/checking_account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,10 +66,12 @@ pub enum CheckingAccountEndpoints {
},
}

#[derive(Debug)]
pub enum CheckingAccountLookups {
MyAccounts,
}

#[derive(Debug)]
pub enum CheckingAccountLookupResponses {
MyAccounts(Vec<Account>),
}
Expand Down
1 change: 1 addition & 0 deletions sample-dApps/checking_account/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand Down
13 changes: 11 additions & 2 deletions src/smart_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -65,6 +64,7 @@ where
Logic: SCLogic + Eq + Debug + Send + Sync,
Logic::Endpoints: Debug,
Logic::Lookups: Debug,
Logic::LookupResponses: Debug,
Record: LedgerClient<Logic::Datums, Logic::Redeemers> + Send + Sync,
{
type Endpoint = Logic::Endpoints;
Expand All @@ -89,6 +89,15 @@ where

async fn lookup(&self, lookup: Self::Lookup) -> Result<Self::LookupResponse> {
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())
}
}
}
}

0 comments on commit 334c83c

Please sign in to comment.