Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add oracle data to cli #1222

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

31 changes: 16 additions & 15 deletions crates/test-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ repository ='https://github.com/entropyxyz/entropy-core'
edition ='2021'

[dependencies]
entropy-client={ version="0.3.0", path="../client" }
clap ={ version="4.5.23", features=["derive"] }
colored ="2.2.0"
subxt ="0.35.3"
sp-core ="31.0.0"
anyhow ="1.0.94"
tokio ={ version="1.42", features=["macros", "rt-multi-thread", "io-util", "process"] }
hex ="0.4.3"
bincode ="1.3.3"
x25519-dalek ="2.0.1"
sp-runtime ={ version="32.0.0", default-features=false }
entropy-shared={ version="0.3.0", path="../shared" }
serde_json ="1.0.133"
serde ={ version="1.0.216", features=["derive"] }
reqwest ="0.12.9"
entropy-client ={ version="0.3.0", path="../client" }
clap ={ version="4.5.23", features=["derive"] }
colored ="2.2.0"
subxt ="0.35.3"
sp-core ="31.0.0"
anyhow ="1.0.94"
tokio ={ version="1.42", features=["macros", "rt-multi-thread", "io-util", "process"] }
hex ="0.4.3"
bincode ="1.3.3"
x25519-dalek ="2.0.1"
sp-runtime ={ version="32.0.0", default-features=false }
entropy-shared ={ version="0.3.0", path="../shared" }
serde_json ="1.0.133"
serde ={ version="1.0.216", features=["derive"] }
reqwest ="0.12.9"
parity-scale-codec={ version="3.6.3", default-features=false }
17 changes: 16 additions & 1 deletion crates/test-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use entropy_client::{
},
};
pub use entropy_shared::{QuoteContext, PROGRAM_VERSION_NUMBER};
use parity_scale_codec::Decode;
use sp_core::{sr25519, Hasher, Pair};
use sp_runtime::{traits::BlakeTwo256, Serialize};
use std::{fs, path::PathBuf, str::FromStr};
Expand Down Expand Up @@ -132,6 +133,8 @@ enum CliCommand {
config_interface_file: Option<PathBuf>,
/// The path to a file containing the program aux interface (defaults to empty)
aux_data_interface_file: Option<PathBuf>,
/// The path to a file containing the program oracle data (defaults to empty)
JesseAbram marked this conversation as resolved.
Show resolved Hide resolved
oracle_data_file: Option<PathBuf>,
/// The version number of the program's runtime you compiled with
program_version_number: Option<u8>,
/// The mnemonic to use for the call
Expand Down Expand Up @@ -207,6 +210,7 @@ pub async fn run_command(
program_file_option: Option<PathBuf>,
config_interface_file_option: Option<PathBuf>,
aux_data_interface_file_option: Option<PathBuf>,
oracle_data_file_option: Option<PathBuf>,
program_version_number_option: Option<u8>,
) -> anyhow::Result<String> {
let endpoint_addr = cli.chain_endpoint.clone().unwrap_or_else(|| {
Expand Down Expand Up @@ -292,6 +296,7 @@ pub async fn run_command(
program_file,
config_interface_file,
aux_data_interface_file,
oracle_data_file,
program_version_number,
} => {
let keypair = handle_mnemonic(mnemonic_option)?;
Expand All @@ -318,6 +323,16 @@ pub async fn run_command(
},
};

let oracle_data: Vec<Vec<u8>> = match oracle_data_file {
Some(file_name) => Vec::<Vec<u8>>::decode(&mut (fs::read(file_name)?).as_ref())?,
None => match oracle_data_file_option {
Some(oracle_data_file) => {
Vec::<Vec<u8>>::decode(&mut (fs::read(oracle_data_file)?).as_ref())?
},
None => vec![],
},
};

let program_version_number = match program_version_number_option {
Some(program_version_number) => program_version_number,
None => program_version_number.unwrap_or(0u8),
Expand All @@ -330,7 +345,7 @@ pub async fn run_command(
program,
config_interface,
aux_data_interface,
vec![],
oracle_data,
program_version_number,
)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/test-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn main() -> anyhow::Result<()> {
let now = Instant::now();
let cli = Cli::parse();
let json_ouput = cli.json;
match run_command(cli, None, None, None, None).await {
match run_command(cli, None, None, None, None, None).await {
Ok(output) => {
if json_ouput {
println!("{}", output);
Expand Down
Loading