Module BSV::Network::Util ¶
Shared utility methods for protocol implementations.
Public Class Methods¶
resolve_tx_hex(tx) ¶
Coerce a transaction input to hex.
Accepts (in order of preference): 1. Hex string — pass-through, zero conversion 2. Binary string — convert to hex 3. Transaction object — prefer EF hex (BRC-30), fall back to raw hex
Detection uses content, not encoding: a string is hex if it has even length and contains only hex characters. This handles hex strings tagged as ASCII-8BIT (e.g. read from IO in binary mode).
Empty input is rejected — an empty transaction cannot meaningfully be broadcast and any downstream rawTx: '' body is a sign of a caller bug, not valid traffic. - @param tx [String, #to_ef_hex, #to_hex] transaction in any supported form - @raise [ArgumentError] if tx is an empty string - @return [String] hex-encoded transaction
safe_parse_json(raw) ¶
Parse JSON, returning a hash with a 'detail' key on parse failure. When the raw input is nil or empty the detail is nil (not an empty string).