diff --git a/node/src/config.rs b/node/src/config.rs index 6d2cad5d..b112951c 100644 --- a/node/src/config.rs +++ b/node/src/config.rs @@ -57,6 +57,7 @@ pub struct Node { pub address: String, pub port: u16, pub counter_uref: String, + pub tree_counter_uref: String, pub dict_uref: String, pub secret_key_path: String, pub chain_name: String, @@ -128,6 +129,7 @@ impl Config { address: "127.0.0.1".to_string(), port: 11101, counter_uref: "uref-".to_string(), + tree_counter_uref: "uref-".to_string(), dict_uref: "uref-".to_string(), secret_key_path: "/".to_string(), chain_name: "cspr-dev-cctl".to_string(), diff --git a/node/src/domain/models/transfers.rs b/node/src/domain/models/transfers.rs index 44f87894..30e3a6cc 100644 --- a/node/src/domain/models/transfers.rs +++ b/node/src/domain/models/transfers.rs @@ -1,14 +1,14 @@ -use diesel::{ExpressionMethods, Insertable, QueryDsl, Queryable, Selectable, SelectableHelper}; +use bigdecimal::{BigDecimal, ToPrimitive}; +use chrono::{NaiveDateTime, Utc}; +use deadpool_diesel::postgres::Pool; use diesel::RunQueryDsl; +use diesel::{ExpressionMethods, Insertable, QueryDsl, Queryable, Selectable, SelectableHelper}; use kairos_risc0_types::{ToBigDecimal, Transfer}; -use chrono::{Utc, NaiveDateTime}; -use bigdecimal::{BigDecimal, ToPrimitive}; use serde::{Deserialize, Serialize}; -use deadpool_diesel::postgres::Pool; +use crate::database::delta_tree_schema as schema; use crate::database::delta_tree_schema::transfers; use crate::database::errors; -use crate::database::delta_tree_schema as schema; // Define struct for schema for transfers #[derive(Serialize, Queryable, Selectable, Insertable)] @@ -27,8 +27,8 @@ pub struct TransferModel { impl From for TransferModel { fn from(transfer: Transfer) -> Self { TransferModel { - sender: transfer.sender.to_string(), - recipient: transfer.recipient.to_string(), + sender: transfer.sender.to_formatted_string(), + recipient: transfer.recipient.to_formatted_string(), amount: transfer.amount.to_big_decimal(), timestamp: Utc::now().naive_utc(), sig: transfer.signature, @@ -41,8 +41,12 @@ impl From for TransferModel { impl Into for TransferModel { fn into(self) -> Transfer { Transfer { - sender: kairos_risc0_types::Key::Account(kairos_risc0_types::AccountHash::from_formatted_str(&self.sender).unwrap()), - recipient: kairos_risc0_types::Key::Account(kairos_risc0_types::AccountHash::from_formatted_str(&self.recipient).unwrap()), + sender: kairos_risc0_types::Key::Account( + kairos_risc0_types::AccountHash::from_formatted_str(&self.sender).unwrap(), + ), + recipient: kairos_risc0_types::Key::Account( + kairos_risc0_types::AccountHash::from_formatted_str(&self.recipient).unwrap(), + ), amount: kairos_risc0_types::U512::from_dec_str(&self.amount.to_string()).unwrap(), timestamp: None, signature: self.sig, @@ -59,22 +63,28 @@ pub struct TransfersFilter { pub processed: Option, } -pub async fn insert(pool: Pool, new_transfer: Transfer) -> Result { +pub async fn insert( + pool: Pool, + new_transfer: Transfer, +) -> Result { let conn = pool.get().await?; let transfer_model = TransferModel::from(new_transfer); let res = conn - .interact(|conn| { - diesel::insert_into(transfers::table) - .values(transfer_model) - .get_result::(conn) - }) + .interact(|conn| { + diesel::insert_into(transfers::table) + .values(transfer_model) + .get_result::(conn) + }) .await??; Ok(res) } // TODO - add get function which just retrieves transfer by ID -pub async fn get_all(pool: Pool, filter: TransfersFilter) -> Result, errors::DatabaseError> { +pub async fn get_all( + pool: Pool, + filter: TransfersFilter, +) -> Result, errors::DatabaseError> { let conn = pool.get().await?; let res = conn .interact(move |conn| { @@ -92,8 +102,10 @@ pub async fn get_all(pool: Pool, filter: TransfersFilter) -> Result(conn) + query + .select(TransferModel::as_select()) + .load::(conn) }) .await??; Ok(res) -} \ No newline at end of file +} diff --git a/node/src/handlers/delta_tree/submit_batch.rs b/node/src/handlers/delta_tree/submit_batch.rs index 206baeb8..493ca809 100644 --- a/node/src/handlers/delta_tree/submit_batch.rs +++ b/node/src/handlers/delta_tree/submit_batch.rs @@ -37,7 +37,7 @@ pub async fn submit_batch(State(AppState): State) -> impl IntoResponse let deposits: Vec = unprocessed_deposits.into_iter().map(|model| model.into()).collect(); // this counter uref is different! - let tree_index = query::query_counter(&CONFIG.node_address(), &CONFIG.node.port.to_string(), &CONFIG.node.counter_uref).await; + let tree_index = query::query_counter(&CONFIG.node_address(), &CONFIG.node.port.to_string(), &CONFIG.node.tree_counter_uref).await; let mut previous_tree: KairosDeltaTree = KairosDeltaTree{ zero_node: hash_bytes(vec![0;32]), zero_levels: Vec::new(),