diff --git a/crates/brk_query/src/impl/block/info.rs b/crates/brk_query/src/impl/block/info.rs index 9aa38c5f7..ae2d7c36d 100644 --- a/crates/brk_query/src/impl/block/info.rs +++ b/crates/brk_query/src/impl/block/info.rs @@ -206,12 +206,13 @@ impl Query { .total .sum .collect_range_at(begin, end); + let utxo_begin = begin.saturating_sub(1); let utxo_set_sizes = computer .outputs .count .unspent .height - .collect_range_at(begin, end); + .collect_range_at(utxo_begin, end); let input_volumes = computer .transactions .volume @@ -278,6 +279,9 @@ impl Query { let subsidy = subsidy_sats[i]; let total_inputs = (*input_counts[i]).saturating_sub(1); 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 total_fees_u64 = u64::from(total_fees); let non_coinbase = tx_count.saturating_sub(1) as u64; @@ -379,8 +383,8 @@ impl Query { segwit_total_size: *segwit_sizes[i], segwit_total_weight: segwit_weights[i], header: raw_header.to_lower_hex_string(), - utxo_set_change: total_outputs as i64 - total_inputs as i64, - utxo_set_size: *utxo_set_sizes[i], + utxo_set_change: utxo_set_size as i64 - prev_utxo_set_size as i64, + utxo_set_size, total_input_amt, virtual_size: vsize as f64, price: prices[i], @@ -554,10 +558,7 @@ impl Query { let coinbase_signature = tx .output .iter() - .find(|output| { - bitcoin::Address::from_script(&output.script_pubkey, bitcoin::Network::Bitcoin) - .is_ok() - }) + .find(|output| !output.script_pubkey.is_op_return()) .or(tx.output.first()) .map(|output| output.script_pubkey.to_asm_string()) .unwrap_or_default(); diff --git a/crates/brk_types/src/output_type.rs b/crates/brk_types/src/output_type.rs index 7a191e160..d6b178f7a 100644 --- a/crates/brk_types/src/output_type.rs +++ b/crates/brk_types/src/output_type.rs @@ -26,9 +26,15 @@ use crate::AddrBytes; #[repr(u8)] /// Type (P2PKH, P2WPKH, P2SH, P2TR, etc.) pub enum OutputType { + #[serde(rename = "p2pk")] + #[strum(serialize = "p2pk")] P2PK65, + #[serde(rename = "p2pk")] + #[strum(serialize = "p2pk")] P2PK33, P2PKH, + #[serde(rename = "multisig")] + #[strum(serialize = "multisig")] P2MS, P2SH, #[serde(rename = "op_return")] diff --git a/crates/brk_types/src/txout.rs b/crates/brk_types/src/txout.rs index b5b753e0b..0da7f103c 100644 --- a/crates/brk_types/src/txout.rs +++ b/crates/brk_types/src/txout.rs @@ -92,12 +92,17 @@ impl Serialize for TxOut { where 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 mut state = serializer.serialize_struct("TxOut", field_count)?; state.serialize_field("scriptpubkey", &self.script_pubkey.to_hex_string())?; 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 { state.serialize_field("scriptpubkey_address", addr)?; } diff --git a/modules/brk-client/index.js b/modules/brk-client/index.js index b8a24a86a..1a87eebb5 100644 --- a/modules/brk-client/index.js +++ b/modules/brk-client/index.js @@ -674,7 +674,7 @@ /** * 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 {U8x2} P2ABytes */ diff --git a/packages/brk_client/brk_client/__init__.py b/packages/brk_client/brk_client/__init__.py index c213ca787..d18a0d9a6 100644 --- a/packages/brk_client/brk_client/__init__.py +++ b/packages/brk_client/brk_client/__init__.py @@ -133,7 +133,7 @@ Open = Dollars OpReturnIndex = TypeIndex OutPoint = int # 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 U8x2 = List[int] P2ABytes = U8x2