sol_did/instructions/
update.rs1use crate::state::{DidAccount, Secp256k1RawSignature};
2use crate::{Service, VerificationMethod};
3use anchor_lang::prelude::*;
4
5pub fn update(
6 ctx: Context<Update>,
7 update_arg: UpdateArg,
8 eth_signature: Option<Secp256k1RawSignature>,
9) -> Result<()> {
10 let data = &mut ctx.accounts.did_data;
12 if eth_signature.is_some() {
13 data.nonce += 1;
14 }
15
16 data.set_services(update_arg.services, false)?;
17 data.set_verification_methods(Vec::new(), update_arg.verification_methods)?;
18 data.set_native_controllers(update_arg.native_controllers)?;
19 data.set_other_controllers(update_arg.other_controllers)?;
20
21 Ok(())
22}
23
24#[derive(Accounts)]
25#[instruction(update_arg: UpdateArg, eth_signature: Option<Secp256k1RawSignature>)]
26pub struct Update<'info> {
27 #[account(
28 mut,
29 seeds = [b"did-account", did_data.initial_verification_method.key_data.as_ref()],
30 bump = did_data.bump,
31 constraint = did_data.find_authority_constraint(&authority.key(), &update_arg.try_to_vec().unwrap(), eth_signature.as_ref(), None).is_some()
32 )]
33 pub did_data: Account<'info, DidAccount>,
34 pub authority: Signer<'info>,
35}
36
37#[derive(AnchorSerialize, AnchorDeserialize, Clone)]
39pub struct UpdateArg {
40 pub verification_methods: Vec<VerificationMethod>,
42 pub services: Vec<Service>,
44 pub native_controllers: Vec<Pubkey>,
46 pub other_controllers: Vec<String>,
48}