Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ pub fn compact_size_decode(slice: &mut &[u8]) -> u64 {
///
/// 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. The `mtype::ScriptPubkey`
/// backwards compatible so we only provide it not a v0.17 specific type. The `mtype::ScriptPubKey`
/// mirrors this design (but with concrete `rust-bitcoin` types).
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct ScriptPubkey {
pub struct ScriptPubKey {
/// Script assembly.
pub asm: String,
/// Inferred descriptor for the output. v23 and later only.
Expand All @@ -204,9 +204,9 @@ pub struct ScriptPubkey {
pub addresses: Option<Vec<String>>,
}

/// Error when converting a `ScriptPubkey` type into the model type.
/// Error when converting a `ScriptPubKey` type into the model type.
#[derive(Debug)]
pub enum ScriptPubkeyError {
pub enum ScriptPubKeyError {
/// Conversion of the `hex` field failed.
Hex(hex::HexToBytesError),
/// Conversion of the `address` field failed.
Expand All @@ -215,7 +215,7 @@ pub enum ScriptPubkeyError {
Addresses(address::ParseError),
}

impl fmt::Display for ScriptPubkeyError {
impl fmt::Display for ScriptPubKeyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Hex(ref e) => write_err!(f, "conversion of the `hex` field failed"; e),
Expand All @@ -227,7 +227,7 @@ impl fmt::Display for ScriptPubkeyError {
}

#[cfg(feature = "std")]
impl std::error::Error for ScriptPubkeyError {
impl std::error::Error for ScriptPubKeyError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Hex(ref e) => Some(e),
Expand All @@ -237,7 +237,7 @@ impl std::error::Error for ScriptPubkeyError {
}
}

impl ScriptPubkey {
impl ScriptPubKey {
fn script_buf(&self) -> Result<ScriptBuf, hex::HexToBytesError> {
ScriptBuf::from_hex(&self.hex)
}
Expand All @@ -247,8 +247,8 @@ impl ScriptPubkey {
}

/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::ScriptPubkey, ScriptPubkeyError> {
use ScriptPubkeyError as E;
pub fn into_model(self) -> Result<model::ScriptPubKey, ScriptPubKeyError> {
use ScriptPubKeyError as E;

let script_pubkey = ScriptBuf::from_hex(&self.hex).map_err(E::Hex)?;

Expand All @@ -264,7 +264,7 @@ impl ScriptPubkey {
})
.transpose()?;

Ok(model::ScriptPubkey {
Ok(model::ScriptPubKey {
script_pubkey,
required_signatures: self.required_signatures,
address,
Expand Down
8 changes: 4 additions & 4 deletions types/src/model/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bitcoin::{
};
use serde::{Deserialize, Serialize};

use super::{GetRawTransactionVerbose, ScriptPubkey};
use super::{GetRawTransactionVerbose, ScriptPubKey};

/// Models the result of JSON-RPC method `dumptxoutset`.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
Expand Down Expand Up @@ -202,7 +202,7 @@ pub struct GetBlockVerboseThreePrevout {
/// The value in BTC.
pub value: Amount,
/// The script pubkey.
pub script_pubkey: ScriptPubkey,
pub script_pubkey: ScriptPubKey,
}

/// Models the result of JSON-RPC method `getblockchaininfo`.
Expand Down Expand Up @@ -636,7 +636,7 @@ pub struct SpendActivity {
/// The vout of the prevout.
pub prevout_vout: u32,
/// The prev scriptPubKey.
pub prevout_spk: ScriptPubkey,
pub prevout_spk: ScriptPubKey,
}

/// Models a 'receive' activity event. Part of `getdescriptoractivity`
Expand All @@ -653,7 +653,7 @@ pub struct ReceiveActivity {
/// The vout of the receiving output.
pub vout: u32,
/// The ScriptPubKey.
pub output_spk: ScriptPubkey,
pub output_spk: ScriptPubKey,
}

/// Models the result of JSON-RPC method `getdifficulty`.
Expand Down
2 changes: 1 addition & 1 deletion types/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub use self::{
/// transaction and psbt methods).
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct ScriptPubkey {
pub struct ScriptPubKey {
/// The script_pubkey parsed from hex.
pub script_pubkey: ScriptBuf,
/// Number of required signatures - deprecated in Core v22.
Expand Down
2 changes: 1 addition & 1 deletion types/src/model/raw_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub struct DecodeRawTransaction(pub Transaction);
/// Models the result of JSON-RPC method `decodescript`.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct DecodeScript {
/// The `scriptPubkey`.
/// The `scriptPubKey`.
pub script_pubkey: Option<ScriptBuf>,
/// Inferred descriptor for the script. v23 and later only.
pub descriptor: Option<String>,
Expand Down
8 changes: 4 additions & 4 deletions types/src/model/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ pub struct GetAddressInfo {
pub enum ScriptType {
/// Non-standard output script type.
NonStandard,
/// Pubkey output script.
Pubkey,
/// Pubkey hash output script.
PubkeyHash,
/// PubKey output script.

@tcharding tcharding Feb 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm surprised the linter doesnt' complain about this? If it starts doing so I'm inclined to think we should just use 'pubkey' and 'Pubkey' (capitalized) in docs and not add an attribute to shoosh the linter.

PubKey,
/// PubKey hash output script.
PubKeyHash,
/// Script hash output script.
ScriptHash,
/// Multisig output script.
Expand Down
18 changes: 9 additions & 9 deletions types/src/psbt/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ pub enum RawTransactionOutputError {
/// Conversion of the output `value` field failed.
Value(amount::ParseAmountError),
/// Conversion of the output `script_pubkey` field failed.
ScriptPubkey(hex::HexToBytesError),
ScriptPubKey(hex::HexToBytesError),
}

impl fmt::Display for RawTransactionOutputError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Value(ref e) => write_err!(f, "conversion of the output `value` field failed"; e),
Self::ScriptPubkey(ref e) =>
Self::ScriptPubKey(ref e) =>
write_err!(f, "conversion of the output `script_pubkey` field failed"; e),
}
}
Expand All @@ -110,7 +110,7 @@ impl std::error::Error for RawTransactionOutputError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Value(ref e) => Some(e),
Self::ScriptPubkey(ref e) => Some(e),
Self::ScriptPubKey(ref e) => Some(e),
}
}
}
Expand All @@ -121,14 +121,14 @@ pub enum WitnessUtxoError {
/// Conversion of the `amount` field failed.
Amount(ParseAmountError),
/// Conversion of the `script_pubkey` field failed.
ScriptPubkey(hex::HexToBytesError),
ScriptPubKey(hex::HexToBytesError),
}

impl fmt::Display for WitnessUtxoError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Amount(ref e) => write_err!(f, "conversion of the `amount` field failed"; e),
Self::ScriptPubkey(ref e) =>
Self::ScriptPubKey(ref e) =>
write_err!(f, "conversion of the `script_pubkey` field failed"; e),
}
}
Expand All @@ -139,7 +139,7 @@ impl std::error::Error for WitnessUtxoError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Amount(ref e) => Some(e),
Self::ScriptPubkey(ref e) => Some(e),
Self::ScriptPubKey(ref e) => Some(e),
}
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ impl std::error::Error for PartialSignatureError {
#[derive(Debug)]
pub enum Bip32DerivError {
/// Conversion of the pubkey failed.
Pubkey(key::ParsePublicKeyError),
PubKey(key::ParsePublicKeyError),
/// Conversion of the `master_fingerprint` field failed.
MasterFingerprint(hex::HexToArrayError),
/// Conversion of the `path` field failed.
Expand All @@ -188,7 +188,7 @@ pub enum Bip32DerivError {
impl fmt::Display for Bip32DerivError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Pubkey(ref e) => write_err!(f, "conversion of the pubkey failed"; e),
Self::PubKey(ref e) => write_err!(f, "conversion of the pubkey failed"; e),
Self::MasterFingerprint(ref e) =>
write_err!(f, "conversion of the `master_fingerprint` field failed"; e),
Self::Path(ref e) => write_err!(f, "conversion of the `path` field failed"; e),
Expand All @@ -200,7 +200,7 @@ impl fmt::Display for Bip32DerivError {
impl std::error::Error for Bip32DerivError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Pubkey(ref e) => Some(e),
Self::PubKey(ref e) => Some(e),
Self::MasterFingerprint(ref e) => Some(e),
Self::Path(ref e) => Some(e),
}
Expand Down
14 changes: 7 additions & 7 deletions types/src/psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use self::error::{
Bip32DerivError, PartialSignatureError, RawTransactionError, RawTransactionInputError,
RawTransactionOutputError, WitnessUtxoError,
};
use crate::{ScriptPubkey, ScriptSig};
use crate::{ScriptPubKey, ScriptSig};

/// Represents a bitcoin transaction.
///
Expand Down Expand Up @@ -147,7 +147,7 @@ pub struct RawTransactionOutput {
pub index: u64,
/// The script pubkey.
#[serde(rename = "scriptPubKey")]
pub script_pubkey: ScriptPubkey,
pub script_pubkey: ScriptPubKey,
}

impl RawTransactionOutput {
Expand All @@ -156,7 +156,7 @@ impl RawTransactionOutput {
use RawTransactionOutputError as E;

let value = Amount::from_btc(self.value).map_err(E::Value)?;
let script_pubkey = self.script_pubkey.script_buf().map_err(E::ScriptPubkey)?;
let script_pubkey = self.script_pubkey.script_buf().map_err(E::ScriptPubKey)?;

Ok(TxOut { value, script_pubkey })
}
Expand All @@ -171,7 +171,7 @@ pub struct WitnessUtxo {
pub amount: f64,
/// The scriptPubKey.
#[serde(rename = "scriptPubKey")]
pub script_pubkey: ScriptPubkey,
pub script_pubkey: ScriptPubKey,
}

impl WitnessUtxo {
Expand All @@ -180,7 +180,7 @@ impl WitnessUtxo {
use WitnessUtxoError as E;

let value = Amount::from_btc(self.amount).map_err(E::Amount)?;
let script_pubkey = self.script_pubkey.script_buf().map_err(E::ScriptPubkey)?;
let script_pubkey = self.script_pubkey.script_buf().map_err(E::ScriptPubKey)?;

Ok(TxOut { value, script_pubkey })
}
Expand Down Expand Up @@ -295,7 +295,7 @@ pub fn map_into_bip32_derivation(

let mut map = BTreeMap::default();
for (k, v) in hash_map.iter() {
let pubkey = k.parse::<PublicKey>().map_err(E::Pubkey)?;
let pubkey = k.parse::<PublicKey>().map_err(E::PubKey)?;
let fingerprint =
Fingerprint::from_hex(&v.master_fingerprint).map_err(E::MasterFingerprint)?;
let path = v.path.parse::<DerivationPath>().map_err(E::Path)?;
Expand All @@ -314,7 +314,7 @@ pub fn vec_into_bip32_derivation(

let mut map = BTreeMap::default();
for deriv in v.iter() {
let pubkey = deriv.pubkey.parse::<PublicKey>().map_err(E::Pubkey)?;
let pubkey = deriv.pubkey.parse::<PublicKey>().map_err(E::PubKey)?;
let fingerprint =
Fingerprint::from_hex(&deriv.master_fingerprint).map_err(E::MasterFingerprint)?;
let path = deriv.path.parse::<DerivationPath>().map_err(E::Path)?;
Expand Down
10 changes: 5 additions & 5 deletions types/src/v17/blockchain/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl From<ParseAmountError> for GetMempoolInfoError {
/// Error when converting a `GetTxOut` type into the model type.
///
/// Note that variants in this type are not named in the usual fashion. The `ScriptBuf` and
/// `Address` variants are named after the functions on [`crate::ScriptPubkey`].
/// `Address` variants are named after the functions on [`crate::ScriptPubKey`].
#[derive(Debug)]
pub enum GetTxOutError {
/// Conversion of numeric type to expected type failed.
Expand All @@ -447,9 +447,9 @@ pub enum GetTxOutError {
BestBlock(hex::HexToArrayError),
/// Conversion of the transaction `value` field failed.
Value(amount::ParseAmountError),
/// Conversion of the `ScriptPubkey` hex to a `ScriptBuf` failed.
/// Conversion of the `ScriptPubKey` hex to a `ScriptBuf` failed.
ScriptBuf(hex::HexToBytesError),
/// Conversion of the `ScriptPubkey` `address` field failed.
/// Conversion of the `ScriptPubKey` `address` field failed.
Address(address::ParseError),
}

Expand All @@ -461,9 +461,9 @@ impl fmt::Display for GetTxOutError {
write_err!(f, "conversion of the `beast_block` field failed"; e),
Self::Value(ref e) => write_err!(f, "conversion of the `value` field failed"; e),
Self::ScriptBuf(ref e) =>
write_err!(f, "conversion of the `ScriptPubkey` hex to a `ScriptBuf` failed"; e),
write_err!(f, "conversion of the `ScriptPubKey` hex to a `ScriptBuf` failed"; e),
Self::Address(ref e) =>
write_err!(f, "conversion of the `ScriptPubkey` `address` field failed"; e),
write_err!(f, "conversion of the `ScriptPubKey` `address` field failed"; e),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions types/src/v17/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};

// TODO: Remove wildcard, use explicit types.
pub use self::error::*;
use crate::{model, ScriptPubkey};
use crate::{model, ScriptPubKey};

/// Result of JSON-RPC method `getbestblockhash`.
///
Expand Down Expand Up @@ -628,7 +628,7 @@ pub struct GetTxOut {
pub value: f64,
/// The script pubkey.
#[serde(rename = "scriptPubKey")]
pub script_pubkey: ScriptPubkey,
pub script_pubkey: ScriptPubKey,
/// Coinbase or not.
pub coinbase: bool,
}
Expand Down
6 changes: 3 additions & 3 deletions types/src/v17/util/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub enum ValidateAddressError {
/// Conversion of the `address` field failed.
Address(address::ParseError),
/// Conversion of the `script_pubkey` field failed.
ScriptPubkey(hex::HexToBytesError),
ScriptPubKey(hex::HexToBytesError),
/// The `witness_version` field's value was too big for a u8.
WitnessVersionValue(i64),
/// Conversion of the `witness_version` field failed.
Expand All @@ -55,7 +55,7 @@ impl fmt::Display for ValidateAddressError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Address(ref e) => write!(f, "conversion of the `address` field failed: {}", e),
Self::ScriptPubkey(ref e) =>
Self::ScriptPubKey(ref e) =>
write!(f, "conversion of the `script_pubkey` field failed: {}", e),
Self::WitnessVersionValue(v) => write!(f, "invalid witness version number: {}", v),
Self::WitnessVersion(ref e) =>
Expand All @@ -76,7 +76,7 @@ impl std::error::Error for ValidateAddressError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Address(ref e) => Some(e),
Self::ScriptPubkey(ref e) => Some(e),
Self::ScriptPubKey(ref e) => Some(e),
Self::WitnessVersionValue(_) => None,
Self::WitnessVersion(ref e) => Some(e),
Self::WitnessProgramBytes(ref e) => Some(e),
Expand Down
2 changes: 1 addition & 1 deletion types/src/v17/util/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl ValidateAddress {
use ValidateAddressError as E;

let address = self.address.parse::<Address<_>>().map_err(E::Address)?;
let script_pubkey = ScriptBuf::from_hex(&self.script_pubkey).map_err(E::ScriptPubkey)?;
let script_pubkey = ScriptBuf::from_hex(&self.script_pubkey).map_err(E::ScriptPubKey)?;
let (witness_version, witness_program) = match (self.witness_version, self.witness_program)
{
(Some(v), Some(hex)) => {
Expand Down
Loading