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:
parent
ad75d5181f
commit
dfd8924398
|
@ -75,7 +75,7 @@ macro_rules! impl_psbtmap_consensus_decoding {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match $crate::consensus::Decodable::consensus_decode(&mut d) {
|
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($crate::consensus::encode::Error::Psbt($crate::util::psbt::Error::NoMorePairs)) => return Ok(rv),
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,34 +37,6 @@ const PSBT_GLOBAL_VERSION: u8 = 0xFB;
|
||||||
const PSBT_GLOBAL_PROPRIETARY: u8 = 0xFC;
|
const PSBT_GLOBAL_PROPRIETARY: u8 = 0xFC;
|
||||||
|
|
||||||
impl Map for PartiallySignedTransaction {
|
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> {
|
fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error> {
|
||||||
let mut rv: Vec<raw::Pair> = Default::default();
|
let mut rv: Vec<raw::Pair> = Default::default();
|
||||||
|
|
||||||
|
|
|
@ -189,8 +189,8 @@ impl PsbtSigHashType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Map for Input {
|
impl Input {
|
||||||
fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
|
pub(super) fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
|
||||||
let raw::Pair {
|
let raw::Pair {
|
||||||
key: raw_key,
|
key: raw_key,
|
||||||
value: raw_value,
|
value: raw_value,
|
||||||
|
@ -303,7 +303,9 @@ impl Map for Input {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Map for Input {
|
||||||
fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error> {
|
fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error> {
|
||||||
let mut rv: Vec<raw::Pair> = Default::default();
|
let mut rv: Vec<raw::Pair> = Default::default();
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,6 @@ pub use self::output::{Output, TapTree};
|
||||||
|
|
||||||
/// A trait that describes a PSBT key-value map.
|
/// A trait that describes a PSBT key-value map.
|
||||||
pub(super) trait 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.
|
/// Attempt to get all key-value pairs.
|
||||||
fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error>;
|
fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error>;
|
||||||
|
|
||||||
|
|
|
@ -120,8 +120,8 @@ impl TapTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Map for Output {
|
impl Output {
|
||||||
fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
|
pub(super) fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
|
||||||
let raw::Pair {
|
let raw::Pair {
|
||||||
key: raw_key,
|
key: raw_key,
|
||||||
value: raw_value,
|
value: raw_value,
|
||||||
|
@ -177,7 +177,9 @@ impl Map for Output {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Map for Output {
|
||||||
fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error> {
|
fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error> {
|
||||||
let mut rv: Vec<raw::Pair> = Default::default();
|
let mut rv: Vec<raw::Pair> = Default::default();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue