Skip to content

Conversation

@natobritto
Copy link
Contributor

@natobritto natobritto commented Jan 27, 2026

This PR:

  • Adds full support for getblock RPC with verbosity levels 2 and 3 for v29 and later.
  • Add coinbase transaction support in RawTransactionInput type, to be fully compliant with the RPC specification.
  • Introduces versioned RPC types and model conversions, including transaction fees and prevout data, extends raw transaction input handling to correctly support coinbase inputs, and updates the client API with verbosity levels.
  • Adds integration tests to validate new models conversions.
  • Removes FIXME comment regarding weight units on getblock verbosity 0 and 1, the value really is weight units (WU).

This partially fixes #474.

Notably missing are the changes in implementation from v17 to v28 inclusive.

Coinbase transactions (either standalone or as inputs for other transcations)
have particularities such as not having a previous outputs. This commits
ehances RawTransactionInput type to handle such scenarios.
Weight::from_wu(x) is the natural mapping when the source value is WU.
This commit confirms that fact.
The RPC `getblock` was missing 2 additional return types corresponding
to verbosity levels 2 and 3. This commits adds them.
weight,
height: crate::to_u32(self.height, "height")?,
version,
merkle_root: self.merkle_root, // TODO: Use hash, which one depends on segwit or not.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other types use the same comment highlighted here, so I kept this TODO to be resolved later.

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct GetBlockVerboseTwoTransaction {
/// The transaction data (same as `getrawtransaction` verbose output).
pub transaction: GetRawTransactionVerbose,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of re-implementing the same getrawtransaction verbose output struct for GetBlockVerboseTwoTransaction or GetBlockVerboseThreeTransaction, I used the existing GetRawTransactionVerbose implementation in raw transaction types because the comment in Bitcoin Core API says the type is the same. This causes the user to type obj.tx[n].transaction.txid instead of obj.tx[n].txid to get the txid, for example. This solution seemed like a fair concession to make. Let me know if you would rather have it be precisely the same structure as RPC response.

/// The prevout information for a transaction input (verbosity 3 only).
/// TODO: This type adding prevouts is exactly the same as the getrawtransaction's type with verbosity set to 2, which is not implemented yet. Consider reusing that structure when implemented.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct GetBlockVerboseThreePrevout {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left a TODO note in code: the GetBlockVerboseThreePrevout type is exactly the same as getrawtransaction's type with verbosity set to 2, which is not implemented yet. When it is implemented, this code could be cut in favor of reusing that type.

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.

Type discrepancies between corepc and v30 blockchain module.

1 participant