Skip to content

Commit

Permalink
scaffold warehouse cli
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Oct 8, 2024
1 parent 4a41416 commit 1bcb815
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"transactional-tests",
"types",
"upgrade-tests",
"warehouse",
]

# All workspace members should inherit these keys for package declarations.
Expand Down Expand Up @@ -48,6 +49,7 @@ libra-twin-tests = { path = "testsuites/twin" }
libra-types = { path = "types" }
libra-txs = { path = "tools/txs" }
libra-wallet = { path = "tools/wallet" }
libra-warehouse = { path = "warehouse" }

diem-api-types = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-debugger = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
Expand Down
67 changes: 67 additions & 0 deletions compatibility/src/version_five/dummy_tx_types.todo
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

#[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<u8>),

/// Transaction that applies a WriteSet to the current storage, it's applied manually via db-bootstrapper.
#[serde(with = "serde_bytes")]

GenesisTransaction(Vec<u8>),

/// Transaction to update the block metadata resource at the beginning of a block.
#[serde(with = "serde_bytes")]
BlockMetadata(Vec<u8>),
}

#[derive(Clone, Debug, Serialize, Deserialize)]
struct DummyTransactionInfoV5 {
/// The hash of this transaction.
#[serde(with = "serde_bytes")]
transaction_hash: Vec<u8>,

/// 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<u8>,

/// The root hash of Merkle Accumulator storing all events emitted during this transaction.
#[serde(with = "serde_bytes")]
event_root_hash: Vec<u8>,

/// 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<u8>,
}

/// 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<u8>,
/// 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<u8>,
/// The data payload of the event
#[serde(with = "serde_bytes")]
event_data: Vec<u8>,
}
2 changes: 2 additions & 0 deletions compatibility/src/version_five/transaction_restore_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub async fn read_transaction_chunk(
while let Some(record_bytes) = file.read_record_bytes().await? {
let txn: TxRecord = bcs::from_bytes(&record_bytes)?;
dbg!(&txn.0);
dbg!(&txn.1);
// dbg!(&txn.2);
txns.push(txn);
}
Ok(txns)
Expand Down
15 changes: 15 additions & 0 deletions warehouse/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "libra-warehouse"
authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
publish.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[dependencies]
anyhow = { workspace = true }
clap = { workspace = true }
tokio ={ workspace = true }
1 change: 1 addition & 0 deletions warehouse/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod warehouse_cli;
9 changes: 9 additions & 0 deletions warehouse/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! entry point
use clap::Parser;
use libra_warehouse::warehouse_cli::WarehouseCli;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
WarehouseCli::parse().run();
Ok(())
}
37 changes: 37 additions & 0 deletions warehouse/src/warehouse_cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use anyhow::{bail, Result};
use clap::{Parser, Subcommand};
use std::{fs, path::PathBuf};

// use crate::{read_snapshot, restore, restore_bundle::RestoreBundle};

#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
#[clap(arg_required_else_help(true))]
/// DB tools e.g.: backup, restore, export to json
pub struct WarehouseCli {
#[clap(subcommand)]
command: Sub,
}

#[derive(Subcommand)]
#[allow(clippy::large_enum_variant)]
pub enum Sub {
/// scans directory and subdirectory for manifests
/// Tries to identify the libra version they belong to (v5 etc.)
// #[clap(su)]
Scan {
#[clap(long, short('d'))]
dir_archive: PathBuf
},

}

impl WarehouseCli {
pub fn run(&self) {
match &self.command {
Sub::Scan { dir_archive } => {
dbg!(&dir_archive)
},
};
}
}

0 comments on commit 1bcb815

Please sign in to comment.