Unverified Commit 7b858f99 authored by Roman Zeyde's avatar Roman Zeyde
Browse files

Implement blockchain_transaction_get RPC

parent 95da35ac
......@@ -10,6 +10,7 @@ bincode = "1.0.0"
bitcoin = "0.12"
crossbeam = "0.3.2"
error-chain = "0.11"
extfmt = "0.1"
itertools = "0.7.8"
log = "0.4"
pbr = "1.0.0"
......
......@@ -3,6 +3,7 @@
extern crate bincode;
extern crate bitcoin;
extern crate crypto;
extern crate extfmt;
extern crate itertools;
extern crate pbr;
extern crate reqwest;
......@@ -28,5 +29,6 @@ pub mod query;
pub mod rpc;
pub mod store;
pub mod waiter;
pub mod util;
mod types;
......@@ -8,6 +8,7 @@ use daemon::Daemon;
use index::{compute_script_hash, hash_prefix, HashPrefix, TxInKey, TxInRow, TxKey, TxOutRow,
HASH_PREFIX_LEN};
use store::Store;
use types::Bytes;
pub struct Query<'a> {
store: &'a Store,
......@@ -95,4 +96,9 @@ impl<'a> Query<'a> {
}
balance as f64 / 100_000_000f64
}
pub fn get_tx(&self, tx_hash: Sha256dHash) -> Bytes {
self.daemon
.get(&format!("tx/{}.bin", tx_hash.be_hex_string()))
}
}
......@@ -4,6 +4,7 @@ use std::io::{BufRead, BufReader, Write};
use std::net::{SocketAddr, TcpListener, TcpStream};
use query::Query;
use util;
error_chain!{}
......@@ -45,7 +46,7 @@ impl<'a> Handler<'a> {
}
fn blockchain_scripthash_get_balance(&self, params: &[&str]) -> Result<Value> {
let script_hash_hex = params.get(0).chain_err(|| "missing parameter")?;
let script_hash_hex = params.get(0).chain_err(|| "missing scripthash")?;
let script_hash =
Sha256dHash::from_hex(script_hash_hex).chain_err(|| "invalid scripthash")?;
let confirmed = self.query.balance(&script_hash[..]);
......@@ -56,8 +57,11 @@ impl<'a> Handler<'a> {
Ok(json!([])) // TODO: list of {tx_hash: "ABC", height: 123}
}
fn blockchain_transaction_get(&self, _params: &[&str]) -> Result<Value> {
Ok(json!("HEX_TX")) // TODO: list of {tx_hash: "ABC", height: 123}
fn blockchain_transaction_get(&self, params: &[&str]) -> Result<Value> {
let tx_hash_hex = params.get(0).chain_err(|| "missing tx_hash")?;
let tx_hash = Sha256dHash::from_hex(tx_hash_hex).chain_err(|| "invalid tx_hash")?;
let tx_hex = util::hexlify(&self.query.get_tx(tx_hash));
Ok(json!(tx_hex))
}
fn blockchain_transaction_get_merkle(&self, _params: &[&str]) -> Result<Value> {
......
use extfmt::Hexlify;
pub fn hexlify(blob: &[u8]) -> String {
format!("{}", Hexlify(blob))
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment