-
Notifications
You must be signed in to change notification settings - Fork 49
Add getblock verbosity 2/3 support for v29 onward
#485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
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. |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
This PR:
getblockRPC with verbosity levels 2 and 3 for v29 and later.RawTransactionInputtype, to be fully compliant with the RPC specification.This partially fixes #474.
Notably missing are the changes in implementation from v17 to v28 inclusive.