From 4ba3415ed53a8e11277b48d21bfac2286d9a5212 Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Fri, 22 Nov 2024 15:17:33 -0500 Subject: [PATCH] add ol specific Move resource bindings --- compatibility/src/version_five/balance_v5.rs | 11 ++- .../src/version_five/dummy_tx_types.todo | 67 ------------- compatibility/src/version_five/freezing_v5.rs | 1 - .../src/version_five/language_storage_v5.rs | 10 +- compatibility/src/version_five/mod.rs | 5 + compatibility/src/version_five/ol_ancestry.rs | 40 ++++++++ .../src/version_five/ol_cumulative_deposit.rs | 38 ++++++++ compatibility/src/version_five/ol_receipts.rs | 41 ++++++++ .../src/version_five/ol_tower_state.rs | 47 +++++++++ compatibility/src/version_five/ol_wallet.rs | 97 +++++++++++++++++++ 10 files changed, 280 insertions(+), 77 deletions(-) delete mode 100644 compatibility/src/version_five/dummy_tx_types.todo create mode 100644 compatibility/src/version_five/ol_ancestry.rs create mode 100644 compatibility/src/version_five/ol_cumulative_deposit.rs create mode 100644 compatibility/src/version_five/ol_receipts.rs create mode 100644 compatibility/src/version_five/ol_tower_state.rs create mode 100644 compatibility/src/version_five/ol_wallet.rs diff --git a/compatibility/src/version_five/balance_v5.rs b/compatibility/src/version_five/balance_v5.rs index f33fbd3b0..13f53cadd 100644 --- a/compatibility/src/version_five/balance_v5.rs +++ b/compatibility/src/version_five/balance_v5.rs @@ -1,10 +1,13 @@ // Copyright (c) The Diem Core Contributors // SPDX-License-Identifier: Apache-2.0 -use crate::version_five::language_storage_v5::{StructTagV5, TypeTagV5}; -use crate::version_five::legacy_address_v5::LEGACY_CORE_CODE_ADDRESS; -use crate::version_five::move_resource_v5::MoveResourceV5; -use crate::version_five::move_resource_v5::MoveStructTypeV5; +use crate::version_five::{ + language_storage_v5::{StructTagV5, TypeTagV5}, + legacy_address_v5::LEGACY_CORE_CODE_ADDRESS, + move_resource_v5::MoveResourceV5, + move_resource_v5::MoveStructTypeV5, +}; + use move_core_types::{ident_str, identifier::IdentStr}; use serde::{Deserialize, Serialize}; /// The balance resource held under an account. diff --git a/compatibility/src/version_five/dummy_tx_types.todo b/compatibility/src/version_five/dummy_tx_types.todo deleted file mode 100644 index 155ad0db4..000000000 --- a/compatibility/src/version_five/dummy_tx_types.todo +++ /dev/null @@ -1,67 +0,0 @@ - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub enum DummyTransactionV5 { - /// Transaction submitted by the user. e.g: P2P payment transaction, publishing module - /// transaction, etc. - /// TODO: We need to rename SignedTransaction to SignedUserTransaction, as well as all the other - /// transaction types we had in our codebase. - #[serde(with = "serde_bytes")] - - UserTransaction(Vec), - - /// Transaction that applies a WriteSet to the current storage, it's applied manually via db-bootstrapper. - #[serde(with = "serde_bytes")] - - GenesisTransaction(Vec), - - /// Transaction to update the block metadata resource at the beginning of a block. - #[serde(with = "serde_bytes")] - BlockMetadata(Vec), -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -struct DummyTransactionInfoV5 { - /// The hash of this transaction. - #[serde(with = "serde_bytes")] - transaction_hash: Vec, - - /// The root hash of Sparse Merkle Tree describing the world state at the end of this - /// transaction. - #[serde(with = "serde_bytes")] - state_root_hash: Vec, - - /// The root hash of Merkle Accumulator storing all events emitted during this transaction. - #[serde(with = "serde_bytes")] - event_root_hash: Vec, - - /// The amount of gas used. - gas_used: u64, - - /// The vm status. If it is not `Executed`, this will provide the general error class. Execution - /// failures and Move abort's recieve more detailed information. But other errors are generally - /// categorized with no status code or other information - #[serde(with = "serde_bytes")] - status: Vec, -} - -/// Support versioning of the data structure. -#[derive(Clone, Debug, Serialize, Deserialize)] -enum DummyContractEventV5 { - V0(ContractEventV0), -} - -/// Entry produced via a call to the `emit_event` builtin. -#[derive(Clone, Debug, Serialize, Deserialize)] -struct ContractEventV0 { - /// The unique key that the event was emitted to - #[serde(with = "serde_bytes")] - key: Vec, - /// The number of messages that have been emitted to the path previously - sequence_number: u64, - /// The type of the data - #[serde(with = "serde_bytes")] - type_tag: Vec, - /// The data payload of the event - #[serde(with = "serde_bytes")] - event_data: Vec, -} diff --git a/compatibility/src/version_five/freezing_v5.rs b/compatibility/src/version_five/freezing_v5.rs index e32d21ae8..a7e86d7e4 100644 --- a/compatibility/src/version_five/freezing_v5.rs +++ b/compatibility/src/version_five/freezing_v5.rs @@ -6,7 +6,6 @@ use super::move_resource_v5::{MoveResourceV5, MoveStructTypeV5}; use move_core_types::{ ident_str, identifier::IdentStr, - // move_resource::{MoveResource, MoveStructType}, }; use serde::{Deserialize, Serialize}; diff --git a/compatibility/src/version_five/language_storage_v5.rs b/compatibility/src/version_five/language_storage_v5.rs index 3e0057e2a..7b14ab548 100644 --- a/compatibility/src/version_five/language_storage_v5.rs +++ b/compatibility/src/version_five/language_storage_v5.rs @@ -61,12 +61,12 @@ impl StructTagV5 { /// Represents the initial key into global storage where we first index by the address, and then /// the struct tag #[derive(Serialize, Deserialize, Debug, PartialEq, Hash, Eq, Clone, PartialOrd, Ord)] -pub struct ResourceKey { +pub struct ResourceKeyV5 { pub address: LegacyAddressV5, pub type_: StructTagV5, } -impl ResourceKey { +impl ResourceKeyV5 { pub fn address(&self) -> LegacyAddressV5 { self.address } @@ -76,9 +76,9 @@ impl ResourceKey { } } -impl ResourceKey { +impl ResourceKeyV5 { pub fn new(address: LegacyAddressV5, type_: StructTagV5) -> Self { - ResourceKey { address, type_ } + ResourceKeyV5 { address, type_ } } } @@ -158,7 +158,7 @@ impl Display for TypeTagV5 { } } -impl Display for ResourceKey { +impl Display for ResourceKeyV5 { fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { write!(f, "0x{}/{}", self.address.short_str_lossless(), self.type_) } diff --git a/compatibility/src/version_five/mod.rs b/compatibility/src/version_five/mod.rs index a71c4a301..4aaf31f1a 100644 --- a/compatibility/src/version_five/mod.rs +++ b/compatibility/src/version_five/mod.rs @@ -3,6 +3,11 @@ pub mod core_account_v5; pub mod diem_account_v5; pub mod freezing_v5; pub mod legacy_address_v5; +pub mod ol_ancestry; +pub mod ol_cumulative_deposit; +pub mod ol_receipts; +pub mod ol_tower_state; +pub mod ol_wallet; pub mod state_snapshot_v5; pub mod transaction_manifest_v5; pub mod transaction_restore_v5; diff --git a/compatibility/src/version_five/ol_ancestry.rs b/compatibility/src/version_five/ol_ancestry.rs new file mode 100644 index 000000000..5e5ccc13d --- /dev/null +++ b/compatibility/src/version_five/ol_ancestry.rs @@ -0,0 +1,40 @@ + +use crate::version_five::{ + language_storage_v5::StructTagV5, move_resource_v5::MoveResourceV5, + move_resource_v5::MoveStructTypeV5, +}; +use anyhow::Result; +use move_core_types::{ident_str, identifier::IdentStr}; +use serde::{Deserialize, Serialize}; + +use super::{language_storage_v5::CORE_CODE_ADDRESS, legacy_address_v5::LegacyAddressV5}; + +/// Struct that represents a AutoPay resource +#[derive(Debug, Serialize, Deserialize)] +pub struct AncestryResource { + /// + pub tree: Vec, +} + +impl MoveStructTypeV5 for AncestryResource { + const MODULE_NAME: &'static IdentStr = ident_str!("Ancestry"); + const STRUCT_NAME: &'static IdentStr = ident_str!("Ancestry"); +} +impl MoveResourceV5 for AncestryResource {} + +impl AncestryResource { + /// + pub fn struct_tag() -> StructTagV5 { + StructTagV5 { + address: CORE_CODE_ADDRESS, + module: AncestryResource::module_identifier(), + name: AncestryResource::struct_identifier(), + type_params: vec![], + } + } + + /// + pub fn try_from_bytes(bytes: &[u8]) -> Result { + bcs::from_bytes(bytes).map_err(Into::into) + } +} diff --git a/compatibility/src/version_five/ol_cumulative_deposit.rs b/compatibility/src/version_five/ol_cumulative_deposit.rs new file mode 100644 index 000000000..8e6a5a3d1 --- /dev/null +++ b/compatibility/src/version_five/ol_cumulative_deposit.rs @@ -0,0 +1,38 @@ + +use crate::version_five::{language_storage_v5::StructTagV5, move_resource_v5::MoveStructTypeV5}; +use anyhow::Result; +use move_core_types::{ident_str, identifier::IdentStr}; +use serde::{Deserialize, Serialize}; + +use super::language_storage_v5::CORE_CODE_ADDRESS; + +/// Struct that represents a CurrencyInfo resource +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CumulativeDepositResource { + /// + pub value: u64, + /// + pub index: u64, +} + +impl MoveStructTypeV5 for CumulativeDepositResource { + const MODULE_NAME: &'static IdentStr = ident_str!("DiemAccount"); + const STRUCT_NAME: &'static IdentStr = ident_str!("CumulativeDeposits"); +} + +impl CumulativeDepositResource { + /// + pub fn struct_tag() -> StructTagV5 { + StructTagV5 { + address: CORE_CODE_ADDRESS, + module: CumulativeDepositResource::module_identifier(), + name: CumulativeDepositResource::struct_identifier(), + type_params: vec![], + } + } + + /// + pub fn try_from_bytes(bytes: &[u8]) -> Result { + bcs::from_bytes(bytes).map_err(Into::into) + } +} diff --git a/compatibility/src/version_five/ol_receipts.rs b/compatibility/src/version_five/ol_receipts.rs new file mode 100644 index 000000000..ffaea75b7 --- /dev/null +++ b/compatibility/src/version_five/ol_receipts.rs @@ -0,0 +1,41 @@ +use crate::version_five::{language_storage_v5::StructTagV5, move_resource_v5::MoveStructTypeV5}; +use anyhow::Result; +use move_core_types::{ident_str, identifier::IdentStr}; +use serde::{Deserialize, Serialize}; + +use super::{language_storage_v5::CORE_CODE_ADDRESS, legacy_address_v5::LegacyAddressV5}; + +/// Struct that represents a CurrencyInfo resource +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ReceiptsResource { + /// + pub destination: Vec, + /// + pub cumulative: Vec, + /// + pub last_payment_timestamp: Vec, + /// + pub last_payment_value: Vec, +} + +impl MoveStructTypeV5 for ReceiptsResource { + const MODULE_NAME: &'static IdentStr = ident_str!("Receipts"); + const STRUCT_NAME: &'static IdentStr = ident_str!("UserReceipts"); +} + +impl ReceiptsResource { + /// + pub fn struct_tag() -> StructTagV5 { + StructTagV5 { + address: CORE_CODE_ADDRESS, + module: ReceiptsResource::module_identifier(), + name: ReceiptsResource::struct_identifier(), + type_params: vec![], + } + } + + /// + pub fn try_from_bytes(bytes: &[u8]) -> Result { + bcs::from_bytes(bytes).map_err(Into::into) + } +} diff --git a/compatibility/src/version_five/ol_tower_state.rs b/compatibility/src/version_five/ol_tower_state.rs new file mode 100644 index 000000000..b25eb2ea3 --- /dev/null +++ b/compatibility/src/version_five/ol_tower_state.rs @@ -0,0 +1,47 @@ +use crate::version_five::{language_storage_v5::StructTagV5, move_resource_v5::MoveStructTypeV5}; +use anyhow::Result; +use move_core_types::{ident_str, identifier::IdentStr}; +use serde::{Deserialize, Serialize}; + +use super::{language_storage_v5::CORE_CODE_ADDRESS, move_resource_v5::MoveResourceV5}; +/// Struct that represents a CurrencyInfo resource +#[derive(Debug, Serialize, Deserialize)] +pub struct TowerStateResource { + /// + pub previous_proof_hash: Vec, + /// user's latest verified_tower_height + pub verified_tower_height: u64, + /// + pub latest_epoch_mining: u64, + /// + pub count_proofs_in_epoch: u64, + /// + pub epochs_validating_and_mining: u64, + /// + pub contiguous_epochs_validating_and_mining: u64, + /// + pub epochs_since_last_account_creation: u64, +} + +impl MoveStructTypeV5 for TowerStateResource { + const MODULE_NAME: &'static IdentStr = ident_str!("TowerState"); + const STRUCT_NAME: &'static IdentStr = ident_str!("TowerProofHistory"); +} +impl MoveResourceV5 for TowerStateResource {} + +impl TowerStateResource { + /// + pub fn struct_tag() -> StructTagV5 { + StructTagV5 { + address: CORE_CODE_ADDRESS, + module: TowerStateResource::module_identifier(), + name: TowerStateResource::struct_identifier(), + type_params: vec![], + } + } + + /// + pub fn try_from_bytes(bytes: &[u8]) -> Result { + bcs::from_bytes(bytes).map_err(Into::into) + } +} diff --git a/compatibility/src/version_five/ol_wallet.rs b/compatibility/src/version_five/ol_wallet.rs new file mode 100644 index 000000000..9af610f0d --- /dev/null +++ b/compatibility/src/version_five/ol_wallet.rs @@ -0,0 +1,97 @@ +use crate::version_five::{language_storage_v5::StructTagV5, move_resource_v5::MoveStructTypeV5}; +use anyhow::Result; +use move_core_types::{ident_str, identifier::IdentStr}; +use serde::{Deserialize, Serialize}; + +use super::{language_storage_v5::CORE_CODE_ADDRESS, legacy_address_v5::LegacyAddressV5}; + +// NOTE: these are legacy structs for v5 + +/// Struct that represents a CommunityWallet resource +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CommunityWalletsResourceLegacy { + /// List + pub list: Vec, +} + +impl MoveStructTypeV5 for CommunityWalletsResourceLegacy { + const MODULE_NAME: &'static IdentStr = ident_str!("Wallet"); + const STRUCT_NAME: &'static IdentStr = ident_str!("CommunityWalletList"); +} + +impl CommunityWalletsResourceLegacy { + /// + pub fn struct_tag() -> StructTagV5 { + StructTagV5 { + address: CORE_CODE_ADDRESS, + module: CommunityWalletsResourceLegacy::module_identifier(), + name: CommunityWalletsResourceLegacy::struct_identifier(), + type_params: vec![], + } + } + + /// + pub fn try_from_bytes(bytes: &[u8]) -> Result { + bcs::from_bytes(bytes).map_err(Into::into) + } +} + +/// Struct that represents a SlowWallet resource +#[derive(Debug, Serialize, Deserialize)] +pub struct SlowWalletResource { + /// + pub unlocked: u64, + /// + pub transferred: u64, +} + +impl MoveStructTypeV5 for SlowWalletResource { + const MODULE_NAME: &'static IdentStr = ident_str!("DiemAccount"); + const STRUCT_NAME: &'static IdentStr = ident_str!("SlowWallet"); +} + +impl SlowWalletResource { + /// + pub fn struct_tag() -> StructTagV5 { + StructTagV5 { + address: CORE_CODE_ADDRESS, + module: SlowWalletResource::module_identifier(), + name: SlowWalletResource::struct_identifier(), + type_params: vec![], + } + } + + /// + pub fn try_from_bytes(bytes: &[u8]) -> Result { + bcs::from_bytes(bytes).map_err(Into::into) + } +} + +/// Struct that represents a SlowWallet resource +#[derive(Debug, Serialize, Deserialize)] +pub struct SlowWalletListResource { + /// + pub list: Vec, +} + +impl MoveStructTypeV5 for SlowWalletListResource { + const MODULE_NAME: &'static IdentStr = ident_str!("DiemAccount"); + const STRUCT_NAME: &'static IdentStr = ident_str!("SlowWalletList"); +} + +impl SlowWalletListResource { + /// + pub fn struct_tag() -> StructTagV5 { + StructTagV5 { + address: CORE_CODE_ADDRESS, + module: SlowWalletListResource::module_identifier(), + name: SlowWalletListResource::struct_identifier(), + type_params: vec![], + } + } + + /// + pub fn try_from_bytes(bytes: &[u8]) -> Result { + bcs::from_bytes(bytes).map_err(Into::into) + } +}