Skip to content

Commit

Permalink
Lightweight Electrum client with SSL/SOCKS5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
afilini committed Jan 27, 2020
1 parent 96c87ea commit 972bd2b
Show file tree
Hide file tree
Showing 29 changed files with 1,091 additions and 8 deletions.
17 changes: 15 additions & 2 deletions core/electrum_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
name = "electrum_client"
version = "0.1.0"
authors = ["Alekos Filini <alekos.filini@gmail.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
# loosely based on https://github.com/evgeniy-scherbina/rust-electrumx-client

[dependencies]
log = "^0.4"
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1.0" }
socks = { version = "^0.3", optional = true }
openssl = { version = "^0.10", optional = true }

[dependencies.bitcoin]
version = "0.23"
features = ["use-serde"]

[features]
debug-calls = []
proxy = ["socks"]
ssl = ["openssl"]
49 changes: 49 additions & 0 deletions core/electrum_client/src/batch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use bitcoin::hashes::hex::ToHex;
use bitcoin::{Script, Txid};

use types::{Param, ToElectrumScriptHash};

pub struct Batch {
calls: Vec<(String, Vec<Param>)>,
}

impl Batch {
pub fn script_list_unspent(&mut self, script: &Script) {
let params = vec![Param::String(script.to_electrum_scripthash().to_hex())];
self.calls
.push((String::from("blockchain.scripthash.listunspent"), params));
}

pub fn script_get_history(&mut self, script: &Script) {
let params = vec![Param::String(script.to_electrum_scripthash().to_hex())];
self.calls
.push((String::from("blockchain.scripthash.get_history"), params));
}

pub fn script_get_balance(&mut self, script: &Script) {
let params = vec![Param::String(script.to_electrum_scripthash().to_hex())];
self.calls
.push((String::from("blockchain.scripthash.get_balance"), params));
}

pub fn transaction_get(&mut self, tx_hash: &Txid) {
let params = vec![Param::String(tx_hash.to_hex())];
self.calls
.push((String::from("blockchain.transaction.get"), params));
}
}

impl std::iter::IntoIterator for Batch {
type Item = (String, Vec<Param>);
type IntoIter = std::vec::IntoIter<Self::Item>;

fn into_iter(self) -> Self::IntoIter {
self.calls.into_iter()
}
}

impl std::default::Default for Batch {
fn default() -> Self {
Batch { calls: Vec::new() }
}
}
Loading

0 comments on commit 972bd2b

Please sign in to comment.