Skip to content

Commit

Permalink
update MoveResource trait
Browse files Browse the repository at this point in the history
  • Loading branch information
nkysg committed Sep 20, 2024
1 parent ba0b75c commit 9477841
Show file tree
Hide file tree
Showing 27 changed files with 100 additions and 52 deletions.
6 changes: 4 additions & 2 deletions vm/types/src/account_config/events/accept_token_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::token::token_code::TokenCode;
use anyhow::Result;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

/// Struct that represents a AcceptTokenEvent.
Expand All @@ -31,6 +31,8 @@ impl AcceptTokenEvent {
}

impl MoveStructType for AcceptTokenEvent {
const STRUCT_NAME: &'static IdentStr = ident_str!("AcceptTokenEvent");
const MODULE_NAME: &'static IdentStr = ident_str!(ACCOUNT_MODULE_NAME);
const STRUCT_NAME: &'static IdentStr = ident_str!("AcceptTokenEvent");
}

impl MoveResource for AcceptTokenEvent {}
6 changes: 4 additions & 2 deletions vm/types/src/account_config/events/account_deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::token::token_code::TokenCode;
use anyhow::Result;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

/// Struct that represents a ReceivedPaymentEvent.
Expand Down Expand Up @@ -48,6 +48,8 @@ impl DepositEvent {
}

impl MoveStructType for DepositEvent {
const STRUCT_NAME: &'static IdentStr = ident_str!("DepositEvent");
const MODULE_NAME: &'static IdentStr = ident_str!(ACCOUNT_MODULE_NAME);
const STRUCT_NAME: &'static IdentStr = ident_str!("DepositEvent");
}

impl MoveResource for DepositEvent {}
6 changes: 4 additions & 2 deletions vm/types/src/account_config/events/account_withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::token::token_code::TokenCode;
use anyhow::Result;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

/// Struct that represents a SentPaymentEvent.
Expand Down Expand Up @@ -47,6 +47,8 @@ impl WithdrawEvent {
}

impl MoveStructType for WithdrawEvent {
const STRUCT_NAME: &'static IdentStr = ident_str!("WithdrawEvent");
const MODULE_NAME: &'static IdentStr = ident_str!(ACCOUNT_MODULE_NAME);
const STRUCT_NAME: &'static IdentStr = ident_str!("WithdrawEvent");
}

impl MoveResource for WithdrawEvent {}
6 changes: 4 additions & 2 deletions vm/types/src/account_config/events/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::account_address::AccountAddress;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
Expand All @@ -21,6 +21,8 @@ impl NewBlockEvent {
}

impl MoveStructType for NewBlockEvent {
const STRUCT_NAME: &'static IdentStr = ident_str!("NewBlockEvent");
const MODULE_NAME: &'static IdentStr = ident_str!("Block");
const STRUCT_NAME: &'static IdentStr = ident_str!("NewBlockEvent");
}

impl MoveResource for NewBlockEvent {}
6 changes: 4 additions & 2 deletions vm/types/src/account_config/events/block_reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::Result;
use move_core_types::account_address::AccountAddress;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -23,6 +23,8 @@ impl BlockRewardEvent {
}

impl MoveStructType for BlockRewardEvent {
const STRUCT_NAME: &'static IdentStr = ident_str!("BlockRewardEvent");
const MODULE_NAME: &'static IdentStr = ident_str!("BlockReward");
const STRUCT_NAME: &'static IdentStr = ident_str!("BlockRewardEvent");
}

impl MoveResource for BlockRewardEvent {}
6 changes: 4 additions & 2 deletions vm/types/src/account_config/events/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::token::token_code::TokenCode;
use anyhow::Result;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

/// Struct that represents a BurnEvent.
Expand All @@ -33,6 +33,8 @@ impl BurnEvent {
}

impl MoveStructType for BurnEvent {
const STRUCT_NAME: &'static IdentStr = ident_str!("BurnEvent");
const MODULE_NAME: &'static IdentStr = ident_str!(TOKEN_MODULE_NAME);
const STRUCT_NAME: &'static IdentStr = ident_str!("BurnEvent");
}

