Skip to content

Commit

Permalink
update template
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Dec 17, 2024
1 parent db8ee33 commit fd215a8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/oracle-example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion templates/basic-template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion templates/basic-template/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
6 changes: 6 additions & 0 deletions templates/basic-template/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,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()
);

let cli = Cli::parse();
let json_ouput = cli.json;
match run_command(
cli,
Some(program.into()),
Some(config_interface.into()),
Some(aux_data_interface.into()),
Some(oracle_data.into()),
Some(PROGRAM_VERSION_NUMBER),
)
.await
Expand Down
1 change: 1 addition & 0 deletions templates/basic-template/generate-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
24 changes: 16 additions & 8 deletions templates/basic-template/generate-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::<Vec<_>>();
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");
}
3 changes: 3 additions & 0 deletions templates/basic-template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}} {
Expand Down

0 comments on commit fd215a8

Please sign in to comment.