server: ms endpoint fixes

This commit is contained in:
nym21
2026-04-04 13:05:39 +02:00
parent 42b497ff65
commit 41ec24c81e
5 changed files with 23 additions and 11 deletions

View File

@@ -206,12 +206,13 @@ impl Query {
.total .total
.sum .sum
.collect_range_at(begin, end); .collect_range_at(begin, end);
let utxo_begin = begin.saturating_sub(1);
let utxo_set_sizes = computer let utxo_set_sizes = computer
.outputs .outputs
.count .count
.unspent .unspent
.height .height
.collect_range_at(begin, end); .collect_range_at(utxo_begin, end);
let input_volumes = computer let input_volumes = computer
.transactions .transactions
.volume .volume
@@ -278,6 +279,9 @@ impl Query {
let subsidy = subsidy_sats[i]; let subsidy = subsidy_sats[i];
let total_inputs = (*input_counts[i]).saturating_sub(1); let total_inputs = (*input_counts[i]).saturating_sub(1);
let total_outputs = *output_counts[i]; let total_outputs = *output_counts[i];
let utxo_idx = begin + i - utxo_begin;
let utxo_set_size = *utxo_set_sizes[utxo_idx];
let prev_utxo_set_size = if utxo_idx > 0 { *utxo_set_sizes[utxo_idx - 1] } else { 0 };
let vsize = weight.to_vbytes_ceil(); let vsize = weight.to_vbytes_ceil();
let total_fees_u64 = u64::from(total_fees); let total_fees_u64 = u64::from(total_fees);
let non_coinbase = tx_count.saturating_sub(1) as u64; let non_coinbase = tx_count.saturating_sub(1) as u64;
@@ -379,8 +383,8 @@ impl Query {
segwit_total_size: *segwit_sizes[i], segwit_total_size: *segwit_sizes[i],
segwit_total_weight: segwit_weights[i], segwit_total_weight: segwit_weights[i],
header: raw_header.to_lower_hex_string(), header: raw_header.to_lower_hex_string(),
utxo_set_change: total_outputs as i64 - total_inputs as i64, utxo_set_change: utxo_set_size as i64 - prev_utxo_set_size as i64,
utxo_set_size: *utxo_set_sizes[i], utxo_set_size,
total_input_amt, total_input_amt,
virtual_size: vsize as f64, virtual_size: vsize as f64,
price: prices[i], price: prices[i],
@@ -554,10 +558,7 @@ impl Query {
let coinbase_signature = tx let coinbase_signature = tx
.output .output
.iter() .iter()
.find(|output| { .find(|output| !output.script_pubkey.is_op_return())
bitcoin::Address::from_script(&output.script_pubkey, bitcoin::Network::Bitcoin)
.is_ok()
})
.or(tx.output.first()) .or(tx.output.first())
.map(|output| output.script_pubkey.to_asm_string()) .map(|output| output.script_pubkey.to_asm_string())
.unwrap_or_default(); .unwrap_or_default();

View File

@@ -26,9 +26,15 @@ use crate::AddrBytes;
#[repr(u8)] #[repr(u8)]
/// Type (P2PKH, P2WPKH, P2SH, P2TR, etc.) /// Type (P2PKH, P2WPKH, P2SH, P2TR, etc.)
pub enum OutputType { pub enum OutputType {
#[serde(rename = "p2pk")]
#[strum(serialize = "p2pk")]
P2PK65, P2PK65,
#[serde(rename = "p2pk")]
#[strum(serialize = "p2pk")]
P2PK33, P2PK33,
P2PKH, P2PKH,
#[serde(rename = "multisig")]
#[strum(serialize = "multisig")]
P2MS, P2MS,
P2SH, P2SH,
#[serde(rename = "op_return")] #[serde(rename = "op_return")]

View File

@@ -92,12 +92,17 @@ impl Serialize for TxOut {
where where
S: Serializer, S: Serializer,
{ {
let addr = self.addr(); let output_type = self.type_();
// P2PK has no standard address format — don't include scriptpubkey_address
let addr = match output_type {
OutputType::P2PK65 | OutputType::P2PK33 => None,
_ => self.addr(),
};
let field_count = if addr.is_some() { 5 } else { 4 }; let field_count = if addr.is_some() { 5 } else { 4 };
let mut state = serializer.serialize_struct("TxOut", field_count)?; let mut state = serializer.serialize_struct("TxOut", field_count)?;
state.serialize_field("scriptpubkey", &self.script_pubkey.to_hex_string())?; state.serialize_field("scriptpubkey", &self.script_pubkey.to_hex_string())?;
state.serialize_field("scriptpubkey_asm", &self.script_pubkey_asm())?; state.serialize_field("scriptpubkey_asm", &self.script_pubkey_asm())?;
state.serialize_field("scriptpubkey_type", &self.type_())?; state.serialize_field("scriptpubkey_type", &output_type)?;
if let Some(addr) = &addr { if let Some(addr) = &addr {
state.serialize_field("scriptpubkey_address", addr)?; state.serialize_field("scriptpubkey_address", addr)?;
} }

View File

@@ -674,7 +674,7 @@
/** /**
* Type (P2PKH, P2WPKH, P2SH, P2TR, etc.) * Type (P2PKH, P2WPKH, P2SH, P2TR, etc.)
* *
* @typedef {("p2pk65"|"p2pk33"|"p2pkh"|"p2ms"|"p2sh"|"op_return"|"v0_p2wpkh"|"v0_p2wsh"|"v1_p2tr"|"p2a"|"empty"|"unknown")} OutputType * @typedef {("p2pk"|"p2pk"|"p2pkh"|"multisig"|"p2sh"|"op_return"|"v0_p2wpkh"|"v0_p2wsh"|"v1_p2tr"|"p2a"|"empty"|"unknown")} OutputType
*/ */
/** @typedef {TypeIndex} P2AAddrIndex */ /** @typedef {TypeIndex} P2AAddrIndex */
/** @typedef {U8x2} P2ABytes */ /** @typedef {U8x2} P2ABytes */

View File

@@ -133,7 +133,7 @@ Open = Dollars
OpReturnIndex = TypeIndex OpReturnIndex = TypeIndex
OutPoint = int OutPoint = int
# Type (P2PKH, P2WPKH, P2SH, P2TR, etc.) # Type (P2PKH, P2WPKH, P2SH, P2TR, etc.)
OutputType = Literal["p2pk65", "p2pk33", "p2pkh", "p2ms", "p2sh", "op_return", "v0_p2wpkh", "v0_p2wsh", "v1_p2tr", "p2a", "empty", "unknown"] OutputType = Literal["p2pk", "p2pk", "p2pkh", "multisig", "p2sh", "op_return", "v0_p2wpkh", "v0_p2wsh", "v1_p2tr", "p2a", "empty", "unknown"]
P2AAddrIndex = TypeIndex P2AAddrIndex = TypeIndex
U8x2 = List[int] U8x2 = List[int]
P2ABytes = U8x2 P2ABytes = U8x2