Created
July 18, 2020 14:36
-
-
Save sgeisler/84448bf71eadb17f5b2b34cce7045754 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// bitcoin = "*" | |
// bitcoin_hashes = "*" | |
use bitcoin::{Address, Network, Script}; | |
use bitcoin::util::address::Payload; | |
use bitcoin::util::psbt::serialize::Deserialize; | |
use bitcoin_hashes::{hash160, Hash}; | |
fn main() { | |
let bytes: &[u8] = &[ | |
65, 4, 103, 138, 253, 176, 254, 85, 72, 39, 25, 103, 241, 166, 113, 48, 183, 16, 92, 214, | |
168, 40, 224, 57, 9, 166, 121, 98, 224, 234, 31, 97, 222, 182, 73, 246, 188, 63, 76, 239, | |
56, 196, 243, 85, 4, 229, 30, 193, 18, 222, 92, 56, 77, 247, 186, 11, 141, 87, 138, 76, | |
112, 43, 107, 241, 29, 95, 172, | |
]; | |
let p2pk = Script::deserialize(bytes).unwrap(); | |
println!("{}", p2pk_to_string(&p2pk)); | |
} | |
fn p2pk_to_string(script: &Script) -> String { | |
assert!(script.is_p2pk()); | |
let pk = match script.as_bytes().len() { | |
67 => &script.as_bytes()[1..66], | |
35 => &script.as_bytes()[1..34], | |
_ => unreachable!(), | |
}; | |
let pkh = hash160::Hash::hash(pk); | |
let fake_addr = Address { | |
payload: Payload::PubkeyHash(pkh.into()), | |
network: Network::Bitcoin, | |
}; | |
fake_addr.to_string() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment