Skip to content
Open
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
.DS_Store
*/**/.DS_Store

.vscode
.vscode

*/tape.*.toml
tape.*.toml
92 changes: 86 additions & 6 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 @@ -69,6 +69,7 @@ mime = "0.3"
mime_guess = "2.0"
log = "0.4"
env_logger = "0.11"
shellexpand = "2.1.0"

# network-specific
futures = "0.3"
Expand All @@ -82,6 +83,7 @@ hyper = { version = "1.6.0", features = ["http1", "server"] }
hyper-util = { version = "0.1", features = ["tokio"] }
lazy_static = "1.5.0"
http-body-util = "0.1.3"
toml = "0.9.5"

[patch.crates-io]

Expand Down
3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ packx.workspace = true

anyhow.workspace = true
chrono.workspace = true
serde.workspace = true
serde_json.workspace = true
clap.workspace = true
colored.workspace = true
Expand All @@ -36,6 +37,8 @@ num_enum.workspace = true
log.workspace = true
env_logger.workspace = true
num_cpus.workspace = true
toml.workspace = true
shellexpand.workspace = true

mime.workspace = true
mime_guess.workspace = true
Expand Down
40 changes: 21 additions & 19 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::commitment_config::CommitmentConfig;
use solana_sdk::signature::Keypair;
use tape_network::store::TapeStore;
use std::env;
use std::str::FromStr;
use std::path::PathBuf;
use std::sync::Arc;

use crate::keypair::{get_keypair_path, get_payer};
use crate::keypair::get_payer;
use crate::config::TapeConfig;

#[derive(Parser)]
#[command(
Expand All @@ -22,18 +22,12 @@ pub struct Cli {
#[command(subcommand)]
pub command: Commands,

#[arg(short = 'c', long = "config", help = "Path to config file (overrides default)", global = true)]
pub config: Option<PathBuf>,

#[arg(short = 'k', long = "keypair", global = true)]
pub keypair_path: Option<PathBuf>,

#[arg(
short = 'u',
long = "cluster",
default_value = "l",
global = true,
help = "Cluster to use: l (localnet), m (mainnet), d (devnet), t (testnet),\n or a custom RPC URL"
)]
pub cluster: Cluster,

#[arg(short = 'v', long = "verbose", help = "Print verbose output", global = true)]
pub verbose: bool,
}
Expand Down Expand Up @@ -239,31 +233,37 @@ impl FromStr for Cluster {
}

pub struct Context {
pub config: Arc<TapeConfig>,
pub rpc: Arc<RpcClient>,
pub keypair_path: PathBuf,
pub payer: Keypair
}

impl Context{
pub fn try_build(cli:&Cli) -> Result<Self> {
let rpc_url = cli.cluster.rpc_url();

// loading up configs
let config = Arc::new(TapeConfig::load(&cli.config)?);

let rpc_url = config.solana.rpc_url.to_string();
let commitment_level = config.solana.commitment.to_commitment_config();
let rpc = Arc::new(
RpcClient::new_with_commitment(rpc_url.clone(),
CommitmentConfig::finalized())
commitment_level)
);
let keypair_path = get_keypair_path(cli.keypair_path.clone());

let keypair_path = config.solana.keypair_path();
let payer = get_payer(keypair_path.clone())?;

Ok(Self {
config,
rpc,
keypair_path,
payer
})

}

pub fn keyapir_path(&self) -> &PathBuf{
&self.keypair_path
pub fn keypair_path(&self) -> PathBuf {
self.config.solana.keypair_path()
}

pub fn rpc(&self) -> &Arc<RpcClient>{
Expand All @@ -275,7 +275,9 @@ impl Context{
}

pub fn open_secondary_store_conn_mine(&self) -> Result<TapeStore> {
Ok(tape_network::store::secondary_mine()?)
let rocksdb_config = self.config.storage.rocksdb.as_ref()
.ok_or_else(|| anyhow::anyhow!("RocksDB config not found"))?;
Ok(tape_network::store::secondary_mine(&rocksdb_config.primary_path, &rocksdb_config.secondary_path_mine)?)
}

pub fn open_secondary_store_conn_web(&self) -> Result<TapeStore> {
Expand Down
Loading