Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracle data type generation #100

Merged
merged 8 commits into from
Dec 20, 2024
Merged

Oracle data type generation #100

merged 8 commits into from
Dec 20, 2024

Conversation

JesseAbram
Copy link
Member

@JesseAbram JesseAbram commented Dec 19, 2024

Generates and posts oracle pointer data for programs pairs with entropyxyz/entropy-core#1222, needs to be merged second to update branch in cargo toml back

examples/oracle-example/src/lib.rs Show resolved Hide resolved
);

// length is 1 if empty and can ignore, scale codec length
let pre = fs::read(oracle_data.clone()).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is pre here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will name better but checking if it can be none, non using oracle causes a decoding error.....could probably fix that but using none is better


// length is 1 if empty and can ignore, scale codec length
let pre = fs::read(oracle_data.clone()).unwrap();
let oracle_option = if pre.len() == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And how come we consider this empty if len == 1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it is scale encoded and scale encoding prefixes the length of the item, so encoding an empty vec![] looks like [0]

templates/basic-template/generate-types/Cargo.toml Outdated Show resolved Hide resolved
@@ -22,13 +23,27 @@ 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come a lossy conversion is being used here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm idk just copying the ones above

Copy link
Contributor

@ameba23 ameba23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇 All looks good.

Although i haven't actually been through the process of generating a program, generating this type and deploying it - maybe there are some gotchas.


pub fn generate_types() {
let schema_config = schema_for!(UserConfig);
fs::write(
"./{{project-name}}_serialized_config_type.txt",
"./tests_serialized_config_type.txt",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im a bit confused about this bit - does it need to be changed back to "./{{project-name}}_serialized_config_type.txt" when this generate template is actually used?


let oracle_data = ORACLE_DATA.iter().map(|x| x.encode()).collect::<Vec<_>>();
fs::write(
"./tests_serialized_oracle_data_type.txt",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i file has a .txt extension i would expect it to be human readable and valid utf-8 - im not sure if scale encoding a vector adds bytes which are invalid utf-8.

@JesseAbram JesseAbram merged commit c351230 into master Dec 20, 2024
2 checks passed
@JesseAbram JesseAbram deleted the Oracle-data-type-generation branch December 20, 2024 20:52
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants