Skip to content

Commit 552132a

Browse files
committed
electrum: Make "asset" and "nonce" available under listunspent (in Liquid mode)
1 parent a808b51 commit 552132a

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/electrum/server.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::config::Config;
2222
use crate::electrum::{get_electrum_height, ProtocolVersion};
2323
use crate::errors::*;
2424
use crate::metrics::{Gauge, HistogramOpts, HistogramVec, MetricOpts, Metrics};
25-
use crate::new_index::Query;
25+
use crate::new_index::{Query, Utxo};
2626
use crate::util::electrum_merkle::{get_header_merkle_proof, get_id_from_pos, get_tx_merkle_proof};
2727
use crate::util::{
2828
create_socket, full_hash, spawn_thread, BlockId, BoolThen, Channel, FullHash, HeaderEntry,
@@ -312,16 +312,28 @@ impl Connection {
312312
fn blockchain_scripthash_listunspent(&self, params: &[Value]) -> Result<Value> {
313313
let script_hash = hash_from_value(params.get(0)).chain_err(|| "bad script_hash")?;
314314
let utxos = self.query.utxo(&script_hash[..])?;
315+
316+
let to_json = |utxo: Utxo| {
317+
let json = json!({
318+
"height": utxo.confirmed.map_or(0, |b| b.height),
319+
"tx_pos": utxo.vout,
320+
"tx_hash": utxo.txid,
321+
"value": utxo.value,
322+
});
323+
324+
#[cfg(feature = "liquid")]
325+
let json = {
326+
let mut json = json;
327+
json["asset"] = json!(utxo.asset);
328+
json["nonce"] = json!(utxo.nonce);
329+
json
330+
};
331+
332+
json
333+
};
334+
315335
Ok(json!(Value::Array(
316-
utxos
317-
.into_iter()
318-
.map(|utxo| json!({
319-
"height": utxo.confirmed.map_or(0, |b| b.height),
320-
"tx_pos": utxo.vout,
321-
"tx_hash": utxo.txid,
322-
"value": utxo.value,
323-
}))
324-
.collect()
336+
utxos.into_iter().map(to_json).collect()
325337
)))
326338
}
327339

0 commit comments

Comments
 (0)