11use crate :: anchor_management:: tentative_device_registration;
22use crate :: archive:: ArchiveState ;
33use crate :: assets:: init_assets;
4+ use crate :: authz_utils:: IdentityUpdateError ;
45use crate :: state:: persistent_state;
56use crate :: stats:: event_stats:: all_aggregations_top_n;
67use anchor_management:: registration;
@@ -12,7 +13,7 @@ use ic_canister_sig_creation::signature_map::LABEL_SIG;
1213use ic_cdk:: api:: { caller, set_certified_data, trap} ;
1314use ic_cdk:: call;
1415use ic_cdk_macros:: { init, post_upgrade, pre_upgrade, query, update} ;
15- use internet_identity_interface:: archive:: types:: BufferedEntry ;
16+ use internet_identity_interface:: archive:: types:: { BufferedEntry , Operation } ;
1617use internet_identity_interface:: http_gateway:: { HttpRequest , HttpResponse } ;
1718use internet_identity_interface:: internet_identity:: types:: openid:: {
1819 OpenIdCredentialAddError , OpenIdCredentialRemoveError , OpenIdDelegationError ,
@@ -402,19 +403,34 @@ fn get_default_account(
402403 Ok ( default_account_info)
403404}
404405
406+ impl From < IdentityUpdateError > for SetDefaultAccountError {
407+ fn from ( src : IdentityUpdateError ) -> Self {
408+ match src {
409+ IdentityUpdateError :: Unauthorized ( principal) => Self :: Unauthorized ( principal) ,
410+ IdentityUpdateError :: StorageError ( anchor_number, storage_error) => {
411+ Self :: InternalCanisterError ( format ! (
412+ "Identity: {}, Error: {}" ,
413+ anchor_number, storage_error
414+ ) )
415+ }
416+ }
417+ }
418+ }
419+
405420#[ update]
406421fn set_default_account (
407422 anchor_number : AnchorNumber ,
408423 origin : FrontendHostname ,
409424 account_number : Option < AccountNumber > ,
410425) -> Result < AccountInfo , SetDefaultAccountError > {
411- check_authorization ( anchor_number)
412- . map_err ( |err| SetDefaultAccountError :: Unauthorized ( err. principal ) ) ?;
413-
414- let default_account_info =
415- account_management:: set_default_account_for_origin ( anchor_number, origin, account_number) ?;
416-
417- Ok ( default_account_info)
426+ anchor_operation_with_authz_check ( anchor_number, |_| {
427+ let result = account_management:: set_default_account_for_origin (
428+ anchor_number,
429+ origin,
430+ account_number,
431+ ) ?;
432+ Ok ( ( result, Operation :: SetDefaultAccount ) )
433+ } )
418434}
419435
420436#[ update]
0 commit comments