feat(addresses): Derive Hash on Address (#235)

authored-by: Turner <mitch@tpfs.io>
This commit is contained in:
Mitchell Turner 2023-03-14 14:10:55 -07:00 committed by GitHub
parent 8cdde5e9a8
commit 61f50b2cca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 10 deletions

View file

@ -161,7 +161,7 @@ pub struct AddressPayload {
}
/// New type wrapping a Byron address primitive
#[derive(Debug, Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ByronAddress {
#[n(0)]
payload: TagWrap<ByteVec, 24>,

View file

@ -66,7 +66,7 @@ pub type TxIdx = u64;
pub type CertIdx = u64;
/// An on-chain pointer to a stake key
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Pointer(Slot, TxIdx, CertIdx);
fn slice_to_hash(slice: &[u8]) -> Result<Hash<28>, Error> {
@ -116,7 +116,7 @@ impl Pointer {
}
/// The payment part of a Shelley address
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)]
pub enum ShelleyPaymentPart {
Key(PaymentKeyHash),
Script(ScriptHash),
@ -168,7 +168,7 @@ impl ShelleyPaymentPart {
}
/// The delegation part of a Shelley address
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)]
pub enum ShelleyDelegationPart {
Key(StakeKeyHash),
Script(ScriptHash),
@ -253,7 +253,7 @@ impl StakePayload {
}
/// The network tag of an address
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Hash)]
pub enum Network {
Testnet,
Mainnet,
@ -271,24 +271,24 @@ impl From<u8> for Network {
}
/// A decoded Shelley address
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)]
pub struct ShelleyAddress(Network, ShelleyPaymentPart, ShelleyDelegationPart);
/// The payload of a Stake address
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)]
pub enum StakePayload {
Stake(StakeKeyHash),
Script(ScriptHash),
}
/// A decoded Stake address
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)]
pub struct StakeAddress(Network, StakePayload);
pub use byron::ByronAddress;
/// A decoded Cardano address of any type
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)]
pub enum Address {
Byron(ByronAddress),
Shelley(ShelleyAddress),