Skip to content

[FIX] [RPC] Align getrawtransaction with Bitcoin Core#985

Open
moisesPompilio wants to merge 4 commits into
getfloresta:masterfrom
moisesPompilio:get_raw_transaction
Open

[FIX] [RPC] Align getrawtransaction with Bitcoin Core#985
moisesPompilio wants to merge 4 commits into
getfloresta:masterfrom
moisesPompilio:get_raw_transaction

Conversation

@moisesPompilio
Copy link
Copy Markdown
Collaborator

Description and Notes

Brings Floresta’s getrawtransaction RPC closer to Bitcoin Core compatibility.

Fixes the RPC method call so the client correctly uses getrawtransaction instead of the incorrect gettransaction, and standardizes verbosity handling to match Bitcoin Core’s numeric behavior.

The response format was aligned with Bitcoin Core as well:

  • RawTx fields such as blockhash, confirmations, blocktime, and time are now optional and only serialized when present.
  • txid encoding was corrected.
  • TxOut.value now uses f64 in BTC instead of u64 in sats, matching Bitcoin Core’s denomination.
  • TxOut.address is now optional and only included when the script can be converted into a valid address.
  • TxIn now handles coinbase inputs properly, including the coinbase field only when applicable.
  • ASM formatting was improved to follow Bitcoin Core’s rules more strictly.
  • TxOut script types were expanded to cover the script types supported by Bitcoin Core.

Note: the desc field was intentionally left out, since matching Bitcoin Core’s descriptor logic requires additional investigation and a more complex implementation. That can be handled in a future PR.

How to verify the changes you have done?

Compare the output of getrawtransaction between Floresta and Bitcoin Core for both verbosity = 0 and verbosity = 1.

The integration test added here already covers this behavior and is the best reference for validation.

  • Check regular transactions across multiple script types, including P2PKH, P2WPKH, P2SH, and P2TR.
  • Check coinbase transactions and confirm the special input/output fields are handled correctly.
  • Review the optional field behavior to ensure fields are only present when they should be.
  • Inspect the integration test to confirm field-by-field validation against Bitcoin Core.

@moisesPompilio
Copy link
Copy Markdown
Collaborator Author

This PR is in draft because it depends on #821. That PR introduces typos for spell checking, allowing more flexibility when using randomly generated addresses without triggering spelling errors

@moisesPompilio moisesPompilio self-assigned this Apr 23, 2026
@moisesPompilio moisesPompilio added the ecosystem support Enable interoperability, compatibility and practical integration with the broader Bitcoin ecosystem label Apr 23, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in Floresta Apr 23, 2026
@moisesPompilio moisesPompilio moved this from Backlog to In progress in Floresta Apr 23, 2026
@jaoleal jaoleal self-requested a review April 23, 2026 10:46
…osity to numeric type

The RPC client was incorrectly calling 'gettransaction' (which doesn't exist on the server)
instead of 'getrawtransaction'.

Additionally, the verbosity parameter handling was inconsistent. While the method signature
correctly accepted Option<u32>, it needed better standardization to match Bitcoin Core's
RPC specification.
@moisesPompilio moisesPompilio force-pushed the get_raw_transaction branch 2 times, most recently from 5a99608 to 9547e4a Compare May 15, 2026 01:31
…format

This commit aligns the getrawtransaction RPC response with Bitcoin Core's
format and behavior. The following changes were made:

RawTx struct:
- Made blockhash, confirmations, blocktime, and time optional fields
  They are now only serialized when present, avoiding null values
- Fixed txid encoding that was previously inverted

TxOut struct:
- Changed value from u64 (sats) to f64 (BTC) for proper denomination
- Made address field optional, only serialized when script can be
  converted to a valid address

TxIn struct:
- Added coinbase field that only appears in coinbase transactions,
  containing the hex-encoded script from scriptSig
- Coinbase inputs have: coinbase, sequence, witness (optional)
- Regular inputs have: txid, vout, script_sig, sequence, witness (optional)

Script handling:
- Improved ASM (assembly) format conversion to strictly follow Bitcoin Core
  rules and formatting standards

TxOut types:
- Updated to include all script types that Bitcoin Core supports

Note: The `desc` field was not implemented due to complex matching rules.
This will be added in a future PR.
Add comprehensive integration test comparing Floresta's `getrawtransaction`
RPC output with Bitcoin Core for verbosity levels 0 and 1, covering:
- Regular transactions (`P2PKH`, `P2WPKH`, `P2SH`, `P2TR types`)
- Coinbase transactions
- Input/output field validation
- Optional field handling

New BaseRPC methods:
- `get_raw_transaction()`

New BitcoinRPC methods:
- `create_wallet()`
- `get_new_address()`
- `generate_block_to_wallet()`
- `send_to_address()`
@moisesPompilio moisesPompilio marked this pull request as ready for review May 15, 2026 01:59
@moisesPompilio
Copy link
Copy Markdown
Collaborator Author

22e29a2 I rebased and converted the added integration test to the pytest format.

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

Labels

ecosystem support Enable interoperability, compatibility and practical integration with the broader Bitcoin ecosystem

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

1 participant