impl MoveResource for BurnEvent {}
4 changes: 2 additions & 2 deletions vm/types/src/account_config/events/config_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use move_core_types::account_address::AccountAddress;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use serde::Serialize;
use serde::{Deserializer, Serialize};

//TODO support deserialize
#[derive(Debug, Serialize)]
Expand All @@ -19,9 +19,9 @@ pub struct ConfigChangeEvent<V: OnChainConfig> {
impl<V> ConfigChangeEvent<V> where V: OnChainConfig {}

impl<V: OnChainConfig> MoveStructType for ConfigChangeEvent<V> {
const MODULE_NAME: &'static IdentStr = ident_str!("Config");
const STRUCT_NAME: &'static IdentStr = ident_str!("ConfigChangeEvent");
fn type_args() -> Vec<TypeTag> {
vec![TypeTag::Struct(Box::new(V::config_id().struct_tag()))]
}
const MODULE_NAME: &'static IdentStr = ident_str!("Config");
}
10 changes: 7 additions & 3 deletions vm/types/src/account_config/events/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::Result;
use move_core_types::account_address::AccountAddress;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

#[derive(Clone, Copy, Serialize, Deserialize)]
Expand All @@ -19,10 +19,12 @@ impl ProposalCreatedEvent {
}
}
impl MoveStructType for ProposalCreatedEvent {
const STRUCT_NAME: &'static IdentStr = ident_str!("ProposalCreatedEvent");
const MODULE_NAME: &'static IdentStr = ident_str!("Dao");
const STRUCT_NAME: &'static IdentStr = ident_str!("ProposalCreatedEvent");
}

impl MoveResource for ProposalCreatedEvent {}

/// emitted when user vote/revoke_vote.
#[derive(Clone, Copy, Serialize, Deserialize)]
pub struct VoteChangedEvent {
Expand All @@ -35,10 +37,12 @@ pub struct VoteChangedEvent {
}

impl MoveStructType for VoteChangedEvent {
const STRUCT_NAME: &'static IdentStr = ident_str!("VoteChangedEvent");
const MODULE_NAME: &'static IdentStr = ident_str!("Dao");
const STRUCT_NAME: &'static IdentStr = ident_str!("VoteChangedEvent");
}

impl MoveResource for VoteChangedEvent {}

impl VoteChangedEvent {
pub fn try_from_bytes(bytes: &[u8]) -> Result<Self> {
bcs_ext::from_bytes(bytes).map_err(Into::into)
Expand Down
6 changes: 4 additions & 2 deletions vm/types/src/account_config/events/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::token::token_code::TokenCode;
use anyhow::Result;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

/// Struct that represents a MintEvent.
Expand All @@ -33,6 +33,8 @@ impl MintEvent {
}

impl MoveStructType for MintEvent {
const STRUCT_NAME: &'static IdentStr = ident_str!("MintEvent");
const MODULE_NAME: &'static IdentStr = ident_str!(TOKEN_MODULE_NAME);
const STRUCT_NAME: &'static IdentStr = ident_str!("MintEvent");
}

impl MoveResource for MintEvent {}
6 changes: 4 additions & 2 deletions vm/types/src/account_config/events/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::account_address::AccountAddress;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};
use starcoin_crypto::HashValue;

Expand All @@ -21,6 +21,8 @@ impl UpgradeEvent {
}

impl MoveStructType for UpgradeEvent {
const STRUCT_NAME: &'static IdentStr = ident_str!("UpgradeEvent");
const MODULE_NAME: &'static IdentStr = ident_str!("PackageTxnManager");
const STRUCT_NAME: &'static IdentStr = ident_str!("UpgradeEvent");
}

impl MoveResource for UpgradeEvent {}
2 changes: 1 addition & 1 deletion vm/types/src/account_config/resources/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ impl AccountResource {
}

impl MoveStructType for AccountResource {
const STRUCT_NAME: &'static IdentStr = ident_str!("Account");
const MODULE_NAME: &'static IdentStr = ident_str!(ACCOUNT_MODULE_NAME);
const STRUCT_NAME: &'static IdentStr = ident_str!("Account");
}

impl MoveResource for AccountResource {}
6 changes: 4 additions & 2 deletions vm/types/src/account_config/resources/auto_accept_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::token::token_code::TokenCode;
use move_core_types::ident_str;
use move_core_types::identifier::{IdentStr, Identifier};
use move_core_types::language_storage::{StructTag, TypeTag};
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

/// The AutoAcceptToken resource held under an account.
Expand Down Expand Up @@ -38,6 +38,8 @@ impl AutoAcceptToken {
}

impl MoveStructType for AutoAcceptToken {
const STRUCT_NAME: &'static IdentStr = ident_str!("AutoAcceptToken");
const MODULE_NAME: &'static IdentStr = ident_str!(ACCOUNT_MODULE_NAME);
const STRUCT_NAME: &'static IdentStr = ident_str!("AutoAcceptToken");
}

impl MoveResource for AutoAcceptToken {}
6 changes: 4 additions & 2 deletions vm/types/src/account_config/resources/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
use move_core_types::ident_str;
use move_core_types::identifier::{IdentStr, Identifier};
use move_core_types::language_storage::{StructTag, TypeTag};
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

/// The balance resource held under an account.
Expand Down Expand Up @@ -61,9 +61,11 @@ impl BalanceResource {
}

impl MoveStructType for BalanceResource {
const MODULE_NAME: &'static IdentStr = ident_str!(ACCOUNT_MODULE_NAME);
const STRUCT_NAME: &'static IdentStr = ident_str!("Balance");
fn type_args() -> Vec<TypeTag> {
vec![stc_type_tag()]
}
const MODULE_NAME: &'static IdentStr = ident_str!(ACCOUNT_MODULE_NAME);
}

impl MoveResource for BalanceResource {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::{account_address::AccountAddress, account_config::constants::ACCOUNT_MODULE_NAME};
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -19,6 +19,8 @@ impl KeyRotationCapabilityResource {
}

impl MoveStructType for KeyRotationCapabilityResource {
const STRUCT_NAME: &'static IdentStr = ident_str!("KeyRotationCapability");
const MODULE_NAME: &'static IdentStr = ident_str!(ACCOUNT_MODULE_NAME);
const STRUCT_NAME: &'static IdentStr = ident_str!("KeyRotationCapability");
}

impl MoveResource for KeyRotationCapabilityResource {}
18 changes: 14 additions & 4 deletions vm/types/src/account_config/resources/module_upgrade_strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::account_address::AccountAddress;
use crate::event::EventHandle;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

pub const _STRATEGY_ARBITRARY: u8 = 0;
Expand All @@ -30,10 +30,12 @@ impl ModuleUpgradeStrategy {
}

impl MoveStructType for ModuleUpgradeStrategy {
const STRUCT_NAME: &'static IdentStr = ident_str!("ModuleUpgradeStrategy");
const MODULE_NAME: &'static IdentStr = ident_str!("PackageTxnManager");
const STRUCT_NAME: &'static IdentStr = ident_str!("ModuleUpgradeStrategy");
}

impl MoveResource for ModuleUpgradeStrategy {}

pub fn access_path_for_module_upgrade_strategy(address: AccountAddress) -> AccessPath {
AccessPath::resource_access_path(address, ModuleUpgradeStrategy::struct_tag())
}
Expand All @@ -54,10 +56,12 @@ impl TwoPhaseUpgradeV2Resource {
}
}
impl MoveStructType for TwoPhaseUpgradeV2Resource {
const STRUCT_NAME: &'static IdentStr = ident_str!("TwoPhaseUpgradeV2");
const MODULE_NAME: &'static IdentStr = ident_str!("PackageTxnManager");
const STRUCT_NAME: &'static IdentStr = ident_str!("TwoPhaseUpgradeV2");
}

impl MoveResource for TwoPhaseUpgradeV2Resource {}

pub fn access_path_for_two_phase_upgrade_v2(address: AccountAddress) -> AccessPath {
AccessPath::resource_access_path(address, TwoPhaseUpgradeV2Resource::struct_tag())
}
Expand All @@ -67,10 +71,12 @@ pub struct TwoPhaseUpgradeConfigResource {
min_time_limit: u64,
}
impl MoveStructType for TwoPhaseUpgradeConfigResource {
const STRUCT_NAME: &'static IdentStr = ident_str!("TwoPhaseUpgradeConfig");
const MODULE_NAME: &'static IdentStr = ident_str!("PackageTxnManager");
const STRUCT_NAME: &'static IdentStr = ident_str!("TwoPhaseUpgradeConfig");
}

impl MoveResource for TwoPhaseUpgradeConfigResource {}

#[derive(Debug, Serialize, Deserialize)]
pub struct UpgradePlanV2Resource {
package_hash: Vec<u8>,
Expand All @@ -83,6 +89,8 @@ impl MoveStructType for UpgradePlanV2Resource {
const STRUCT_NAME: &'static IdentStr = ident_str!("UpgradePlanV2");
}

impl MoveResource for UpgradePlanV2Resource {}

#[derive(Debug, Serialize, Deserialize)]
struct ModifyConfigCapabilityResource {
account_address: AccountAddress,
Expand All @@ -92,3 +100,5 @@ impl MoveStructType for ModifyConfigCapabilityResource {
const MODULE_NAME: &'static IdentStr = ident_str!("PackageTxnManager");
const STRUCT_NAME: &'static IdentStr = ident_str!("ModifyConfigCapability");
}

impl MoveResource for ModifyConfigCapabilityResource {}
6 changes: 4 additions & 2 deletions vm/types/src/account_config/resources/withdraw_capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::{account_address::AccountAddress, account_config::constants::ACCOUNT_MODULE_NAME};
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -19,6 +19,8 @@ impl WithdrawCapabilityResource {
}

impl MoveStructType for WithdrawCapabilityResource {
const STRUCT_NAME: &'static IdentStr = ident_str!("WithdrawCapability");
const MODULE_NAME: &'static IdentStr = ident_str!(ACCOUNT_MODULE_NAME);
const STRUCT_NAME: &'static IdentStr = ident_str!("WithdrawCapability");
}

impl MoveResource for WithdrawCapabilityResource {}
2 changes: 1 addition & 1 deletion vm/types/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ impl Into<u8> for ChainId {
}

impl MoveStructType for ChainId {
const STRUCT_NAME: &'static IdentStr = ident_str!("ChainId");
const MODULE_NAME: &'static IdentStr = ident_str!("ChainId");
const STRUCT_NAME: &'static IdentStr = ident_str!("ChainId");
}

impl MoveResource for ChainId {}
6 changes: 4 additions & 2 deletions vm/types/src/on_chain_config/move_lang_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::on_chain_config::OnChainConfig;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use move_core_types::move_resource::MoveStructType;
use move_core_types::move_resource::{MoveResource, MoveStructType};
use serde::{Deserialize, Serialize};

const MV_LANG_VERSION_MODULE_NAME: &str = "LanguageVersion";
Expand All @@ -21,6 +21,8 @@ impl OnChainConfig for MoveLanguageVersion {
const TYPE_IDENTIFIER: &'static str = MV_LANG_VERSION_STRUCT_NAME;
}
impl MoveStructType for MoveLanguageVersion {
const STRUCT_NAME: &'static IdentStr = ident_str!(MV_LANG_VERSION_STRUCT_NAME);
const MODULE_NAME: &'static IdentStr = ident_str!(MV_LANG_VERSION_MODULE_NAME);
const STRUCT_NAME: &'static IdentStr = ident_str!(MV_LANG_VERSION_STRUCT_NAME);
}

impl MoveResource for MoveLanguageVersion {}
Loading

0 comments on commit 9477841

Please sign in to comment.