Skip to content

Conversation

@jamillambert
Copy link
Collaborator

ScriptPubKey has fields that can be modelled with rust-bitcoin types. And says in it's own rustdoc The `mtype::ScriptPubkey` mirrors this design, but there is none.

Two RPCs use this type, getdescriptoractivity and gettxout. The GetTxOut model extracts individual fields from the ScriptPubKey to create a TxOut and Address, and does not model a ScriptPubKey type.

  • Add the ScriptPubKey model, error and into function.
  • Use the model in GetDescriptorActivity.

},
};

/// Models the data returned by Core for a script pubkey.
Copy link
Member

Choose a reason for hiding this comment

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

I believe 'script pubkey' is definitely wrong but I don't know if it should be scriptPubkey or scriptPubKey. See #371

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have gone with scriptPubKey to match Core.

Comment on lines 81 to 82
/// Script assembly.
pub asm: String,
Copy link
Member

Choose a reason for hiding this comment

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

We don't want this field. ScritpBuf has a method to get this. We could consider adding code during into_model that checks the string from Core against the string returned by rust-bitcoin but the we are probably just testing other crates ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

Comment on lines 85 to 86
/// Script hex.
pub hex: ScriptBuf,
Copy link
Member

Choose a reason for hiding this comment

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

I'd put this as the first field and call it script, or script_pubkey, or inner. Anything but hex, which it no longer is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

script_pubkey seems to be the most common name in the rest of the RPCs so I went with it.

Comment on lines 92 to 93
/// The type, eg pubkeyhash.
pub type_: String,
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this? We have predicates in rust-bitcoin eg is_p2pkh. I'm inclined to think drop it, its still there before one calls into_model if its needed. I'm not too fussed though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think it is needed. As you say it is there before converting into the model type if needed.

Script(ref e) => write_err!(f, "conversion of the script `hex` field failed"; e),
Address(ref e) => write_err!(f, "conversion of the `address` field failed"; e),
ActivityEntry(ref e) => write_err!(f, "conversion of an activity entry failed"; e),
PrevoutSPK(ref e) => write_err!(f, "conversion of the `prevout_spk` field failed"; e),
Copy link
Member

Choose a reason for hiding this comment

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

Rust convention for accronyms is just to capitalize the first character. So PrevoutsSpk

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment on lines 75 to 77
/// This is used by methods in the blockchain section and in the raw transaction section (i.e raw
/// transaction and psbt methods). The shape changed in Core v22 but the new shape is fully
/// backwards compatible so we only provide it not a v0.17 specific type.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// This is used by methods in the blockchain section and in the raw transaction section (i.e raw
/// transaction and psbt methods). The shape changed in Core v22 but the new shape is fully
/// backwards compatible so we only provide it not a v0.17 specific type.
/// This is used by methods in the blockchain section and in the raw transaction section (i.e raw
/// transaction and psbt methods).

That other bit is not relevant here in model, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah it's not relevant here. I removed it.

Comment on lines 85 to 86
/// Only returned before in versions prior to 22 or for version 22 onwards if
/// config option `-deprecatedrpc=addresses` is passed.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Only returned before in versions prior to 22 or for version 22 onwards if
/// config option `-deprecatedrpc=addresses` is passed.
/// Only returned in versions prior to 22 or for version 22 onwards if
/// config option `-deprecatedrpc=addresses` is passed.

Copy link
Member

Choose a reason for hiding this comment

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

There are 4 instances of this typo in the codebase:

gg 'returned before in'
lib.rs:196:    /// Only returned before in versions prior to 22 or for version 22 onwards if
lib.rs:207:    /// Only returned before in versions prior to 22 or for version 22 onwards if
model/mod.rs:85:    /// Only returned before in versions prior to 22 or for version 22 onwards if
model/mod.rs:92:    /// Only returned before in versions prior to 22 or for version 22 onwards if

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

ScriptPubKey has fields that can be modeled with rust-bitcoin types.

Add a model, an into_model function and error.
A new model with strongly typed fields for ScriptPubKey has been added.

Update GetDescriptorActivity model to use it.

Add the required error variants and into_model function.
Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 478a53c

@tcharding tcharding merged commit 40b6314 into rust-bitcoin:master Oct 2, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants