-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rust/cardano-chain-follower): Use CIP509 from
rbac-registration
(…
…#96) * fix: remove Cip509 from chain follower Signed-off-by: bkioshn <[email protected]> * feat: add rbac-registration lib to chain-follower Signed-off-by: bkioshn <[email protected]> * fix: modify cip509 metadatum Signed-off-by: bkioshn <[email protected]> * fix: remove unused function Signed-off-by: bkioshn <[email protected]> * fix: remove unused transaction index Signed-off-by: bkioshn <[email protected]> * fix: remove unused dependencies Signed-off-by: bkioshn <[email protected]> * fix: add getter function Signed-off-by: bkioshn <[email protected]> * fix: remove label Signed-off-by: bkioshn <[email protected]> * test: test new rbac-reg branch Signed-off-by: bkioshn <[email protected]> * fix: remove getter (for consistency) Signed-off-by: bkioshn <[email protected]> * fix: update rbac-registration to tag v0.0.8 Signed-off-by: bkioshn <[email protected]> --------- Signed-off-by: bkioshn <[email protected]>
- Loading branch information
Showing
13 changed files
with
88 additions
and
2,242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//! Cardano Improvement Proposal 509 (CIP-509) metadata module. | ||
//! Doc Reference: <https://github.com/input-output-hk/catalyst-CIPs/tree/x509-envelope-metadata/CIP-XXXX> | ||
//! CDDL Reference: <https://github.com/input-output-hk/catalyst-CIPs/blob/x509-envelope-metadata/CIP-XXXX/x509-envelope.cddl> | ||
use std::sync::Arc; | ||
|
||
use minicbor::{Decode, Decoder}; | ||
use pallas::ledger::traverse::MultiEraTx; | ||
use rbac_registration::cardano::cip509::{Cip509 as RbacRegCip509, Cip509Validation, LABEL}; | ||
|
||
use super::{ | ||
DecodedMetadata, DecodedMetadataItem, DecodedMetadataValues, RawAuxData, ValidationReport, | ||
}; | ||
|
||
/// CIP509 metadatum. | ||
#[derive(Debug, PartialEq, Clone, Default)] | ||
pub struct Cip509 { | ||
/// CIP509 data. | ||
pub cip509: RbacRegCip509, | ||
/// Validation value, not a part of CIP509, justs storing validity of the data. | ||
pub validation: Cip509Validation, | ||
} | ||
|
||
impl Cip509 { | ||
/// Decode and validate CIP509 Metadata | ||
/// | ||
/// # Returns | ||
/// | ||
/// Nothing. IF CIP509 Metadata is found it will be updated in `decoded_metadata`. | ||
pub(crate) fn decode_and_validate( | ||
decoded_metadata: &DecodedMetadata, txn: &MultiEraTx, raw_aux_data: &RawAuxData, | ||
) { | ||
// Get the CIP509 metadata if possible | ||
let Some(k509) = raw_aux_data.get_metadata(LABEL) else { | ||
return; | ||
}; | ||
|
||
let mut validation_report = ValidationReport::new(); | ||
let mut decoder = Decoder::new(k509.as_slice()); | ||
|
||
let cip509 = match RbacRegCip509::decode(&mut decoder, &mut ()) { | ||
Ok(metadata) => metadata, | ||
Err(e) => { | ||
Cip509::default().validation_failure( | ||
&format!("Failed to decode CIP509 metadata: {e}"), | ||
&mut validation_report, | ||
decoded_metadata, | ||
); | ||
return; | ||
}, | ||
}; | ||
|
||
// Validate the decoded metadata | ||
let validation = cip509.validate(txn, &mut validation_report); | ||
|
||
// Create a Cip509 struct and insert it into decoded_metadata | ||
decoded_metadata.0.insert( | ||
LABEL, | ||
Arc::new(DecodedMetadataItem { | ||
value: DecodedMetadataValues::Cip509(Arc::new(Cip509 { cip509, validation })), | ||
report: validation_report.clone(), | ||
}), | ||
); | ||
} | ||
|
||
/// Handle validation failure. | ||
fn validation_failure( | ||
&self, reason: &str, validation_report: &mut ValidationReport, | ||
decoded_metadata: &DecodedMetadata, | ||
) { | ||
validation_report.push(reason.into()); | ||
decoded_metadata.0.insert( | ||
LABEL, | ||
Arc::new(DecodedMetadataItem { | ||
value: DecodedMetadataValues::Cip509(Arc::new(self.clone()).clone()), | ||
report: validation_report.clone(), | ||
}), | ||
); | ||
} | ||
} |
215 changes: 0 additions & 215 deletions
215
rust/cardano-chain-follower/src/metadata/cip509/decode_helper.rs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.