mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 07:08:05 -05:00
script/research/blockchain-explorer: fixed building
This commit is contained in:
@@ -11,9 +11,9 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
# Darkfi
|
||||
darkfi = {path = "../../../", features = ["async-daemonize", "validator", "rusqlite"]}
|
||||
darkfi = {path = "../../../", features = ["async-daemonize", "validator"]}
|
||||
darkfi-sdk = {path = "../../../src/sdk"}
|
||||
darkfi-serial = {path = "../../../src/serial"}
|
||||
darkfi-serial = "0.4.2"
|
||||
drk = {path = "../../../bin/drk"}
|
||||
|
||||
# Misc
|
||||
|
||||
@@ -141,7 +141,7 @@ impl BlockchainExplorer {
|
||||
serialize(&block.signature),
|
||||
],
|
||||
) {
|
||||
return Err(Error::RusqliteError(format!("[put_block] Block insert failed: {e:?}")))
|
||||
return Err(Error::DatabaseError(format!("[put_block] Block insert failed: {e:?}")))
|
||||
};
|
||||
|
||||
Ok(())
|
||||
@@ -216,7 +216,7 @@ impl BlockchainExplorer {
|
||||
let rows = match self.database.query_multiple(BLOCKS_TABLE, &[], &[]) {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[get_blocks] Blocks retrieval failed: {e:?}"
|
||||
)))
|
||||
}
|
||||
@@ -239,7 +239,7 @@ impl BlockchainExplorer {
|
||||
) {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[get_block_by_hash] Block retrieval failed: {e:?}"
|
||||
)))
|
||||
}
|
||||
@@ -299,7 +299,7 @@ impl BlockchainExplorer {
|
||||
let row = match rows.next() {
|
||||
Ok(r) => r,
|
||||
Err(_) => {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[get_last_n_blocks] {}",
|
||||
WalletDbError::QueryExecutionFailed
|
||||
)))
|
||||
@@ -340,13 +340,13 @@ impl BlockchainExplorer {
|
||||
BLOCKS_TABLE, BLOCKS_COL_HEIGHT, n
|
||||
);
|
||||
let Ok(conn) = self.database.conn.lock() else {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[get_last_n_blocks] {}",
|
||||
WalletDbError::FailedToAquireLock
|
||||
)))
|
||||
};
|
||||
let Ok(mut stmt) = conn.prepare(&query) else {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[get_last_n_blocks] {}",
|
||||
WalletDbError::QueryPreparationFailed
|
||||
)))
|
||||
@@ -354,7 +354,7 @@ impl BlockchainExplorer {
|
||||
|
||||
// Execute the query using provided params
|
||||
let Ok(mut rows) = stmt.query([]) else {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[get_last_n_blocks] {}",
|
||||
WalletDbError::QueryExecutionFailed
|
||||
)))
|
||||
@@ -371,13 +371,13 @@ impl BlockchainExplorer {
|
||||
BLOCKS_TABLE, BLOCKS_COL_HEIGHT, start, BLOCKS_COL_HEIGHT, end, BLOCKS_COL_HEIGHT
|
||||
);
|
||||
let Ok(conn) = self.database.conn.lock() else {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[get_blocks_in_height_range] {}",
|
||||
WalletDbError::FailedToAquireLock
|
||||
)))
|
||||
};
|
||||
let Ok(mut stmt) = conn.prepare(&query) else {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[get_blocks_in_height_range] {}",
|
||||
WalletDbError::QueryPreparationFailed
|
||||
)))
|
||||
@@ -385,7 +385,7 @@ impl BlockchainExplorer {
|
||||
|
||||
// Execute the query using provided params
|
||||
let Ok(mut rows) = stmt.query([]) else {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[get_blocks_in_height_range] {}",
|
||||
WalletDbError::QueryExecutionFailed
|
||||
)))
|
||||
|
||||
@@ -149,7 +149,7 @@ impl BlockchainExplorer {
|
||||
Err(e) => {
|
||||
let err = format!("{e:?}");
|
||||
error!(target: "blockchain-explorer", "Error initializing database: {err}");
|
||||
return Err(Error::RusqliteError(err))
|
||||
return Err(Error::DatabaseError(err))
|
||||
}
|
||||
};
|
||||
|
||||
@@ -162,12 +162,12 @@ impl BlockchainExplorer {
|
||||
if let Err(e) = explorer.initialize_blocks().await {
|
||||
let err = format!("{e:?}");
|
||||
error!(target: "blockchain-explorer", "Error initializing blocks database table: {err}");
|
||||
return Err(Error::RusqliteError(err))
|
||||
return Err(Error::DatabaseError(err))
|
||||
}
|
||||
if let Err(e) = explorer.initialize_transactions().await {
|
||||
let err = format!("{e:?}");
|
||||
error!(target: "blockchain-explorer", "Error initializing transactions database table: {err}");
|
||||
return Err(Error::RusqliteError(err))
|
||||
return Err(Error::DatabaseError(err))
|
||||
}
|
||||
// TODO: Map deployed contracts to their corresponding files with sql table and retrieval methods
|
||||
|
||||
@@ -207,7 +207,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
|
||||
if let Err(e) = explorer.sync_blocks(args.reset).await {
|
||||
let err = format!("{e:?}");
|
||||
error!(target: "blockchain-explorer", "Error syncing blocks: {err}");
|
||||
return Err(Error::RusqliteError(err))
|
||||
return Err(Error::DatabaseError(err))
|
||||
}
|
||||
|
||||
info!(target: "blockchain-explorer", "Subscribing to new blocks...");
|
||||
@@ -222,7 +222,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
|
||||
Err(e) => {
|
||||
let err = format!("{e:?}");
|
||||
error!(target: "blockchain-explorer", "Error while setting up blocks subscriber: {err}");
|
||||
return Err(Error::RusqliteError(err))
|
||||
return Err(Error::DatabaseError(err))
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -256,7 +256,7 @@ pub async fn subscribe_blocks(
|
||||
let (last_synced, _) = match explorer.last_block().await {
|
||||
Ok(l) => l,
|
||||
Err(e) => {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[subscribe_blocks] Retrieving last synced block failed: {e:?}"
|
||||
)))
|
||||
}
|
||||
@@ -265,7 +265,7 @@ pub async fn subscribe_blocks(
|
||||
if last_known != last_synced {
|
||||
warn!(target: "blockchain-explorer::rpc_blocks::subscribe_blocks", "Warning: Last synced block is not the last known block.");
|
||||
warn!(target: "blockchain-explorer::rpc_blocks::subscribe_blocks", "You should first fully sync the blockchain, and then subscribe");
|
||||
return Err(Error::RusqliteError(
|
||||
return Err(Error::DatabaseError(
|
||||
"[subscribe_blocks] Blockchain not fully synced".to_string(),
|
||||
))
|
||||
}
|
||||
@@ -342,7 +342,7 @@ pub async fn subscribe_blocks(
|
||||
|
||||
info!(target: "blockchain-explorer::rpc_blocks::subscribe_blocks", "Deserialized successfully. Storring block...");
|
||||
if let Err(e) = explorer.put_block(&(&block_data).into()).await {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[subscribe_blocks] Insert block failed: {e:?}"
|
||||
)))
|
||||
}
|
||||
@@ -350,7 +350,7 @@ pub async fn subscribe_blocks(
|
||||
let block_hash = block_data.hash().to_string();
|
||||
for transaction in block_data.txs {
|
||||
if let Err(e) = explorer.put_transaction(&(&block_hash, &transaction).into()).await {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[subscribe_blocks] Insert block transaction failed: {e:?}"
|
||||
)))
|
||||
};
|
||||
|
||||
@@ -103,7 +103,7 @@ impl BlockchainExplorer {
|
||||
serialize(&transaction.payload),
|
||||
],
|
||||
) {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[put_transaction] Transaction insert failed: {e:?}"
|
||||
)))
|
||||
};
|
||||
@@ -140,7 +140,7 @@ impl BlockchainExplorer {
|
||||
let rows = match self.database.query_multiple(TRANSACTIONS_TABLE, &[], &[]) {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[get_transactions] Transactions retrieval failed: {e:?}"
|
||||
)))
|
||||
}
|
||||
@@ -166,7 +166,7 @@ impl BlockchainExplorer {
|
||||
) {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[get_transactions_by_header_hash] Transactions retrieval failed: {e:?}"
|
||||
)))
|
||||
}
|
||||
@@ -189,7 +189,7 @@ impl BlockchainExplorer {
|
||||
) {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
return Err(Error::RusqliteError(format!(
|
||||
return Err(Error::DatabaseError(format!(
|
||||
"[get_transaction_by_hash] Transaction retrieval failed: {e:?}"
|
||||
)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user