feat(traverse): Expose multi-era metadata (#151)
This commit is contained in:
parent
758d6e2119
commit
0b23d7b638
3 changed files with 45 additions and 4 deletions
|
|
@ -14,6 +14,7 @@ pub mod cert;
|
|||
pub mod era;
|
||||
pub mod header;
|
||||
pub mod input;
|
||||
pub mod meta;
|
||||
pub mod output;
|
||||
pub mod probe;
|
||||
mod support;
|
||||
|
|
@ -87,6 +88,8 @@ pub enum MultiEraCert<'b> {
|
|||
AlonzoCompatible(Box<Cow<'b, alonzo::Certificate>>),
|
||||
}
|
||||
|
||||
pub struct MultiEraMeta<'b>(Cow<'b, alonzo::Metadata>);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct OutputRef(Hash<32>, u64);
|
||||
|
||||
|
|
|
|||
15
pallas-traverse/src/meta.rs
Normal file
15
pallas-traverse/src/meta.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use pallas_primitives::alonzo;
|
||||
|
||||
use crate::MultiEraMeta;
|
||||
|
||||
impl<'b> MultiEraMeta<'b> {
|
||||
pub fn entries(&self) -> &alonzo::Metadata {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn find(&self, label: alonzo::MetadatumLabel) -> Option<&alonzo::Metadatum> {
|
||||
self.entries()
|
||||
.iter()
|
||||
.find_map(|(key, value)| if key.eq(&label) { Some(value) } else { None })
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
use pallas_codec::minicbor;
|
||||
use pallas_codec::{minicbor, utils::KeepRaw};
|
||||
use pallas_crypto::hash::Hash;
|
||||
use pallas_primitives::{alonzo, babbage, byron, ToHash};
|
||||
use std::borrow::Cow;
|
||||
use pallas_primitives::{
|
||||
alonzo::{self, AuxiliaryData},
|
||||
babbage, byron, ToHash,
|
||||
};
|
||||
use std::{borrow::Cow, ops::Deref};
|
||||
|
||||
use crate::{Era, MultiEraCert, MultiEraInput, MultiEraOutput, MultiEraTx};
|
||||
use crate::{Era, MultiEraCert, MultiEraInput, MultiEraMeta, MultiEraOutput, MultiEraTx};
|
||||
|
||||
impl<'b> MultiEraTx<'b> {
|
||||
pub fn from_byron(tx: &'b byron::MintedTxPayload<'b>) -> Self {
|
||||
|
|
@ -148,6 +151,26 @@ impl<'b> MultiEraTx<'b> {
|
|||
}
|
||||
}
|
||||
|
||||
fn aux_data(&self) -> Option<&KeepRaw<'_, AuxiliaryData>> {
|
||||
match self {
|
||||
MultiEraTx::AlonzoCompatible(x, _) => x.auxiliary_data.as_ref(),
|
||||
MultiEraTx::Babbage(x) => x.auxiliary_data.as_ref(),
|
||||
MultiEraTx::Byron(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn metadata(&self) -> Option<MultiEraMeta> {
|
||||
match self.aux_data()?.deref() {
|
||||
AuxiliaryData::Shelley(x) => MultiEraMeta(Cow::Borrowed(x)).into(),
|
||||
AuxiliaryData::ShelleyMa(x) => {
|
||||
MultiEraMeta(Cow::Borrowed(&x.transaction_metadata)).into()
|
||||
}
|
||||
AuxiliaryData::PostAlonzo(x) => {
|
||||
x.metadata.as_ref().map(|x| MultiEraMeta(Cow::Borrowed(x)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_babbage(&self) -> Option<&babbage::MintedTx> {
|
||||
match self {
|
||||
MultiEraTx::AlonzoCompatible(_, _) => None,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue