Skip to content

Commit

Permalink
electrum: Make "asset" and "nonce" available under listunspent (in Li…
Browse files Browse the repository at this point in the history
…quid mode)
  • Loading branch information
shesek committed Feb 16, 2023
1 parent a808b51 commit 552132a
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/electrum/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::config::Config;
use crate::electrum::{get_electrum_height, ProtocolVersion};
use crate::errors::*;
use crate::metrics::{Gauge, HistogramOpts, HistogramVec, MetricOpts, Metrics};
use crate::new_index::Query;
use crate::new_index::{Query, Utxo};
use crate::util::electrum_merkle::{get_header_merkle_proof, get_id_from_pos, get_tx_merkle_proof};
use crate::util::{
create_socket, full_hash, spawn_thread, BlockId, BoolThen, Channel, FullHash, HeaderEntry,
Expand Down Expand Up @@ -312,16 +312,28 @@ impl Connection {
fn blockchain_scripthash_listunspent(&self, params: &[Value]) -> Result<Value> {
let script_hash = hash_from_value(params.get(0)).chain_err(|| "bad script_hash")?;
let utxos = self.query.utxo(&script_hash[..])?;

let to_json = |utxo: Utxo| {
let json = json!({
"height": utxo.confirmed.map_or(0, |b| b.height),
"tx_pos": utxo.vout,
"tx_hash": utxo.txid,
"value": utxo.value,
});

#[cfg(feature = "liquid")]
let json = {
let mut json = json;
json["asset"] = json!(utxo.asset);
json["nonce"] = json!(utxo.nonce);
json
};

json
};

Ok(json!(Value::Array(
utxos
.into_iter()
.map(|utxo| json!({
"height": utxo.confirmed.map_or(0, |b| b.height),
"tx_pos": utxo.vout,
"tx_hash": utxo.txid,
"value": utxo.value,
}))
.collect()
utxos.into_iter().map(to_json).collect()
)))
}

Expand Down

0 comments on commit 552132a

Please sign in to comment.