#31252 rpc: print P2WSH and P2SH redem Script in getrawtransaction and getblock
| Reviewability | Reviews | Agreement | Size | ||||
|---|---|---|---|---|---|---|---|
| #31252 rpc: print P2WSH and P2SH redem Script in getrawtransaction and getblock | Ready | 0 | Strong | 114 + 255 tests | |||
|
|
|
|
| |||
Reviewability: ReadyStalePaused Agreement: StrongPositivePositive w/ caveatsNeutralMildDisputedBlockedCrickets Reviews: current code-review ACKs, then (+stale ACKs) and -NACKs; greener = more ACKs. Size: lines added or modified outside tests, then in tests; greener = smaller. | |||||||
Goal
Decodes and displays redeem and witness scripts in transaction inputs for RPCs returning detailed transaction data. When prevout undo data is available, `getrawtransaction` (verbosity 2), `getblock` (verbosity 2 and 3), and REST block endpoints now return `redeemScript` and `witnessScript` objects alongside input data. The output includes disassembly, descriptor representation, script type, and address when applicable.
Problem: Users and tooling inspecting spending transactions via RPC or REST cannot directly see decoded redeem scripts or witness scripts for P2SH, P2WSH, or nested SegWit inputs. Instead, they must manually extract raw byte pushes from `scriptSig` or witness stacks and run separate decoding calls.
Evidence of importance:
- The PR author cites issue #27391 as motivation and references earlier PR #8849 proposing a similar feature.
- Release notes specify new `redeemScript` and `witnessScript` RPC fields in `getrawtransaction` (verbosity=2), `getblock` (verbosity 2 and 3), and `/rest/block/`.
Scope: Adds `GetRedeemAndWitnessScripts` to the script solver, which evaluates the `scriptSig` without flags to extract the serialized redeem script from the stack when spending a P2SH prevout, and inspects the witness stack for P2WSH.
Reviewability
Ready
Nothing known that would invalidate a review now.
Agreement
Strong
substantive support, no open objection (sedited)
Thread notes: Initial record creation. All raised concerns (luke-jr on P2WSH detection, naiyoma on redeem/witness naming and false-positive non-P2SH detection, sedited on nested segwit redeem scripts) were addressed and resolved by polespinasa.
Objections, suggestions, and questions:
| Reviewer | Type | Harm, request, or question | Status | Must be | Author replied | Quote |
|---|---|---|---|---|---|---|
| luke-jr (contributor) | objection, correctness | incorrect detection of P2WSH | fixed · fix pushed · v1, not yet re-checked | answered | yes | 2024-11-20: 'This isn't an indicator of p2wsh... Maybe use d1f0ff0e1fed2c4124d0d81f18daf7b76a770dda or similar?' Status from: 2024-11-22: polespinasa: 'code rewritten based on this comment' |
| naiyoma (member) | objection, interface | misidentifies script field names by outputting redeemScript for both P2SH and P2WSH | fixed · fix pushed · v1, not yet re-checked | answered | yes | 2025-02-12: 'this outputs `redeemScript` for both P2SH and P2WSH, but it should be P2SH `redeemScript` and P2WSH `witnessScript`' Status from: 2025-05-08: polespinasa: 'done' |
| naiyoma (member) | objection, correctness | non-P2SH inputs erroneously emit a redeemScript field | fixed · fix pushed · v1, not yet re-checked | answered | yes | 2025-08-26: 'For a non-P2SH transaction, returning` -1` will result in a `redeemScript` field being added. I tested this using a P2PKH transaction, and this was the output: `"redeemScript": { "asm": "304402...7981", "type": "nonstandard" }`' Status from: 2025-09-15: polespinasa: 'Nice catch! You're right, solved in 18c513f8babf65ea73ea9c785fba90446ef947db. Now non-P2SH and non-segwit inputs return -2 and don't show any script as it's out the scope of the PR.' |
| sedited (member) | objection, interface | clearing redeem script for nested segwit (P2SH-P2WPKH) omits valid witness program redeem script information | fixed · fix pushed · v1, not yet re-checked | answered | yes | 2026-09-08: 'Should we also add a branch for the nested segwit case? It seems more natural to me to not clear its redeem script.' Status from: 2026-09-10: polespinasa: 'Done :)' |
Support:
- murchandamus (member) (Concept ACK, 2025-11-03): Concept ACK [not substantive]
- sedited (member) (Concept ACK, 2026-06-19): Concept ACK; engaged in reviewing structure and implementation details
Participants:
- kevkevinpal (contributor, neutral, 2 statements 2024-11-13 to 2024-11-13): suggested naming nit ('witnessScript' instead of 'witScript') and commit squashing
- luke-jr (contributor, objection, 1 statements 2024-11-20 to 2024-11-20): pointed out incorrect P2WSH detection logic
- naiyoma (member, objection, 5 statements 2025-01-11 to 2025-08-26): tested, noted RPC limitation without undo data, distinction between redeemScript and witnessScript, and false-positive redeemScript on non-P2SH
- murchandamus (member, support, 1 statements 2025-11-03 to 2025-11-03): Concept ACK
- sedited (member, support, 9 statements 2026-06-19 to 2026-09-09): Concept ACK; reviewed architecture, test fixes, and suggested keeping redeem script for nested segwit
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
The short text the ranking pass compares across PRs.
Decodes and surfaces redeem and witness scripts for P2SH, P2WSH, and nested SegWit inputs in getrawtransaction, getblock, and REST block endpoints when undo data is available. Currently, callers examining historical spends must manually extract raw scripts from scriptSig or witness stacks and decode them separately. The PR cites issue #27391 and previous PR #8849 as motivation for providing disassembled and descriptor-formatted input scripts directly in verbosity 2+ RPC output.
Data
thread read through 2026-09-10 (36 statements), head 9d23cae2f7
Discussion read under schema 1 rules: suggestions and questions may be missing, and an objection may combine several harms (schema history).
labels: RPC/REST/ZMQ
Categories
RPC / REST / ZMQ
P3 · user request (ranking pass: Moved down 12: additive output field with tooling demand, but no existing caller is broken today.)
Resolves a known tooling gap where consumers had to manually extract and decode serialized scripts from inputs. Cites issue #27391 and earlier PR #8849 seeking decoded `redeemScript` and `witnessScript` outputs in verbose transaction queries.
Membership: Carries RPC/REST/ZMQ label and adds `redeemScript` and `witnessScript` fields to `getrawtransaction`, `getblock`, and REST endpoints.
Factors: security/stability 0, bug 0, performance 0, user value 2, leverage 0