Ver Fonte

drk: moved info table from money to wallet generic schema

skoupidi há 1 ano atrás
pai
commit
04bc7e14de
9 ficheiros alterados com 181 adições e 154 exclusões
  1. 0 2
      bin/drk/dao.sql
  2. 0 5
      bin/drk/money.sql
  3. 1 1
      bin/drk/src/dao.rs
  4. 13 9
      bin/drk/src/error.rs
  5. 50 20
      bin/drk/src/lib.rs
  6. 105 79
      bin/drk/src/main.rs
  7. 2 34
      bin/drk/src/money.rs
  8. 3 4
      bin/drk/src/rpc.rs
  9. 7 0
      bin/drk/wallet.sql

+ 0 - 2
bin/drk/dao.sql

@@ -124,8 +124,6 @@
 --   $ drk dao exec f6cae...1f6cf > dao_exec_tx
 --   $ drk dao exec f6cae...1f6cf > dao_exec_tx
 --   $ drk broadcast < dao_exec_tx
 --   $ drk broadcast < dao_exec_tx
 
 
-PRAGMA foreign_keys = ON;
-
 CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_daos (
 CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_daos (
     -- Bulla identifier of the DAO
     -- Bulla identifier of the DAO
     bulla BLOB PRIMARY KEY NOT NULL,
     bulla BLOB PRIMARY KEY NOT NULL,

+ 0 - 5
bin/drk/money.sql

@@ -1,11 +1,6 @@
 -- Wallet definitions for this contract.
 -- Wallet definitions for this contract.
 -- We store data that is needed to be able to receive and send tokens.
 -- We store data that is needed to be able to receive and send tokens.
 
 
--- Arbitrary info that is potentially useful
-CREATE TABLE IF NOT EXISTS BZHKGQ26bzmBithTQYTJtjo2QdCqpkR9tjSBopT4yf4o_money_info (
-	last_scanned_block INTEGER NOT NULL
-);
-
 -- The Merkle tree containing coins
 -- The Merkle tree containing coins
 CREATE TABLE IF NOT EXISTS BZHKGQ26bzmBithTQYTJtjo2QdCqpkR9tjSBopT4yf4o_money_tree (
 CREATE TABLE IF NOT EXISTS BZHKGQ26bzmBithTQYTJtjo2QdCqpkR9tjSBopT4yf4o_money_tree (
 	tree BLOB NOT NULL
 	tree BLOB NOT NULL

+ 1 - 1
bin/drk/src/dao.rs

@@ -79,7 +79,7 @@ use crate::{
     Drk,
     Drk,
 };
 };
 
 
-// Wallet SQL table constant names. These have to represent the `wallet.sql`
+// Wallet SQL table constant names. These have to represent the `dao.sql`
 // SQL schema. Table names are prefixed with the contract ID to avoid collisions.
 // SQL schema. Table names are prefixed with the contract ID to avoid collisions.
 lazy_static! {
 lazy_static! {
     pub static ref DAO_DAOS_TABLE: String = format!("{}_dao_daos", DAO_CONTRACT_ID.to_string());
     pub static ref DAO_DAOS_TABLE: String = format!("{}_dao_daos", DAO_CONTRACT_ID.to_string());

+ 13 - 9
bin/drk/src/error.rs

@@ -23,27 +23,31 @@ pub type WalletDbResult<T> = std::result::Result<T, WalletDbError>;
 /// Please sort them sensefully.
 /// Please sort them sensefully.
 #[derive(Debug)]
 #[derive(Debug)]
 pub enum WalletDbError {
 pub enum WalletDbError {
+    // Initialization error
+    InitializationFailed = -32100,
+
     // Connection related errors
     // Connection related errors
-    ConnectionFailed = -32100,
-    FailedToAquireLock = -32101,
+    ConnectionFailed = -32110,
+    FailedToAquireLock = -32111,
 
 
     // Configuration related errors
     // Configuration related errors
-    PragmaUpdateError = -32110,
+    PragmaUpdateError = -32120,
 
 
     // Query execution related errors
     // Query execution related errors
-    QueryPreparationFailed = -32120,
-    QueryExecutionFailed = -32121,
-    QueryFinalizationFailed = -32122,
-    ParseColumnValueError = -32123,
-    RowNotFound = -32124,
+    QueryPreparationFailed = -32130,
+    QueryExecutionFailed = -32131,
+    QueryFinalizationFailed = -32132,
+    ParseColumnValueError = -32133,
+    RowNotFound = -32134,
 
 
     // Generic error
     // Generic error
-    GenericError = -32130,
+    GenericError = -32140,
 }
 }
 
 
 impl std::fmt::Display for WalletDbError {
 impl std::fmt::Display for WalletDbError {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         match self {
         match self {
+            WalletDbError::InitializationFailed => write!(f, "WalletDbError::InitializationFailed"),
             WalletDbError::ConnectionFailed => write!(f, "WalletDbError::ConnectionFailed"),
             WalletDbError::ConnectionFailed => write!(f, "WalletDbError::ConnectionFailed"),
             WalletDbError::FailedToAquireLock => write!(f, "WalletDbError::FailedToAquireLock"),
             WalletDbError::FailedToAquireLock => write!(f, "WalletDbError::FailedToAquireLock"),
             WalletDbError::PragmaUpdateError => write!(f, "WalletDbError::PragmaUpdateError"),
             WalletDbError::PragmaUpdateError => write!(f, "WalletDbError::PragmaUpdateError"),

+ 50 - 20
bin/drk/src/lib.rs

@@ -16,14 +16,16 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
 
 
-use std::{fs, process::exit, sync::Arc};
+use std::{fs, sync::Arc};
 
 
+use rusqlite::types::Value;
 use url::Url;
 use url::Url;
 
 
-use darkfi::{rpc::client::RpcClient, util::path::expand_path, Result};
+use darkfi::{rpc::client::RpcClient, util::path::expand_path, Error, Result};
 
 
 /// Error codes
 /// Error codes
 pub mod error;
 pub mod error;
+use error::{WalletDbError, WalletDbResult};
 
 
 /// darkfid JSON-RPC related methods
 /// darkfid JSON-RPC related methods
 pub mod rpc;
 pub mod rpc;
@@ -56,6 +58,11 @@ pub mod txs_history;
 pub mod walletdb;
 pub mod walletdb;
 use walletdb::{WalletDb, WalletPtr};
 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: &str = "last_scanned_block";
+
 /// CLI-util structure
 /// CLI-util structure
 pub struct Drk {
 pub struct Drk {
     /// Wallet database operations handler
     /// Wallet database operations handler
@@ -74,12 +81,6 @@ impl Drk {
         ex: Arc<smol::Executor<'static>>,
         ex: Arc<smol::Executor<'static>>,
         fun: bool,
         fun: bool,
     ) -> Result<Self> {
     ) -> Result<Self> {
-        // Script kiddies protection
-        if wallet_pass == "changeme" {
-            eprintln!("Please don't use default wallet password...");
-            exit(2);
-        }
-
         // Initialize wallet
         // Initialize wallet
         let wallet_path = expand_path(&wallet_path)?;
         let wallet_path = expand_path(&wallet_path)?;
         if !wallet_path.exists() {
         if !wallet_path.exists() {
@@ -87,12 +88,8 @@ impl Drk {
                 fs::create_dir_all(parent)?;
                 fs::create_dir_all(parent)?;
             }
             }
         }
         }
-        let wallet = match WalletDb::new(Some(wallet_path), Some(&wallet_pass)) {
-            Ok(w) => w,
-            Err(e) => {
-                eprintln!("Error initializing wallet: {e:?}");
-                exit(2);
-            }
+        let Ok(wallet) = WalletDb::new(Some(wallet_path), Some(&wallet_pass)) else {
+            return Err(Error::DatabaseError(format!("{}", WalletDbError::InitializationFailed)));
         };
         };
 
 
         // Initialize rpc client
         // Initialize rpc client
@@ -105,14 +102,47 @@ impl Drk {
         Ok(Self { wallet, rpc_client, fun })
         Ok(Self { wallet, rpc_client, fun })
     }
     }
 
 
-    /// Initialize wallet with tables for drk
-    pub fn initialize_wallet(&self) -> Result<()> {
-        let wallet_schema = include_str!("../wallet.sql");
-        if let Err(e) = self.wallet.exec_batch_sql(wallet_schema) {
-            eprintln!("Error initializing wallet: {e:?}");
-            exit(2);
+    /// Initialize wallet with tables for `Drk`.
+    pub fn initialize_wallet(&self) -> WalletDbResult<()> {
+        // 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().is_err() {
+            let query = format!(
+                "INSERT INTO {} ({}) VALUES (?1);",
+                WALLET_INFO_TABLE, WALLET_INFO_COL_LAST_SCANNED_BLOCK
+            );
+            self.wallet.exec_sql(&query, rusqlite::params![0])?;
         }
         }
 
 
         Ok(())
         Ok(())
     }
     }
+
+    /// Update the last scanned block height in the wallet.
+    pub fn update_last_scanned_block(&self, height: u32) -> WalletDbResult<()> {
+        let query = format!(
+            "UPDATE {} SET {} = ?1;",
+            WALLET_INFO_TABLE, WALLET_INFO_COL_LAST_SCANNED_BLOCK
+        );
+        self.wallet.exec_sql(&query, rusqlite::params![height])
+    }
+
+    /// Get the last scanned block height from the wallet.
+    pub fn last_scanned_block(&self) -> WalletDbResult<u32> {
+        let ret = self.wallet.query_single(
+            WALLET_INFO_TABLE,
+            &[WALLET_INFO_COL_LAST_SCANNED_BLOCK],
+            &[],
+        )?;
+        let Value::Integer(height) = ret[0] else {
+            return Err(WalletDbError::ParseColumnValueError);
+        };
+        let Ok(height) = u32::try_from(height) else {
+            return Err(WalletDbError::ParseColumnValueError);
+        };
+
+        Ok(height)
+    }
 }
 }

+ 105 - 79
bin/drk/src/main.rs

@@ -572,6 +572,29 @@ async fn parse_blockchain_config(
     Ok(network_config)
     Ok(network_config)
 }
 }
 
 
+/// Auxiliary function to create a `Drk` wallet for provided configuration.
+async fn new_wallet(
+    wallet_path: String,
+    wallet_pass: String,
+    endpoint: Option<Url>,
+    ex: Arc<smol::Executor<'static>>,
+    fun: bool,
+) -> Drk {
+    // Script kiddies protection
+    if wallet_pass == "changeme" {
+        eprintln!("Please don't use default wallet password...");
+        exit(2);
+    }
+
+    match Drk::new(wallet_path, wallet_pass, endpoint, ex, fun).await {
+        Ok(wallet) => wallet,
+        Err(e) => {
+            eprintln!("Error initializing wallet: {e:?}");
+            exit(2);
+        }
+    }
+}
+
 async_daemonize!(realmain);
 async_daemonize!(realmain);
 async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
 async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
     // Grab blockchain network configuration
     // Grab blockchain network configuration
@@ -596,14 +619,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
         }
         }
 
 
         Subcmd::Ping => {
         Subcmd::Ping => {
-            let drk = Drk::new(
+            let drk = new_wallet(
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_pass,
                 blockchain_config.wallet_pass,
                 Some(blockchain_config.endpoint),
                 Some(blockchain_config.endpoint),
                 ex,
                 ex,
                 args.fun,
                 args.fun,
             )
             )
-            .await?;
+            .await;
             drk.ping().await?;
             drk.ping().await?;
             drk.stop_rpc_client().await
             drk.stop_rpc_client().await
         }
         }
@@ -638,17 +661,20 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                 exit(2);
                 exit(2);
             }
             }
 
 
-            let drk = Drk::new(
+            let drk = new_wallet(
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_pass,
                 blockchain_config.wallet_pass,
                 None,
                 None,
                 ex,
                 ex,
                 args.fun,
                 args.fun,
             )
             )
-            .await?;
+            .await;
 
 
             if initialize {
             if initialize {
-                drk.initialize_wallet()?;
+                if let Err(e) = drk.initialize_wallet() {
+                    eprintln!("Error initializing wallet: {e:?}");
+                    exit(2);
+                }
                 if let Err(e) = drk.initialize_money().await {
                 if let Err(e) = drk.initialize_money().await {
                     eprintln!("Failed to initialize Money: {e:?}");
                     eprintln!("Failed to initialize Money: {e:?}");
                     exit(2);
                     exit(2);
@@ -866,14 +892,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
         Subcmd::Spend => {
         Subcmd::Spend => {
             let tx = parse_tx_from_stdin().await?;
             let tx = parse_tx_from_stdin().await?;
 
 
-            let drk = Drk::new(
+            let drk = new_wallet(
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_pass,
                 blockchain_config.wallet_pass,
                 None,
                 None,
                 ex,
                 ex,
                 args.fun,
                 args.fun,
             )
             )
-            .await?;
+            .await;
 
 
             if let Err(e) = drk.mark_tx_spend(&tx).await {
             if let Err(e) = drk.mark_tx_spend(&tx).await {
                 eprintln!("Failed to mark transaction coins as spent: {e:?}");
                 eprintln!("Failed to mark transaction coins as spent: {e:?}");
@@ -901,14 +927,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             };
             };
 
 
             let coin = Coin::from(elem);
             let coin = Coin::from(elem);
-            let drk = Drk::new(
+            let drk = new_wallet(
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_pass,
                 blockchain_config.wallet_pass,
                 None,
                 None,
                 ex,
                 ex,
                 args.fun,
                 args.fun,
             )
             )
-            .await?;
+            .await;
             if let Err(e) = drk.unspend_coin(&coin).await {
             if let Err(e) = drk.unspend_coin(&coin).await {
                 eprintln!("Failed to mark coin as unspent: {e:?}");
                 eprintln!("Failed to mark coin as unspent: {e:?}");
                 exit(2);
                 exit(2);
@@ -918,14 +944,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
         }
         }
 
 
         Subcmd::Transfer { amount, token, recipient, spend_hook, user_data, half_split } => {
         Subcmd::Transfer { amount, token, recipient, spend_hook, user_data, half_split } => {
-            let drk = Drk::new(
+            let drk = new_wallet(
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_pass,
                 blockchain_config.wallet_pass,
                 Some(blockchain_config.endpoint),
                 Some(blockchain_config.endpoint),
                 ex,
                 ex,
                 args.fun,
                 args.fun,
             )
             )
-            .await?;
+            .await;
 
 
             if let Err(e) = f64::from_str(&amount) {
             if let Err(e) = f64::from_str(&amount) {
                 eprintln!("Invalid amount: {e:?}");
                 eprintln!("Invalid amount: {e:?}");
@@ -998,14 +1024,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
 
 
         Subcmd::Otc { command } => match command {
         Subcmd::Otc { command } => match command {
             OtcSubcmd::Init { value_pair, token_pair } => {
             OtcSubcmd::Init { value_pair, token_pair } => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     Some(blockchain_config.endpoint),
                     Some(blockchain_config.endpoint),
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let value_pair = parse_value_pair(&value_pair)?;
                 let value_pair = parse_value_pair(&value_pair)?;
                 let token_pair = parse_token_pair(&drk, &token_pair).await?;
                 let token_pair = parse_token_pair(&drk, &token_pair).await?;
 
 
@@ -1031,14 +1057,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
 
 
                 let partial: PartialSwapData = deserialize_async(&bytes).await?;
                 let partial: PartialSwapData = deserialize_async(&bytes).await?;
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     Some(blockchain_config.endpoint),
                     Some(blockchain_config.endpoint),
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let tx = match drk.join_swap(partial, None, None, None).await {
                 let tx = match drk.join_swap(partial, None, None, None).await {
                     Ok(tx) => tx,
                     Ok(tx) => tx,
                     Err(e) => {
                     Err(e) => {
@@ -1059,14 +1085,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                     exit(2);
                     exit(2);
                 };
                 };
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 if let Err(e) = drk.inspect_swap(bytes).await {
                 if let Err(e) = drk.inspect_swap(bytes).await {
                     eprintln!("Failed to inspect swap: {e:?}");
                     eprintln!("Failed to inspect swap: {e:?}");
                     exit(2);
                     exit(2);
@@ -1078,14 +1104,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             OtcSubcmd::Sign => {
             OtcSubcmd::Sign => {
                 let mut tx = parse_tx_from_stdin().await?;
                 let mut tx = parse_tx_from_stdin().await?;
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 if let Err(e) = drk.sign_swap(&mut tx).await {
                 if let Err(e) = drk.sign_swap(&mut tx).await {
                     eprintln!("Failed to sign joined swap transaction: {e:?}");
                     eprintln!("Failed to sign joined swap transaction: {e:?}");
                     exit(2);
                     exit(2);
@@ -1118,14 +1144,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                 let approval_ratio_base = 100_u64;
                 let approval_ratio_base = 100_u64;
                 let approval_ratio_quot = (approval_ratio * approval_ratio_base as f64) as u64;
                 let approval_ratio_quot = (approval_ratio * approval_ratio_base as f64) as u64;
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let gov_token_id = match drk.get_token(gov_token_id).await {
                 let gov_token_id = match drk.get_token(gov_token_id).await {
                     Ok(g) => g,
                     Ok(g) => g,
                     Err(e) => {
                     Err(e) => {
@@ -1169,14 +1195,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                 let bytes = bs58::decode(&buf.trim()).into_vec()?;
                 let bytes = bs58::decode(&buf.trim()).into_vec()?;
                 let params: DaoParams = deserialize_async(&bytes).await?;
                 let params: DaoParams = deserialize_async(&bytes).await?;
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 if let Err(e) = drk.import_dao(&name, params).await {
                 if let Err(e) = drk.import_dao(&name, params).await {
                     eprintln!("Failed to import DAO: {e:?}");
                     eprintln!("Failed to import DAO: {e:?}");
                     exit(2);
                     exit(2);
@@ -1186,14 +1212,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             }
             }
 
 
             DaoSubcmd::List { name } => {
             DaoSubcmd::List { name } => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 if let Err(e) = drk.dao_list(&name).await {
                 if let Err(e) = drk.dao_list(&name).await {
                     eprintln!("Failed to list DAO: {e:?}");
                     eprintln!("Failed to list DAO: {e:?}");
                     exit(2);
                     exit(2);
@@ -1203,14 +1229,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             }
             }
 
 
             DaoSubcmd::Balance { name } => {
             DaoSubcmd::Balance { name } => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let balmap = match drk.dao_balance(&name).await {
                 let balmap = match drk.dao_balance(&name).await {
                     Ok(b) => b,
                     Ok(b) => b,
                     Err(e) => {
                     Err(e) => {
@@ -1254,14 +1280,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             }
             }
 
 
             DaoSubcmd::Mint { name } => {
             DaoSubcmd::Mint { name } => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     Some(blockchain_config.endpoint),
                     Some(blockchain_config.endpoint),
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let tx = match drk.dao_mint(&name).await {
                 let tx = match drk.dao_mint(&name).await {
                     Ok(tx) => tx,
                     Ok(tx) => tx,
                     Err(e) => {
                     Err(e) => {
@@ -1283,14 +1309,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                 spend_hook,
                 spend_hook,
                 user_data,
                 user_data,
             } => {
             } => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     Some(blockchain_config.endpoint),
                     Some(blockchain_config.endpoint),
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
 
 
                 if let Err(e) = f64::from_str(&amount) {
                 if let Err(e) = f64::from_str(&amount) {
                     eprintln!("Invalid amount: {e:?}");
                     eprintln!("Invalid amount: {e:?}");
@@ -1364,14 +1390,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             }
             }
 
 
             DaoSubcmd::Proposals { name } => {
             DaoSubcmd::Proposals { name } => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let proposals = drk.get_dao_proposals(&name).await?;
                 let proposals = drk.get_dao_proposals(&name).await?;
 
 
                 for (i, proposal) in proposals.iter().enumerate() {
                 for (i, proposal) in proposals.iter().enumerate() {
@@ -1390,14 +1416,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                     }
                     }
                 };
                 };
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     Some(blockchain_config.endpoint),
                     Some(blockchain_config.endpoint),
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let proposal = drk.get_dao_proposal_by_bulla(&bulla).await?;
                 let proposal = drk.get_dao_proposal_by_bulla(&bulla).await?;
 
 
                 if export {
                 if export {
@@ -1581,14 +1607,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                 };
                 };
                 let encrypted_proposal: AeadEncryptedNote = deserialize_async(&bytes).await?;
                 let encrypted_proposal: AeadEncryptedNote = deserialize_async(&bytes).await?;
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
 
 
                 // Retrieve all DAOs to try to decrypt the proposal
                 // Retrieve all DAOs to try to decrypt the proposal
                 let daos = drk.get_daos().await?;
                 let daos = drk.get_daos().await?;
@@ -1640,14 +1666,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                     None => None,
                     None => None,
                 };
                 };
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     Some(blockchain_config.endpoint),
                     Some(blockchain_config.endpoint),
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let tx = match drk.dao_vote(&bulla, vote, weight).await {
                 let tx = match drk.dao_vote(&bulla, vote, weight).await {
                     Ok(tx) => tx,
                     Ok(tx) => tx,
                     Err(e) => {
                     Err(e) => {
@@ -1669,14 +1695,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                     }
                     }
                 };
                 };
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     Some(blockchain_config.endpoint),
                     Some(blockchain_config.endpoint),
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let proposal = drk.get_dao_proposal_by_bulla(&bulla).await?;
                 let proposal = drk.get_dao_proposal_by_bulla(&bulla).await?;
 
 
                 for call in &proposal.proposal.auth_calls {
                 for call in &proposal.proposal.auth_calls {
@@ -1712,14 +1738,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
         Subcmd::AttachFee => {
         Subcmd::AttachFee => {
             let mut tx = parse_tx_from_stdin().await?;
             let mut tx = parse_tx_from_stdin().await?;
 
 
-            let drk = Drk::new(
+            let drk = new_wallet(
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_pass,
                 blockchain_config.wallet_pass,
                 Some(blockchain_config.endpoint),
                 Some(blockchain_config.endpoint),
                 ex,
                 ex,
                 args.fun,
                 args.fun,
             )
             )
-            .await?;
+            .await;
             if let Err(e) = drk.attach_fee(&mut tx).await {
             if let Err(e) = drk.attach_fee(&mut tx).await {
                 eprintln!("Failed to attach the fee call to the transaction: {e:?}");
                 eprintln!("Failed to attach the fee call to the transaction: {e:?}");
                 exit(2);
                 exit(2);
@@ -1741,14 +1767,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
         Subcmd::Broadcast => {
         Subcmd::Broadcast => {
             let tx = parse_tx_from_stdin().await?;
             let tx = parse_tx_from_stdin().await?;
 
 
-            let drk = Drk::new(
+            let drk = new_wallet(
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_pass,
                 blockchain_config.wallet_pass,
                 Some(blockchain_config.endpoint),
                 Some(blockchain_config.endpoint),
                 ex,
                 ex,
                 args.fun,
                 args.fun,
             )
             )
-            .await?;
+            .await;
 
 
             if let Err(e) = drk.simulate_tx(&tx).await {
             if let Err(e) = drk.simulate_tx(&tx).await {
                 eprintln!("Failed to simulate tx: {e:?}");
                 eprintln!("Failed to simulate tx: {e:?}");
@@ -1774,14 +1800,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
         }
         }
 
 
         Subcmd::Subscribe => {
         Subcmd::Subscribe => {
-            let drk = Drk::new(
+            let drk = new_wallet(
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_pass,
                 blockchain_config.wallet_pass,
                 Some(blockchain_config.endpoint.clone()),
                 Some(blockchain_config.endpoint.clone()),
                 ex.clone(),
                 ex.clone(),
                 args.fun,
                 args.fun,
             )
             )
-            .await?;
+            .await;
 
 
             if let Err(e) = drk.subscribe_blocks(blockchain_config.endpoint, ex).await {
             if let Err(e) = drk.subscribe_blocks(blockchain_config.endpoint, ex).await {
                 eprintln!("Block subscription failed: {e:?}");
                 eprintln!("Block subscription failed: {e:?}");
@@ -1792,14 +1818,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
         }
         }
 
 
         Subcmd::Scan { reset } => {
         Subcmd::Scan { reset } => {
-            let drk = Drk::new(
+            let drk = new_wallet(
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_path,
                 blockchain_config.wallet_pass,
                 blockchain_config.wallet_pass,
                 Some(blockchain_config.endpoint),
                 Some(blockchain_config.endpoint),
                 ex,
                 ex,
                 args.fun,
                 args.fun,
             )
             )
-            .await?;
+            .await;
 
 
             if reset {
             if reset {
                 println!("Reset requested.");
                 println!("Reset requested.");
@@ -1825,14 +1851,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             ExplorerSubcmd::FetchTx { tx_hash, full, encode } => {
             ExplorerSubcmd::FetchTx { tx_hash, full, encode } => {
                 let tx_hash = TransactionHash(*blake3::Hash::from_hex(&tx_hash)?.as_bytes());
                 let tx_hash = TransactionHash(*blake3::Hash::from_hex(&tx_hash)?.as_bytes());
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     Some(blockchain_config.endpoint),
                     Some(blockchain_config.endpoint),
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
 
 
                 let tx = match drk.get_tx(&tx_hash).await {
                 let tx = match drk.get_tx(&tx_hash).await {
                     Ok(tx) => tx,
                     Ok(tx) => tx,
@@ -1866,14 +1892,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             ExplorerSubcmd::SimulateTx => {
             ExplorerSubcmd::SimulateTx => {
                 let tx = parse_tx_from_stdin().await?;
                 let tx = parse_tx_from_stdin().await?;
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     Some(blockchain_config.endpoint),
                     Some(blockchain_config.endpoint),
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
 
 
                 let is_valid = match drk.simulate_tx(&tx).await {
                 let is_valid = match drk.simulate_tx(&tx).await {
                     Ok(b) => b,
                     Ok(b) => b,
@@ -1890,14 +1916,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             }
             }
 
 
             ExplorerSubcmd::TxsHistory { tx_hash, encode } => {
             ExplorerSubcmd::TxsHistory { tx_hash, encode } => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
 
 
                 if let Some(c) = tx_hash {
                 if let Some(c) = tx_hash {
                     let (tx_hash, status, tx) = drk.get_tx_history_record(&c).await?;
                     let (tx_hash, status, tx) = drk.get_tx_history_record(&c).await?;
@@ -1955,14 +1981,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                     }
                     }
                 };
                 };
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 if let Err(e) = drk.add_alias(alias, token_id).await {
                 if let Err(e) = drk.add_alias(alias, token_id).await {
                     eprintln!("Failed to add alias: {e:?}");
                     eprintln!("Failed to add alias: {e:?}");
                     exit(2);
                     exit(2);
@@ -1983,14 +2009,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                     None => None,
                     None => None,
                 };
                 };
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let map = drk.get_aliases(alias, token_id).await?;
                 let map = drk.get_aliases(alias, token_id).await?;
 
 
                 // Create a prettytable with the new data:
                 // Create a prettytable with the new data:
@@ -2011,14 +2037,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             }
             }
 
 
             AliasSubcmd::Remove { alias } => {
             AliasSubcmd::Remove { alias } => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 if let Err(e) = drk.remove_alias(alias).await {
                 if let Err(e) = drk.remove_alias(alias).await {
                     eprintln!("Failed to remove alias: {e:?}");
                     eprintln!("Failed to remove alias: {e:?}");
                     exit(2);
                     exit(2);
@@ -2046,14 +2072,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                     }
                     }
                 };
                 };
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let token_id = drk.import_mint_authority(mint_authority, token_blind).await?;
                 let token_id = drk.import_mint_authority(mint_authority, token_blind).await?;
                 println!("Successfully imported mint authority for token ID: {token_id}");
                 println!("Successfully imported mint authority for token ID: {token_id}");
 
 
@@ -2061,14 +2087,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             }
             }
 
 
             TokenSubcmd::GenerateMint => {
             TokenSubcmd::GenerateMint => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let mint_authority = SecretKey::random(&mut OsRng);
                 let mint_authority = SecretKey::random(&mut OsRng);
                 let token_blind = BaseBlind::random(&mut OsRng);
                 let token_blind = BaseBlind::random(&mut OsRng);
                 let token_id = drk.import_mint_authority(mint_authority, token_blind).await?;
                 let token_id = drk.import_mint_authority(mint_authority, token_blind).await?;
@@ -2078,14 +2104,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             }
             }
 
 
             TokenSubcmd::List => {
             TokenSubcmd::List => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let tokens = drk.get_mint_authorities().await?;
                 let tokens = drk.get_mint_authorities().await?;
                 let aliases_map = match drk.get_aliases_mapped_by_token().await {
                 let aliases_map = match drk.get_aliases_mapped_by_token().await {
                     Ok(map) => map,
                     Ok(map) => map,
@@ -2124,14 +2150,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             }
             }
 
 
             TokenSubcmd::Mint { token, amount, recipient, spend_hook, user_data } => {
             TokenSubcmd::Mint { token, amount, recipient, spend_hook, user_data } => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     Some(blockchain_config.endpoint),
                     Some(blockchain_config.endpoint),
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
 
 
                 if let Err(e) = f64::from_str(&amount) {
                 if let Err(e) = f64::from_str(&amount) {
                     eprintln!("Invalid amount: {e:?}");
                     eprintln!("Invalid amount: {e:?}");
@@ -2201,14 +2227,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             }
             }
 
 
             TokenSubcmd::Freeze { token } => {
             TokenSubcmd::Freeze { token } => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     Some(blockchain_config.endpoint),
                     Some(blockchain_config.endpoint),
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let token_id = match drk.get_token(token).await {
                 let token_id = match drk.get_token(token).await {
                     Ok(t) => t,
                     Ok(t) => t,
                     Err(e) => {
                     Err(e) => {
@@ -2233,14 +2259,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
 
 
         Subcmd::Contract { command } => match command {
         Subcmd::Contract { command } => match command {
             ContractSubcmd::GenerateDeploy => {
             ContractSubcmd::GenerateDeploy => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
 
 
                 if let Err(e) = drk.deploy_auth_keygen().await {
                 if let Err(e) = drk.deploy_auth_keygen().await {
                     eprintln!("Error creating deploy auth keypair: {:?}", e);
                     eprintln!("Error creating deploy auth keypair: {:?}", e);
@@ -2251,14 +2277,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             }
             }
 
 
             ContractSubcmd::List => {
             ContractSubcmd::List => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     None,
                     None,
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
                 let auths = drk.list_deploy_auth().await?;
                 let auths = drk.list_deploy_auth().await?;
 
 
                 let mut table = Table::new();
                 let mut table = Table::new();
@@ -2283,14 +2309,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                 let wasm_bin = smol::fs::read(expand_path(&wasm_path)?).await?;
                 let wasm_bin = smol::fs::read(expand_path(&wasm_path)?).await?;
                 let deploy_ix = smol::fs::read(expand_path(&deploy_ix)?).await?;
                 let deploy_ix = smol::fs::read(expand_path(&deploy_ix)?).await?;
 
 
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     Some(blockchain_config.endpoint),
                     Some(blockchain_config.endpoint),
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
 
 
                 let mut tx = match drk.deploy_contract(deploy_auth, wasm_bin, deploy_ix).await {
                 let mut tx = match drk.deploy_contract(deploy_auth, wasm_bin, deploy_ix).await {
                     Ok(v) => v,
                     Ok(v) => v,
@@ -2311,14 +2337,14 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
             }
             }
 
 
             ContractSubcmd::Lock { deploy_auth } => {
             ContractSubcmd::Lock { deploy_auth } => {
-                let drk = Drk::new(
+                let drk = new_wallet(
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_path,
                     blockchain_config.wallet_pass,
                     blockchain_config.wallet_pass,
                     Some(blockchain_config.endpoint),
                     Some(blockchain_config.endpoint),
                     ex,
                     ex,
                     args.fun,
                     args.fun,
                 )
                 )
-                .await?;
+                .await;
 
 
                 let mut tx = match drk.lock_contract(deploy_auth).await {
                 let mut tx = match drk.lock_contract(deploy_auth).await {
                     Ok(v) => v,
                     Ok(v) => v,

+ 2 - 34
bin/drk/src/money.rs

@@ -60,16 +60,14 @@ use darkfi_serial::{deserialize_async, serialize_async, AsyncEncodable};
 use crate::{
 use crate::{
     cli_util::kaching,
     cli_util::kaching,
     convert_named_params,
     convert_named_params,
-    error::{WalletDbError, WalletDbResult},
+    error::WalletDbResult,
     walletdb::{WalletSmt, WalletStorage},
     walletdb::{WalletSmt, WalletStorage},
     Drk,
     Drk,
 };
 };
 
 
-// Wallet SQL table constant names. These have to represent the `wallet.sql`
+// Wallet SQL table constant names. These have to represent the `money.sql`
 // SQL schema. Table names are prefixed with the contract ID to avoid collisions.
 // SQL schema. Table names are prefixed with the contract ID to avoid collisions.
 lazy_static! {
 lazy_static! {
-    pub static ref MONEY_INFO_TABLE: String =
-        format!("{}_money_info", MONEY_CONTRACT_ID.to_string());
     pub static ref MONEY_TREE_TABLE: String =
     pub static ref MONEY_TREE_TABLE: String =
         format!("{}_money_tree", MONEY_CONTRACT_ID.to_string());
         format!("{}_money_tree", MONEY_CONTRACT_ID.to_string());
     pub static ref MONEY_SMT_TABLE: String = format!("{}_money_smt", MONEY_CONTRACT_ID.to_string());
     pub static ref MONEY_SMT_TABLE: String = format!("{}_money_smt", MONEY_CONTRACT_ID.to_string());
@@ -83,9 +81,6 @@ lazy_static! {
         format!("{}_money_aliases", MONEY_CONTRACT_ID.to_string());
         format!("{}_money_aliases", MONEY_CONTRACT_ID.to_string());
 }
 }
 
 
-// MONEY_INFO_TABLE
-pub const MONEY_INFO_COL_LAST_SCANNED_BLOCK: &str = "last_scanned_block";
-
 // MONEY_TREE_TABLE
 // MONEY_TREE_TABLE
 pub const MONEY_TREE_COL_TREE: &str = "tree";
 pub const MONEY_TREE_COL_TREE: &str = "tree";
 
 
@@ -147,16 +142,6 @@ impl Drk {
             println!("Successfully initialized Merkle tree for the Money contract");
             println!("Successfully initialized Merkle tree for the Money contract");
         }
         }
 
 
-        // We maintain the last scanned block as part of the Money contract,
-        // but at this moment it is also somewhat applicable to DAO scans.
-        if self.last_scanned_block().is_err() {
-            let query = format!(
-                "INSERT INTO {} ({}) VALUES (?1);",
-                *MONEY_INFO_TABLE, MONEY_INFO_COL_LAST_SCANNED_BLOCK
-            );
-            self.wallet.exec_sql(&query, rusqlite::params![0])?;
-        }
-
         // Insert DRK alias
         // Insert DRK alias
         self.add_alias("DRK".to_string(), *DARK_TOKEN_ID).await?;
         self.add_alias("DRK".to_string(), *DARK_TOKEN_ID).await?;
 
 
@@ -717,23 +702,6 @@ impl Drk {
         Ok(smt)
         Ok(smt)
     }
     }
 
 
-    /// Get the last scanned block height from the wallet.
-    pub fn last_scanned_block(&self) -> WalletDbResult<u32> {
-        let ret = self.wallet.query_single(
-            &MONEY_INFO_TABLE,
-            &[MONEY_INFO_COL_LAST_SCANNED_BLOCK],
-            &[],
-        )?;
-        let Value::Integer(height) = ret[0] else {
-            return Err(WalletDbError::ParseColumnValueError);
-        };
-        let Ok(height) = u32::try_from(height) else {
-            return Err(WalletDbError::ParseColumnValueError);
-        };
-
-        Ok(height)
-    }
-
     /// Auxiliary function to grab all the nullifiers, coins, notes and freezes from
     /// Auxiliary function to grab all the nullifiers, coins, notes and freezes from
     /// a transaction money call.
     /// a transaction money call.
     async fn parse_money_call(
     async fn parse_money_call(

+ 3 - 4
bin/drk/src/rpc.rs

@@ -40,7 +40,6 @@ use darkfi_serial::{deserialize_async, serialize_async};
 
 
 use crate::{
 use crate::{
     error::{WalletDbError, WalletDbResult},
     error::{WalletDbError, WalletDbResult},
-    money::{MONEY_INFO_COL_LAST_SCANNED_BLOCK, MONEY_INFO_TABLE},
     Drk,
     Drk,
 };
 };
 
 
@@ -68,6 +67,8 @@ impl Drk {
             }
             }
         };
         };
 
 
+        // TODO/FIXME: we can subscribe without scanning the geneseis(0) block,
+        // when no other block has been created.
         if last_known != last_scanned {
         if last_known != last_scanned {
             eprintln!("Warning: Last scanned block is not the last known block.");
             eprintln!("Warning: Last scanned block is not the last known block.");
             eprintln!("You should first fully scan the blockchain, and then subscribe");
             eprintln!("You should first fully scan the blockchain, and then subscribe");
@@ -220,9 +221,7 @@ impl Drk {
         }
         }
 
 
         // Write this block height into `last_scanned_block`
         // Write this block height into `last_scanned_block`
-        let query =
-            format!("UPDATE {} SET {} = ?1;", *MONEY_INFO_TABLE, MONEY_INFO_COL_LAST_SCANNED_BLOCK);
-        if let Err(e) = self.wallet.exec_sql(&query, rusqlite::params![block.header.height]) {
+        if let Err(e) = self.update_last_scanned_block(block.header.height) {
             return Err(Error::DatabaseError(format!(
             return Err(Error::DatabaseError(format!(
                 "[scan_block] Update last scanned block failed: {e:?}"
                 "[scan_block] Update last scanned block failed: {e:?}"
             )))
             )))

+ 7 - 0
bin/drk/wallet.sql

@@ -1,6 +1,13 @@
 -- Wallet definitions for drk.
 -- Wallet definitions for drk.
 -- We store data that is needed for wallet operations.
 -- We store data that is needed for wallet operations.
 
 
+PRAGMA foreign_keys = ON;
+
+-- Arbitrary info that is potentially useful
+CREATE TABLE IF NOT EXISTS wallet_info (
+	last_scanned_block INTEGER NOT NULL
+);
+
 -- Transactions history
 -- Transactions history
 CREATE TABLE IF NOT EXISTS transactions_history (
 CREATE TABLE IF NOT EXISTS transactions_history (
     transaction_hash TEXT PRIMARY KEY NOT NULL,
     transaction_hash TEXT PRIMARY KEY NOT NULL,