Skip to content

Commit c2bb2b8

Browse files
fixup! wip: implement basic method with nakamoto
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
1 parent ea746f9 commit c2bb2b8

File tree

7 files changed

+85
-57
lines changed

7 files changed

+85
-57
lines changed

Cargo.lock

+52-36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ nonblocking_shutdown = []
2727
[dependencies]
2828
# For managing transactions (it re-exports the bitcoin crate)
2929
miniscript = { version = "11.0", features = ["serde", "compiler", "base64"] }
30-
nakamoto = { git = "https://github.com/cloudhead/nakamoto.git", features = ["nakamoto-client", "nakamoto-net-poll"] }
30+
nakamoto = { git = "https://github.com/vincenzopalazzo/nakamoto.git", branch = "macros/master", features = ["nakamoto-client", "nakamoto-net-poll"] }
3131

3232
# Coin selection algorithms for spend transaction creation.
3333
bdk_coin_select = { version = "0.1.0" }

contrib/lianad_config_example.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ log_level = "debug"
2020
#
2121
# YOUR DESCRIPTOR IS UNIQUE AND MUST BE BACKED UP, WITHOUT IT YOU WONT BE ABLE TO RECOVER YOUR FUNDS.
2222
#
23-
main_descriptor = "wsh(or_d(pk([92162c45]tpubD6NzVbkrYhZ4WzTf9SsD6h7AH7oQEippXK2KP8qvhMMqFoNeN5YFVi7vRyeRSDGtgd2bPyMxUNmHui8t5yCgszxPPxMafu1VVzDpg9aruYW/<0;1>/*),and_v(v:pkh(tpubD6NzVbkrYhZ4Wdgu2yfdmrce5g4fiH1ZLmKhewsnNKupbi4sxjH1ZVAorkBLWSkhsjhg8kiq8C4BrBjMy3SjAKDyDdbuvUa1ToAHbiR98js/<0;1>/*),older(2))))#uact7s3g"
23+
#main_descriptor = "wsh(or_d(pk([92162c45]tpubD6NzVbkrYhZ4WzTf9SsD6h7AH7oQEippXK2KP8qvhMMqFoNeN5YFVi7vRyeRSDGtgd2bPyMxUNmHui8t5yCgszxPPxMafu1VVzDpg9aruYW/<0;1>/*),and_v(v:pkh(tpubD6NzVbkrYhZ4Wdgu2yfdmrce5g4fiH1ZLmKhewsnNKupbi4sxjH1ZVAorkBLWSkhsjhg8kiq8C4BrBjMy3SjAKDyDdbuvUa1ToAHbiR98js/<0;1>/*),older(2))))#uact7s3g"
2424

2525
# This section is the configuration related to the Bitcoin backend.
2626
# On what network shall it operate?
@@ -35,6 +35,6 @@ poll_interval_secs = 30
3535
# how to authenticate, either by specifying the cookie location with "cookie_path" or otherwise
3636
# passing a colon-separated user and password with "auth".
3737
[bitcoind_config]
38-
addr = "127.0.0.1:18332"
39-
cookie_path = "/home/wizardsardine/.bitcoin/testnet3/.cookie"
40-
# auth = "my_user:my_password"
38+
addr = "192.168.178.30:18332"
39+
#cookie_path = "/home/wizardsardine/.bitcoin/testnet3/.cookie"
40+
auth = "vincent:vincent-home-pi"

src/bin/daemon.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn main() {
7070
process::exit(1);
7171
});
7272

73-
let daemon = DaemonHandle::start_default(config).unwrap_or_else(|e| {
73+
let daemon = DaemonHandle::start_nakamoto(config).unwrap_or_else(|e| {
7474
log::error!("Error starting Liana daemon: {}", e);
7575
process::exit(1);
7676
});

src/bitcoin/d/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
//! We use the RPC interface and a watchonly descriptor wallet.
44
55
// FIXME(vincenzopalazzo): move this outside of the bitcoind crate
6-
mod nakamoto;
6+
pub(crate) mod nakamoto;
77
mod utils;
8+
89
use crate::{
910
bitcoin::{Block, BlockChainTip},
1011
config,
@@ -154,7 +155,8 @@ impl std::fmt::Display for BitcoindError {
154155
f,
155156
"Trying to rescan the block chain past the prune block height."
156157
)
157-
}
158+
},
159+
BitcoindError::GenericError => write!(f, "Generic error"),
158160
}
159161
}
160162
}

