-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
2,323 additions
and
189 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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,9 @@ | ||
{ | ||
"accountId": "0x00d2bf2d5f62e38d70739c45b56be6170ea26da6370c529cbf3b854b2c95f44f", | ||
"networkId": "substrate", | ||
"publicKey": "0x00d2bf2d5f62e38d70739c45b56be6170ea26da6370c529cbf3b854b2c95f44f", | ||
"secretPhrase": "input scrap paddle tape fiction dentist differ sorry cargo cube mammal width", | ||
"secretSeed": "0xfc9b279be387e666c3e8013c5abdf6780c8db8cb0e5374812e651cd1c331212f", | ||
"ss58Address": "5C5nTkXmGFf56Ew7fXz1TmYzdGyhcTvAZ3KQeLrXeMfcFTFa", | ||
"ss58PublicKey": "5C5nTkXmGFf56Ew7fXz1TmYzdGyhcTvAZ3KQeLrXeMfcFTFa" | ||
} |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
|
@@ -2,8 +2,6 @@ pub mod init; | |
|
||
pub mod prompt; | ||
|
||
pub mod constants; | ||
|
||
pub mod list; | ||
|
||
pub mod run; |
This file contains 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,55 @@ | ||
use std::fs; | ||
|
||
use hex::encode; | ||
use serde_json::json; | ||
use sp_core::{sr25519, Pair}; | ||
|
||
use crate::da::da_layers::DaConfig; | ||
use crate::da::errors::KeyGenError; | ||
use crate::utils::constants::{APP_DA_CONFIG_NAME, APP_SECRET_PHRASE}; | ||
use crate::utils::paths::get_app_home; | ||
|
||
pub struct AvailConfig {} | ||
|
||
impl DaConfig for AvailConfig { | ||
fn setup_and_generate_keypair(&self, app_chain: &str) -> Result<(), KeyGenError> { | ||
let file_path = get_app_home(app_chain)?.join(APP_SECRET_PHRASE); | ||
let file_path_str = file_path.to_string_lossy().to_string(); | ||
let (pair, phrase, seed) = <sr25519::Pair as Pair>::generate_with_phrase(None); | ||
let seed_str = format!("0x{}", encode(seed.as_ref())); | ||
|
||
if let Err(err) = fs::write(file_path, phrase) { | ||
panic!("Error writing to file: {}", err); | ||
} else { | ||
log::info!("Secret phrase stored in app home: {}", file_path_str); | ||
log::info!( | ||
"Please fund {} with atleast 1 AVL (https://docs.availproject.org/about/faucet/)", | ||
pair.public() | ||
); | ||
} | ||
|
||
generate_config(app_chain, &seed_str)?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
fn generate_config(app_chain: &str, seed: &str) -> Result<(), KeyGenError> { | ||
let file_path = get_app_home(app_chain)?.join(APP_DA_CONFIG_NAME); | ||
|
||
let avail_config = json! ({ | ||
"ws_provider": "wss://goldberg.avail.tools:443/ws", | ||
"mode": "sovereign", | ||
"seed": seed, | ||
"app_id": 0, | ||
}) | ||
.to_string(); | ||
|
||
if let Err(err) = fs::write(file_path, avail_config) { | ||
panic!("Error writing to file: {}", err); | ||
} else { | ||
log::info!("Successfully generated Avail config!"); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains 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,29 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use strum_macros::{Display, EnumIter}; | ||
|
||
use crate::da::avail::AvailConfig; | ||
use crate::da::errors::KeyGenError; | ||
use crate::da::no_da::NoDAConfig; | ||
|
||
#[derive(Debug, Serialize, Deserialize, EnumIter, Display)] | ||
pub enum DALayer { | ||
Avail, | ||
Celestia, | ||
Ethereum, | ||
NoDA, | ||
} | ||
|
||
pub trait DaConfig { | ||
fn setup_and_generate_keypair(&self, app_chain: &str) -> Result<(), KeyGenError>; | ||
} | ||
|
||
pub struct DAFactory; | ||
|
||
impl DAFactory { | ||
pub fn new_da(da: &DALayer) -> Box<dyn DaConfig> { | ||
match da { | ||
DALayer::Avail => Box::new(AvailConfig {}), | ||
_ => Box::new(NoDAConfig {}), | ||
} | ||
} | ||
} |
This file contains 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,14 @@ | ||
use std::io; | ||
use std::string::FromUtf8Error; | ||
|
||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum KeyGenError { | ||
#[error("Failed to read file: {0}")] | ||
FailedToIoFilesystem(#[from] io::Error), | ||
#[error("Failed to parse output: {0}")] | ||
FailedToParseOutput(#[from] FromUtf8Error), | ||
#[error("Failed to parse to json: {0}")] | ||
FailedToParseToJson(#[from] serde_json::Error), | ||
} |
This file contains 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,7 @@ | ||
pub mod da_layers; | ||
|
||
pub mod avail; | ||
|
||
pub mod errors; | ||
|
||
pub mod no_da; |
This file contains 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,11 @@ | ||
pub struct NoDAConfig; | ||
|
||
use crate::da::da_layers::DaConfig; | ||
use crate::da::errors::KeyGenError; | ||
|
||
impl DaConfig for NoDAConfig { | ||
fn setup_and_generate_keypair(&self, app_chain: &str) -> Result<(), KeyGenError> { | ||
log::info!("Launching {} without any DA mode", app_chain); | ||
Ok(()) | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -3,3 +3,5 @@ pub mod cli; | |
pub mod app; | ||
|
||
pub mod utils; | ||
|
||
pub mod da; |
This file contains 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 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 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,6 @@ | ||
pub const MADARA_REPO_ORG: &str = "keep-starknet-strange"; | ||
pub const MADARA_REPO_NAME: &str = "madara"; | ||
|
||
pub const APP_CONFIG_NAME: &str = "config.toml"; | ||
pub const APP_DA_CONFIG_NAME: &str = "da-config.json"; | ||
pub const APP_SECRET_PHRASE: &str = "secret-phrase.txt"; |
This file contains 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 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 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 |
---|---|---|
|
@@ -9,3 +9,5 @@ pub mod madara; | |
pub mod errors; | ||
|
||
pub mod toml; | ||
|
||
pub mod constants; |
Oops, something went wrong.