|
| 1 | +use bitcoin::hashes::hex::ToHex; |
| 2 | +use bitcoin::{Script, Txid}; |
| 3 | + |
| 4 | +use types::{Param, ToElectrumScriptHash}; |
| 5 | + |
| 6 | +pub struct Batch { |
| 7 | + calls: Vec<(String, Vec<Param>)>, |
| 8 | +} |
| 9 | + |
| 10 | +impl Batch { |
| 11 | + pub fn script_list_unspent(&mut self, script: &Script) { |
| 12 | + let params = vec![Param::String(script.to_electrum_scripthash().to_hex())]; |
| 13 | + self.calls |
| 14 | + .push((String::from("blockchain.scripthash.listunspent"), params)); |
| 15 | + } |
| 16 | + |
| 17 | + pub fn script_get_history(&mut self, script: &Script) { |
| 18 | + let params = vec![Param::String(script.to_electrum_scripthash().to_hex())]; |
| 19 | + self.calls |
| 20 | + .push((String::from("blockchain.scripthash.get_history"), params)); |
| 21 | + } |
| 22 | + |
| 23 | + pub fn script_get_balance(&mut self, script: &Script) { |
| 24 | + let params = vec![Param::String(script.to_electrum_scripthash().to_hex())]; |
| 25 | + self.calls |
| 26 | + .push((String::from("blockchain.scripthash.get_balance"), params)); |
| 27 | + } |
| 28 | + |
| 29 | + pub fn transaction_get(&mut self, tx_hash: &Txid) { |
| 30 | + let params = vec![Param::String(tx_hash.to_hex())]; |
| 31 | + self.calls |
| 32 | + .push((String::from("blockchain.transaction.get"), params)); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +impl std::iter::IntoIterator for Batch { |
| 37 | + type Item = (String, Vec<Param>); |
| 38 | + type IntoIter = std::vec::IntoIter<Self::Item>; |
| 39 | + |
| 40 | + fn into_iter(self) -> Self::IntoIter { |
| 41 | + self.calls.into_iter() |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +impl std::default::Default for Batch { |
| 46 | + fn default() -> Self { |
| 47 | + Batch { calls: Vec::new() } |
| 48 | + } |
| 49 | +} |
0 commit comments