Skip to content

Give Tx and Header native field newtypes - #597

Draft
metaphorics wants to merge 2 commits into
cursor/native-primitives-encode-hotpath-b001from
cursor/native-primitives-typed-fields-b001
Draft

Give Tx and Header native field newtypes#597
metaphorics wants to merge 2 commits into
cursor/native-primitives-encode-hotpath-b001from
cursor/native-primitives-typed-fields-b001

Conversation

@metaphorics

@metaphorics metaphorics commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Stacked on #522 (and #483). Breaking field types for native primitives.

Tx, TxIn, TxOut, and Header now use bitcoin-rs newtypes instead of raw integers and byte vectors:

  • TxOut.value: Amount
  • TxIn.sequence / Tx.lock_time: Sequence / LockTime
  • TxIn.script_sig / TxOut.script_pubkey: Script
  • TxIn.witness: Witness
  • Header.bits: CompactTarget

These types live in crates/primitives (units.rs, script.rs). They are not rust-bitcoin aliases or conversion shims. Wire conversion is from_sat / to_sat and from_consensus / to_consensus. JSON, RPC, and packed UTXO layouts still speak satoshis and consensus u32 at those boundaries.

Integer comparisons (Amount == 50_000, Sequence < 0xfffffffe, CompactTarget == 0x1d00ffff) and From<u32>/From<u64> keep call sites tight without Deref to the inner integer.

Workspace consumers (chain, consensus, script, mempool, mining, utxo, node, rpc, p2p, index) are updated. rust-bitcoin remains only at RPC/wallet-facing and differential-oracle seams.

Toward #172: crates/primitives owns the protocol vocabulary end to end.

Review follow-up (fda86b80):

  • Amount::MAX_MONEY is the sole 21-million-BTC owner; consensus MAX_MONEY is Amount::MAX_MONEY.to_sat(), and output-value checks compare against the typed limit.
  • Verbose RPC vin again emits txid, vout, and scriptSig for non-coinbase inputs.
  • Production primitive imports stay limited to types named on the production path; tests import the rest under cfg(test).
Open in Web Open in Cursor 

Replace raw integer and byte-vector protocol fields with bitcoin-rs
newtypes: Amount, Sequence, Script, Witness, LockTime, and CompactTarget.
JSON, RPC, and packed UTXO layouts stay in satoshis and consensus u32 at
those boundaries via to_sat and to_consensus.

This is the typed-field half of keeping crates/primitives native (#172).

Co-authored-by: metaphorics <metaphorics@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: e27fa20d-1c89-4b3f-9b55-c578f08b439d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cursor

cursor Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_f213d1c5-111e-4c00-a895-d76e7ecfc197)

@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Adopt native newtypes for transaction and header fields

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Replaces raw transaction and header fields with native protocol newtypes.
• Preserves consensus, storage, JSON, and RPC representations at system boundaries.
• Migrates workspace consumers and fixtures without changing wire behavior.
Diagram

graph TD
  P["Native newtypes"] --> T["Tx and Header"] --> C["Consensus logic"] --> N["Node services"] --> B["RPC boundaries"]
  T --> W["Wire codec"]
  C --> M["Mempool mining"]
  N --> U["UTXO index"]
Loading
High-Level Assessment

The chosen approach is appropriate: primitives owns the protocol vocabulary while explicit from_sat/to_sat and consensus conversions isolate legacy scalar layouts at real boundaries. Reusing rust-bitcoin aliases would weaken crate ownership and couple internal consensus types to an external API; keeping raw integers would preserve the type-safety problem this PR addresses.

Files changed (120) +2963 / -2047

Enhancement (7) +727 / -62
encode.rsEncode and decode native field types +25/-25

Encode and decode native field types

• Wraps decoded wire scalars and byte collections in newtypes while preserving existing consensus serialization layouts.

crates/primitives/src/encode.rs

header.rsType compact target header field +5/-5

Type compact target header field

• Changes 'Header.bits' to 'CompactTarget' and explicitly converts it during 80-byte header serialization and parsing.

crates/primitives/src/header.rs

lib.rsExport native field modules +6/-0

Export native field modules

• Publishes script, witness, amount, sequence, locktime, and compact-target modules and types.

crates/primitives/src/lib.rs

script.rsAdd native script and witness types +269/-0

Add native script and witness types

• Introduces owned 'Script' and 'Witness' wrappers with byte, stack, comparison, dereference, conversion, and iteration APIs.

crates/primitives/src/script.rs

sighash.rsUse typed values in sighash APIs +31/-19

Use typed values in sighash APIs

• Changes sequence and segwit amount inputs to native types and updates legacy, BIP143, and BIP341 fixtures.

crates/primitives/src/sighash.rs

tx.rsType native transaction fields +13/-13

