Skip to content

Commit

Permalink
dev check in before switching approaches
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Oct 8, 2023
1 parent 78c3627 commit 2b1f0c0
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 8 deletions.
5 changes: 5 additions & 0 deletions x-export/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cargo run --release --bin x-export -- utxo-index

Optional args:
--appdir defaults to default rusty-kaspa appdir
--outdir defauls to home dir
37 changes: 35 additions & 2 deletions x-export/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{
use std::{
fs,
path::PathBuf,
};
Expand All @@ -25,4 +25,37 @@ pub fn get_out_dir() -> PathBuf {
return outdir;
}

// TODO get_out_dir() to put file in users home dir by default

pub struct Dirs {
home_dir: PathBuf,

app_dir: PathBuf,
network_dir: PathBuf,

db_dir: PathBuf,
utxo_index_db_dir: PathBuf,
meta_db_dir: PathBuf,
consensus_db_dir: PathBuf,
active_consensus_db_dir: PathBuf,

out_dir: PathBuf,
}

impl Dirs {
pub fn new(&self, appdir: PathBuf, out_dir: PathBuf) -> Self {
// TODO
Dirs {
home_dir: get_home_dir(),

app_dir: appdir,
network_dir: self.app_dir.join("kaspa-mainnet"), // TODO undo hardcode

db_dir: self.network_dir.join("datadir"),
utxo_index_db_dir: self.db_dir.join("utxoindex"),
meta_db_dir: self.db_dir.join("meta"),
consensus_db_dir: self.db_dir.join("consensus")

out_dir: PathBuf
}
}
}
2 changes: 2 additions & 0 deletions x-export/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod utxoindex;
mod stores;

use clap::Parser;
use config::Dirs;

fn main() {
let cli = cli::Cli::parse();
Expand All @@ -12,6 +13,7 @@ fn main() {
cli::Commands::UtxoIndex(args) => {
println!("Running subcommand to export utxo index");

Dirs::new(args.appdir, args.outdir);
utxoindex::export::export_utxo_index(args);
}
}
Expand Down
Empty file added x-export/src/stores/meta.rs
Empty file.
32 changes: 26 additions & 6 deletions x-export/src/utxoindex/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use kaspa_consensus::model::stores::tips::{
DbTipsStore,
TipsStoreReader,
};
use kaspa_consensus_core::tx::ScriptPublicKey;
use kaspa_consensus_core::{
tx::ScriptPublicKey,
BlockHashSet
};
use kaspa_database::{
prelude::{
CachedDbAccess,
Expand Down Expand Up @@ -41,20 +44,35 @@ pub fn export_utxo_index(args: UtxoIndexArgs) {
println!("outdir: {}", args.outdir.display());
println!("db_dir: {}", db_dir.display());

// Init utxoindex DB and access object
// utxoindex DB and access object
let utxoindex_db_dir = db_dir.join("utxoindex");
println!("utxoindex_db_dir: {}", utxoindex_db_dir.display());
let utxo_db = kaspa_database::prelude::ConnBuilder
::default()
.with_db_path(utxoindex_db_dir)
.build();
let db_access: CachedDbAccess<UtxoEntryFullAccessKey, CompactUtxoEntry> = CachedDbAccess::new(
utxo_db,
utxo_db.clone(),
0,
DatabaseStorePrefixes::UtxoIndex.into()
);

// Init meta DB and access object
/******** START: Read UtxoIndexTips store ********/
// UtxoIndexTips reader
let utxo_index_tips_item: CachedDbItem<Arc<BlockHashSet>> = CachedDbItem::new(
utxo_db.clone(),
DatabaseStorePrefixes::UtxoIndexTips.into()
);
let utxo_tips = utxo_index_tips_item.read().unwrap();
println!("num tip hashes: {}", utxo_tips.as_ref().len());
for utxo_tip in utxo_tips.iter() {
println!("tip hash: {:?}", utxo_tip);
}
/******** END: Read UtxoIndexTips store ********/

/******** START: Read Tips store ********/
// Meta DB reader
// TODO move to ./stores/meta.rs
let meta_db_dir = db_dir.join("meta");
println!("meta_db_dir: {}", meta_db_dir.display());
let meta_db = kaspa_database::prelude::ConnBuilder
Expand All @@ -70,15 +88,15 @@ pub fn export_utxo_index(args: UtxoIndexArgs) {
let consensus = ConsensusEntry::from_key(meta_db_item.read().unwrap().current_consensus_key.unwrap());
println!("active consensus dir: {}", consensus.directory_name);

// Init consensus DB and access obejct
// Consensus DB reader
let consensus_db_root_dir = db_dir.join("consensus");
let active_consensus_db_dir = consensus_db_root_dir.join(consensus.directory_name);
let consensus_db = kaspa_database::prelude::ConnBuilder
::default()
.with_db_path(active_consensus_db_dir)
.build();

// dag tip store
// Use pub dag tip store
let tip_store = DbTipsStore::new(consensus_db);

// get dag tip hashes
Expand All @@ -87,6 +105,8 @@ pub fn export_utxo_index(args: UtxoIndexArgs) {
for tip in tips.iter() {
println!("tip hash: {:?}", tip);
}

/******** END: Read Tips store ********/

// TODO get selected dag tip hash?
// TODO get timestamp and daa for selected tip hash
Expand Down

0 comments on commit 2b1f0c0

Please sign in to comment.