|
|
@@ -18,7 +18,6 @@
|
|
|
|
|
|
use std::{fs, sync::Arc};
|
|
|
|
|
|
-use rusqlite::types::Value;
|
|
|
use url::Url;
|
|
|
|
|
|
use darkfi::{rpc::client::RpcClient, util::path::expand_path, Error, Result};
|
|
|
@@ -61,12 +60,6 @@ pub mod scanned_blocks;
|
|
|
pub mod walletdb;
|
|
|
use walletdb::{WalletDb, WalletPtr};
|
|
|
|
|
|
-// Wallet SQL table constant names. These have to represent the `wallet.sql`
|
|
|
-// SQL schema.
|
|
|
-const WALLET_INFO_TABLE: &str = "wallet_info";
|
|
|
-const WALLET_INFO_COL_LAST_SCANNED_BLOCK_HEIGHT: &str = "last_scanned_block_height";
|
|
|
-const WALLET_INFO_COL_LAST_SCANNED_BLOCK_HASH: &str = "last_scanned_block_hash";
|
|
|
-
|
|
|
/// CLI-util structure
|
|
|
pub struct Drk {
|
|
|
/// Wallet database operations handler
|
|
|
@@ -111,50 +104,9 @@ impl Drk {
|
|
|
// Initialize wallet schema
|
|
|
self.wallet.exec_batch_sql(include_str!("../wallet.sql"))?;
|
|
|
|
|
|
- // We maintain the last scanned block as part of the wallet
|
|
|
- // info table.
|
|
|
- if self.last_scanned_block().await.is_err() {
|
|
|
- let query = format!(
|
|
|
- "INSERT INTO {} ({}, {}) VALUES (?1, ?2);",
|
|
|
- WALLET_INFO_TABLE,
|
|
|
- WALLET_INFO_COL_LAST_SCANNED_BLOCK_HEIGHT,
|
|
|
- WALLET_INFO_COL_LAST_SCANNED_BLOCK_HASH
|
|
|
- );
|
|
|
- self.wallet.exec_sql(&query, rusqlite::params![0, "-"])?;
|
|
|
- }
|
|
|
-
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
- /// Update the last scanned block height and hash in the wallet.
|
|
|
- pub fn update_last_scanned_block(&self, height: u32, hash: &str) -> WalletDbResult<()> {
|
|
|
- let query = format!(
|
|
|
- "UPDATE {} SET {} = ?1, {} = ?2;",
|
|
|
- WALLET_INFO_TABLE,
|
|
|
- WALLET_INFO_COL_LAST_SCANNED_BLOCK_HEIGHT,
|
|
|
- WALLET_INFO_COL_LAST_SCANNED_BLOCK_HASH
|
|
|
- );
|
|
|
- self.wallet.exec_sql(&query, rusqlite::params![height, hash])
|
|
|
- }
|
|
|
-
|
|
|
- /// Get the last scanned block height and hash from the wallet.
|
|
|
- pub async fn last_scanned_block(&self) -> WalletDbResult<(u32, String)> {
|
|
|
- let ret = self.wallet.query_single(WALLET_INFO_TABLE, &[], &[])?;
|
|
|
-
|
|
|
- let Value::Integer(height) = ret[0] else {
|
|
|
- return Err(WalletDbError::ParseColumnValueError);
|
|
|
- };
|
|
|
- let Ok(height) = u32::try_from(height) else {
|
|
|
- return Err(WalletDbError::ParseColumnValueError);
|
|
|
- };
|
|
|
-
|
|
|
- let Value::Text(ref hash) = ret[1] else {
|
|
|
- return Err(WalletDbError::ParseColumnValueError);
|
|
|
- };
|
|
|
-
|
|
|
- Ok((height, hash.clone()))
|
|
|
- }
|
|
|
-
|
|
|
/// Auxiliary function to reset `walletdb` inverse cache state.
|
|
|
/// Additionally, set current trees state inverse queries.
|
|
|
/// We keep the entire trees state as two distinct inverse queries,
|