diff --git a/src/daemon.rs b/src/daemon.rs index 529369954..d64fb26e9 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -509,6 +509,13 @@ impl Daemon { ) } + pub fn gettransaction_raw_verbose(&self, txid: &Txid) -> Result { + self.request( + "getrawtransaction", + json!([txid.to_hex(), 1]), + ) + } + pub fn getmempooltx(&self, txhash: &Txid) -> Result { let value = self.request( "getrawtransaction", diff --git a/src/electrum/server.rs b/src/electrum/server.rs index 6157fbef4..7acd37ecf 100644 --- a/src/electrum/server.rs +++ b/src/electrum/server.rs @@ -337,21 +337,29 @@ impl Connection { fn blockchain_transaction_get(&self, params: &[Value]) -> Result { let tx_hash = Txid::from(hash_from_value(params.get(0)).chain_err(|| "bad tx_hash")?); + let verbose = match params.get(1) { - Some(value) => value.as_bool().chain_err(|| "non-bool verbose value")?, + Some(value) => if value == 1 || value == "1" { + true + } else { + value.as_bool().chain_err(|| "non-bool verbose value")? + }, None => false, }; - // FIXME: implement verbose support if verbose { - bail!("verbose transactions are currently unsupported"); + let tx = self + .query + .lookup_raw_txn_verbose(&tx_hash) + .chain_err(|| "missing transaction")?; + Ok(json!(tx)) + } else { + let tx = self + .query + .lookup_raw_txn(&tx_hash) + .chain_err(|| "missing transaction")?; + Ok(json!(hex::encode(tx))) } - - let tx = self - .query - .lookup_raw_txn(&tx_hash) - .chain_err(|| "missing transaction")?; - Ok(json!(hex::encode(tx))) } fn blockchain_transaction_get_merkle(&self, params: &[Value]) -> Result { diff --git a/src/new_index/query.rs b/src/new_index/query.rs index c7211af43..e95110502 100644 --- a/src/new_index/query.rs +++ b/src/new_index/query.rs @@ -4,6 +4,8 @@ use std::collections::{BTreeSet, HashMap}; use std::sync::{Arc, RwLock, RwLockReadGuard}; use std::time::{Duration, Instant}; +use serde_json::{Value}; + use crate::chain::{Network, OutPoint, Transaction, TxOut}; use crate::config::Config; use crate::daemon::Daemon; @@ -114,12 +116,17 @@ impl Query { .lookup_txn(txid, None) .or_else(|| self.mempool().lookup_txn(txid)) } + pub fn lookup_raw_txn(&self, txid: &Txid) -> Option { self.chain .lookup_raw_txn(txid, None) .or_else(|| self.mempool().lookup_raw_txn(txid)) } + pub fn lookup_raw_txn_verbose(&self, txid: &Txid) -> Result { + self.daemon.gettransaction_raw_verbose(txid) + } + pub fn lookup_txos(&self, outpoints: &BTreeSet) -> HashMap { // the mempool lookup_txos() internally looks up confirmed txos as well self.mempool()