Skip to content

Commit

Permalink
test manifest can be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Oct 6, 2024
1 parent 07d5e2e commit ac5c688
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 74 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":119757649,"root_hash":"d2e6b6c474529cd3c3ea76cf211a528ee28bb13d7bcd8dcbef0ecf4c43bc3703","chunks":[{"first_idx":0,"last_idx":17338,"first_key":"000131122524ba9f4a13bd90a8b13c5d03ab621649c8100c6bbf7846fe8eaf0f","last_key":"fffed52c1dd93cc7aa5b79a8699df0c33eb4d65ab8d2a21bbe79f9d05ad62377","blobs":"state_ver_119757649.17a8/0-.chunk","proof":"state_ver_119757649.17a8/0-17338.proof"}],"proof":"state_ver_119757649.17a8/state.proof"}
Binary file not shown.
6 changes: 3 additions & 3 deletions compatibility/src/legacy_recovery_v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use libra_types::{
move_resource::{
ancestry::AncestryResource,
burn::{BurnCounterResource, UserBurnPreferenceResource},
cumulative_deposits::{CumulativeDepositResource, LegacyBalanceResource},
cumulative_deposits::{CumulativeDepositResource, LegacyBalanceResourceV6},
donor_voice::RegistryResource,
donor_voice_txs::TxScheduleResource,
fee_maker::{EpochFeeMakerRegistryResource, FeeMakerResource},
Expand Down Expand Up @@ -67,7 +67,7 @@ pub struct LegacyRecoveryV6 {
pub role: AccountRole,

/// The balance resource of the account in the legacy system.
pub balance: Option<LegacyBalanceResource>,
pub balance: Option<LegacyBalanceResourceV6>,

/// Validator configuration information.
pub val_cfg: Option<ValidatorConfig>,
Expand Down Expand Up @@ -201,7 +201,7 @@ pub fn get_legacy_recovery(account_state: &AccountState) -> anyhow::Result<Legac
// balance
legacy_recovery.balance = account_state
.get_coin_store_resource()?
.map(|r| LegacyBalanceResource { coin: r.coin() });
.map(|r| LegacyBalanceResourceV6 { coin: r.coin() });

// validator config
legacy_recovery.val_cfg = account_state.get_validator_config_resource()?;
Expand Down
51 changes: 27 additions & 24 deletions compatibility/src/version_five/account_blob_v5.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

#[allow(unused)]

#[allow(dead_code)]
use crate::version_five::{
core_account_v5::AccountResourceV5, diem_account_v5::DiemAccountResourceV5,
language_storage_v5::StructTagV5, legacy_address_v5::LegacyAddressV5,
};
use anyhow::bail;
use anyhow::{Context, Result};
use crate::version_five::move_resource_v5::MoveResourceV5;
use anyhow::{bail, Context, Result};
use diem_crypto::{
hash::{CryptoHash, CryptoHasher},
HashValue,
};

use diem_crypto_derive::CryptoHasher;
use move_core_types::language_storage::StructTag;
use move_core_types::move_resource::MoveResource;
// use move_core_types::language_storage::StructTag;
// use move_core_types::move_resource::MoveResource;
use serde::{Deserialize, Deserializer, Serialize};
use std::collections::BTreeMap;

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct AccountStateV5(pub BTreeMap<Vec<u8>, Vec<u8>>);

impl AccountStateV5 {
pub fn get_resource_data<T: MoveResource>(&self) -> Result<&[u8]> {
pub fn get_resource_data<T: MoveResourceV5>(&self) -> Result<&[u8]> {
// NOTE: don't forget access_vector: has a byte prepended
let struct_tag = T::struct_tag();

let legacy_struct_tag = convert_to_legacy(&struct_tag)?;
let key = legacy_struct_tag.access_vector();
// let legacy_struct_tag = convert_to_legacy(&struct_tag)?;
let key = struct_tag.access_vector();

let errmsg = format!(
"could not find in btree type {}",
Expand All @@ -39,11 +38,11 @@ impl AccountStateV5 {
Ok(self.0.get(&key).context(errmsg)?)
}

pub fn find_bytes_struct_tag(&self, s: &StructTag) -> Result<&[u8]> {
let errmsg = format!("could not find in btree type {}", s.to_canonical_string());
let key = s.access_vector();
Ok(self.0.get(&key).context(errmsg)?)
}
// pub fn find_bytes_struct_tag(&self, s: &StructTagV5) -> Result<&[u8]> {
// let errmsg = format!("could not find in btree type {}", s.to_canonical_string());
// let key = s.access_vector();
// Ok(self.0.get(&key).context(errmsg)?)
// }

pub fn find_bytes_legacy_struct_tag_v5(
&self,
Expand All @@ -57,7 +56,7 @@ impl AccountStateV5 {
Ok(self.0.get(&key).context(errmsg)?)
}

pub fn get_resource<T: MoveResource>(&self) -> Result<T> {
pub fn get_resource<T: MoveResourceV5>(&self) -> Result<T> {
let bytes = self.get_resource_data::<T>()?;
Ok(bcs::from_bytes(bytes)?)
}
Expand Down Expand Up @@ -115,6 +114,10 @@ impl AccountStateBlob {
let hash = hasher.finish();
Self { blob, hash }
}
// convert from vec<u8> to btree k-v representation
pub fn to_account_state(&self) -> Result<AccountStateV5> {
Ok(bcs::from_bytes(&self.blob)?)
}
}

impl CryptoHash for AccountStateBlob {
Expand All @@ -125,13 +128,13 @@ impl CryptoHash for AccountStateBlob {
}
}

pub fn convert_to_legacy(s: &StructTag) -> Result<StructTagV5> {
let legacy_address = LegacyAddressV5::from_hex_literal(&s.address.to_hex_literal())?;
// pub fn convert_to_legacy(s: &StructTag) -> Result<StructTagV5> {
// let legacy_address = LegacyAddressV5::from_hex_literal(&s.address.to_hex_literal())?;

Ok(StructTagV5 {
address: legacy_address,
module: s.module.clone(),
name: s.name.clone(),
type_params: vec![], // TODO // s.type_params.clone(),
})
}
// Ok(StructTagV5 {
// address: legacy_address,
// module: s.module.clone(),
// name: s.name.clone(),
// type_params: vec![], // TODO // s.type_params.clone(),
// })
// }
40 changes: 24 additions & 16 deletions compatibility/src/version_five/balance_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ use move_core_types::account_address::AccountAddress;
use move_core_types::{
ident_str,
identifier::IdentStr,
language_storage::{StructTag, TypeTag},
// language_storage::{StructTagV5, TypeTag},
move_resource::{MoveResource, MoveStructType},
};
use serde::{Deserialize, Serialize};

use crate::version_five::language_storage_v5::{StructTagV5, TypeTagV5};
use crate::version_five::legacy_address_v5::{LegacyAddressV5, LEGACY_CORE_CODE_ADDRESS};
use crate::version_five::move_resource_v5::MoveStructTypeV5;
use crate::version_five::move_resource_v5::MoveResourceV5;
/// The balance resource held under an account.
#[derive(Debug, Serialize, Deserialize)]
pub struct BalanceResource {
pub struct BalanceResourceV5 {
coin: u64,
}

impl BalanceResource {
impl BalanceResourceV5 {
pub fn new(coin: u64) -> Self {
Self { coin }
}
Expand All @@ -26,22 +29,27 @@ impl BalanceResource {
}
}

impl MoveStructType for BalanceResource {
impl MoveStructTypeV5 for BalanceResourceV5 {
const MODULE_NAME: &'static IdentStr = ident_str!("DiemAccount");
const STRUCT_NAME: &'static IdentStr = ident_str!("Balance");

fn type_params() -> Vec<TypeTag> {
vec![xus_tag()]
fn type_params() -> Vec<TypeTagV5> {
vec![TypeTagV5::Struct(Box::new(StructTagV5 {
address: LEGACY_CORE_CODE_ADDRESS,
module: ident_str!("GAS").into(),
name: ident_str!("GAS").into(),
type_params: vec![],
}))]
}
}

impl MoveResource for BalanceResource {}
impl MoveResourceV5 for BalanceResourceV5 {}

pub fn xus_tag() -> TypeTag {
TypeTag::Struct(Box::new(StructTag {
address: AccountAddress::ONE,
module: ident_str!("GAS").into(),
name: ident_str!("GAS").into(),
type_params: vec![],
}))
}
// pub fn xus_tag() -> TypeTag {
// TypeTag::Struct(Box::new(StructTagV5 {
// address: AccountAddress::ONE,
// module: ident_str!("GAS").into(),
// name: ident_str!("GAS").into(),
// type_params: vec![],
// }))
// }
15 changes: 8 additions & 7 deletions compatibility/src/version_five/diem_account_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ use crate::version_five::event_v5::EventHandleV5;
use move_core_types::ident_str;
use move_core_types::{
identifier::IdentStr,
move_resource::{MoveResource, MoveStructType},
};
use serde::{Deserialize, Serialize};

use super::legacy_address_v5::LEGACY_CORE_CODE_ADDRESS;
use super::move_resource_v5::{MoveResourceV5, MoveStructTypeV5};


/// The Identifier for the Account module.
pub const DIEM_ACCOUNT_MODULE_IDENTIFIER: &IdentStr = ident_str!("DiemAccount");
Expand Down Expand Up @@ -99,33 +100,33 @@ impl DiemAccountResourceV5 {
}
}

impl MoveStructType for DiemAccountResourceV5 {
impl MoveStructTypeV5 for DiemAccountResourceV5 {
const MODULE_NAME: &'static IdentStr = DIEM_ACCOUNT_MODULE_IDENTIFIER;
const STRUCT_NAME: &'static IdentStr = DIEM_ACCOUNT_MODULE_IDENTIFIER;
}

impl MoveResource for DiemAccountResourceV5 {}
impl MoveResourceV5 for DiemAccountResourceV5 {}

#[derive(Debug, Serialize, Deserialize)]
pub struct WithdrawCapabilityResource {
account_address: LegacyAddressV5,
}

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

impl MoveResource for WithdrawCapabilityResource {}
impl MoveResourceV5 for WithdrawCapabilityResource {}

#[derive(Debug, Serialize, Deserialize)]
pub struct KeyRotationCapabilityResource {
account_address: LegacyAddressV5,
}

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

impl MoveResource for KeyRotationCapabilityResource {}
impl MoveResourceV5 for KeyRotationCapabilityResource {}
9 changes: 5 additions & 4 deletions compatibility/src/version_five/freezing_v5.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

// Sanity test the parsing
use super::move_resource_v5::{MoveResourceV5, MoveStructTypeV5};

use move_core_types::{
ident_str,
identifier::IdentStr,
move_resource::{MoveResource, MoveStructType},
// move_resource::{MoveResource, MoveStructType},
};

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -21,9 +22,9 @@ impl FreezingBit {
}
}

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

impl MoveResource for FreezingBit {}
impl MoveResourceV5 for FreezingBit {}
9 changes: 7 additions & 2 deletions compatibility/src/version_five/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
pub mod balance_v5;
pub mod core_account_v5;
pub mod diem_account_v5;
pub mod freezing_v5;
pub mod legacy_address_v5;
pub mod state_snapshot_v5;
// NOTE: the ones below should likely be private always,
// so that they do not get suggested in the place of
// up-to-date structs of the same name.

mod account_blob_v5;
mod balance_v5;
mod event_v5;
mod freezing_v5;
mod hash_value_v5;
mod language_storage_v5;
mod move_resource_v5;
mod safe_serialize_v5;
42 changes: 42 additions & 0 deletions compatibility/src/version_five/move_resource_v5.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) The Diem Core Contributors
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0
use super::{
language_storage_v5::{StructTagV5, TypeTagV5},
legacy_address_v5::{LegacyAddressV5, LEGACY_CORE_CODE_ADDRESS},
};
use move_core_types::identifier::{IdentStr, Identifier};
use serde::de::DeserializeOwned;

pub trait MoveStructTypeV5 {
const ADDRESS: LegacyAddressV5 = LEGACY_CORE_CODE_ADDRESS;
const MODULE_NAME: &'static IdentStr;
const STRUCT_NAME: &'static IdentStr;

fn module_identifier() -> Identifier {
Self::MODULE_NAME.to_owned()
}

fn struct_identifier() -> Identifier {
Self::STRUCT_NAME.to_owned()
}

fn type_params() -> Vec<TypeTagV5> {
vec![]
}

fn struct_tag() -> StructTagV5 {
StructTagV5 {
address: Self::ADDRESS,
name: Self::struct_identifier(),
module: Self::module_identifier(),
type_params: Self::type_params(),
}
}
}

pub trait MoveResourceV5: MoveStructTypeV5 + DeserializeOwned {
fn resource_path() -> Vec<u8> {
Self::struct_tag().access_vector()
}
}
Loading

0 comments on commit ac5c688

Please sign in to comment.