Skip to content

Commit 358b640

Browse files
committed
fix(cardano-blockchain-types): return type for cip36 constructor
Signed-off-by: bkioshn <[email protected]>
1 parent a919a6f commit 358b640

File tree

1 file changed

+18
-11
lines changed
  • rust/cardano-blockchain-types/src/metadata/cip36

1 file changed

+18
-11
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,25 @@ impl Cip36 {
9898
/// * `txn_idx` - The transaction index that contain the auxiliary data.
9999
/// * `is_catalyst_strict` - Is this a Catalyst strict registration?
100100
///
101+
/// # Returns
102+
/// None if the metadata is not in the block at given index.
103+
///
101104
/// # Errors
102105
///
103106
/// If the CIP-36 key registration or registration witness metadata is not found.
104107
/// or if the CIP-36 key registration or registration witness metadata cannot be
105108
/// decoded.
106109
pub fn new(
107110
block: &MultiEraBlock, txn_idx: TxnIndex, is_catalyst_strict: bool,
108-
) -> Result<Cip36, Cip36Error> {
111+
) -> Result<Option<Cip36>, Cip36Error> {
109112
// Record of errors found during decoding and validation
110113
let mut err_report = ProblemReport::new("CIP36 Registration Decoding and Validation");
111114

112115
let Some(k61284) = block.txn_metadata(txn_idx, MetadatumLabel::CIP036_REGISTRATION) else {
113-
return Err(Cip36Error {
114-
error: anyhow::anyhow!("CIP-36 key registration metadata not found"),
115-
report: err_report,
116-
});
116+
return Ok(None);
117117
};
118118
let Some(k61285) = block.txn_metadata(txn_idx, MetadatumLabel::CIP036_WITNESS) else {
119-
return Err(Cip36Error {
120-
error: anyhow::anyhow!("CIP-36 registration witness metadata not found"),
121-
report: err_report,
122-
});
119+
return Ok(None);
123120
};
124121

125122
let slot = block.decode().slot();
@@ -185,7 +182,7 @@ impl Cip36 {
185182
cip36.validate_voting_keys();
186183
cip36.validate_purpose();
187184

188-
Ok(cip36)
185+
Ok(Some(cip36))
189186
}
190187

191188
/// Collect all CIP-36 registrations from a block.
@@ -208,7 +205,17 @@ impl Cip36 {
208205
for (txn_idx, _tx) in block.decode().txs().iter().enumerate() {
209206
let txn_idx: TxnIndex = txn_idx.into();
210207
let cip36 = Cip36::new(block, txn_idx, is_catalyst_strict);
211-
cip36_map.insert(txn_idx, cip36);
208+
match cip36 {
209+
Ok(Some(cip36)) => {
210+
cip36_map.insert(txn_idx, Ok(cip36));
211+
},
212+
// None - no CIP-36 metadata found in the block
213+
Ok(None) => {},
214+
// Error - found CIP-36 but there is some error
215+
Err(e) => {
216+
cip36_map.insert(txn_idx, Err(e));
217+
},
218+
}
212219
}
213220

214221
cip36_map.is_empty().then_some(cip36_map)

0 commit comments

Comments
 (0)