Skip to content

Commit

Permalink
Remove insert_pair from Map trait
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tcharding committed Jan 14, 2022
1 parent 0ca7bd1 commit 112169c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/util/psbt/macros.rs
Expand Up @@ -75,7 +75,7 @@ macro_rules! impl_psbtmap_consensus_decoding {

loop {
match $crate::consensus::Decodable::consensus_decode(&mut d) {
Ok(pair) => $crate::util::psbt::Map::insert_pair(&mut rv, pair)?,
Ok(pair) => rv.insert_pair(pair)?,
Err($crate::consensus::encode::Error::Psbt($crate::util::psbt::Error::NoMorePairs)) => return Ok(rv),
Err(e) => return Err(e),
}
Expand Down
28 changes: 0 additions & 28 deletions src/util/psbt/map/global.rs
Expand Up @@ -37,34 +37,6 @@ const PSBT_GLOBAL_VERSION: u8 = 0xFB;
const PSBT_GLOBAL_PROPRIETARY: u8 = 0xFC;

impl Map for PartiallySignedTransaction {
fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
let raw::Pair {
key: raw_key,
value: raw_value,
} = pair;

match raw_key.type_value {
PSBT_GLOBAL_UNSIGNED_TX => return Err(Error::DuplicateKey(raw_key).into()),
PSBT_GLOBAL_PROPRIETARY => {
let key = raw::ProprietaryKey::from_key(raw_key.clone())?;
match self.proprietary.entry(key) {
btree_map::Entry::Vacant(empty_key) => {
empty_key.insert(raw_value);
},
btree_map::Entry::Occupied(_) => return Err(Error::DuplicateKey(raw_key).into()),
}
}
_ => match self.unknown.entry(raw_key) {
btree_map::Entry::Vacant(empty_key) => {
empty_key.insert(raw_value);
},
btree_map::Entry::Occupied(k) => return Err(Error::DuplicateKey(k.key().clone()).into()),
}
}

Ok(())
}

fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error> {
let mut rv: Vec<raw::Pair> = Default::default();

Expand Down
6 changes: 4 additions & 2 deletions src/util/psbt/map/input.rs
Expand Up @@ -189,8 +189,8 @@ impl PsbtSigHashType {
}
}

impl Map for Input {
fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
impl Input {
pub(super) fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
let raw::Pair {
key: raw_key,
value: raw_value,
Expand Down Expand Up @@ -303,7 +303,9 @@ impl Map for Input {

Ok(())
}
}

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

Expand Down
3 changes: 0 additions & 3 deletions src/util/psbt/map/mod.rs
Expand Up @@ -29,9 +29,6 @@ pub use self::output::{Output, TapTree};

/// A trait that describes a PSBT key-value map.
pub(super) trait Map {
/// Attempt to insert a key-value pair.
fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error>;

/// Attempt to get all key-value pairs.
fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error>;

Expand Down
6 changes: 4 additions & 2 deletions src/util/psbt/map/output.rs
Expand Up @@ -120,8 +120,8 @@ impl TapTree {
}
}

impl Map for Output {
fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
impl Output {
pub(super) fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
let raw::Pair {
key: raw_key,
value: raw_value,
Expand Down Expand Up @@ -177,7 +177,9 @@ impl Map for Output {

Ok(())
}
}

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

Expand Down

0 comments on commit 112169c

Please sign in to comment.