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.
This commit is contained in:
Tobin Harding 2022-01-05 14:37:39 +11:00
parent ad75d5181f
commit dfd8924398
5 changed files with 9 additions and 36 deletions

View File

@ -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),
}

View File

@ -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();

View File

@ -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,
@ -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();

View File

@ -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>;

View File

@ -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,
@ -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();