diff --git a/examples/oracle-example/src/lib.rs b/examples/oracle-example/src/lib.rs index 169fa4f..45e79d1 100644 --- a/examples/oracle-example/src/lib.rs +++ b/examples/oracle-example/src/lib.rs @@ -4,8 +4,12 @@ extern crate alloc; -use alloc::{string::ToString, vec::Vec}; -use codec::Decode; +use alloc::{ + string::{String, ToString}, + vec, + vec::Vec, +}; +use codec::{Decode, Encode}; use entropy_programs_core::{bindgen::Error, bindgen::*, export_program, prelude::*}; use serde::{Deserialize, Serialize}; /// JSON-deserializable struct that will be used to derive the program-JSON interface. @@ -18,6 +22,9 @@ pub struct UserConfig {} #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] pub struct AuxData {} +// Oracle data is heading block_number_entropy as I expect that to be passed below to the evaluate function. +pub const ORACLE_DATA: [&str; 1] = ["block_number_entropy"]; + // TODO confirm this isn't an issue for audit register_custom_getrandom!(always_fail); diff --git a/templates/basic-template/Cargo.toml b/templates/basic-template/Cargo.toml index ef305de..61c3259 100644 --- a/templates/basic-template/Cargo.toml +++ b/templates/basic-template/Cargo.toml @@ -18,7 +18,7 @@ strip = "debuginfo" crate-type = ["cdylib", "rlib"] [dependencies] -entropy-programs-core = { git = "https://github.com/entropyxyz/programs.git", tag = "v0.10.0" } +entropy-programs-core = { git = "https://github.com/entropyxyz/programs.git", branch = "master" } schemars = { version = "0.8.16", optional = true } serde = { version = "1.0", default-features = false, features = [ "alloc", diff --git a/templates/basic-template/cli/src/main.rs b/templates/basic-template/cli/src/main.rs index abfb492..dcb3d1f 100644 --- a/templates/basic-template/cli/src/main.rs +++ b/templates/basic-template/cli/src/main.rs @@ -4,6 +4,7 @@ use dotenv::dotenv; use entropy_test_cli::{run_command, Cli, PROGRAM_VERSION_NUMBER}; use generate_types::generate_types; use project_root::get_project_root; +use std::fs; #[tokio::main] async fn main() -> anyhow::Result<()> { @@ -22,6 +23,19 @@ async fn main() -> anyhow::Result<()> { get_project_root()?.to_string_lossy() ); + let oracle_data = format!( + "{}/{{project-name}}_serialized_oracle_data_type.txt", + get_project_root()?.to_string_lossy() + ); + + // length is 1 if empty and can ignore, scale codec length + let decoded_oracle_data = fs::read(oracle_data.clone()).unwrap(); + let oracle_option = if decoded_oracle_data.len() == 1 { + None + } else { + Some(oracle_data.into()) + }; + let cli = Cli::parse(); let json_ouput = cli.json; match run_command( @@ -29,6 +43,7 @@ async fn main() -> anyhow::Result<()> { Some(program.into()), Some(config_interface.into()), Some(aux_data_interface.into()), + oracle_option, Some(PROGRAM_VERSION_NUMBER), ) .await diff --git a/templates/basic-template/generate-types/Cargo.toml b/templates/basic-template/generate-types/Cargo.toml index a1c0529..c67c16f 100644 --- a/templates/basic-template/generate-types/Cargo.toml +++ b/templates/basic-template/generate-types/Cargo.toml @@ -11,3 +11,4 @@ program = { package = "{{project-name}}", path = "..", default-features = false, ] } schemars = "0.8.16" serde_json = { version = "1.0" } +codec = { package = "parity-scale-codec", version = "3.6.8", default-features = false } diff --git a/templates/basic-template/generate-types/src/lib.rs b/templates/basic-template/generate-types/src/lib.rs index ed3eb57..f1cc9a7 100644 --- a/templates/basic-template/generate-types/src/lib.rs +++ b/templates/basic-template/generate-types/src/lib.rs @@ -1,27 +1,35 @@ use schemars::schema_for; use std::fs; -use program::{UserConfig, AuxData}; +use program::{UserConfig, AuxData, ORACLE_DATA}; +use codec::Encode; pub fn generate_types() { let schema_config = schema_for!(UserConfig); fs::write( - "./{{project-name}}_serialized_config_type.txt", + "./tests_serialized_config_type.txt", format!( "{:?}", serde_json::to_vec(&schema_config) - .expect("error converting user config for device key proxy") + .expect("error converting user config") ), ) - .expect("Failed to write to device key proxy config"); + .expect("Failed to write to config"); let schema_aux_data = schema_for!(AuxData); fs::write( - "./{{project-name}}_serialized_aux_data_type.txt", + "./tests_serialized_aux_data_type.txt", format!( "{:?}", serde_json::to_vec(&schema_aux_data) - .expect("error converting user aux_data for device key proxy") + .expect("error converting user aux_data") ), ) - .expect("Failed to write to device key proxy aux_data"); -} + .expect("Failed to write to proxy aux_data"); + + let oracle_data = ORACLE_DATA.iter().map(|x| x.encode()).collect::>(); + fs::write( + "./tests_serialized_oracle_data_type.txt", + oracle_data.encode() + ) + .expect("Failed to write oracle_data"); +} \ No newline at end of file diff --git a/templates/basic-template/src/lib.rs b/templates/basic-template/src/lib.rs index 77df903..25f03c7 100644 --- a/templates/basic-template/src/lib.rs +++ b/templates/basic-template/src/lib.rs @@ -27,6 +27,9 @@ pub struct UserConfig { pub struct AuxData { } +/// Oracle data used, (change 0 to amount of items in vector) +pub const ORACLE_DATA: [&str; 0] = []; + pub struct {{project-name | upper_camel_case}}; impl Program for {{project-name | upper_camel_case}} {