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

Implement blockchain.transaction.get verbose support #36

Open
wants to merge 2 commits into
base: new-index
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,13 @@ impl Daemon {
)
}

pub fn gettransaction_raw_verbose(&self, txid: &Txid) -> Result<Value> {
self.request(
"getrawtransaction",
json!([txid.to_hex(), 1]),
)
}

pub fn getmempooltx(&self, txhash: &Txid) -> Result<Transaction> {
let value = self.request(
"getrawtransaction",
Expand Down
26 changes: 17 additions & 9 deletions src/electrum/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,21 +337,29 @@ impl Connection {

fn blockchain_transaction_get(&self, params: &[Value]) -> Result<Value> {
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<Value> {
Expand Down
7 changes: 7 additions & 0 deletions src/new_index/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Bytes> {
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<Value> {
self.daemon.gettransaction_raw_verbose(txid)
}

pub fn lookup_txos(&self, outpoints: &BTreeSet<OutPoint>) -> HashMap<OutPoint, TxOut> {
// the mempool lookup_txos() internally looks up confirmed txos as well
self.mempool()
Expand Down