Skip to content

Commit 356a7c8

Browse files
committed
Remove insert_pair from Map trait
The method implementation of `insert_pair` is currently not used for `PartiallySignedTransaction`. Having an implementation available is deceiving. Delete the unused `insert_pair` code from `PartiallySignedTransaction` (dead code). Make the `insert_pair` methods from `Input` and `Output` be standalone functions.
1 parent 7057c85 commit 356a7c8

File tree

5 files changed

+9
-36
lines changed

5 files changed

+9
-36
lines changed

src/util/psbt/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ macro_rules! impl_psbtmap_consensus_decoding {
7575

7676
loop {
7777
match $crate::consensus::Decodable::consensus_decode(&mut d) {
78-
Ok(pair) => $crate::util::psbt::Map::insert_pair(&mut rv, pair)?,
78+
Ok(pair) => rv.insert_pair(pair)?,
7979
Err($crate::consensus::encode::Error::Psbt($crate::util::psbt::Error::NoMorePairs)) => return Ok(rv),
8080
Err(e) => return Err(e),
8181
}

src/util/psbt/map/global.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,6 @@ const PSBT_GLOBAL_VERSION: u8 = 0xFB;
3737
const PSBT_GLOBAL_PROPRIETARY: u8 = 0xFC;
3838

3939
impl Map for PartiallySignedTransaction {
40-
fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
41-
let raw::Pair {
42-
key: raw_key,
43-
value: raw_value,
44-
} = pair;
45-
46-
match raw_key.type_value {
47-
PSBT_GLOBAL_UNSIGNED_TX => return Err(Error::DuplicateKey(raw_key).into()),
48-
PSBT_GLOBAL_PROPRIETARY => {
49-
let key = raw::ProprietaryKey::from_key(raw_key.clone())?;
50-
match self.proprietary.entry(key) {
51-
btree_map::Entry::Vacant(empty_key) => {
52-
empty_key.insert(raw_value);
53-
},
54-
btree_map::Entry::Occupied(_) => return Err(Error::DuplicateKey(raw_key).into()),
55-
}
56-
}
57-
_ => match self.unknown.entry(raw_key) {
58-
btree_map::Entry::Vacant(empty_key) => {
59-
empty_key.insert(raw_value);
60-
},
61-
btree_map::Entry::Occupied(k) => return Err(Error::DuplicateKey(k.key().clone()).into()),
62-
}
63-
}
64-
65-
Ok(())
66-
}
67-
6840
fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error> {
6941
let mut rv: Vec<raw::Pair> = Default::default();
7042

src/util/psbt/map/input.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ impl PsbtSigHashType {
189189
}
190190
}
191191

192-
impl Map for Input {
193-
fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
192+
impl Input {
193+
pub(super) fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
194194
let raw::Pair {
195195
key: raw_key,
196196
value: raw_value,
@@ -303,7 +303,9 @@ impl Map for Input {
303303

304304
Ok(())
305305
}
306+
}
306307

308+
impl Map for Input {
307309
fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error> {
308310
let mut rv: Vec<raw::Pair> = Default::default();
309311

src/util/psbt/map/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ pub use self::output::{Output, TapTree};
2929

3030
/// A trait that describes a PSBT key-value map.
3131
pub(super) trait Map {
32-
/// Attempt to insert a key-value pair.
33-
fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error>;
34-
3532
/// Attempt to get all key-value pairs.
3633
fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error>;
3734

src/util/psbt/map/output.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ impl TapTree {
120120
}
121121
}
122122

123-
impl Map for Output {
124-
fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
123+
impl Output {
124+
pub(super) fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
125125
let raw::Pair {
126126
key: raw_key,
127127
value: raw_value,
@@ -177,7 +177,9 @@ impl Map for Output {
177177

178178
Ok(())
179179
}
180+
}
180181

182+
impl Map for Output {
181183
fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error> {
182184
let mut rv: Vec<raw::Pair> = Default::default();
183185

0 commit comments

Comments
 (0)