-
Notifications
You must be signed in to change notification settings - Fork 41
feat(core): load genesis file by network id #250
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
Open
dan-da
wants to merge
8
commits into
kindelia:dev
Choose a base branch
from
dan-da:issue_243
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f345e8f
feat(node): store state for any # of networks
dan-da 99499bd
change network id
o-santi 375f80b
feat(core): load genesis file by network id
dan-da f638273
feat(cli): git init installs genesis file
dan-da ea0ec5d
fix(cli): network_id --> genesis for test cmd
dan-da f2a8acd
refactor(cli): simplify genesis file loading
dan-da 8a31299
feat(cli): accept genesis statements from user
dan-da 6e2b77b
fix(cli): use default if prop not in config file
dan-da File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # About this directory | ||
|
|
||
| The `genesis/networks` directory holds genesis block files, one per network. | ||
|
|
||
| Important! All files inside the `networks` sub-directory get compiled into the | ||
| `kindelia` executable. So please do not put any other type of file inside and | ||
| observe the naming convention. | ||
|
|
||
| The files are named to match hexadecimal network identifiers as specified | ||
| in the config file with extension `.kdl`. For example, `network/0xCAFE0006.kdl` corresponds to network `0xCAFE0006`. | ||
|
|
||
| Typically a new network is created by bumping this value, eg creating the | ||
| file `networks/0xCAFE0007.kdl`. Also `../default.toml` should be updated to match. |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| use include_dir::{include_dir, Dir}; | ||
| use thiserror::Error; | ||
|
|
||
| #[derive(Error, Debug)] | ||
| pub enum GenesisCodeError { | ||
| #[error("Unknown network: {0}.")] | ||
| UnknownNetwork(u32), | ||
|
|
||
| #[error("Invalid Utf8 in genesis block for network: {network_id:?}.")] | ||
| InvalidUtf8 { network_id: u32, source: std::str::Utf8Error }, | ||
| } | ||
|
|
||
| // Todo: it would be cleaner to return the contents as &[u8] without | ||
| // UTF8 conversion. However the result ultimately gets passed to | ||
| // parse_code() as &str, so the UTF-8 conversion has to happen somewhere. | ||
| // Likely the correct thing would be to change parse_code to accept | ||
| // &[u8] instead. | ||
| pub fn genesis_code(network_id: u32) -> Result<&'static str, GenesisCodeError> { | ||
| const GENESIS_DIR: Dir<'_> = | ||
| include_dir!("$CARGO_MANIFEST_DIR/genesis/networks"); | ||
|
|
||
| let fname = format!("{:#02X}.kdl", network_id); | ||
| let contents = GENESIS_DIR | ||
| .get_file(&fname) | ||
| .ok_or(GenesisCodeError::UnknownNetwork(network_id))? | ||
| .contents(); | ||
|
|
||
| std::str::from_utf8(contents) | ||
| .map_err(|e| GenesisCodeError::InvalidUtf8 { network_id, source: e }) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.