Skip to content

Commit b53e51b

Browse files
committed
rustfmt: add src/pset/mod.rs and src/blind.rs
1 parent 11bc71b commit b53e51b

File tree

10 files changed

+982
-520
lines changed

10 files changed

+982
-520
lines changed

src/blind.rs

+356-157
Large diffs are not rendered by default.

src/pset/error.rs

+80-30
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
use std::{error, fmt};
1616

17-
use crate::Txid;
1817
use crate::encode;
18+
use crate::Txid;
1919

2020
use super::raw;
2121

22-
use crate::hashes;
2322
use crate::blind::ConfidentialTxOutError;
23+
use crate::hashes;
2424
use secp256k1_zkp;
2525

2626
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
@@ -119,52 +119,94 @@ impl fmt::Display for Error {
119119
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
120120
match *self {
121121
Error::InvalidKey(ref rkey) => write!(f, "invalid key: {}", rkey),
122-
Error::InvalidProprietaryKey => write!(f, "non-proprietary key type found when proprietary key was expected"),
122+
Error::InvalidProprietaryKey => write!(
123+
f,
124+
"non-proprietary key type found when proprietary key was expected"
125+
),
123126
Error::DuplicateKey(ref rkey) => write!(f, "duplicate key: {}", rkey),
124127
Error::LocktimeConflict => write!(f, "conflicting locktime requirements"),
125-
Error::UniqueIdMismatch { expected: ref e, actual: ref a } => write!(f, "different id: expected {}, actual {}", e, a),
126-
Error::NonStandardSigHashType(ref sht) => write!(f, "non-standard sighash type: {}", sht),
128+
Error::UniqueIdMismatch {
129+
expected: ref e,
130+
actual: ref a,
131+
} => write!(f, "different id: expected {}, actual {}", e, a),
132+
Error::NonStandardSigHashType(ref sht) => {
133+
write!(f, "non-standard sighash type: {}", sht)
134+
}
127135
Error::InvalidMagic => f.write_str("invalid magic"),
128136
Error::InvalidSeparator => f.write_str("invalid separator"),
129-
Error::UnsignedTxHasScriptSigs => f.write_str("the unsigned transaction has script sigs"),
130-
Error::UnsignedTxHasScriptWitnesses => f.write_str("the unsigned transaction has script witnesses"),
137+
Error::UnsignedTxHasScriptSigs => {
138+
f.write_str("the unsigned transaction has script sigs")
139+
}
140+
Error::UnsignedTxHasScriptWitnesses => {
141+
f.write_str("the unsigned transaction has script witnesses")
142+
}
131143
Error::MustHaveUnsignedTx => {
132144
f.write_str("partially signed transactions must have an unsigned transaction")
133145
}
134146
Error::NoMorePairs => f.write_str("no more key-value pairs for this pset map"),
135147
Error::HashParseError(e) => write!(f, "Hash Parse Error: {}", e),
136-
Error::InvalidPreimageHashPair{ref preimage, ref hash, ref hash_type} => {
148+
Error::InvalidPreimageHashPair {
149+
ref preimage,
150+
ref hash,
151+
ref hash_type,
152+
} => {
137153
// directly using debug forms of psethash enums
138-
write!(f, "Preimage {:?} does not match {:?} hash {:?}", preimage, hash_type, hash )
154+
write!(
155+
f,
156+
"Preimage {:?} does not match {:?} hash {:?}",
157+
preimage, hash_type, hash
158+
)
159+
}
160+
Error::MergeConflict(ref s) => {
161+
write!(f, "Merge conflict: {}", s)
139162
}
140-
Error::MergeConflict(ref s) => { write!(f, "Merge conflict: {}", s) }
141163
Error::ConsensusEncoding => f.write_str("bitcoin consensus encoding error"),
142164
Error::TooLargePset => {
143165
write!(f, "Psets with 10_000 or more inputs/outputs unsupported")
144166
}
145-
Error::ExpiredPsbtv0Field => f.write_str("psbt v0 field specified in pset(based on pset)"),
167+
Error::ExpiredPsbtv0Field => {
168+
f.write_str("psbt v0 field specified in pset(based on pset)")
169+
}
146170
Error::IncorrectPsetVersion => f.write_str("Pset version must be 2"),
147171
Error::MissingTxVersion => f.write_str("PSET missing global transaction version"),
148172
Error::MissingInputCount => f.write_str("PSET missing input count"),
149173
Error::MissingOutputCount => f.write_str("PSET missing output count"),
150174
Error::MissingInputPrevTxId => f.write_str("PSET input missing previous txid"),
151175
Error::MissingInputPrevVout => f.write_str("PSET input missing previous output index"),
152176
Error::SecpScalarSizeError(actual) => {
153-
write!(f, "PSET blinding scalars must be 32 bytes. Found {} bytes", actual)
154-
}
155-
Error::MissingOutputValue => f.write_str("PSET output missing value. Must have \
156-
at least one of explicit/confidential value set"),
157-
Error::MissingOutputAsset => f.write_str("PSET output missing asset. Must have \
158-
at least one of explicit/confidential asset set"),
159-
Error::MissingBlinderIndex => f.write_str("Output is blinded but does not have a blinder index"),
160-
Error::MissingBlindingInfo => f.write_str("Output marked for blinding, but missing \
161-
some blinding information"),
162-
Error::MissingOutputSpk => f.write_str("PSET output missing script pubkey. Must have \
163-
exactly one of explicit/confidential script pubkey set"),
164-
Error::InputCountMismatch => f.write_str("PSET input count global field must \
165-
match the number of inputs"),
166-
Error::OutputCountMismatch => f.write_str("PSET output count global field must \
167-
match the number of outputs"),
177+
write!(
178+
f,
179+
"PSET blinding scalars must be 32 bytes. Found {} bytes",
180+
actual
181+
)
182+
}
183+
Error::MissingOutputValue => f.write_str(
184+
"PSET output missing value. Must have \
185+
at least one of explicit/confidential value set",
186+
),
187+
Error::MissingOutputAsset => f.write_str(
188+
"PSET output missing asset. Must have \
189+
at least one of explicit/confidential asset set",
190+
),
191+
Error::MissingBlinderIndex => {
192+
f.write_str("Output is blinded but does not have a blinder index")
193+
}
194+
Error::MissingBlindingInfo => f.write_str(
195+
"Output marked for blinding, but missing \
196+
some blinding information",
197+
),
198+
Error::MissingOutputSpk => f.write_str(
199+
"PSET output missing script pubkey. Must have \
200+
exactly one of explicit/confidential script pubkey set",
201+
),
202+
Error::InputCountMismatch => f.write_str(
203+
"PSET input count global field must \
204+
match the number of inputs",
205+
),
206+
Error::OutputCountMismatch => f.write_str(
207+
"PSET output count global field must \
208+
match the number of outputs",
209+
),
168210
}
169211
}
170212
}
@@ -223,8 +265,12 @@ impl fmt::Display for PsetBlindError {
223265
write!(f, "Atleast one output secrets should be provided")
224266
}
225267
PsetBlindError::BlinderIndexOutOfBounds(i, bl) => {
226-
write!(f, "Blinder index {} for output index {} must be less \
227-
than total input count", bl, i)
268+
write!(
269+
f,
270+
"Blinder index {} for output index {} must be less \
271+
than total input count",
272+
bl, i
273+
)
228274
}
229275
PsetBlindError::MissingInputBlinds(i, bl) => {
230276
write!(f, "Output index {} expects blinding input index {}", i, bl)
@@ -239,9 +285,13 @@ impl fmt::Display for PsetBlindError {
239285
write!(f, "Blinding error {} at output index {}", e, i)
240286
}
241287
PsetBlindError::BlindingProofsCreationError(i, e) => {
242-
write!(f, "Blinding proof creation error {} at output index {}", e, i)
288+
write!(
289+
f,
290+
"Blinding proof creation error {} at output index {}",
291+
e, i
292+
)
243293
}
244294
}
245295
}
246296
}
247-
impl error::Error for PsetBlindError {}
297+
impl error::Error for PsetBlindError {}

src/pset/macros.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
#[allow(unused_macros)]
1616
macro_rules! hex_pset {
17-
($s:expr) => { $crate::encode::deserialize(&<Vec<u8> as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()) };
17+
($s:expr) => {
18+
$crate::encode::deserialize(
19+
&<Vec<u8> as $crate::hashes::hex::FromHex>::from_hex($s).unwrap(),
20+
)
21+
};
1822
}
1923

2024
macro_rules! merge {
@@ -61,10 +65,7 @@ macro_rules! impl_psetmap_consensus_encoding {
6165
) -> Result<usize, $crate::encode::Error> {
6266
let mut len = 0;
6367
for pair in $crate::pset::Map::get_pairs(self)? {
64-
len += $crate::encode::Encodable::consensus_encode(
65-
&pair,
66-
&mut s,
67-
)?;
68+
len += $crate::encode::Encodable::consensus_encode(&pair, &mut s)?;
6869
}
6970

7071
Ok(len + $crate::encode::Encodable::consensus_encode(&0x00_u8, s)?)
@@ -143,7 +144,6 @@ macro_rules! impl_pset_insert_pair {
143144
};
144145
}
145146

146-
147147
#[cfg_attr(rustfmt, rustfmt_skip)]
148148
macro_rules! impl_pset_get_pair {
149149
($rv:ident.push($slf:ident.$unkeyed_name:ident as <$unkeyed_typeval:expr, _>)) => {
@@ -211,9 +211,8 @@ macro_rules! impl_pset_hash_deserialize {
211211
($hash_type:ty) => {
212212
impl $crate::pset::serialize::Deserialize for $hash_type {
213213
fn deserialize(bytes: &[u8]) -> Result<Self, $crate::encode::Error> {
214-
<$hash_type>::from_slice(&bytes[..]).map_err(|e| {
215-
$crate::pset::Error::from(e).into()
216-
})
214+
<$hash_type>::from_slice(&bytes[..])
215+
.map_err(|e| $crate::pset::Error::from(e).into())
217216
}
218217
}
219218
};

0 commit comments

Comments
 (0)