From 853513ed271a035497541a4e8517c45ca23e30f6 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Mon, 3 Sep 2018 12:04:28 +0300 Subject: [PATCH] Add 'blockchain.address.get_history' API For easier invocation (e.g. using curl). --- src/rpc.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/rpc.rs b/src/rpc.rs index 16c9d5a..fa3629a 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -212,6 +212,19 @@ impl Connection { ))) } + fn blockchain_address_get_history(&self, params: &[Value]) -> Result { + let addr = address_from_value(params.get(0)).chain_err(|| "bad address")?; + let script_hash = compute_script_hash(&addr.script_pubkey().into_bytes()); + let status = self.query.status(&script_hash[..])?; + Ok(json!(Value::Array( + status + .history() + .into_iter() + .map(|item| json!({"height": item.0, "tx_hash": item.1.be_hex_string()})) + .collect() + ))) + } + fn blockchain_scripthash_listunspent(&self, params: &[Value]) -> Result { let script_hash = hash_from_value(params.get(0)).chain_err(|| "bad script_hash")?; Ok(unspent_from_status(&self.query.status(&script_hash[..])?)) @@ -281,6 +294,7 @@ impl Connection { "blockchain.relayfee" => self.blockchain_relayfee(), "blockchain.address.subscribe" => self.blockchain_address_subscribe(¶ms), "blockchain.address.get_balance" => self.blockchain_address_get_balance(¶ms), + "blockchain.address.get_history" => self.blockchain_address_get_history(¶ms), "blockchain.address.listunspent" => self.blockchain_address_listunspent(¶ms), "blockchain.scripthash.subscribe" => self.blockchain_scripthash_subscribe(¶ms), "blockchain.scripthash.get_balance" => self.blockchain_scripthash_get_balance(¶ms),