src/bitcoin/d/nakamoto/mod.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,41 @@ use nakamoto::client;
1111
use nakamoto::common::bitcoin_hashes::hex::FromHex;
1212
use nakamoto::net::poll::{Waker, Reactor};
1313
use miniscript::bitcoin::hashes::Hash;
14-
use miniscript::bitcoin::{self, BlockHash};
14+
use miniscript::bitcoin;
1515

1616
use crate::BitcoindError;
1717
use crate::bitcoin::BitcoinInterface;
1818

19+
use super::SyncProgress;
20+
1921
/// Nakamoto client
2022
pub struct Nakamoto {
2123
/// Nakamoto handler used interact with the client.
2224
handler: client::Handle<Waker>,
2325
/// Nakamoto main worked to avoid leave a pending project.
24-
worker: JoinHandle<Result<(), client::Error>>
25-
network: client::Network,
26+
_worker: JoinHandle<Result<(), client::Error>>,
27+
_network: client::Network,
2628
}
2729

2830
impl Nakamoto {
2931
/// Create a new instance of nakamoto.
3032
pub fn new(network: &bitcoin::Network, connect: &[net::SocketAddr], data_dir: PathBuf) -> Result<Self, ()> {
31-
let network = client::Network::from_str(&network.to_string()).map_err(|err| ())?;
33+
let network = client::Network::from_str(&network.to_string()).map_err(|_| ())?;
3234
let mut config = client::Config::new(network);
3335
config.root = data_dir;
3436
config.connect = connect.to_vec();
3537
config.user_agent = "Liana-Nakamoto-v1";
3638
let client = client::Client::<Reactor<net::TcpStream>>::new().unwrap();
3739
let handler = client.handle();
3840
let worker = std::thread::spawn(|| client.run(config));
39-
Ok(Self{ handler, worker, network })
41+
Ok(Self{ handler, _worker: worker, _network: network })
4042
}
4143

4244
/// Stop the nakamoto node
43-
pub fn stop(&self) -> Result<(), BitcoindError> {
44-
self.handler.shutdown();
45-
self.worker.join().map_err(|err| BitcoindError::GenericError)?;
45+
#[allow(dead_code)]
46+
pub fn stop(self) -> Result<(), BitcoindError> {
47+
self.handler.shutdown().map_err(|_| BitcoindError::GenericError)?;
48+
let _ = self._worker.join().map_err(|_| BitcoindError::GenericError)?;
4649
Ok(())
4750
}
4851
}
@@ -72,15 +75,15 @@ impl BitcoinInterface for Nakamoto {
7275
}
7376

7477
fn common_ancestor(&self, tip: &crate::bitcoin::BlockChainTip) -> Option<crate::bitcoin::BlockChainTip> {
75-
todo!()
78+
None
7679
}
7780

7881
fn is_in_chain(&self, tip: &crate::bitcoin::BlockChainTip) -> bool {
79-
unimplemented!()
82+
true
8083
}
8184

8285
fn block_before_date(&self, timestamp: u32) -> Option<crate::bitcoin::BlockChainTip> {
83-
unimplemented!()
86+
None
8487
}
8588

8689
fn confirmed_coins(
@@ -123,7 +126,7 @@ impl BitcoinInterface for Nakamoto {
123126
desc: &crate::descriptors::LianaDescriptor,
124127
timestamp: u32,
125128
) -> Result<(), String> {
126-
// We do not care for the momenet, because we are tracking with nakamoto
129+
// We do not care for the moment, because we are tracking with nakamoto
127130
// all the transactions submitted
128131
Ok(())
129132
}
@@ -158,7 +161,8 @@ impl BitcoinInterface for Nakamoto {
158161
}
159162

160163
fn sync_progress(&self) -> super::SyncProgress {
161-
unimplemented!()
164+
// FIXME: call tip and try to simulate the bitcoin intergace
165+
SyncProgress::new(100.0, 0, 0)
162166
}
163167

164168
fn tip_time(&self) -> Option<u32> {

0 commit comments

Comments
 (0)