Skip to content

Commit

Permalink
Add oracle data to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Dec 17, 2024
1 parent a1e3698 commit b7e4157
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
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.

1 change: 1 addition & 0 deletions crates/test-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ 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)
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 @@ -209,6 +212,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 @@ -294,6 +298,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 @@ -320,6 +325,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 @@ -332,7 +347,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

0 comments on commit b7e4157

Please sign in to comment.