/// Perform a change on a canister by upgrading it or
/// reinstalling entirely, depending on the `how` argument.
/// Argument `wasm` is ensured to have a different
/// hash relative to the current binary.
/// In argument `arg` additional arguments can be provided
/// that serve as input to the upgrade hook or as init arguments
/// to the fresh installation.
///
/// This is an internal method.
Perform a change on a canister by upgrading it or
reinstalling entirely, depending on the `how` argument.
Argument `wasm` is ensured to have a different
hash relative to the current binary.
In argument `arg` additional arguments can be provided
that serve as input to the upgrade hook or as init arguments
to the fresh installation.

This is an internal method.
Perform a change on a canister by upgrading it or reinstalling entirely depending on the ` how ` argument . Argument ` wasm ` is ensured to have a different hash relative to the current binary . In argument ` arg ` additional arguments can be provided that serve as input to the upgrade hook or as init arguments to the fresh installation . This is an internal method .
async fn change_nns_canister_by_proposal(
    how: CanisterInstallMode,
    canister_id: CanisterId,
    governance: &Canister<'_>,
    root: &Canister<'_>,
    stop_before_installing: bool,
    wasm: Wasm,
    arg: Option<Vec<u8>>,
) {
    let wasm = wasm.bytes();
    let new_module_hash = &ic_crypto_sha::Sha256::hash(&wasm);
    let status: CanisterStatusResult = root
        .update_(
            "canister_status",
            candid_one,
            CanisterIdRecord::from(canister_id),
        )
        .await
        .unwrap();
    let old_module_hash = status.module_hash.unwrap();
    assert_ne!(old_module_hash.as_slice(), new_module_hash, "change_nns_canister_by_proposal: both module hashes prev, cur are the same {:?}, but they should be different for upgrade", old_module_hash);
    let proposal_payload =
        ChangeNnsCanisterProposalPayload::new(stop_before_installing, how, canister_id)
            .with_wasm(wasm);
    let proposal_payload = if let Some(arg) = arg {
        proposal_payload.with_arg(arg)
    } else {
        proposal_payload
    };
    // Submitting a proposal also implicitly records a vote from the proposer,
    // which with TEST_NEURON_1 is enough to trigger execution.
    submit_external_update_proposal(
        governance,
        Sender::from_keypair(&TEST_NEURON_1_OWNER_KEYPAIR),
        NeuronId(TEST_NEURON_1_ID),
        NnsFunction::NnsCanisterUpgrade,
        proposal_payload,
        "Upgrade NNS Canister".to_string(),
        "<proposal created by change_nns_canister_by_proposal>".to_string(),
    )
    .await;
    // Wait 'till the hash matches and the canister is running again.
    loop {
        let status: CanisterStatusResult = root
            .update_(
                "canister_status",
                candid_one,
                CanisterIdRecord::from(canister_id),
            )
            .await
            .unwrap();
        if status.module_hash.unwrap().as_slice() == new_module_hash && status.status == Running {
            break;
        }
    }
}
async fn change_nns_canister_by_proposal ( how : CanisterInstallMode , canister_id : CanisterId , governance : & Canister < ' _ > , root : & Canister < ' _ > , stop_before_installing : bool , wasm : Wasm , arg : Option < Vec < u8 > > , ) { let wasm = wasm . bytes ( ) ; let new_module_hash = & ic_crypto_sha :: Sha256 :: hash ( & wasm ) ; let status : CanisterStatusResult = root . update_ ( " " , candid_one , CanisterIdRecord :: from ( canister_id ) , ) . await . unwrap ( ) ; let old_module_hash = status . module_hash . unwrap ( ) ; assert_ne ! ( old_module_hash as_slice ( ) new_module_hash " " old_module_hash ) ; let proposal_payload = ChangeNnsCanisterProposalPayload :: new ( stop_before_installing , how , canister_id ) . with_wasm ( wasm ) ; let proposal_payload = if let Some ( arg ) = arg { proposal_payload . with_arg ( arg ) } else { proposal_payload } ; // Submitting a proposal also implicitly records a vote from the proposer, // which with TEST_NEURON_1 is enough to trigger execution. submit_external_update_proposal ( governance , Sender :: from_keypair ( & TEST_NEURON_1_OWNER_KEYPAIR ) , NeuronId ( TEST_NEURON_1_ID ) , NnsFunction :: NnsCanisterUpgrade , proposal_payload , " " . to_string ( ) , " " . to_string ( ) , ) . await ; // Wait 'till the hash matches and the canister is running again. loop { let status : CanisterStatusResult = root . update_ ( " " , candid_one , CanisterIdRecord :: from ( canister_id ) , ) . await . unwrap ( ) ; if status . module_hash . unwrap ( ) . as_slice ( ) == new_module_hash && status . status == Running { break ; } } }
Perform a change on a canister by upgrading it or
reinstalling entirely, depending on the `how` argument.
Perform a change on a canister by upgrading it or reinstalling entirely depending on the ` how ` argument .
how
CanisterInstallMode
canister_id
CanisterId
governance
&Canister<'_>
root
&Canister<'_>
stop_before_installing
bool
wasm
Wasm
arg
Option<Vec<u8>>