Type native transaction fields

• Replaces raw transaction scripts, witness stacks, sequences, amounts, and locktime with dedicated native newtypes.

crates/primitives/src/tx.rs

units.rsAdd native scalar protocol newtypes +378/-0

Add native scalar protocol newtypes

• Introduces 'Amount', 'Sequence', 'LockTime', and 'CompactTarget' with constants, conversions, formatting, comparisons, and checked amount arithmetic.

crates/primitives/src/units.rs

Refactor (43) +1204 / -1096
header_sync.rsType header difficulty calculations +16/-16

Type header difficulty calculations

• Changes work-requirement and proof-of-work helpers to consume and return 'CompactTarget', converting only when reporting scalar errors.

crates/chain/src/header_sync.rs

bip143.rsAccept typed amounts in BIP143 +16/-11

Accept typed amounts in BIP143

• Changes BIP143 verification to accept 'Amount' and migrates its transaction fixtures.

crates/consensus/src/bip143.rs

kernel.rsConvert amounts at kernel boundary +2/-2

Convert amounts at kernel boundary

• Converts native 'Amount' values to satoshis before calling bitcoinkernel.

crates/consensus/src/kernel.rs

verify_tx.rsValidate transactions with typed fields +124/-120

Validate transactions with typed fields

• Reads locktime, sequence, and amounts through explicit consensus or satoshi conversions and migrates extensive validation fixtures.

crates/consensus/src/verify_tx.rs

index.rsConvert native amounts at index boundaries +24/-21

Convert native amounts at index boundaries

• Keeps indexed values in satoshis via 'to_sat' while migrating internal transaction and header fixtures to newtypes.

crates/index/src/index.rs

accept.rsConvert amounts during mempool admission +20/-18

Convert amounts during mempool admission

• Extracts satoshis for fee calculations and migrates admission, RBF, and script fixtures to native fields.

crates/mempool/src/accept.rs

entry.rsUse typed sequence in entries +12/-12

Use typed sequence in entries

• Checks RBF signaling through 'Sequence' consensus values and migrates entry fixtures.

crates/mempool/src/entry.rs

gateway.rsMigrate gateway admission paths +46/-42

Migrate gateway admission paths

• Updates gateway fixtures and locktime, replacement, prevout, and script mutations to native field types.

crates/mempool/src/gateway.rs

pool.rsUse typed fields throughout mempool +142/-138

Use typed fields throughout mempool

• Converts sequences for RBF checks and migrates pool, replacement, spend-index, and memory fixtures to newtypes.

crates/mempool/src/pool.rs

standardness.rsApply policy to native amounts +41/-41

Apply policy to native amounts

• Converts output amounts for dust policy and migrates standardness scripts, values, witnesses, and locktimes.

crates/mempool/src/standardness.rs

coinbase.rsBuild typed coinbase transactions +11/-9

Build typed coinbase transactions

• Constructs coinbase amounts, scripts, witnesses, sequences, and locktimes with native primitives.

crates/mining/src/coinbase.rs

context.rsType mining chain targets +13/-9

Type mining chain targets

• Changes candidate chain context and validation to carry 'CompactTarget' end to end.

crates/mining/src/context.rs

control.rsExpose typed mining targets +8/-5

Expose typed mining targets

• Stores current and next targets as 'CompactTarget' and converts them inside difficulty calculation.

crates/mining/src/control.rs

policy.rsEvaluate typed locktime and sequence +17/-13

Evaluate typed locktime and sequence

• Converts locktime and sequence newtypes for finality and sequence-lock policy checks.

crates/mining/src/policy.rs

template.rsType candidate template targets +5/-4

Type candidate template targets

• Carries 'CompactTarget' through candidate assembly and converts coinbase values to satoshis for metadata.

crates/mining/src/template.rs

apply.rsApply blocks with typed targets and outputs +126/-122

Apply blocks with typed targets and outputs

• Makes proof-of-work helpers accept 'CompactTarget' and migrates extensive block-application and UTXO fixtures.

crates/node/src/apply.rs

checkpoint.rsMigrate checkpoint target and UTXO fields +13/-12

Migrate checkpoint target and UTXO fields

• Uses typed targets in checkpoint validation and native amounts and scripts in persisted-state fixtures.

crates/node/src/checkpoint.rs

checkpoint_worker.rsImport native amount support +1/-0

Import native amount support

• Adds native amount access needed by checkpoint worker processing.

crates/node/src/checkpoint_worker.rs

import.rsImport blocks with typed targets +30/-28

Import blocks with typed targets

• Updates import proof-of-work helpers and malformed-block fixtures for typed targets and transaction fields.

crates/node/src/import.rs

mining.rsPropagate typed mining information +22/-13

Propagate typed mining information

• Uses typed zero targets, difficulty inputs, candidate data, and transaction fixtures in the mining coordinator.

crates/node/src/mining.rs

recovery_evidence.rsImport typed recovery fields +1/-0

Import typed recovery fields

• Adds native field support required by recovery evidence fixtures.

crates/node/src/recovery_evidence.rs

reorg.rsConvert amounts during reorg admission +6/-2

Convert amounts during reorg admission

• Converts native output amounts to satoshis when reconstructing transaction fees across reorganizations.

crates/node/src/reorg.rs

state.rsMigrate node state fixtures +16/-12

Migrate node state fixtures

• Updates state, transaction channel, block-tree, and proof-of-work fixtures for native fields.

crates/node/src/state.rs

sync.rsSynchronize typed headers and transactions +44/-43

Synchronize typed headers and transactions

• Migrates synchronization, fork, invalid-body, mining, and proof-of-work fixtures to native protocol fields.

crates/node/src/sync.rs

tx_admission.rsMigrate admission fixtures +7/-7

Migrate admission fixtures

• Updates node transaction-admission data to native protocol fields.

crates/node/src/tx_admission.rs

tx_ingress.rsConvert amounts during transaction ingress +36/-35

Convert amounts during transaction ingress

• Extracts satoshis for fee accounting and migrates ingress, locktime, witness, and UTXO fixtures.

crates/node/src/tx_ingress.rs

window_overlay.rsMigrate UTXO window overlay +25/-20

Migrate UTXO window overlay

• Updates overlay transactions, restored outputs, and header fixtures to native field types.

crates/node/src/window_overlay.rs

chain_query.rsRender typed header targets +2/-2

Render typed header targets

• Converts compact targets to consensus integers where P2P chain-query output requires them.

crates/p2p/src/chain_query.rs

dispatch.rsConvert transactions at P2P boundary +15/-9

Convert transactions at P2P boundary

• Adapts native scripts, witnesses, sequences, locktimes, and amounts when dispatching protocol messages.

crates/p2p/src/dispatch.rs

convert.rsConvert newtypes at RPC compatibility boundary +32/-16

Convert newtypes at RPC compatibility boundary

• Emits consensus locktime, sequence, target, and satoshi values from native fields while preserving Core-compatible schemas.

crates/rpc/src/compat/convert.rs

context.rsType RPC difficulty inputs +12/-11

Type RPC difficulty inputs

• Changes RPC context difficulty calculation to accept 'CompactTarget' and migrates context fixtures.

crates/rpc/src/context.rs

projection.rsConvert newtypes in Esplora projections +11/-12

Convert newtypes in Esplora projections

• Converts amounts, sequence, locktime, and target fields to scalar API representations during projection.

crates/rpc/src/esplora/projection.rs

public.rsRender mempool amounts as satoshis +3/-5

Render mempool amounts as satoshis

• Converts native output amounts when aggregating recent mempool transaction values.

crates/rpc/src/esplora/public.rs

chain.rsConvert typed chain data for RPC +63/-61

Convert typed chain data for RPC

• Uses native targets and amounts internally while preserving scalar block, statistics, scan, and difficulty RPC output.

crates/rpc/src/handlers/chain.rs

mining.rsRender typed mining targets +36/-27

Render typed mining targets

• Migrates mining fixtures and converts typed current and next targets to Core-compatible hexadecimal output.

crates/rpc/src/handlers/mining.rs

tx.rsUse native fields in transaction RPCs +75/-75

Use native fields in transaction RPCs

• Builds raw transactions with newtypes and converts amounts and consensus scalars for fee calculation and RPC rendering.

crates/rpc/src/handlers/tx.rs

rest.rsConvert newtypes at REST boundary +30/-29

Convert newtypes at REST boundary

• Renders native UTXO amounts and typed header targets in unchanged REST representations.

crates/rpc/src/rest.rs

tx_render.rsRender native transactions as legacy JSON +27/-30

Render native transactions as legacy JSON

• Converts native amount, sequence, and locktime fields while preserving transaction JSON and script rendering.

crates/rpc/src/tx_render.rs

checker.rsUse typed amounts and timing fields +40/-34

Use typed amounts and timing fields

• Changes signature checker amounts to 'Amount' and explicitly reads locktime and sequence consensus values for CLTV and CSV.

crates/script/src/checker.rs

interpreter.rsGraft native scripts and witnesses +17/-13

Graft native scripts and witnesses

• Wraps substituted script and witness data in native types and passes typed zero amounts to taproot checking.

crates/script/src/interpreter.rs

connect.rsAdapt UTXO connection amounts +2/-2

Adapt UTXO connection amounts

• Uses native transaction output fields while retaining existing connection semantics.

