Refactor match arms
Refactor the match arms to make the code around the key used for map look up easier read. Refactor only, no logic changes.
This commit is contained in:
parent
e6af569490
commit
11c046b707
|
@ -45,12 +45,19 @@ impl Map for PartiallySignedTransaction {
|
|||
|
||||
match raw_key.type_value {
|
||||
PSBT_GLOBAL_UNSIGNED_TX => return Err(Error::DuplicateKey(raw_key).into()),
|
||||
PSBT_GLOBAL_PROPRIETARY => match self.proprietary.entry(raw::ProprietaryKey::from_key(raw_key.clone())?) {
|
||||
btree_map::Entry::Vacant(empty_key) => {empty_key.insert(raw_value);},
|
||||
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::Vacant(empty_key) => {
|
||||
empty_key.insert(raw_value);
|
||||
},
|
||||
btree_map::Entry::Occupied(k) => return Err(Error::DuplicateKey(k.key().clone()).into()),
|
||||
}
|
||||
}
|
||||
|
@ -278,11 +285,15 @@ impl PartiallySignedTransaction {
|
|||
}
|
||||
}
|
||||
PSBT_GLOBAL_PROPRIETARY => match proprietary.entry(raw::ProprietaryKey::from_key(pair.key.clone())?) {
|
||||
btree_map::Entry::Vacant(empty_key) => {empty_key.insert(pair.value);},
|
||||
btree_map::Entry::Vacant(empty_key) => {
|
||||
empty_key.insert(pair.value);
|
||||
},
|
||||
btree_map::Entry::Occupied(_) => return Err(Error::DuplicateKey(pair.key).into()),
|
||||
}
|
||||
_ => match unknowns.entry(pair.key) {
|
||||
btree_map::Entry::Vacant(empty_key) => {empty_key.insert(pair.value);},
|
||||
btree_map::Entry::Vacant(empty_key) => {
|
||||
empty_key.insert(pair.value);
|
||||
},
|
||||
btree_map::Entry::Occupied(k) => return Err(Error::DuplicateKey(k.key().clone()).into()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -284,17 +284,20 @@ impl Map for Input {
|
|||
self.tap_merkle_root <= <raw_key: _>|< raw_value: TapBranchHash>
|
||||
}
|
||||
}
|
||||
PSBT_IN_PROPRIETARY => match self.proprietary.entry(raw::ProprietaryKey::from_key(raw_key.clone())?) {
|
||||
btree_map::Entry::Vacant(empty_key) => {empty_key.insert(raw_value);},
|
||||
PSBT_IN_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())
|
||||
}
|
||||
btree_map::Entry::Occupied(k) => return Err(Error::DuplicateKey(k.key().clone()).into()),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -142,10 +142,15 @@ impl Map for Output {
|
|||
self.bip32_derivation <= <raw_key: secp256k1::PublicKey>|<raw_value: KeySource>
|
||||
}
|
||||
}
|
||||
PSBT_OUT_PROPRIETARY => match self.proprietary.entry(raw::ProprietaryKey::from_key(raw_key.clone())?) {
|
||||
btree_map::Entry::Vacant(empty_key) => {empty_key.insert(raw_value);},
|
||||
PSBT_OUT_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()),
|
||||
}
|
||||
}
|
||||
PSBT_OUT_TAP_INTERNAL_KEY => {
|
||||
impl_psbt_insert_pair! {
|
||||
self.tap_internal_key <= <raw_key: _>|<raw_value: XOnlyPublicKey>
|
||||
|
@ -165,10 +170,8 @@ impl Map for Output {
|
|||
btree_map::Entry::Vacant(empty_key) => {
|
||||
empty_key.insert(raw_value);
|
||||
}
|
||||
btree_map::Entry::Occupied(k) => {
|
||||
return Err(Error::DuplicateKey(k.key().clone()).into())
|
||||
btree_map::Entry::Occupied(k) => return Err(Error::DuplicateKey(k.key().clone()).into()),
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue