-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Versioning of on-chain
Identity
(#1435)
* add package version, identity version and upgrade proposal * rust implementation of upgrade identity proposal * commit missing files * review comments * fix merge issues & emit events when dealing with upgrade proposals
- Loading branch information
Showing
9 changed files
with
253 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
identity_iota_core/packages/iota_identity/sources/proposals/upgrade.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
module iota_identity::upgrade_proposal { | ||
/// Proposal's action used to upgrade an `Identity` to the package's current version. | ||
public struct Upgrade has store, copy, drop {} | ||
|
||
/// Creates a new `Upgrade` action. | ||
public fun new(): Upgrade { | ||
Upgrade {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright 2020-2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::marker::PhantomData; | ||
|
||
use crate::rebased::client::IdentityClient; | ||
use crate::rebased::client::IotaKeySignature; | ||
use crate::rebased::sui::move_calls; | ||
use async_trait::async_trait; | ||
use iota_sdk::rpc_types::IotaTransactionBlockResponse; | ||
use iota_sdk::types::base_types::ObjectID; | ||
use iota_sdk::types::TypeTag; | ||
use secret_storage::Signer; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
|
||
use crate::rebased::migration::OnChainIdentity; | ||
use crate::rebased::migration::Proposal; | ||
use crate::rebased::utils::MoveType; | ||
use crate::rebased::Error; | ||
|
||
use super::CreateProposalTx; | ||
use super::ExecuteProposalTx; | ||
use super::ProposalT; | ||
|
||
/// Action for upgrading the version of an on-chain identity to the package's version. | ||
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)] | ||
pub struct Upgrade; | ||
|
||
impl Upgrade { | ||
/// Creates a new [`Upgrade`] action. | ||
pub const fn new() -> Self { | ||
Self | ||
} | ||
} | ||
|
||
impl MoveType for Upgrade { | ||
fn move_type(package: ObjectID) -> TypeTag { | ||
format!("{package}::upgrade_proposal::Upgrade") | ||
.parse() | ||
.expect("valid utf8") | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl ProposalT for Proposal<Upgrade> { | ||
type Action = Upgrade; | ||
type Output = (); | ||
|
||
async fn create<'i, S>( | ||
_action: Self::Action, | ||
expiration: Option<u64>, | ||
identity: &'i mut OnChainIdentity, | ||
client: &IdentityClient<S>, | ||
) -> Result<CreateProposalTx<'i, Self::Action>, Error> | ||
where | ||
S: Signer<IotaKeySignature> + Sync, | ||
{ | ||
let identity_ref = client | ||
.get_object_ref_by_id(identity.id()) | ||
.await? | ||
.expect("identity exists on-chain"); | ||
let controller_cap_ref = identity.get_controller_cap(client).await?; | ||
let sender_vp = identity | ||
.controller_voting_power(controller_cap_ref.0) | ||
.expect("controller exists"); | ||
let chained_execution = sender_vp >= identity.threshold(); | ||
let tx = | ||
move_calls::identity::propose_upgrade(identity_ref, controller_cap_ref, expiration, client.package_id()) | ||
.map_err(|e| Error::TransactionBuildingFailed(e.to_string()))?; | ||
|
||
Ok(CreateProposalTx { | ||
identity, | ||
tx, | ||
chained_execution, | ||
_action: PhantomData, | ||
}) | ||
} | ||
|
||
async fn into_tx<'i, S>( | ||
self, | ||
identity: &'i mut OnChainIdentity, | ||
client: &IdentityClient<S>, | ||
) -> Result<ExecuteProposalTx<'i, Self::Action>, Error> | ||
where | ||
S: Signer<IotaKeySignature> + Sync, | ||
{ | ||
let proposal_id = self.id(); | ||
let identity_ref = client | ||
.get_object_ref_by_id(identity.id()) | ||
.await? | ||
.expect("identity exists on-chain"); | ||
let controller_cap_ref = identity.get_controller_cap(client).await?; | ||
|
||
let tx = | ||
move_calls::identity::execute_upgrade(identity_ref, controller_cap_ref, proposal_id, client.package_id()) | ||
.map_err(|e| Error::TransactionBuildingFailed(e.to_string()))?; | ||
|
||
Ok(ExecuteProposalTx { | ||
identity, | ||
tx, | ||
_action: PhantomData, | ||
}) | ||
} | ||
|
||
fn parse_tx_effects(_tx_response: &IotaTransactionBlockResponse) -> Result<Self::Output, Error> { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.