From fd215a86f4404edf73ddff75c275014423596c86 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Tue, 17 Dec 2024 14:40:58 -0500 Subject: [PATCH] update template --- examples/oracle-example/src/lib.rs | 2 +- templates/basic-template/Cargo.toml | 2 +- templates/basic-template/cli/Cargo.toml | 2 +- templates/basic-template/cli/src/main.rs | 6 +++++ .../basic-template/generate-types/Cargo.toml | 1 + .../basic-template/generate-types/src/lib.rs | 24 ++++++++++++------- templates/basic-template/src/lib.rs | 3 +++ 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/examples/oracle-example/src/lib.rs b/examples/oracle-example/src/lib.rs index 86c55cf..99ed5b5 100644 --- a/examples/oracle-example/src/lib.rs +++ b/examples/oracle-example/src/lib.rs @@ -22,7 +22,7 @@ pub struct UserConfig {} #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] pub struct AuxData {} -pub const Oracle_Data: [&str; 1] = ["block_number_entropy"]; +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/Cargo.toml b/templates/basic-template/cli/Cargo.toml index b057ec0..6b1c423 100644 --- a/templates/basic-template/cli/Cargo.toml +++ b/templates/basic-template/cli/Cargo.toml @@ -17,4 +17,4 @@ anyhow = "1.0.82" dotenv = "0.15.0" generate-types = { path = "../generate-types" } project-root = "0.2.2" -entropy-test-cli = { git = "https://github.com/entropyxyz/entropy-core.git", branch = "master" } +entropy-test-cli = { git = "https://github.com/entropyxyz/entropy-core.git", branch = "add-oracle-data-to-store-program" } diff --git a/templates/basic-template/cli/src/main.rs b/templates/basic-template/cli/src/main.rs index abfb492..4fb7afa 100644 --- a/templates/basic-template/cli/src/main.rs +++ b/templates/basic-template/cli/src/main.rs @@ -22,6 +22,11 @@ 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() + ); + let cli = Cli::parse(); let json_ouput = cli.json; match run_command( @@ -29,6 +34,7 @@ async fn main() -> anyhow::Result<()> { Some(program.into()), Some(config_interface.into()), Some(aux_data_interface.into()), + Some(oracle_data.into()), 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..ec1b2b1 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.0.0", 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..55721a5 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", + serde_json::to_vec(&oracle_data).expect("error converting user oracle_data") + ) + .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}} {