feat(interop): introduce field-mask context for u5c (#502)

This commit is contained in:
Santiago Carmuega 2024-08-15 10:35:58 -03:00 committed by GitHub
parent 81390296a3
commit c6621730eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View file

@ -17,6 +17,7 @@ pallas-codec = { version = "=0.29.0", path = "../pallas-codec" }
pallas-crypto = { version = "=0.29.0", path = "../pallas-crypto" }
utxorpc-spec = { version = "0.8.0" }
prost-types = "0.13.1"
[dev-dependencies]
hex = "0.4.3"

View file

@ -5,6 +5,7 @@ use pallas_crypto::hash::Hash;
use pallas_primitives::{alonzo, babbage, conway};
use pallas_traverse as trv;
use prost_types::FieldMask;
use trv::OriginalHash;
pub use utxorpc_spec::utxorpc::v1alpha as spec;
@ -25,12 +26,22 @@ pub trait LedgerContext: Clone {
#[derive(Default, Clone)]
pub struct Mapper<C: LedgerContext> {
ledger: Option<C>,
mask: FieldMask,
}
impl<C: LedgerContext> Mapper<C> {
pub fn new(ledger: C) -> Self {
Self {
ledger: Some(ledger),
mask: FieldMask { paths: vec![] },
}
}
/// Creates a clone of this mapper using a custom field mask
pub fn masked(&self, mask: FieldMask) -> Self {
Self {
ledger: self.ledger.clone(),
mask,
}
}
}