Skip to content

Commit

Permalink
add v5 slow wallet state
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Nov 22, 2024
1 parent 432dd42 commit 7350865
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/extract_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ use std::path::Path;

use anyhow::Result;
use diem_types::account_view::AccountView;
use libra_backwards_compatibility::version_five::{balance_v5::BalanceResourceV5, state_snapshot_v5::v5_accounts_from_manifest_path};
use libra_backwards_compatibility::version_five::{
balance_v5::BalanceResourceV5, ol_wallet::SlowWalletResourceV5,
state_snapshot_v5::v5_accounts_from_manifest_path,
};
use libra_storage::read_snapshot::{accounts_from_snapshot_backup, load_snapshot_manifest};
use libra_types::exports::AccountAddress;
use log::{info, warn};
use log::{error, info, warn};

use crate::schema_account_state::WarehouseAccState;

// uses libra-compatibility to parse the v5 manifest files, and decode v5 format bytecode into current version data structures (v6+);
pub async fn extract_v5_snapshot(v5_manifest_path: &Path) -> Result<Vec<WarehouseAccState>> {
let account_blobs = v5_accounts_from_manifest_path(v5_manifest_path).await?;
dbg!(&account_blobs.len());
info!("account records found: {}", &account_blobs.len());
let mut warehouse_state = vec![];
for el in account_blobs.iter() {
let acc = el.to_account_state()?;
Expand All @@ -24,18 +27,21 @@ pub async fn extract_v5_snapshot(v5_manifest_path: &Path) -> Result<Vec<Warehous
let mut s = WarehouseAccState::new(cast_address);

if let Some(r) = acc.get_diem_account_resource().ok() {
s.sequence_num = r.sequence_number();
s.sequence_num = r.sequence_number();
}

if let Some(b) = acc.get_resource::<BalanceResourceV5>().ok() {
s.balance = Some(b.coin())
s.balance = Some(b.coin())
}
if let Some(sw) = acc.get_resource::<SlowWalletResourceV5>().ok() {
s.slow_wallet_locked = sw.unlocked;
s.slow_wallet_transferred = sw.transferred;
}


warehouse_state.push(s);
}
Err(e) => {
println!("WARN: could not parse blob to V5 Address{}", &e);
error!("could not parse blob to V5 Address: {}", &e);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/schema_account_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub struct WarehouseAccState {
pub time: WarehouseTime,
pub sequence_num: u64,
pub balance: Option<u64>,
pub slow_wallet_locked: u64,
pub slow_wallet_transferred: u64,
}

impl WarehouseAccState {
Expand All @@ -16,6 +18,9 @@ impl WarehouseAccState {
sequence_num: 0,
time: WarehouseTime::default(),
balance: None,
slow_wallet_locked: 0,
slow_wallet_transferred: 0,

}
}
pub fn set_time(&mut self, timestamp: u64, version: u64, epoch: u64) {
Expand Down
File renamed without changes.

0 comments on commit 7350865

Please sign in to comment.