mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
client: create tree if doesn't exist
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use async_std::sync::{Arc, Mutex};
|
||||
use incrementalmerkletree::Tree;
|
||||
use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
|
||||
use log::{debug, info, trace, warn};
|
||||
use smol::Executor;
|
||||
use url::Url;
|
||||
@@ -52,6 +52,8 @@ pub enum ClientFailed {
|
||||
ClientError(String),
|
||||
#[error("Verify error: {0}")]
|
||||
VerifyError(String),
|
||||
#[error("Merkle tree already exists")]
|
||||
TreeExists,
|
||||
}
|
||||
|
||||
pub type ClientResult<T> = std::result::Result<T, ClientFailed>;
|
||||
@@ -89,6 +91,11 @@ impl Client {
|
||||
wallet.key_gen().await?;
|
||||
}
|
||||
|
||||
// Generate merkle tree if we don't have one.
|
||||
if wallet.get_tree().await.is_err() {
|
||||
wallet.tree_gen().await?;
|
||||
}
|
||||
|
||||
// TODO: Think about multiple keypairs
|
||||
let main_keypair = wallet.get_keypairs().await?[0];
|
||||
info!("Main keypair: {}", bs58::encode(&serialize(&main_keypair.public)).into_string());
|
||||
@@ -373,4 +380,8 @@ impl Client {
|
||||
pub async fn get_balances(&self) -> Result<Balances> {
|
||||
self.wallet.get_balances().await
|
||||
}
|
||||
|
||||
pub async fn get_tree(&self) -> Result<BridgeTree<MerkleNode, 32>> {
|
||||
self.wallet.get_tree().await
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user