crates/utxo/src/connect.rs

coin_stats.rsConvert amounts in coin statistics +12/-12

Convert amounts in coin statistics

• Extracts satoshis for aggregate accounting, MuHash input, and packed encoding while retaining native 'TxOut' fields.

crates/utxo/src/stats/coin_stats.rs

undo_codec.rsPreserve undo layout with native outputs +3/-3

Preserve undo layout with native outputs

• Migrates undo fixtures to native amounts and scripts while keeping consensus record encoding unchanged.

crates/utxo/src/undo_codec.rs

Tests (68) +1021 / -884
wallet_facing.rsAdapt wallet-facing transaction fixtures +4/-4

Adapt wallet-facing transaction fixtures

• Converts wallet-generated script buffers into the script types expected at compatibility seams.

bin/bitcoin-rs/tests/wallet_facing.rs

deployment.rsUse typed targets in deployment tests +2/-2

Use typed targets in deployment tests

• Constructs deployment test headers with 'CompactTarget'.

crates/chain/src/deployment.rs

tree.rsMigrate chain-tree header fixtures +5/-5

Migrate chain-tree header fixtures

• Builds tree test headers with typed compact targets.

crates/chain/src/tree.rs

header_sync_roundtrip.rsValidate typed target synchronization +21/-8

Validate typed target synchronization

• Updates header synchronization, tampering, mining, and rust-bitcoin oracle helpers for 'CompactTarget'.

crates/chain/tests/header_sync_roundtrip.rs

reorg_deep.rsMigrate deep-reorg target fixtures +6/-5

Migrate deep-reorg target fixtures

• Uses typed compact targets in reorganization mining and differential proof-of-work checks.

crates/chain/tests/reorg_deep.rs

merkle.rsMigrate Merkle benchmark fixtures +2/-2

Migrate Merkle benchmark fixtures

• Constructs benchmark transactions with native typed fields.

crates/consensus/benches/merkle.rs

bip141.rsMigrate BIP141 fixtures to newtypes +9/-7

Migrate BIP141 fixtures to newtypes

• Uses native amount, locktime, script, sequence, and witness values in BIP141 tests.

crates/consensus/src/bip141.rs

verify_block.rsMigrate block verification fixtures +52/-48

Migrate block verification fixtures

• Updates block-validation tests and witness commitments to use native transaction and target field types.

crates/consensus/src/verify_block.rs

kernel_block_parity.rsPreserve kernel block parity +11/-9

Preserve kernel block parity

• Builds kernel parity prevouts and transactions with native amount and script types.

crates/consensus/tests/kernel_block_parity.rs

kernel_vector_parity.rsMigrate kernel vector amounts +3/-3

Migrate kernel vector amounts

• Converts differential kernel-vector prevouts to native amount and script fields.

crates/consensus/tests/kernel_vector_parity.rs

history_resolve.rsMigrate history benchmark fixtures +17/-17

Migrate history benchmark fixtures

• Uses native typed transaction fields in history-resolution benchmarks.

crates/index/benches/history_resolve.rs

index_roundtrip.rsMigrate index round-trip fixtures +7/-7

Migrate index round-trip fixtures

• Updates indexed blocks and transactions to native field types.

crates/index/tests/index_roundtrip.rs

le_order.rsMigrate index ordering fixtures +9/-8

Migrate index ordering fixtures

• Constructs ordering-test headers and transactions with typed targets, amounts, scripts, sequences, and locktimes.

crates/index/tests/le_order.rs

resolver_fallback.rsMigrate resolver fallback fixtures +9/-8

Migrate resolver fallback fixtures

• Updates fallback-resolution blocks and transactions for native protocol fields.

crates/index/tests/resolver_fallback.rs

script_live.rsAdapt live-script index test +2/-2

Adapt live-script index test

• Wraps script and amount fixture data in native transaction field types.

crates/index/tests/script_live.rs

tx_positions.rsMigrate transaction-position fixtures +10/-9

Migrate transaction-position fixtures

• Uses typed targets and transaction fields while retaining satoshi inputs in fixture helpers.

crates/index/tests/tx_positions.rs

pareto.rsMigrate Pareto benchmark fixtures +9/-7

Migrate Pareto benchmark fixtures

• Constructs benchmark entries with native transaction field types.

crates/mempool/benches/pareto.rs

eviction.rsMigrate eviction fixtures +9/-7

Migrate eviction fixtures

• Builds mempool eviction transactions with typed amounts, scripts, sequence, witness, and locktime.

crates/mempool/src/eviction.rs

orphan.rsMigrate orphan transaction fixtures +13/-13

Migrate orphan transaction fixtures

• Constructs orphan-pool transactions and large outputs with native protocol fields.

crates/mempool/src/orphan.rs

pareto.rsMigrate Pareto memory fixtures +9/-7

Migrate Pareto memory fixtures

• Updates memory-accounting test entries for typed transaction fields.

crates/mempool/src/pareto.rs

ancestor_limits.rsMigrate ancestor-limit fixtures +16/-13

Migrate ancestor-limit fixtures

• Updates package and ancestor-limit transactions to native field types.

crates/mempool/tests/ancestor_limits.rs

policy_contract.rsMigrate mempool policy contracts +19/-15

Migrate mempool policy contracts

• Uses native protocol fields across policy contract fixtures and assertions.

crates/mempool/tests/policy_contract.rs

rbf_bip125.rsMigrate BIP125 fixtures +10/-8

Migrate BIP125 fixtures

• Wraps BIP125 sequence, amount, and script fixture values in native types.

crates/mempool/tests/rbf_bip125.rs

coinbase_template.rsMigrate coinbase template tests +11/-8

Migrate coinbase template tests

• Updates coinbase and candidate fixtures for native protocol fields.

crates/mining/tests/coinbase_template.rs

policy_pareto.rsMigrate mining policy fixtures +23/-20

Migrate mining policy fixtures

• Uses typed target and transaction fields in package-selection and Pareto tests.

crates/mining/tests/policy_pareto.rs

template_shape.rsMigrate template shape fixtures +18/-15

Migrate template shape fixtures

• Updates candidate construction and expected transactions to native field types.

crates/mining/tests/template_shape.rs

witness_commitment_vector.rsPreserve witness commitment vectors +12/-9

Preserve witness commitment vectors

• Migrates witness commitment fixtures and assertions to native target, amount, script, sequence, and witness types.

crates/mining/tests/witness_commitment_vector.rs

chainstate_journal.rsMigrate journal benchmark fixtures +16/-9

Migrate journal benchmark fixtures

• Builds benchmark coins, blocks, and transactions with native field types.

crates/node/benches/chainstate_journal.rs

sync_pipeline.rsMigrate sync benchmark fixtures +59/-53

Migrate sync benchmark fixtures

• Updates synthetic synchronization blocks and transactions for native protocol fields.

crates/node/benches/sync_pipeline.rs

delta.rsMigrate journal delta fixtures +4/-4

Migrate journal delta fixtures

• Uses native amounts and scripts for journal mutation tests.

crates/node/src/chainstate_journal/delta.rs

record.rsPreserve typed journal records +6/-6

Preserve typed journal records

• Migrates record round-trip and property fixtures to native amount and script fields without changing encoding.

crates/node/src/chainstate_journal/record.rs

replay.rsMigrate journal replay fixtures +4/-4

Migrate journal replay fixtures

• Uses typed targets, amounts, and scripts when replaying synthetic journal state.

crates/node/src/chainstate_journal/replay.rs

writer.rsMigrate journal writer fixtures +5/-5

Migrate journal writer fixtures

• Constructs written and removed coin records with native amount and script fields.

crates/node/src/chainstate_journal/writer.rs

embed.rsMigrate embedded-node fixtures +11/-9

Migrate embedded-node fixtures

• Uses native transaction fields for embedded admission and UTXO tests.

crates/node/src/embed.rs

stage.rsMigrate sync staging fixtures +8/-7

Migrate sync staging fixtures

• Constructs staged transactions with native script, sequence, witness, amount, and locktime fields.

crates/node/src/sync/stage.rs

txindex_worker.rsMigrate transaction-index worker fixtures +4/-4

Migrate transaction-index worker fixtures

• Updates indexed transaction and block fixtures for native fields.

crates/node/src/txindex_worker.rs

txindex_worker_query_tests.rsMigrate transaction-index query tests +17/-17

Migrate transaction-index query tests

• Uses native amounts, scripts, sequences, witnesses, locktimes, and targets in worker query fixtures.

crates/node/src/txindex_worker_query_tests.rs

zmq_publisher.rsMigrate ZMQ transaction fixtures +13/-13

Migrate ZMQ transaction fixtures

• Uses native typed transactions in compatibility and sequence notification tests.

crates/node/src/zmq_publisher.rs

chainstate_journal.rsMigrate chainstate journal tests +13/-9

Migrate chainstate journal tests

• Updates end-to-end journal blocks and UTXOs to native protocol fields.

crates/node/tests/chainstate_journal.rs

crash_recovery.rsMigrate crash recovery fixtures +13/-9

Migrate crash recovery fixtures

• Uses typed transaction and header fields in crash-recovery scenarios.

crates/node/tests/crash_recovery.rs

embed.rsMigrate embedded-node integration tests +19/-15

Migrate embedded-node integration tests

• Updates embedded node blocks, transactions, and UTXOs for native field types.

crates/node/tests/embed.rs

mining.rsMigrate node mining tests +33/-29

Migrate node mining tests

• Uses typed targets and transaction fields across mining coordinator integration fixtures.

crates/node/tests/mining.rs

mining_e2e.rsMigrate end-to-end mining tests +61/-56

Migrate end-to-end mining tests

• Updates generated blocks, coinbases, spends, targets, and public-boundary assertions for native fields.

crates/node/tests/mining_e2e.rs

sync_smoke.rsMigrate synchronization smoke tests +16/-13

Migrate synchronization smoke tests

• Constructs smoke-test chains and transactions with native protocol fields.

crates/node/tests/sync_smoke.rs

tx_ingress_e2e.rsMigrate transaction ingress integration tests +11/-9

Migrate transaction ingress integration tests

• Uses native transaction and UTXO fields in end-to-end ingress scenarios.

crates/node/tests/tx_ingress_e2e.rs

core_compat.rsMigrate P2P compatibility fixtures +2/-2

Migrate P2P compatibility fixtures

• Updates Core compatibility transactions and headers for native fields.

crates/p2p/tests/core_compat.rs

block.rsMigrate block primitive fixtures +11/-9

Migrate block primitive fixtures

• Updates block size and witness tests to construct typed transactions and headers.

crates/primitives/src/block.rs

differential.rsPreserve primitive differential parity +18/-13

Preserve primitive differential parity

• Migrates malformed-input and sighash differential fixtures to native transaction field types.

crates/primitives/tests/differential.rs

genesis.rsAssert typed genesis subsidy +2/-1

Assert typed genesis subsidy

• Checks the genesis output against a native 'Amount'.

crates/primitives/tests/genesis.rs

schema.rsMigrate compatibility schema fixtures +3/-3

Migrate compatibility schema fixtures

• Uses typed current and next mining targets in schema tests.

crates/rpc/src/compat/schema.rs

esplora.rsMigrate Esplora integration fixtures +40/-39

Migrate Esplora integration fixtures

• Uses native fields internally while retaining satoshi amounts in Esplora query interfaces and responses.

crates/rpc/src/esplora.rs

mempool.rsMigrate mempool RPC fixtures +44/-36

Migrate mempool RPC fixtures

• Updates mempool graph, RBF, usage, and spent-by tests to native transaction fields.

crates/rpc/src/handlers/mempool.rs

core_compat.rsMigrate RPC Core compatibility tests +11/-8

Migrate RPC Core compatibility tests

• Updates Core-compatible block and transaction fixtures for native fields.

crates/rpc/tests/core_compat.rs

handler_smoke.rsMigrate RPC handler smoke tests +34/-34

Migrate RPC handler smoke tests

• Uses native fields throughout handler smoke-test transactions, blocks, and UTXOs.

crates/rpc/tests/handler_smoke.rs

policy_contract.rsMigrate RPC policy contracts +71/-65

Migrate RPC policy contracts

• Updates transaction admission and policy contract fixtures while preserving public satoshi and consensus representations.

crates/rpc/tests/policy_contract.rs

chain.rsType shared RPC chain fixtures +15/-9

Type shared RPC chain fixtures

• Constructs shared RPC test chains and transactions using native protocol fields.

crates/rpc/tests/support/chain.rs

transaction_methods.rsMigrate transaction RPC tests +22/-21

Migrate transaction RPC tests

• Updates raw transaction, prevout, amount, script, sequence, and locktime fixtures for native fields.

crates/rpc/tests/transaction_methods.rs

sigops.rsMigrate sigop transaction fixtures +10/-8

Migrate sigop transaction fixtures

• Updates legacy and block sigop tests to native transaction field types.

crates/script/src/sigops.rs

core_vectors.rsMigrate Core script vectors +25/-18

Migrate Core script vectors

• Constructs vector transactions and prevouts with native amounts, scripts, sequences, witnesses, and locktimes.

crates/script/tests/core_vectors.rs

proptest.rsMigrate script property tests +15/-15

Migrate script property tests

• Updates generated transaction fields and checker amounts to native types.

crates/script/tests/proptest.rs

utxo_commit.rsMigrate UTXO commit benchmarks +7/-7

Migrate UTXO commit benchmarks

• Builds benchmark outputs with native amount and script fields.

crates/utxo/benches/utxo_commit.rs

shard.rsMigrate UTXO shard fixtures +4/-4

Migrate UTXO shard fixtures

• Updates shard output fixtures to native amounts and scripts.

crates/utxo/src/shard.rs

coin_stats_roundtrip.rsMigrate coin statistics round trips +7/-7

Migrate coin statistics round trips

• Uses native amounts and scripts in coin-stat persistence fixtures.

crates/utxo/tests/coin_stats_roundtrip.rs

