From a5c69b2a1d6e1fe571ba7194899343db50f834e4 Mon Sep 17 00:00:00 2001 From: JesseAbram <33698952+JesseAbram@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:01:28 -0500 Subject: [PATCH] Add oracle data to cli (#1222) * Add oracle data to cli * fmt * Update crates/test-cli/src/lib.rs Co-authored-by: peg --------- Co-authored-by: peg --- Cargo.lock | 1 + crates/test-cli/Cargo.toml | 31 ++++++++++++++++--------------- crates/test-cli/src/lib.rs | 17 ++++++++++++++++- crates/test-cli/src/main.rs | 2 +- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c3a526da8..6cc06a0fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2768,6 +2768,7 @@ dependencies = [ "entropy-client", "entropy-shared", "hex", + "parity-scale-codec", "reqwest", "serde", "serde_json", diff --git a/crates/test-cli/Cargo.toml b/crates/test-cli/Cargo.toml index b21357028..a77daa104 100644 --- a/crates/test-cli/Cargo.toml +++ b/crates/test-cli/Cargo.toml @@ -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 } diff --git a/crates/test-cli/src/lib.rs b/crates/test-cli/src/lib.rs index 731ab0812..410c57c97 100644 --- a/crates/test-cli/src/lib.rs +++ b/crates/test-cli/src/lib.rs @@ -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}; @@ -132,6 +133,8 @@ enum CliCommand { config_interface_file: Option, /// The path to a file containing the program aux interface (defaults to empty) aux_data_interface_file: Option, + /// The path to a file containing the program oracle data headings (defaults to empty) + oracle_data_file: Option, /// The version number of the program's runtime you compiled with program_version_number: Option, /// The mnemonic to use for the call @@ -207,6 +210,7 @@ pub async fn run_command( program_file_option: Option, config_interface_file_option: Option, aux_data_interface_file_option: Option, + oracle_data_file_option: Option, program_version_number_option: Option, ) -> anyhow::Result { let endpoint_addr = cli.chain_endpoint.clone().unwrap_or_else(|| { @@ -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)?; @@ -318,6 +323,16 @@ pub async fn run_command( }, }; + let oracle_data: Vec> = match oracle_data_file { + Some(file_name) => Vec::>::decode(&mut (fs::read(file_name)?).as_ref())?, + None => match oracle_data_file_option { + Some(oracle_data_file) => { + Vec::>::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), @@ -330,7 +345,7 @@ pub async fn run_command( program, config_interface, aux_data_interface, - vec![], + oracle_data, program_version_number, ) .await?; diff --git a/crates/test-cli/src/main.rs b/crates/test-cli/src/main.rs index 5e176d074..9f41cfd55 100644 --- a/crates/test-cli/src/main.rs +++ b/crates/test-cli/src/main.rs @@ -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);