Skip to content

Commit

Permalink
Merge pull request #1411 from mintlayer/feature/api-server-addressabl…
Browse files Browse the repository at this point in the history
…e-ids

Change pool and delegation IDs in the DB to addressable strings
  • Loading branch information
OBorce authored Jan 5, 2024
2 parents 3ebfda7 + 383a14f commit 4fe66bb
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ impl ApiServerInMemoryStorage {
.iter()
.filter_map(|(delegation_id, delegation)| {
let delegation = delegation.values().last().expect("must be present");
(delegation.pool_id() == pool_id).then_some((*delegation_id, delegation.clone()))
(*delegation.pool_id() == pool_id)
.then_some((delegation_id.to_owned(), delegation.clone()))
})
.collect())
}
Expand Down Expand Up @@ -305,7 +306,8 @@ impl ApiServerInMemoryStorage {
.iter()
.filter_map(|(delegation_id, by_height)| {
let last = by_height.values().last().expect("not empty");
(last.spend_destination() == address).then_some((*delegation_id, last.clone()))
(last.spend_destination() == address)
.then_some((delegation_id.to_owned(), last.clone()))
})
.collect())
}
Expand Down
22 changes: 17 additions & 5 deletions api-server/api-server-common/src/storage/impls/postgres/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ pub mod transactional;
mod queries;

use std::str::FromStr;
use std::sync::Arc;

use bb8_postgres::bb8::Pool;
use bb8_postgres::bb8::PooledConnection;
use bb8_postgres::PostgresConnectionManager;
use common::chain::ChainConfig;
use tokio_postgres::NoTls;

use crate::storage::storage_api::ApiServerStorageError;
Expand All @@ -37,6 +39,7 @@ pub struct TransactionalApiServerPostgresStorage {
db_tx_conn_sender: tokio::sync::mpsc::UnboundedSender<
PooledConnection<'static, PostgresConnectionManager<NoTls>>,
>,
chain_config: Arc<ChainConfig>,
}

impl Drop for TransactionalApiServerPostgresStorage {
Expand All @@ -54,7 +57,7 @@ impl TransactionalApiServerPostgresStorage {
passsword: Option<&str>,
database: Option<&str>,
max_connections: u32,
_chain_config: &common::chain::ChainConfig,
chain_config: Arc<ChainConfig>,
) -> Result<Self, ApiServerStorageError> {
let password_part = match passsword {
Some(p) => format!("password={}", p),
Expand Down Expand Up @@ -105,6 +108,7 @@ impl TransactionalApiServerPostgresStorage {
pool,
tx_dropper_joiner,
db_tx_conn_sender: conn_tx,
chain_config,
};

Ok(result)
Expand All @@ -118,8 +122,12 @@ impl TransactionalApiServerPostgresStorage {
.get_owned()
.await
.map_err(|e| ApiServerStorageError::AcquiringConnectionFailed(e.to_string()))?;
ApiServerPostgresTransactionalRo::from_connection(conn, self.db_tx_conn_sender.clone())
.await
ApiServerPostgresTransactionalRo::from_connection(
conn,
self.db_tx_conn_sender.clone(),
self.chain_config.clone(),
)
.await
}

pub async fn begin_rw_transaction(
Expand All @@ -130,7 +138,11 @@ impl TransactionalApiServerPostgresStorage {
.get_owned()
.await
.map_err(|e| ApiServerStorageError::AcquiringConnectionFailed(e.to_string()))?;
ApiServerPostgresTransactionalRw::from_connection(conn, self.db_tx_conn_sender.clone())
.await
ApiServerPostgresTransactionalRw::from_connection(
conn,
self.db_tx_conn_sender.clone(),
self.chain_config.clone(),
)
.await
}
}
Loading

0 comments on commit 4fe66bb

Please sign in to comment.