#31252 rpc: print P2WSH and P2SH redem Script in getrawtransaction and getblock

full analysis

https://github.com/bitcoin/bitcoin/pull/31252 · polespinasa · +369/-5 in 10 files, 5 commits · labels: RPC/REST/ZMQ

Goal

  • Expose decoded redeem and witness scripts directly in verbose block and transaction RPCs
  • Saves developers and explorers from having to manually extract and parse input spend scripts

Adds decoded `redeemScript` and `witnessScript` fields to the JSON output of `getrawtransaction` (verbosity 2), `getblock` (verbosity 2 and 3), and the REST block endpoint when input undo data is available. Extracts P2SH redeem scripts, P2WSH witness scripts, and nested segwit script details via a new helper in `src/script/solver.cpp`.

Problem: When inspecting transactions, users and indexing tools currently need to manually extract and parse redeem and witness scripts from the input scriptSig and witness stack to obtain the underlying script assembly, descriptor, or multisig keys.

Category: RPC / REST / ZMQ (#7 of 52)

P3 · new feature

  • P3 because it improves transaction inspection convenience for block explorers and developers
  • Eliminates custom parsing logic for common multisig and script hash spends

Adds useful diagnostic fields to verbose transaction RPCs requested in #27391 and earlier work in #8849, making it easier for explorers and developers to inspect multisig and script hash spends.

Membership: Modifies `TxToUniv` and RPC documentation for `getrawtransaction` and `getblock`.

Factors: security/stability 0, bug 0, performance 0, user value 2, leverage 0

Reviewability: Ready

  • Ready for review
  • Clean patch with test coverage and all reviewer feedback addressed

The patch is clean, fully covered by tests, and the author has addressed the latest feedback.

Author status: active, implemented nested segwit suggestions in recent push

Resolved concerns:

  • Handling of false-positive script detection for non-P2SH/P2WSH inputs (pointed out by naiyoma).
  • Separation of helper logic from core script headers into solver (raised by sedited).
  • Inclusion of redeem script for nested segwit P2SH-P2WPKH and P2SH-P2WSH inputs (suggested by sedited).

Agreement: Strong

  • Concept approval for exposing decoded spend scripts in verbose RPC outputs (murchandamus, sedited)
  • Iterative feedback on edge-case script detection and nested segwit has been resolved (naiyoma, sedited)
  • Script identification and handling feedback incorporated (luke-jr)

Strong: concept ACKs from murchandamus and sedited, with constructive review feedback addressed.

Multiple contributors support adding these decoded script fields to RPC outputs, and iterative feedback regarding solver extraction edge cases has been addressed.

  • murchandamus gave Concept ACK.
  • sedited gave Concept ACK and guided structural refinements to script extraction and documentation.
  • naiyoma and luke-jr gave feedback on script identification and handling.

Review verdicts (DrahtBot): 0

Files

257 lines under test/bench/ci.

  • test/functional/rpc_rawtransaction.py +183/-1
  • test/functional/rpc_blockchain.py +72/-1
  • src/script/solver.cpp +38/-0
  • src/script/solver.h +25/-0
  • src/core_io.cpp +17/-3
  • src/rpc/rawtransaction_util.cpp +20/-0
  • doc/release-notes-31252.md +9/-0
  • src/rpc/blockchain.cpp +2/-0
  • src/rpc/rawtransaction_util.h +2/-0
  • src/rpc/rawtransaction.cpp +1/-0

Card

This PR adds decoded `redeemScript` and `witnessScript` objects to transaction input objects in `getrawtransaction` (verbosity 2), `getblock` (verbosity 2/3), and REST block responses. It addresses long-standing issue #27391 to save external tooling and callers from manually decoding scriptSig and witness payloads for P2SH and P2WSH spends. The PR has Concept ACKs from murchandamus and sedited and has resolved all material review comments, remaining ready for final review.

Data

dossier JSON · extract JSON · model openrouter/google/gemini-3.8-flash, generated 2026-09-17T15:48, confidence high, input hash 982af0e9b344fc7d