mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-17 01:17:36 +00:00
bitcoin 0.32.1
This commit is contained in:
parent
cd69f3b9d6
commit
f4147c39b2
2 changed files with 11 additions and 19 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -973,9 +973,9 @@ checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitcoin"
|
name = "bitcoin"
|
||||||
version = "0.32.0"
|
version = "0.32.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7170e7750a20974246f17ece04311b4205a6155f1db564c5b224af817663c3ea"
|
checksum = "4bf33434c870e98ecc8608588ccc990c5daba9ba9ad39733dc85fba22c211504"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base58ck",
|
"base58ck",
|
||||||
"bech32",
|
"bech32",
|
||||||
|
|
|
@ -83,12 +83,6 @@ impl TryFrom<Vec<u8>> for Address {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_to_vec(addr: &Address) -> Result<Vec<u8>, ()> {
|
fn try_to_vec(addr: &Address) -> Result<Vec<u8>, ()> {
|
||||||
let witness_program = |addr: &Address| {
|
|
||||||
let program_push = addr.0.as_script().instructions().last().ok_or(())?.map_err(|_| ())?;
|
|
||||||
let program = program_push.push_bytes().ok_or(())?.as_bytes();
|
|
||||||
Ok::<_, ()>(program.to_vec())
|
|
||||||
};
|
|
||||||
|
|
||||||
let parsed_addr =
|
let parsed_addr =
|
||||||
BAddress::<NetworkChecked>::from_script(&addr.0, Network::Bitcoin).map_err(|_| ())?;
|
BAddress::<NetworkChecked>::from_script(&addr.0, Network::Bitcoin).map_err(|_| ())?;
|
||||||
Ok(
|
Ok(
|
||||||
|
@ -100,21 +94,19 @@ fn try_to_vec(addr: &Address) -> Result<Vec<u8>, ()> {
|
||||||
EncodedAddress::P2SH(*parsed_addr.script_hash().unwrap().as_raw_hash().as_byte_array())
|
EncodedAddress::P2SH(*parsed_addr.script_hash().unwrap().as_raw_hash().as_byte_array())
|
||||||
}
|
}
|
||||||
Some(AddressType::P2wpkh) => {
|
Some(AddressType::P2wpkh) => {
|
||||||
let program = witness_program(addr)?;
|
let program = parsed_addr.witness_program().ok_or(())?;
|
||||||
let mut buf = [0; 20];
|
let program = program.program().as_bytes();
|
||||||
buf.copy_from_slice(program.as_ref());
|
EncodedAddress::P2WPKH(program.try_into().map_err(|_| ())?)
|
||||||
EncodedAddress::P2WPKH(buf)
|
|
||||||
}
|
}
|
||||||
Some(AddressType::P2wsh) => {
|
Some(AddressType::P2wsh) => {
|
||||||
let program = witness_program(addr)?;
|
let program = parsed_addr.witness_program().ok_or(())?;
|
||||||
let mut buf = [0; 32];
|
let program = program.program().as_bytes();
|
||||||
buf.copy_from_slice(program.as_ref());
|
EncodedAddress::P2WSH(program.try_into().map_err(|_| ())?)
|
||||||
EncodedAddress::P2WSH(buf)
|
|
||||||
}
|
}
|
||||||
Some(AddressType::P2tr) => {
|
Some(AddressType::P2tr) => {
|
||||||
let program = witness_program(addr)?;
|
let program = parsed_addr.witness_program().ok_or(())?;
|
||||||
let program_ref: &[u8] = program.as_ref();
|
let program = program.program().as_bytes();
|
||||||
EncodedAddress::P2TR(program_ref.try_into().map_err(|_| ())?)
|
EncodedAddress::P2TR(program.try_into().map_err(|_| ())?)
|
||||||
}
|
}
|
||||||
_ => Err(())?,
|
_ => Err(())?,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue