@@ -45,7 +45,7 @@ impl RegistrationChain {
4545 /// # Errors
4646 ///
4747 /// 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 > {
4949 let inner = RegistrationChainInner :: new ( cip509) ?;
5050
5151 Ok ( Self {
@@ -61,7 +61,7 @@ impl RegistrationChain {
6161 /// # Errors
6262 ///
6363 /// 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 > {
6565 let latest_signing_pk = self . get_latest_signing_pk_for_role ( & RoleId :: Role0 ) ;
6666 let new_inner = if let Some ( ( signing_pk, _) ) = latest_signing_pk {
6767 self . inner . update ( cip509, signing_pk) ?
@@ -274,7 +274,7 @@ impl RegistrationChainInner {
274274 /// # Errors
275275 ///
276276 /// Returns an error if data is invalid
277- fn new ( cip509 : & Cip509 ) -> anyhow:: Result < Self > {
277+ fn new ( cip509 : Cip509 ) -> anyhow:: Result < Self > {
278278 let context = "Registration Chain new" ;
279279 // Should be chain root, return immediately if not
280280 if cip509. previous_transaction ( ) . is_some ( ) {
@@ -292,25 +292,19 @@ impl RegistrationChainInner {
292292 let current_tx_id_hash = cip509. txn_hash ( ) ;
293293 let validation_signature = cip509. validation_signature ( ) . cloned ( ) ;
294294 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- } ;
303295
304296 // Role data
305297 let mut role_data_history = HashMap :: new ( ) ;
306298 let mut role_data_record = HashMap :: new ( ) ;
307299
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+ }
314308
315309 // There should be role 0 since we already check that the chain root (no previous tx id)
316310 // must contain role 0
@@ -337,6 +331,15 @@ impl RegistrationChainInner {
337331 context,
338332 ) ?;
339333
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+
340343 let purpose = vec ! [ purpose] ;
341344 let certificate_uris = registration. certificate_uris . clone ( ) ;
342345 let mut x509_certs = HashMap :: new ( ) ;
@@ -382,7 +385,7 @@ impl RegistrationChainInner {
382385 /// # Errors
383386 ///
384387 /// 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 > {
386389 let context = "Registration Chain update" ;
387390 let mut new_inner = self . clone ( ) ;
388391
@@ -418,7 +421,7 @@ impl RegistrationChainInner {
418421 }
419422
420423 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 ( ) {
422425 Ok ( v) => v,
423426 Err ( e) => {
424427 let error = format ! ( "Invalid Cip509: {e:?}" ) ;
@@ -516,7 +519,7 @@ mod test {
516519 data. assert_valid ( & registration) ;
517520
518521 // Create a chain with the first registration.
519- let chain = RegistrationChain :: new ( & registration) . unwrap ( ) ;
522+ let chain = RegistrationChain :: new ( registration) . unwrap ( ) ;
520523 assert_eq ! ( chain. purpose( ) , & [ data. purpose] ) ;
521524 assert_eq ! ( 1 , chain. x509_certs( ) . len( ) ) ;
522525 let origin = & chain. x509_certs ( ) . get ( & 0 ) . unwrap ( ) . first ( ) . unwrap ( ) ;
@@ -542,7 +545,7 @@ mod test {
542545 . unwrap ( ) ;
543546 assert ! ( registration. report( ) . is_problematic( ) ) ;
544547
545- let error = chain. update ( & registration) . unwrap_err ( ) ;
548+ let error = chain. update ( registration) . unwrap_err ( ) ;
546549 let error = format ! ( "{error:?}" ) ;
547550 assert ! (
548551 error. contains( "Invalid previous transaction ID" ) ,
@@ -556,7 +559,7 @@ mod test {
556559 . unwrap ( )
557560 . unwrap ( ) ;
558561 data. assert_valid ( & registration) ;
559- let update = chain. update ( & registration) . unwrap ( ) ;
562+ let update = chain. update ( registration) . unwrap ( ) ;
560563 // Current tx hash should be equal to the hash from block 4.
561564 assert_eq ! ( update. current_tx_id_hash( ) , data. txn_hash) ;
562565 assert ! ( update. role_data_record( ) . contains_key( & data. role) ) ;
0 commit comments