commit_roundtrip.rsMigrate UTXO commit round trips +25/-25

Migrate UTXO commit round trips

• Updates committed, removed, and restored output fixtures to native field types.

crates/utxo/tests/commit_roundtrip.rs

reorg.rsMigrate UTXO reorg fixtures +3/-3

Migrate UTXO reorg fixtures

• Uses native amount and script fields in UTXO reorganization tests.

crates/utxo/tests/reorg.rs

snapshot_roundtrip.rsMigrate snapshot round trips +7/-7

Migrate snapshot round trips

• Constructs snapshot outputs with native amounts and scripts while preserving stored layouts.

crates/utxo/tests/snapshot_roundtrip.rs

snapshot_with_muhash.rsMigrate MuHash snapshot fixtures +5/-5

Migrate MuHash snapshot fixtures

• Uses native output fields in snapshot and MuHash consistency tests.

crates/utxo/tests/snapshot_with_muhash.rs

script_eval.rsMigrate script evaluation fuzzing +9/-8

Migrate script evaluation fuzzing

• Constructs fuzzed transactions and prevouts with native amount, script, sequence, witness, and locktime fields.

fuzz/fuzz_targets/script_eval.rs

Documentation (2) +11 / -5
CONCEPTS.mdDocument native typed protocol fields +5/-2

Document native typed protocol fields

• Expands the native-primitives concept to include scalar, script, and witness newtypes used directly by transactions and headers.

CONCEPTS.md

README.mdDocument native primitive vocabulary +6/-3

Document native primitive vocabulary

• Describes the new scalar, script, and witness types and their direct use by transactions and headers.

crates/primitives/README.md

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (2)

Grey Divider


Action required

1. Non-coinbase inputs lose fields 🐞 Bug
Description
input_json now emits only sequence for non-coinbase inputs, dropping txid, vout, and
scriptSig from verbose transaction responses. Clients can no longer identify the spent outpoint or
inspect the unlocking script.
Code

crates/rpc/src/tx_render.rs[L183-186]

