Skip to content

Commit bf15b3e

Browse files
committed
fix(cardano-blockchain-types): add cip36_from_block function
Signed-off-by: bkioshn <[email protected]>
1 parent e281ac5 commit bf15b3e

File tree

1 file changed

+28
-0
lines changed
  • rust/cardano-blockchain-types/src/metadata/cip36

1 file changed

+28
-0
lines changed

rust/cardano-blockchain-types/src/metadata/cip36/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ pub mod registration_witness;
55
mod validation;
66
pub mod voting_pk;
77

8+
use std::collections::HashMap;
9+
810
use catalyst_types::problem_report::ProblemReport;
911
use ed25519_dalek::VerifyingKey;
1012
use key_registration::Cip36KeyRegistration;
@@ -153,6 +155,32 @@ impl Cip36 {
153155
Ok(cip36)
154156
}
155157

158+
/// Collect all CIP-36 registrations from a block.
159+
///
160+
/// # Parameters
161+
///
162+
/// * `block` - The block that wanted to be processed.
163+
/// * `is_catalyst_strict` - Is this a Catalyst strict registration?
164+
///
165+
/// # Returns
166+
///
167+
/// A map of transaction index to the Result of CIP-36 and its errors.
168+
/// None if there is no CIP-36 registration found in the block.
169+
#[must_use]
170+
pub fn cip36_from_block(
171+
block: &MultiEraBlock, is_catalyst_strict: bool,
172+
) -> Option<HashMap<TxnIndex, Result<Cip36, Cip36Error>>> {
173+
let mut cip36_map = HashMap::new();
174+
175+
for (txn_idx, _tx) in block.decode().txs().iter().enumerate() {
176+
let txn_idx: TxnIndex = txn_idx.into();
177+
let cip36 = Cip36::new(block, txn_idx, is_catalyst_strict);
178+
cip36_map.insert(txn_idx, cip36);
179+
}
180+
181+
cip36_map.is_empty().then_some(cip36_map)
182+
}
183+
156184
/// Get the `is_cip36` flag from the registration.
157185
/// True if it is CIP-36 format, false if CIP-15 format.
158186
pub fn is_cip36(&self) -> Option<bool> {

0 commit comments

Comments
 (0)