@@ -45,7 +45,7 @@ impl RegistrationChain {
45
45
/// # Errors
46
46
///
47
47
/// Returns an error if data is invalid
48
- pub fn new ( cip509 : & Cip509 ) -> anyhow:: Result < Self > {
48
+ pub fn new ( cip509 : Cip509 ) -> anyhow:: Result < Self > {
49
49
let inner = RegistrationChainInner :: new ( cip509) ?;
50
50
51
51
Ok ( Self {
@@ -61,7 +61,7 @@ impl RegistrationChain {
61
61
/// # Errors
62
62
///
63
63
/// Returns an error if data is invalid
64
- pub fn update ( & self , cip509 : & Cip509 ) -> anyhow:: Result < Self > {
64
+ pub fn update ( & self , cip509 : Cip509 ) -> anyhow:: Result < Self > {
65
65
let latest_signing_pk = self . get_latest_signing_pk_for_role ( & RoleId :: Role0 ) ;
66
66
let new_inner = if let Some ( ( signing_pk, _) ) = latest_signing_pk {
67
67
self . inner . update ( cip509, signing_pk) ?
@@ -274,7 +274,7 @@ impl RegistrationChainInner {
274
274
/// # Errors
275
275
///
276
276
/// Returns an error if data is invalid
277
- fn new ( cip509 : & Cip509 ) -> anyhow:: Result < Self > {
277
+ fn new ( cip509 : Cip509 ) -> anyhow:: Result < Self > {
278
278
let context = "Registration Chain new" ;
279
279
// Should be chain root, return immediately if not
280
280
if cip509. previous_transaction ( ) . is_some ( ) {
@@ -292,25 +292,19 @@ impl RegistrationChainInner {
292
292
let current_tx_id_hash = cip509. txn_hash ( ) ;
293
293
let validation_signature = cip509. validation_signature ( ) . cloned ( ) ;
294
294
let raw_aux_data = cip509. raw_aux_data ( ) . to_vec ( ) ;
295
- let ( purpose, registration, payment_history) = match cip509. clone ( ) . consume ( ) {
296
- Ok ( v) => v,
297
- Err ( e) => {
298
- let error = format ! ( "Invalid Cip509: {e:?}" ) ;
299
- error ! ( error) ;
300
- bail ! ( error) ;
301
- } ,
302
- } ;
303
295
304
296
// Role data
305
297
let mut role_data_history = HashMap :: new ( ) ;
306
298
let mut role_data_record = HashMap :: new ( ) ;
307
299
308
- update_role_data (
309
- & registration,
310
- & mut role_data_history,
311
- & mut role_data_record,
312
- & point_tx_idx,
313
- ) ;
300
+ if let Some ( registration) = cip509. metadata ( ) {
301
+ update_role_data (
302
+ registration,
303
+ & mut role_data_history,
304
+ & mut role_data_record,
305
+ & point_tx_idx,
306
+ ) ;
307
+ }
314
308
315
309
// There should be role 0 since we already check that the chain root (no previous tx id)
316
310
// must contain role 0
@@ -337,6 +331,15 @@ impl RegistrationChainInner {
337
331
context,
338
332
) ?;
339
333
334
+ let ( purpose, registration, payment_history) = match cip509. consume ( ) {
335
+ Ok ( v) => v,
336
+ Err ( e) => {
337
+ let error = format ! ( "Invalid Cip509: {e:?}" ) ;
338
+ error ! ( error) ;
339
+ bail ! ( error) ;
340
+ } ,
341
+ } ;
342
+
340
343
let purpose = vec ! [ purpose] ;
341
344
let certificate_uris = registration. certificate_uris . clone ( ) ;
342
345
let mut x509_certs = HashMap :: new ( ) ;
@@ -382,7 +385,7 @@ impl RegistrationChainInner {
382
385
/// # Errors
383
386
///
384
387
/// Returns an error if data is invalid
385
- fn update ( & self , cip509 : & Cip509 , signing_pk : VerifyingKey ) -> anyhow:: Result < Self > {
388
+ fn update ( & self , cip509 : Cip509 , signing_pk : VerifyingKey ) -> anyhow:: Result < Self > {
386
389
let context = "Registration Chain update" ;
387
390
let mut new_inner = self . clone ( ) ;
388
391
@@ -418,7 +421,7 @@ impl RegistrationChainInner {
418
421
}
419
422
420
423
let point_tx_idx = cip509. origin ( ) . clone ( ) ;
421
- let ( purpose, registration, payment_history) = match cip509. clone ( ) . consume ( ) {
424
+ let ( purpose, registration, payment_history) = match cip509. consume ( ) {
422
425
Ok ( v) => v,
423
426
Err ( e) => {
424
427
let error = format ! ( "Invalid Cip509: {e:?}" ) ;
@@ -516,7 +519,7 @@ mod test {
516
519
data. assert_valid ( & registration) ;
517
520
518
521
// Create a chain with the first registration.
519
- let chain = RegistrationChain :: new ( & registration) . unwrap ( ) ;
522
+ let chain = RegistrationChain :: new ( registration) . unwrap ( ) ;
520
523
assert_eq ! ( chain. purpose( ) , & [ data. purpose] ) ;
521
524
assert_eq ! ( 1 , chain. x509_certs( ) . len( ) ) ;
522
525
let origin = & chain. x509_certs ( ) . get ( & 0 ) . unwrap ( ) . first ( ) . unwrap ( ) ;
@@ -542,7 +545,7 @@ mod test {
542
545
. unwrap ( ) ;
543
546
assert ! ( registration. report( ) . is_problematic( ) ) ;
544
547
545
- let error = chain. update ( & registration) . unwrap_err ( ) ;
548
+ let error = chain. update ( registration) . unwrap_err ( ) ;
546
549
let error = format ! ( "{error:?}" ) ;
547
550
assert ! (
548
551
error. contains( "Invalid previous transaction ID" ) ,
@@ -556,7 +559,7 @@ mod test {
556
559
. unwrap ( )
557
560
. unwrap ( ) ;
558
561
data. assert_valid ( & registration) ;
559
- let update = chain. update ( & registration) . unwrap ( ) ;
562
+ let update = chain. update ( registration) . unwrap ( ) ;
560
563
// Current tx hash should be equal to the hash from block 4.
561
564
assert_eq ! ( update. current_tx_id_hash( ) , data. txn_hash) ;
562
565
assert ! ( update. role_data_record( ) . contains_key( & data. role) ) ;
0 commit comments