Merge rust-bitcoin/rust-bitcoin#1771: Use slice patterns
873501a85f
Use slice patterns (Martin Habovstiak) Pull request description: Some code looks better with slice patterns. This changes `bip32` to use them. ACKs for top commit: apoelstra: ACK873501a85f
tcharding: ACK873501a85f
Tree-SHA512: 2e91b21d0f943c04f592112f241444ba3b1b1dad47ea6bea162f62cfbcaf98e383257cad144072b3807aaa0c122dabab638ac10b1cc1f5179727a5f05aac0659
This commit is contained in:
commit
142b4fc431
|
@ -607,14 +607,11 @@ impl ExtendedPrivKey {
|
||||||
return Err(Error::WrongExtendedKeyLength(data.len()));
|
return Err(Error::WrongExtendedKeyLength(data.len()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let network = if data[0..4] == [0x04u8, 0x88, 0xAD, 0xE4] {
|
let network = match data {
|
||||||
Network::Bitcoin
|
[0x04u8, 0x88, 0xAD, 0xE4, ..] => Network::Bitcoin,
|
||||||
} else if data[0..4] == [0x04u8, 0x35, 0x83, 0x94] {
|
[0x04u8, 0x35, 0x83, 0x94, ..] => Network::Testnet,
|
||||||
Network::Testnet
|
[b0, b1, b2, b3, ..] => return Err(Error::UnknownVersion([*b0, *b1, *b2, *b3])),
|
||||||
} else {
|
_ => unreachable!("length checked above"),
|
||||||
let mut ver = [0u8; 4];
|
|
||||||
ver.copy_from_slice(&data[0..4]);
|
|
||||||
return Err(Error::UnknownVersion(ver));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(ExtendedPrivKey {
|
Ok(ExtendedPrivKey {
|
||||||
|
@ -745,16 +742,15 @@ impl ExtendedPubKey {
|
||||||
return Err(Error::WrongExtendedKeyLength(data.len()));
|
return Err(Error::WrongExtendedKeyLength(data.len()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let network = match data {
|
||||||
|
[0x04u8, 0x88, 0xB2, 0x1E, ..] => Network::Bitcoin,
|
||||||
|
[0x04u8, 0x35, 0x87, 0xCF, ..] => Network::Testnet,
|
||||||
|
[b0, b1, b2, b3, ..] => return Err(Error::UnknownVersion([*b0, *b1, *b2, *b3])),
|
||||||
|
_ => unreachable!("length checked above"),
|
||||||
|
};
|
||||||
|
|
||||||
Ok(ExtendedPubKey {
|
Ok(ExtendedPubKey {
|
||||||
network: if data[0..4] == [0x04u8, 0x88, 0xB2, 0x1E] {
|
network,
|
||||||
Network::Bitcoin
|
|
||||||
} else if data[0..4] == [0x04u8, 0x35, 0x87, 0xCF] {
|
|
||||||
Network::Testnet
|
|
||||||
} else {
|
|
||||||
let mut ver = [0u8; 4];
|
|
||||||
ver.copy_from_slice(&data[0..4]);
|
|
||||||
return Err(Error::UnknownVersion(ver));
|
|
||||||
},
|
|
||||||
depth: data[4],
|
depth: data[4],
|
||||||
parent_fingerprint: data[5..9]
|
parent_fingerprint: data[5..9]
|
||||||
.try_into()
|
.try_into()
|
||||||
|
|
Loading…
Reference in New Issue