server: ms endpoint fixes

This commit is contained in:
nym21
2026-04-04 12:16:15 +02:00
parent 01d908a560
commit 42b497ff65
10 changed files with 63 additions and 24 deletions

View File

@@ -8198,7 +8198,7 @@ pub struct BrkClient {
impl BrkClient { impl BrkClient {
/// Client version. /// Client version.
pub const VERSION: &'static str = "v0.3.0-alpha.3"; pub const VERSION: &'static str = "v0.3.0-alpha.4";
/// Create a new client with the given base URL. /// Create a new client with the given base URL.
pub fn new(base_url: impl Into<String>) -> Self { pub fn new(base_url: impl Into<String>) -> Self {

View File

@@ -53,11 +53,6 @@ impl Query {
.transactions .transactions
.height .height
.collect_range_at(start, end); .collect_range_at(start, end);
let versions = indexer
.vecs
.transactions
.tx_version
.collect_range_at(start, end);
let lock_times = indexer let lock_times = indexer
.vecs .vecs
.transactions .transactions
@@ -185,7 +180,7 @@ impl Query {
let mut transaction = Transaction { let mut transaction = Transaction {
index: Some(TxIndex::from(start + i)), index: Some(TxIndex::from(start + i)),
txid: txids[i].clone(), txid: txids[i].clone(),
version: versions[i], version: tx.version.into(),
lock_time: lock_times[i], lock_time: lock_times[i],
total_size: *total_sizes[i] as usize, total_size: *total_sizes[i] as usize,
weight, weight,

View File

@@ -171,6 +171,7 @@ mod tx;
mod tx_index; mod tx_index;
mod tx_status; mod tx_status;
mod tx_version; mod tx_version;
mod tx_version_raw;
mod tx_with_hex; mod tx_with_hex;
mod txid; mod txid;
mod txid_prefix; mod txid_prefix;
@@ -361,6 +362,7 @@ pub use tx::*;
pub use tx_index::*; pub use tx_index::*;
pub use tx_status::*; pub use tx_status::*;
pub use tx_version::*; pub use tx_version::*;
pub use tx_version_raw::*;
pub use tx_with_hex::*; pub use tx_with_hex::*;
pub use txid::*; pub use txid::*;
pub use txid_prefix::*; pub use txid_prefix::*;

View File

@@ -1,5 +1,6 @@
use crate::{ use crate::{
FeeRate, RawLockTime, Sats, TxIn, TxIndex, TxOut, TxStatus, TxVersion, Txid, VSize, Weight, FeeRate, RawLockTime, Sats, TxIn, TxIndex, TxOut, TxStatus, TxVersionRaw, Txid, VSize,
Weight,
}; };
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -16,9 +17,9 @@ pub struct Transaction {
#[schemars(example = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")] #[schemars(example = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")]
pub txid: Txid, pub txid: Txid,
/// Transaction version /// Transaction version (raw i32 from Bitcoin protocol, may contain non-standard values in coinbase txs)
#[schemars(example = 2)] #[schemars(example = 2)]
pub version: TxVersion, pub version: TxVersionRaw,
/// Transaction lock time /// Transaction lock time
#[schemars(example = 0)] #[schemars(example = 0)]

View File

@@ -0,0 +1,16 @@
use derive_more::Deref;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
/// Raw transaction version (i32) from Bitcoin protocol.
/// Unlike TxVersion (u8, indexed), this preserves non-standard values
/// used in coinbase txs for miner signaling/branding.
#[derive(Debug, Deref, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct TxVersionRaw(i32);
impl From<bitcoin::transaction::Version> for TxVersionRaw {
#[inline]
fn from(value: bitcoin::transaction::Version) -> Self {
Self(value.0)
}
}

View File

@@ -54,8 +54,12 @@ impl Serialize for TxIn {
let has_witness = !self.witness.is_empty(); let has_witness = !self.witness.is_empty();
let has_scriptsig = !self.script_sig.is_empty(); let has_scriptsig = !self.script_sig.is_empty();
// P2SH-wrapped SegWit: both scriptsig and witness present (not coinbase) // P2SH / P2SH-wrapped SegWit: extract redeemscript from scriptsig
let inner_redeem = if has_scriptsig && has_witness && !self.is_coinbase { let is_p2sh = self
.prevout
.as_ref()
.is_some_and(|p| p.script_pubkey.is_p2sh());
let inner_redeem = if has_scriptsig && is_p2sh && !self.is_coinbase {
self.script_sig self.script_sig
.redeem_script() .redeem_script()
.map(|s| s.to_asm_string()) .map(|s| s.to_asm_string())
@@ -64,10 +68,20 @@ impl Serialize for TxIn {
String::new() String::new()
}; };
// P2WSH / P2SH-P2WSH: witness has >2 items, last is the witnessScript // P2WSH/P2SH-P2WSH: last witness item is the witnessScript
// P2TR script path: second-to-last is the script, last is the control block
let is_p2tr = self
.prevout
.as_ref()
.is_some_and(|p| p.script_pubkey.is_p2tr());
let inner_witness = if has_witness && self.witness.len() > 2 { let inner_witness = if has_witness && self.witness.len() > 2 {
if let Some(last) = self.witness.last() { let script_hex = if is_p2tr {
let bytes: Vec<u8> = bitcoin::hex::FromHex::from_hex(last).unwrap_or_default(); self.witness.get(self.witness.len() - 2)
} else {
self.witness.last()
};
if let Some(hex) = script_hex {
let bytes: Vec<u8> = bitcoin::hex::FromHex::from_hex(hex).unwrap_or_default();
ScriptBuf::from(bytes).to_asm_string() ScriptBuf::from(bytes).to_asm_string()
} else { } else {
String::new() String::new()

View File

@@ -1004,7 +1004,7 @@
* @typedef {Object} Transaction * @typedef {Object} Transaction
* @property {(TxIndex|null)=} index - Internal transaction index (brk-specific, not in mempool.space) * @property {(TxIndex|null)=} index - Internal transaction index (brk-specific, not in mempool.space)
* @property {Txid} txid - Transaction ID * @property {Txid} txid - Transaction ID
* @property {TxVersion} version - Transaction version * @property {TxVersionRaw} version - Transaction version (raw i32 from Bitcoin protocol, may contain non-standard values in coinbase txs)
* @property {RawLockTime} locktime - Transaction lock time * @property {RawLockTime} locktime - Transaction lock time
* @property {TxIn[]} vin - Transaction inputs * @property {TxIn[]} vin - Transaction inputs
* @property {TxOut[]} vout - Transaction outputs * @property {TxOut[]} vout - Transaction outputs
@@ -1067,6 +1067,13 @@
* *
* @typedef {number} TxVersion * @typedef {number} TxVersion
*/ */
/**
* Raw transaction version (i32) from Bitcoin protocol.
* Unlike TxVersion (u8, indexed), this preserves non-standard values
* used in coinbase txs for miner signaling/branding.
*
* @typedef {number} TxVersionRaw
*/
/** /**
* Transaction ID (hash) * Transaction ID (hash)
* *
@@ -6566,7 +6573,7 @@ function createTransferPattern(client, acc) {
* @extends BrkClientBase * @extends BrkClientBase
*/ */
class BrkClient extends BrkClientBase { class BrkClient extends BrkClientBase {
VERSION = "v0.3.0-alpha.3"; VERSION = "v0.3.0-alpha.4";
INDEXES = /** @type {const} */ ([ INDEXES = /** @type {const} */ ([
"minute10", "minute10",

View File

@@ -40,5 +40,5 @@
"url": "git+https://github.com/bitcoinresearchkit/brk.git" "url": "git+https://github.com/bitcoinresearchkit/brk.git"
}, },
"type": "module", "type": "module",
"version": "0.3.0-alpha.3" "version": "0.3.0-alpha.4"
} }

View File

@@ -198,12 +198,16 @@ StoredU64 = int
TimePeriod = Literal["24h", "3d", "1w", "1m", "3m", "6m", "1y", "2y", "3y"] TimePeriod = Literal["24h", "3d", "1w", "1m", "3m", "6m", "1y", "2y", "3y"]
# Index of the output being spent in the previous transaction # Index of the output being spent in the previous transaction
Vout = int Vout = int
# Transaction version number # Raw transaction version (i32) from Bitcoin protocol.
TxVersion = int # Unlike TxVersion (u8, indexed), this preserves non-standard values
# used in coinbase txs for miner signaling/branding.
TxVersionRaw = int
TxInIndex = int TxInIndex = int
TxOutIndex = int TxOutIndex = int
# Input index in the spending transaction # Input index in the spending transaction
Vin = int Vin = int
# Transaction version number
TxVersion = int
UnknownOutputIndex = TypeIndex UnknownOutputIndex = TypeIndex
Week1 = int Week1 = int
Year1 = int Year1 = int
@@ -1380,7 +1384,7 @@ class Transaction(TypedDict):
Attributes: Attributes:
index: Internal transaction index (brk-specific, not in mempool.space) index: Internal transaction index (brk-specific, not in mempool.space)
txid: Transaction ID txid: Transaction ID
version: Transaction version version: Transaction version (raw i32 from Bitcoin protocol, may contain non-standard values in coinbase txs)
locktime: Transaction lock time locktime: Transaction lock time
vin: Transaction inputs vin: Transaction inputs
vout: Transaction outputs vout: Transaction outputs
@@ -1392,7 +1396,7 @@ class Transaction(TypedDict):
""" """
index: Union[TxIndex, None] index: Union[TxIndex, None]
txid: Txid txid: Txid
version: TxVersion version: TxVersionRaw
locktime: RawLockTime locktime: RawLockTime
vin: List[TxIn] vin: List[TxIn]
vout: List[TxOut] vout: List[TxOut]
@@ -6007,7 +6011,7 @@ class SeriesTree:
class BrkClient(BrkClientBase): class BrkClient(BrkClientBase):
"""Main BRK client with series tree and API methods.""" """Main BRK client with series tree and API methods."""
VERSION = "v0.3.0-alpha.3" VERSION = "v0.3.0-alpha.4"
INDEXES = [ INDEXES = [
"minute10", "minute10",

View File

@@ -1,6 +1,6 @@
[project] [project]
name = "brk-client" name = "brk-client"
version = "0.3.0-alpha.3" version = "0.3.0-alpha.4"
description = "Bitcoin on-chain analytics client — thousands of metrics, block explorer, and address index" description = "Bitcoin on-chain analytics client — thousands of metrics, block explorer, and address index"
readme = "README.md" readme = "README.md"
requires-python = ">=3.9" requires-python = ">=3.9"