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 {
|
match raw_key.type_value {
|
||||||
PSBT_GLOBAL_UNSIGNED_TX => return Err(Error::DuplicateKey(raw_key).into()),
|
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())?) {
|
PSBT_GLOBAL_PROPRIETARY => {
|
||||||
btree_map::Entry::Vacant(empty_key) => {empty_key.insert(raw_value);},
|
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()),
|
btree_map::Entry::Occupied(_) => return Err(Error::DuplicateKey(raw_key).into()),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
_ => match self.unknown.entry(raw_key) {
|
_ => 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()),
|
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())?) {
|
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()),
|
btree_map::Entry::Occupied(_) => return Err(Error::DuplicateKey(pair.key).into()),
|
||||||
}
|
}
|
||||||
_ => match unknowns.entry(pair.key) {
|
_ => 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()),
|
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>
|
self.tap_merkle_root <= <raw_key: _>|< raw_value: TapBranchHash>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PSBT_IN_PROPRIETARY => match self.proprietary.entry(raw::ProprietaryKey::from_key(raw_key.clone())?) {
|
PSBT_IN_PROPRIETARY => {
|
||||||
btree_map::Entry::Vacant(empty_key) => {empty_key.insert(raw_value);},
|
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()),
|
btree_map::Entry::Occupied(_) => return Err(Error::DuplicateKey(raw_key).into()),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
_ => match self.unknown.entry(raw_key) {
|
_ => match self.unknown.entry(raw_key) {
|
||||||
btree_map::Entry::Vacant(empty_key) => {
|
btree_map::Entry::Vacant(empty_key) => {
|
||||||
empty_key.insert(raw_value);
|
empty_key.insert(raw_value);
|
||||||
}
|
}
|
||||||
btree_map::Entry::Occupied(k) => {
|
btree_map::Entry::Occupied(k) => return Err(Error::DuplicateKey(k.key().clone()).into()),
|
||||||
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>
|
self.bip32_derivation <= <raw_key: secp256k1::PublicKey>|<raw_value: KeySource>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PSBT_OUT_PROPRIETARY => match self.proprietary.entry(raw::ProprietaryKey::from_key(raw_key.clone())?) {
|
PSBT_OUT_PROPRIETARY => {
|
||||||
btree_map::Entry::Vacant(empty_key) => {empty_key.insert(raw_value);},
|
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()),
|
btree_map::Entry::Occupied(_) => return Err(Error::DuplicateKey(raw_key).into()),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
PSBT_OUT_TAP_INTERNAL_KEY => {
|
PSBT_OUT_TAP_INTERNAL_KEY => {
|
||||||
impl_psbt_insert_pair! {
|
impl_psbt_insert_pair! {
|
||||||
self.tap_internal_key <= <raw_key: _>|<raw_value: XOnlyPublicKey>
|
self.tap_internal_key <= <raw_key: _>|<raw_value: XOnlyPublicKey>
|
||||||
|
@ -165,10 +170,8 @@ impl Map for Output {
|
||||||
btree_map::Entry::Vacant(empty_key) => {
|
btree_map::Entry::Vacant(empty_key) => {
|
||||||
empty_key.insert(raw_value);
|
empty_key.insert(raw_value);
|
||||||
}
|
}
|
||||||
btree_map::Entry::Occupied(k) => {
|
btree_map::Entry::Occupied(k) => return Err(Error::DuplicateKey(k.key().clone()).into()),
|
||||||
return Err(Error::DuplicateKey(k.key().clone()).into())
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue