Selaa lähdekoodia

darkfid: use base64 encoding | drk: minor fixes

skoupidi 2 vuotta sitten
vanhempi
sitoutus
44103f0359

+ 0 - 1
Cargo.lock

@@ -2095,7 +2095,6 @@ version = "0.4.1"
 dependencies = [
  "async-trait",
  "blake3 1.5.0",
- "bs58",
  "darkfi",
  "darkfi-contract-test-harness",
  "darkfi-sdk",

+ 1 - 2
bin/darkfid/Cargo.toml

@@ -10,7 +10,7 @@ edition = "2021"
 
 [dependencies]
 # Darkfi
-darkfi = {path = "../../", features = ["async-daemonize", "bs58"]}
+darkfi = {path = "../../", features = ["async-daemonize"]}
 darkfi_money_contract = {path = "../../src/contract/money"}
 darkfi-contract-test-harness = {path = "../../src/contract/test-harness"}
 darkfi-sdk = {path = "../../src/sdk"}
@@ -18,7 +18,6 @@ darkfi-serial = {path = "../../src/serial"}
 
 # Misc
 blake3 = "1.5.0"
-bs58 = "0.5.0"
 log = "0.4.20"
 num-bigint = "0.4.4"
 rand = "0.8.5"

+ 1 - 1
bin/darkfid/genesis_block_localnet

@@ -1 +1 @@
-jMzUeHqekqCSaE33631ze2H9K94hxHiUFsoTUgeTdme6WGZSmS9v6ntUmm8BCch7UUcfrQo48LFKBEECgQ7zeSYTfMW6CLqR9hMmWnnJFmysucuC1y5tFSCCARqkfVGJwwyYppNRfg6Bz7rwDpEbMebJuJrxEEzQAxhciocjYEyYsuJuJ5g6iFrWZRfGQAtDe67J7aX6T3c59fj6v53zXkM6Bm1Kc61R1YADWaLbNn7E3KeMW3pBVh
+AYa7rEMKSzoYLxJbN6SG6cSGu/o02E70pmtKI+XwxiWxAAAAAAAAAAAfq8xlAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAI5SX/BDpM3cjKjfCsHUms/OAh2F68zs3tw48/GJChU8AAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==

+ 1 - 1
bin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/src/main.rs

@@ -38,7 +38,7 @@ use darkfi::{
         server::{listen_and_serve, RequestHandler},
     },
     system::{StoppableTask, StoppableTaskPtr},
-    util::path::expand_path,
+    util::{encoding::base64, path::expand_path},
     validator::{Validator, ValidatorConfig, ValidatorPtr},
     Error, Result,
 };
@@ -204,7 +204,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
     };
 
     // Parse the genesis block
-    let bytes = bs58::decode(&genesis_block.trim()).into_vec()?;
+    let bytes = base64::decode(genesis_block.trim()).unwrap();
     let genesis_block: BlockInfo = deserialize_async(&bytes).await?;
 
     // Initialize or open sled database

+ 2 - 3
bin/darkfid/src/task/consensus.rs

@@ -16,7 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use darkfi::{rpc::util::JsonValue, Result};
+use darkfi::{rpc::util::JsonValue, util::encoding::base64, Result};
 use darkfi_serial::serialize;
 use log::info;
 
@@ -43,8 +43,7 @@ pub async fn consensus_task(node: &Darkfid) -> Result<()> {
         if !finalized.is_empty() {
             let mut notif_blocks = Vec::with_capacity(finalized.len());
             for block in finalized {
-                notif_blocks
-                    .push(JsonValue::String(bs58::encode(&serialize(&block)).into_string()));
+                notif_blocks.push(JsonValue::String(base64::encode(&serialize(&block))));
             }
             block_sub.notify(JsonValue::Array(notif_blocks)).await;
         }

+ 2 - 4
bin/darkfid/src/task/miner.rs

@@ -99,8 +99,7 @@ pub async fn miner_task(node: &Darkfid, recipient: &PublicKey, skip_sync: bool)
             if !finalized.is_empty() {
                 let mut notif_blocks = Vec::with_capacity(finalized.len());
                 for block in finalized {
-                    notif_blocks
-                        .push(JsonValue::String(bs58::encode(&serialize(&block)).into_string()));
+                    notif_blocks.push(JsonValue::String(base64::encode(&serialize(&block))));
                 }
                 block_sub.notify(JsonValue::Array(notif_blocks)).await;
                 break;
@@ -125,8 +124,7 @@ pub async fn miner_task(node: &Darkfid, recipient: &PublicKey, skip_sync: bool)
         if !finalized.is_empty() {
             let mut notif_blocks = Vec::with_capacity(finalized.len());
             for block in finalized {
-                notif_blocks
-                    .push(JsonValue::String(bs58::encode(&serialize(&block)).into_string()));
+                notif_blocks.push(JsonValue::String(base64::encode(&serialize(&block))));
             }
             block_sub.notify(JsonValue::Array(notif_blocks)).await;
         }

+ 1 - 1
bin/drk/drk_config.toml

@@ -1,4 +1,4 @@
-## darkfid configuration file
+## drk configuration file
 ##
 ## Please make sure you go through all the settings so you can configure
 ## your daemon properly.

+ 2 - 2
bin/drk/src/rpc.rs

@@ -124,7 +124,7 @@ impl Drk {
 
                     for param in params {
                         let param = param.get::<String>().unwrap();
-                        let bytes = bs58::decode(param).into_vec()?;
+                        let bytes = base64::decode(param).unwrap();
 
                         let block_data: BlockInfo = deserialize(&bytes)?;
                         eprintln!("=======================================");
@@ -271,7 +271,7 @@ impl Drk {
 
         let params = self.rpc_client.request(req).await?;
         let param = params.get::<String>().unwrap();
-        let bytes = bs58::decode(param).into_vec()?;
+        let bytes = base64::decode(param).unwrap();
         let block = deserialize(&bytes)?;
         Ok(block)
     }

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

@@ -164,7 +164,7 @@ impl Drk {
         let mut txs_hashes = Vec::with_capacity(txs.len());
         for tx in txs {
             let Ok(tx_hash) = tx.hash() else { return Err(WalletDbError::QueryPreparationFailed) };
-            txs_hashes.push(tx_hash);
+            txs_hashes.push(format!("{tx_hash}"));
         }
         let txs_hashes_string = format!("{:?}", txs_hashes).replace('[', "(").replace(']', ")");
         let query = format!(

+ 14 - 3
bin/drk/src/walletdb.rs

@@ -167,9 +167,20 @@ impl WalletDb {
 
         // Grab returned values
         let mut result = vec![];
-        for col in col_names {
-            let Ok(value) = row.get(*col) else { return Err(WalletDbError::ParseColumnValueError) };
-            result.push(value);
+        if col_names.is_empty() {
+            let mut idx = 0;
+            loop {
+                let Ok(value) = row.get(idx) else { break };
+                result.push(value);
+                idx += 1;
+            }
+        } else {
+            for col in col_names {
+                let Ok(value) = row.get(*col) else {
+                    return Err(WalletDbError::ParseColumnValueError)
+                };
+                result.push(value);
+            }
         }
 
         Ok(result)

+ 0 - 1
script/research/gg/Cargo.toml

@@ -21,7 +21,6 @@ darkfi-serial = {path = "../../../src/serial"}
 # Misc
 anyhow = "1.0.79"
 async-std = {version = "1.12.0", features = ["attributes"]}
-bs58 = "0.5.0"
 clap = {version = "4.4.14", features = ["derive"]}
 sled = "0.34.7"
 

+ 4 - 4
script/research/gg/src/main.rs

@@ -27,7 +27,7 @@ use darkfi::{
     blockchain::{BlockInfo, Blockchain, BlockchainOverlay},
     cli_desc,
     tx::Transaction,
-    util::{path::expand_path, time::Timestamp},
+    util::{encoding::base64, path::expand_path, time::Timestamp},
     validator::verification::verify_genesis_block,
 };
 use darkfi_contract_test_harness::vks;
@@ -65,7 +65,7 @@ fn read_block() -> Result<BlockInfo> {
     eprintln!("Reading genesis block from stdin...");
     let mut buf = String::new();
     stdin().read_to_string(&mut buf)?;
-    let bytes = bs58::decode(&buf.trim()).into_vec()?;
+    let bytes = base64::decode(buf.trim()).unwrap();
     let block = deserialize(&bytes)?;
     Ok(block)
 }
@@ -88,7 +88,7 @@ async fn main() -> Result<()> {
             let txs_folder = expand_path(&txs_folder).unwrap();
             let mut genesis_txs: Vec<Transaction> = vec![];
             for file in read_dir(txs_folder)? {
-                let bytes = bs58::decode(&read_to_string(file?.path())?.trim()).into_vec()?;
+                let bytes = base64::decode(read_to_string(file?.path())?.trim()).unwrap();
                 let tx = deserialize(&bytes)?;
                 genesis_txs.push(tx);
             }
@@ -111,7 +111,7 @@ async fn main() -> Result<()> {
             genesis_block.append_txs(vec![producer_tx])?;
 
             // Write generated genesis block to stdin
-            let encoded = bs58::encode(&serialize(&genesis_block)).into_string();
+            let encoded = base64::encode(&serialize(&genesis_block));
             println!("{encoded}");
 
             Ok(())