Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

electrum client #1

Merged
merged 1 commit into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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