fix(traverse): use Conway types in places they are meant to (#499)
This commit is contained in:
parent
3e2c657f20
commit
5c18f06fa2
8 changed files with 78 additions and 22 deletions
|
|
@ -8,6 +8,7 @@ impl<'b> MultiEraPolicyAssets<'b> {
|
|||
MultiEraPolicyAssets::AlonzoCompatibleMint(x, _) => x,
|
||||
MultiEraPolicyAssets::AlonzoCompatibleOutput(x, _) => x,
|
||||
MultiEraPolicyAssets::ConwayMint(x, _) => x,
|
||||
MultiEraPolicyAssets::ConwayOutput(x, _) => x,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ impl<'b> MultiEraPolicyAssets<'b> {
|
|||
MultiEraPolicyAssets::AlonzoCompatibleMint(_, _) => false,
|
||||
MultiEraPolicyAssets::AlonzoCompatibleOutput(_, _) => true,
|
||||
MultiEraPolicyAssets::ConwayMint(_, _) => false,
|
||||
MultiEraPolicyAssets::ConwayOutput(_, _) => true,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -24,6 +26,7 @@ impl<'b> MultiEraPolicyAssets<'b> {
|
|||
MultiEraPolicyAssets::AlonzoCompatibleMint(_, _) => true,
|
||||
MultiEraPolicyAssets::AlonzoCompatibleOutput(_, _) => false,
|
||||
MultiEraPolicyAssets::ConwayMint(_, _) => true,
|
||||
MultiEraPolicyAssets::ConwayOutput(_, _) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -41,6 +44,10 @@ impl<'b> MultiEraPolicyAssets<'b> {
|
|||
.iter()
|
||||
.map(|(k, v)| MultiEraAsset::ConwayMint(p, k, *v))
|
||||
.collect(),
|
||||
MultiEraPolicyAssets::ConwayOutput(p, x) => x
|
||||
.iter()
|
||||
.map(|(k, v)| MultiEraAsset::ConwayOutput(p, k, *v))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +64,11 @@ impl<'b> MultiEraPolicyAssets<'b> {
|
|||
}
|
||||
MultiEraPolicyAssets::ConwayMint(_, x) => x
|
||||
.iter()
|
||||
.map(|(k, v)| (k.as_slice(), i64::from(v) as i128))
|
||||
.map(|(k, v)| (k.as_slice(), i64::from(*v) as i128))
|
||||
.collect(),
|
||||
MultiEraPolicyAssets::ConwayOutput(_, x) => x
|
||||
.iter()
|
||||
.map(|(k, v)| (k.as_slice(), u64::from(*v) as i128))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
|
@ -69,6 +80,7 @@ impl<'b> MultiEraAsset<'b> {
|
|||
MultiEraAsset::AlonzoCompatibleMint(x, ..) => x,
|
||||
MultiEraAsset::AlonzoCompatibleOutput(x, ..) => x,
|
||||
MultiEraAsset::ConwayMint(x, ..) => x,
|
||||
MultiEraAsset::ConwayOutput(x, ..) => x,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,6 +89,7 @@ impl<'b> MultiEraAsset<'b> {
|
|||
MultiEraAsset::AlonzoCompatibleMint(_, x, _) => x,
|
||||
MultiEraAsset::AlonzoCompatibleOutput(_, x, _) => x,
|
||||
MultiEraAsset::ConwayMint(_, x, _) => x,
|
||||
MultiEraAsset::ConwayOutput(_, x, _) => x,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -85,6 +98,7 @@ impl<'b> MultiEraAsset<'b> {
|
|||
MultiEraAsset::AlonzoCompatibleMint(..) => false,
|
||||
MultiEraAsset::AlonzoCompatibleOutput(..) => true,
|
||||
MultiEraAsset::ConwayMint(..) => false,
|
||||
MultiEraAsset::ConwayOutput(..) => true,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,6 +107,7 @@ impl<'b> MultiEraAsset<'b> {
|
|||
MultiEraAsset::AlonzoCompatibleMint(..) => true,
|
||||
MultiEraAsset::AlonzoCompatibleOutput(..) => false,
|
||||
MultiEraAsset::ConwayMint(..) => true,
|
||||
MultiEraAsset::ConwayOutput(..) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -101,6 +116,7 @@ impl<'b> MultiEraAsset<'b> {
|
|||
MultiEraAsset::AlonzoCompatibleMint(_, _, x) => Some(*x),
|
||||
MultiEraAsset::AlonzoCompatibleOutput(_, _, _) => None,
|
||||
MultiEraAsset::ConwayMint(_, _, x) => Some(x.into()),
|
||||
MultiEraAsset::ConwayOutput(_, _, _) => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -109,6 +125,7 @@ impl<'b> MultiEraAsset<'b> {
|
|||
MultiEraAsset::AlonzoCompatibleMint(_, _, _) => None,
|
||||
MultiEraAsset::AlonzoCompatibleOutput(_, _, x) => Some(*x),
|
||||
MultiEraAsset::ConwayMint(_, _, _) => None,
|
||||
MultiEraAsset::ConwayOutput(_, _, x) => Some(u64::from(x)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -117,6 +134,7 @@ impl<'b> MultiEraAsset<'b> {
|
|||
MultiEraAsset::AlonzoCompatibleMint(_, _, x) => *x as i128,
|
||||
MultiEraAsset::AlonzoCompatibleOutput(_, _, x) => *x as i128,
|
||||
MultiEraAsset::ConwayMint(_, _, x) => i64::from(x) as i128,
|
||||
MultiEraAsset::ConwayOutput(_, _, x) => u64::from(x) as i128,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
//! Utilities to traverse over multi-era block data
|
||||
|
||||
use pallas_codec::utils::NonZeroInt;
|
||||
use pallas_codec::utils::PositiveCoin;
|
||||
use std::{borrow::Cow, fmt::Display, hash::Hash as StdHash};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
use pallas_codec::utils::{KeepRaw, KeyValuePairs, NonEmptyKeyValuePairs, NonZeroInt};
|
||||
use pallas_codec::utils::{KeepRaw, KeyValuePairs, NonEmptyKeyValuePairs};
|
||||
use pallas_crypto::hash::Hash;
|
||||
use pallas_primitives::{alonzo, babbage, byron, conway};
|
||||
|
||||
|
|
@ -145,6 +147,10 @@ pub enum MultiEraPolicyAssets<'b> {
|
|||
&'b alonzo::PolicyId,
|
||||
&'b NonEmptyKeyValuePairs<alonzo::AssetName, NonZeroInt>,
|
||||
),
|
||||
ConwayOutput(
|
||||
&'b alonzo::PolicyId,
|
||||
&'b NonEmptyKeyValuePairs<alonzo::AssetName, PositiveCoin>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -152,6 +158,7 @@ pub enum MultiEraPolicyAssets<'b> {
|
|||
pub enum MultiEraAsset<'b> {
|
||||
AlonzoCompatibleOutput(&'b alonzo::PolicyId, &'b alonzo::AssetName, u64),
|
||||
AlonzoCompatibleMint(&'b alonzo::PolicyId, &'b alonzo::AssetName, i64),
|
||||
ConwayOutput(&'b alonzo::PolicyId, &'b alonzo::AssetName, PositiveCoin),
|
||||
ConwayMint(&'b alonzo::PolicyId, &'b alonzo::AssetName, NonZeroInt),
|
||||
}
|
||||
|
||||
|
|
@ -161,6 +168,7 @@ pub enum MultiEraWithdrawals<'b> {
|
|||
NotApplicable,
|
||||
Empty,
|
||||
AlonzoCompatible(&'b alonzo::Withdrawals),
|
||||
Conway(&'b conway::Withdrawals),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
|||
|
|
@ -188,8 +188,8 @@ impl<'b> MultiEraOutput<'b> {
|
|||
babbage::Value::Multiasset(c, _) => c,
|
||||
},
|
||||
conway::MintedTransactionOutput::PostAlonzo(x) => match x.value {
|
||||
babbage::Value::Coin(c) => c,
|
||||
babbage::Value::Multiasset(c, _) => c,
|
||||
conway::Value::Coin(c) => c,
|
||||
conway::Value::Multiasset(c, _) => c,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -235,10 +235,10 @@ impl<'b> MultiEraOutput<'b> {
|
|||
.collect(),
|
||||
},
|
||||
conway::MintedTransactionOutput::PostAlonzo(x) => match &x.value {
|
||||
babbage::Value::Coin(_) => vec![],
|
||||
babbage::Value::Multiasset(_, x) => x
|
||||
conway::Value::Coin(_) => vec![],
|
||||
conway::Value::Multiasset(_, x) => x
|
||||
.iter()
|
||||
.map(|(k, v)| MultiEraPolicyAssets::AlonzoCompatibleOutput(k, v))
|
||||
.map(|(k, v)| MultiEraPolicyAssets::ConwayOutput(k, v))
|
||||
.collect(),
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -228,6 +228,11 @@ impl<'b> MultiEraTx<'b> {
|
|||
.map(|(k, v)| (k.as_slice(), *v))
|
||||
.sorted_by_key(|(k, _)| *k)
|
||||
.collect(),
|
||||
MultiEraWithdrawals::Conway(x) => x
|
||||
.iter()
|
||||
.map(|(k, v)| (k.as_slice(), *v))
|
||||
.sorted_by_key(|(k, _)| *k)
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -463,9 +468,8 @@ impl<'b> MultiEraTx<'b> {
|
|||
None => MultiEraWithdrawals::Empty,
|
||||
},
|
||||
MultiEraTx::Byron(_) => MultiEraWithdrawals::NotApplicable,
|
||||
// TODO: non empty still compatible?
|
||||
MultiEraTx::Conway(x) => match &x.transaction_body.withdrawals {
|
||||
Some(x) => MultiEraWithdrawals::AlonzoCompatible(x),
|
||||
Some(x) => MultiEraWithdrawals::Conway(x),
|
||||
None => MultiEraWithdrawals::Empty,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ impl<'b> MultiEraWithdrawals<'b> {
|
|||
MultiEraWithdrawals::AlonzoCompatible(x) => {
|
||||
x.iter().map(|(k, v)| (k.as_slice(), *v)).collect()
|
||||
}
|
||||
MultiEraWithdrawals::Conway(x) => x.iter().map(|(k, v)| (k.as_slice(), *v)).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue