Skip to content

Commit

Permalink
add ol specific Move resource bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Nov 22, 2024
1 parent 9a5a4c2 commit 4ba3415
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 77 deletions.
11 changes: 7 additions & 4 deletions compatibility/src/version_five/balance_v5.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
67 changes: 0 additions & 67 deletions compatibility/src/version_five/dummy_tx_types.todo

This file was deleted.

1 change: 0 additions & 1 deletion compatibility/src/version_five/freezing_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
10 changes: 5 additions & 5 deletions compatibility/src/version_five/language_storage_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -76,9 +76,9 @@ impl ResourceKey {
}
}

impl ResourceKey {
impl ResourceKeyV5 {
pub fn new(address: LegacyAddressV5, type_: StructTagV5) -> Self {
ResourceKey { address, type_ }
ResourceKeyV5 { address, type_ }
}
}

Expand Down Expand Up @@ -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_)
}
Expand Down
5 changes: 5 additions & 0 deletions compatibility/src/version_five/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 40 additions & 0 deletions compatibility/src/version_five/ol_ancestry.rs
Original file line number Diff line number Diff line change
@@ -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<LegacyAddressV5>,
}

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<Self> {
bcs::from_bytes(bytes).map_err(Into::into)
}
}
38 changes: 38 additions & 0 deletions compatibility/src/version_five/ol_cumulative_deposit.rs
Original file line number Diff line number Diff line change
@@ -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<Self> {
bcs::from_bytes(bytes).map_err(Into::into)
}
}
41 changes: 41 additions & 0 deletions compatibility/src/version_five/ol_receipts.rs
Original file line number Diff line number Diff line change
@@ -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<LegacyAddressV5>,
///
pub cumulative: Vec<u64>,
///
pub last_payment_timestamp: Vec<u64>,
///
pub last_payment_value: Vec<u64>,
}

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<Self> {
bcs::from_bytes(bytes).map_err(Into::into)
}
}
47 changes: 47 additions & 0 deletions compatibility/src/version_five/ol_tower_state.rs
Original file line number Diff line number Diff line change
@@ -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<u8>,
/// 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<Self> {
bcs::from_bytes(bytes).map_err(Into::into)
}
}
Loading

0 comments on commit 4ba3415

Please sign in to comment.