Skip to content

Commit

Permalink
[types] remove more legacy diem code around account blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidiw authored and aptos-bot committed Apr 26, 2022
1 parent 4431f4f commit 594c4cc
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 309 deletions.
93 changes: 0 additions & 93 deletions types/src/account_config/resources/account.rs

This file was deleted.

70 changes: 0 additions & 70 deletions types/src/account_config/resources/dual_attestation.rs

This file was deleted.

27 changes: 0 additions & 27 deletions types/src/account_config/resources/key_rotation_capability.rs

This file was deleted.

8 changes: 0 additions & 8 deletions types/src/account_config/resources/mod.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

pub mod account;
pub mod balance;
pub mod chain_account_info;
pub mod chain_id;
pub mod core_account;
pub mod crsn;
pub mod dual_attestation;
pub mod key_rotation_capability;
pub mod withdraw_capability;

pub use account::*;
pub use balance::*;
pub use chain_account_info::*;
pub use chain_id::*;
pub use core_account::*;
pub use crsn::*;
pub use dual_attestation::*;
pub use key_rotation_capability::*;
pub use withdraw_capability::*;
27 changes: 0 additions & 27 deletions types/src/account_config/resources/withdraw_capability.rs

This file was deleted.

29 changes: 4 additions & 25 deletions types/src/account_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
use crate::{
access_path::Path,
account_address::AccountAddress,
account_config::{
AccountResource, AptosAccountResource, BalanceResource, CRSNResource, ChainIdResource,
},
account_config::{AccountResource, BalanceResource, CRSNResource, ChainIdResource},
account_state_blob::AccountStateBlob,
block_metadata::BlockResource,
on_chain_config::{
Expand All @@ -32,24 +30,13 @@ impl AccountState {
.map(|opt_ar| opt_ar.map(|ar| ar.address()))
}

pub fn get_diem_account_resource(&self) -> Result<Option<AptosAccountResource>> {
self.get_resource::<AptosAccountResource>()
}

// Return the `AccountResource` for this blob. If the blob doesn't have an `AccountResource`
// then it must have a `AptosAccountResource` in which case we convert that to an
// `AccountResource`.
pub fn get_account_resource(&self) -> Result<Option<AccountResource>> {
match self.get_resource::<AccountResource>()? {
x @ Some(_) => Ok(x),
None => match self.get_resource::<AptosAccountResource>()? {
Some(diem_ar) => Ok(Some(AccountResource::new(
diem_ar.sequence_number(),
diem_ar.authentication_key().to_vec(),
diem_ar.address(),
))),
None => Ok(None),
},
None => Ok(None),
}
}

Expand Down Expand Up @@ -259,25 +246,17 @@ impl TryFrom<&Vec<u8>> for AccountState {
}
}

impl TryFrom<(&AccountResource, &AptosAccountResource, &BalanceResource)> for AccountState {
impl TryFrom<(&AccountResource, &BalanceResource)> for AccountState {
type Error = Error;

fn try_from(
(account_resource, diem_account_resource, balance_resource): (
&AccountResource,
&AptosAccountResource,
&BalanceResource,
),
(account_resource, balance_resource): (&AccountResource, &BalanceResource),
) -> Result<Self> {
let mut btree_map: BTreeMap<Vec<u8>, Vec<u8>> = BTreeMap::new();
btree_map.insert(
AccountResource::resource_path(),
bcs::to_bytes(account_resource)?,
);
btree_map.insert(
AptosAccountResource::resource_path(),
bcs::to_bytes(diem_account_resource)?,
);
btree_map.insert(
BalanceResource::resource_path(),
bcs::to_bytes(balance_resource)?,
Expand Down
25 changes: 5 additions & 20 deletions types/src/account_state_blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{
account_config::{AccountResource, AptosAccountResource, BalanceResource},
account_config::{AccountResource, BalanceResource},
account_state::AccountState,
state_store::state_value::StateValue,
};
Expand Down Expand Up @@ -110,34 +110,19 @@ impl TryFrom<StateValue> for AccountStateBlob {
}
}

impl TryFrom<(&AccountResource, &AptosAccountResource, &BalanceResource)> for AccountStateBlob {
impl TryFrom<(&AccountResource, &BalanceResource)> for AccountStateBlob {
type Error = Error;

fn try_from(
(account_resource, diem_account_resource, balance_resource): (
&AccountResource,
&AptosAccountResource,
&BalanceResource,
),
(account_resource, balance_resource): (&AccountResource, &BalanceResource),
) -> Result<Self> {
Self::try_from(&AccountState::try_from((
account_resource,
diem_account_resource,
balance_resource,
))?)
}
}

impl TryFrom<&AccountStateBlob> for AptosAccountResource {
type Error = Error;

fn try_from(account_state_blob: &AccountStateBlob) -> Result<Self> {
AccountState::try_from(account_state_blob)?
.get_diem_account_resource()?
.ok_or_else(|| anyhow!("AptosAccountResource not found."))
}
}

impl TryFrom<&AccountStateBlob> for AccountResource {
type Error = Error;

Expand All @@ -158,8 +143,8 @@ impl CryptoHash for AccountStateBlob {

#[cfg(any(test, feature = "fuzzing"))]
prop_compose! {
fn account_state_blob_strategy()(account_resource in any::<AccountResource>(), diem_account_resource in any::<AptosAccountResource>(), balance_resource in any::<BalanceResource>()) -> AccountStateBlob {
AccountStateBlob::try_from((&account_resource, &diem_account_resource, &balance_resource)).unwrap()
fn account_state_blob_strategy()(account_resource in any::<AccountResource>(), balance_resource in any::<BalanceResource>()) -> AccountStateBlob {
AccountStateBlob::try_from((&account_resource, &balance_resource)).unwrap()
}
}

Expand Down
Loading

0 comments on commit 594c4cc

Please sign in to comment.