Wallet logic
This commit is contained in:
1039
src/wallet/mod.rs
Normal file
1039
src/wallet/mod.rs
Normal file
File diff suppressed because it is too large
Load Diff
52
src/wallet/offline_stream.rs
Normal file
52
src/wallet/offline_stream.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use std::io::{self, Error, ErrorKind, Read, Write};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OfflineStream {}
|
||||
|
||||
impl Read for OfflineStream {
|
||||
fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> {
|
||||
Err(Error::new(
|
||||
ErrorKind::NotConnected,
|
||||
"Trying to read from an OfflineStream",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl Write for OfflineStream {
|
||||
fn write(&mut self, _buf: &[u8]) -> io::Result<usize> {
|
||||
Err(Error::new(
|
||||
ErrorKind::NotConnected,
|
||||
"Trying to read from an OfflineStream",
|
||||
))
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
Err(Error::new(
|
||||
ErrorKind::NotConnected,
|
||||
"Trying to read from an OfflineStream",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
// #[cfg(any(feature = "electrum", feature = "default"))]
|
||||
// use electrum_client::Client;
|
||||
//
|
||||
// #[cfg(any(feature = "electrum", feature = "default"))]
|
||||
// impl OfflineStream {
|
||||
// fn new_client() -> {
|
||||
// use std::io::bufreader;
|
||||
//
|
||||
// let stream = OfflineStream{};
|
||||
// let buf_reader = BufReader::new(stream.clone());
|
||||
//
|
||||
// Client {
|
||||
// stream,
|
||||
// buf_reader,
|
||||
// headers: VecDeque::new(),
|
||||
// script_notifications: BTreeMap::new(),
|
||||
//
|
||||
// #[cfg(feature = "debug-calls")]
|
||||
// calls: 0,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
48
src/wallet/utils.rs
Normal file
48
src/wallet/utils.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
// De-facto standard "dust limit" (even though it should change based on the output type)
|
||||
const DUST_LIMIT_SATOSHI: u64 = 546;
|
||||
|
||||
// we implement this trait to make sure we don't mess up the comparison with off-by-one like a <
|
||||
// instead of a <= etc. The constant value for the dust limit is not public on purpose, to
|
||||
// encourage the usage of this trait.
|
||||
pub trait IsDust {
|
||||
fn is_dust(&self) -> bool;
|
||||
}
|
||||
|
||||
impl IsDust for u64 {
|
||||
fn is_dust(&self) -> bool {
|
||||
*self <= DUST_LIMIT_SATOSHI
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ChunksIterator<I: Iterator> {
|
||||
iter: I,
|
||||
size: usize,
|
||||
}
|
||||
|
||||
impl<I: Iterator> ChunksIterator<I> {
|
||||
pub fn new(iter: I, size: usize) -> Self {
|
||||
ChunksIterator { iter, size }
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Iterator> Iterator for ChunksIterator<I> {
|
||||
type Item = Vec<<I as std::iter::Iterator>::Item>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let mut v = Vec::new();
|
||||
for _ in 0..self.size {
|
||||
let e = self.iter.next();
|
||||
|
||||
match e {
|
||||
None => break,
|
||||
Some(val) => v.push(val),
|
||||
}
|
||||
}
|
||||
|
||||
if v.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(v)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user