Skip to content

Commit b9d9c4f

Browse files
Store the point of latest transaction in RegistrationChain (#329)
1 parent 34094d4 commit b9d9c4f

File tree

1 file changed

+14
-6
lines changed
  • rust/rbac-registration/src/registration/cardano

1 file changed

+14
-6
lines changed

rust/rbac-registration/src/registration/cardano/mod.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99

1010
use anyhow::{bail, Context};
1111
use c509_certificate::c509::C509;
12-
use cardano_blockchain_types::{StakeAddress, TransactionId};
12+
use cardano_blockchain_types::{Point, StakeAddress, TransactionId};
1313
use catalyst_types::{
1414
catalyst_id::{key_rotation::KeyRotation, role_index::RoleId, CatalystId},
1515
conversion::zero_out_last_n_bytes,
@@ -86,7 +86,14 @@ impl RegistrationChain {
8686
/// Get the current transaction ID hash.
8787
#[must_use]
8888
pub fn current_tx_id_hash(&self) -> TransactionId {
89-
self.inner.current_tx_id_hash
89+
*self.inner.current_tx_id_hash.data()
90+
}
91+
92+
/// Returns a point (slot and transaction index) of the latest transaction in the
93+
/// registration chain.
94+
#[must_use]
95+
pub fn current_point(&self) -> &Point {
96+
self.inner.current_tx_id_hash.point()
9097
}
9198

9299
/// Get a list of purpose for this registration chain.
@@ -234,7 +241,7 @@ struct RegistrationChainInner {
234241
/// A Catalyst ID.
235242
catalyst_id: CatalystId,
236243
/// The current transaction ID hash (32 bytes)
237-
current_tx_id_hash: TransactionId,
244+
current_tx_id_hash: PointData<TransactionId>,
238245
/// List of purpose for this registration chain
239246
purpose: Vec<UuidV4>,
240247

@@ -289,7 +296,7 @@ impl RegistrationChainInner {
289296
};
290297

291298
let point_tx_idx = cip509.origin().clone();
292-
let current_tx_id_hash = cip509.txn_hash();
299+
let current_tx_id_hash = PointData::new(point_tx_idx.clone(), cip509.txn_hash());
293300
let validation_signature = cip509.validation_signature().cloned();
294301
let raw_aux_data = cip509.raw_aux_data().to_vec();
295302

@@ -397,7 +404,7 @@ impl RegistrationChainInner {
397404
};
398405

399406
// Previous transaction ID in the CIP509 should equal to the current transaction ID
400-
if prv_tx_id == self.current_tx_id_hash {
407+
if &prv_tx_id == self.current_tx_id_hash.data() {
401408
// Perform signature validation
402409
// This should be done before updating the signing key
403410
check_validation_signature(
@@ -409,7 +416,8 @@ impl RegistrationChainInner {
409416
)?;
410417

411418
// If successful, update the chain current transaction ID hash
412-
new_inner.current_tx_id_hash = cip509.txn_hash();
419+
new_inner.current_tx_id_hash =
420+
PointData::new(cip509.origin().clone(), cip509.txn_hash());
413421
} else {
414422
cip509.report().invalid_value(
415423
"previous transaction ID",

0 commit comments

Comments
 (0)