-        "txid": prev_txid.to_string(),
-        "vout": prev_vout,
-        "scriptSig": {
-            "asm": script_asm(&input.script_sig),
Relevance

●●● Strong

Dropping standard verbose input fields is a clear RPC compatibility regression; similar
compatibility fixes are accepted.

PR-#150

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The non-coinbase renderer copies the previous transaction ID and output index but constructs JSON
containing only sequence; later code adds only optional witness and prevout data. The parallel
typed compatibility renderer still emits txid, vout, and script_sig, confirming these fields
were not intentionally removed by the newtype migration.

crates/rpc/src/tx_render.rs[180-202]
crates/rpc/src/compat/convert.rs[323-334]
crates/rpc/src/tx_render.rs[90-118]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Restore `txid`, `vout`, and the `scriptSig` object in the non-coinbase branch of `input_json`, while retaining the new `Sequence::to_consensus()` conversion.

## Issue Context
The typed-field migration accidentally removed public transaction JSON fields rather than only adapting the sequence value. The compatibility projection demonstrates the intended non-coinbase shape.

## Fix Focus Areas
- crates/rpc/src/tx_render.rs[180-202]
- crates/rpc/src/compat/convert.rs[323-334]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Clippy fails on imports 🐞 Bug
Description
checker.rs imports LockTime, Script, Sequence, and Witness in the production module but
only uses them in its separately-importing test submodule; this produces unused_imports. The CI
clippy command passes -D warnings, so the PR cannot pass the required lint gate.
Code

crates/script/src/checker.rs[R12-15]

+use bitcoin_rs_primitives::{
+    Amount, Hash256, LockTime, Script, Sequence, Sighash, SighashCache, SighashError, Tx, TxOut,
+    Witness,
+};
Relevance

●●● Strong

Unused production imports under warnings-denied Clippy are a deterministic CI failure and
straightforward cleanup.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changed production import includes types that have no production references: Sequence is
accessed by its fully qualified path in the production code, while LockTime, Script, and
Witness occur only in the test module, which has its own import list. CI runs workspace clippy
with warnings denied.

crates/script/src/checker.rs[12-15]
crates/script/src/checker.rs[344-405]
crates/script/src/checker.rs[681-710]
.github/workflows/ci.yml[59-80]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Remove primitive types imported into production scopes but used only by nested test modules. These trigger `unused_imports`, which CI promotes to an error.

## Issue Context
`checker.rs` already imports the test-only types inside its `#[cfg(test)]` module. Apply the same cleanup to analogous migration imports in other production modules where applicable.

## Fix Focus Areas
- crates/script/src/checker.rs[12-15]
- .github/workflows/ci.yml[59-80]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Compliance rules (platform): 18 rules
✅ REVIEW.md
Review mode: 🧠 Deep: This is a dense, breaking type migration across 120 files and 809 hunks spanning consensus, serialization, mempool, node, RPC, mining, and script paths, creating many independent opportunities for subtle boundary or semantic defects.
ⓘ  3 issues published inline · 2 in summary

Grey Divider

Comment thread crates/primitives/src/units.rs Outdated
/// One bitcoin in satoshis.
pub const COIN: Self = Self(100_000_000);
/// Consensus maximum money (21 million bitcoin).
pub const MAX_MONEY: Self = Self(21_000_000 * 100_000_000);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

1. max_money has duplicate owners 📘 Rule violation ⚙ Maintainability

Amount::MAX_MONEY independently redefines the existing consensus maximum-money rule instead of
reusing its canonical owner. The duplicate constants can diverge and cause inconsistent amount
validation.
Agent Prompt
## Issue description
`Amount::MAX_MONEY` duplicates the existing consensus `MAX_MONEY` constant and its 21-million-BTC literal, creating multiple owners for the same protocol rule.

## Issue Context
Choose one canonical owner for the maximum-money limit. Either remove the unused associated constant or migrate consensus validation to the primitives-owned typed constant and eliminate the old independent definition.

## Fix Focus Areas
- crates/primitives/src/units.rs[14-21]
- crates/consensus/src/lib.rs[201-202]
- crates/consensus/src/verify_tx.rs[789-798]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines -183 to -186
"txid": prev_txid.to_string(),
"vout": prev_vout,
"scriptSig": {
"asm": script_asm(&input.script_sig),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

2. Non-coinbase inputs lose fields 🐞 Bug ≡ Correctness

input_json now emits only sequence for non-coinbase inputs, dropping txid, vout, and
scriptSig from verbose transaction responses. Clients can no longer identify the spent outpoint or
inspect the unlocking script.
Agent Prompt
## Issue description
Restore `txid`, `vout`, and the `scriptSig` object in the non-coinbase branch of `input_json`, while retaining the new `Sequence::to_consensus()` conversion.

## Issue Context
The typed-field migration accidentally removed public transaction JSON fields rather than only adapting the sequence value. The compatibility projection demonstrates the intended non-coinbase shape.

## Fix Focus Areas
- crates/rpc/src/tx_render.rs[180-202]
- crates/rpc/src/compat/convert.rs[323-334]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread crates/script/src/checker.rs Outdated
Comment on lines +12 to +15
use bitcoin_rs_primitives::{
Amount, Hash256, LockTime, Script, Sequence, Sighash, SighashCache, SighashError, Tx, TxOut,
Witness,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

3. Clippy fails on imports 🐞 Bug ⚙ Maintainability

checker.rs imports LockTime, Script, Sequence, and Witness in the production module but
only uses them in its separately-importing test submodule; this produces unused_imports. The CI
clippy command passes -D warnings, so the PR cannot pass the required lint gate.
Agent Prompt
## Issue description
Remove primitive types imported into production scopes but used only by nested test modules. These trigger `unused_imports`, which CI promotes to an error.

## Issue Context
`checker.rs` already imports the test-only types inside its `#[cfg(test)]` module. Apply the same cleanup to analogous migration imports in other production modules where applicable.

## Fix Focus Areas
- crates/script/src/checker.rs[12-15]
- .github/workflows/ci.yml[59-80]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo Fixer

🍒 Ready to be cherry-picked — ✅ Merged (0) · ☑ Fixed (3)

Grey Divider

🔗 Fix PR: #601

This fix PR was closed automatically. Its branch is preserved so you can cherry pick the changes into the original PR.

Prompt for coding agent

This is an automated fix prepared on a separate branch (#601). It is NOT applied to this PR.
To use it: review Fix PR #601 (https://github.com/gosuda/bitcoin-rs/pull/601), evaluate each change critically against your local context, and cherry-pick the changes that are correct into this branch. Do not accept them blindly.
Process — 3 fixed
  • ☑ Fixed: Non-coinbase inputs lose fields
  • ☑ Fixed: Clippy fails on imports
  • ☑ Fixed: MAX_MONEY has duplicate owners

Amount::MAX_MONEY owns the 21-million-BTC rule (derived from COIN).
Consensus MAX_MONEY is now a satoshi view of that constant, and
transaction output checks compare against the typed limit.

Keep production primitive imports to types named on the production
path and restore test-only names under cfg(test) so clippy -D warnings
stays clean. Restore verbose non-coinbase vin txid, vout, and
scriptSig that wrapping sequence dropped.

Co-authored-by: metaphorics <metaphorics@users.noreply.github.com>
@cursor

cursor Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_6f2ab73a-461c-49fe-9f19-fc7251197e6e)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants