Add AddressPayloadHash type
Includes From impls for Script, secp256k1::PublicKey
This commit is contained in:
parent
9a4e4e4236
commit
72ddc7d7a1
|
@ -1364,6 +1364,17 @@ dependencies = [
|
|||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ripemd160"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad5112e0dbbb87577bfbc56c42450235e3012ce336e29c5befd7807bd626da4a"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"digest",
|
||||
"opaque-debug",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.16"
|
||||
|
@ -2034,6 +2045,7 @@ dependencies = [
|
|||
"proptest",
|
||||
"proptest-derive",
|
||||
"redjubjub",
|
||||
"ripemd160",
|
||||
"secp256k1",
|
||||
"sha2",
|
||||
"thiserror",
|
||||
|
|
|
@ -13,6 +13,7 @@ chrono = "0.4"
|
|||
futures = "0.3"
|
||||
hex = "0.4"
|
||||
lazy_static = "1.4.0"
|
||||
ripemd160 = "0.8.0"
|
||||
secp256k1 = "0.17.2"
|
||||
sha2 = "0.8"
|
||||
thiserror = "1"
|
||||
|
|
|
@ -1,6 +1,64 @@
|
|||
//! Address types.
|
||||
|
||||
use secp256k1::PublicKey;
|
||||
|
||||
use crate::serialization::{
|
||||
ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize,
|
||||
};
|
||||
|
||||
use crate::types::Script;
|
||||
|
||||
/// A hash of a redeem script, as used in transparent
|
||||
/// pay-to-script-hash addresses.
|
||||
///
|
||||
/// https://en.bitcoin.it/Base58Check_encoding#Encoding_a_Bitcoin_address
|
||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
#[cfg_attr(test, derive(Arbitrary))]
|
||||
struct AddressPayloadHash(pub [u8; 20]);
|
||||
|
||||
impl From<Script> for AddressPayloadHash {
|
||||
fn from(script: Script) -> Self {
|
||||
use ripemd160::Ripdemd160;
|
||||
use sha2::Sha256;
|
||||
|
||||
let hash = Ripdemd160::digest(Sha256::digest(&script.0[..]));
|
||||
|
||||
Self(hash)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PublicKey> for AddressPayloadHash {
|
||||
fn from(publickey: PublicKey) -> Self {
|
||||
use ripemd160::Ripdemd160;
|
||||
use sha2::Sha256;
|
||||
|
||||
let hash = Ripdemd160::digest(Sha256::digest(&publickey.0[..]));
|
||||
|
||||
Self(hash)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for AddressPayloadHash {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_tuple("AddressPayloadHash")
|
||||
.field(&hex::encode(&self.0))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
pub enum TransparentAddress {
|
||||
PayToScriptHash,
|
||||
PayToPublicKeyHash,
|
||||
}
|
||||
|
||||
impl ZcashSerialize for Transaction {
|
||||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
impl ZcashDeserialize for Transaction {
|
||||
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,7 @@ use std::io;
|
|||
|
||||
use secp256k1::PublicKey;
|
||||
|
||||
use crate::serialization::{
|
||||
ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize,
|
||||
};
|
||||
use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize};
|
||||
|
||||
impl ZcashSerialize for PublicKey {
|
||||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
|
|
Loading…
Reference in New Issue