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

Add testnet account json #769

Merged
merged 5 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ entropy-runtime ={ version="0.0.11", path="../../runtime" }
entropy-shared ={ path="../../crates/shared", default-features=false, features=["wasm-no-std"] }
pallet-registry ={ version="0.0.11", path="../../pallets/registry" }
pallet-staking-extension={ version="0.0.11", path="../../pallets/staking" }
project-root ="0.2.2"

[build-dependencies]
clap={ version="4.2.5", optional=true }
Expand Down
1 change: 1 addition & 0 deletions node/cli/src/chain_spec/testnet-accounts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
33 changes: 28 additions & 5 deletions node/cli/src/endowed_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,26 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Pre-endowed accounts used for the development network
use entropy_runtime::AccountId;
use sp_core::sr25519;

use crate::chain_spec::get_account_id_from_seed;
use entropy_runtime::AccountId;
use project_root::get_project_root;
use sp_core::{crypto::Ss58Codec, sr25519};
use std::{fs::File, io::Read};

pub fn endowed_accounts_dev() -> Vec<AccountId> {
vec![
// handle user submitted file for tokens
let mut file = File::open(
get_project_root()
.expect("Error getting project root")
.join("node/cli/src/chain_spec/testnet-accounts.json"),
)
.expect("unable to open testnet-accounts.json");
let mut data = String::new();
file.read_to_string(&mut data).expect("Unable to read file");
let externally_endowed_accounts: Vec<String> =
serde_json::from_str(&data).expect("JSON parse error");

let mut inital_accounts = vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
Expand All @@ -40,5 +53,15 @@ pub fn endowed_accounts_dev() -> Vec<AccountId> {
crate::chain_spec::tss_account_id::ALICE.clone(),
crate::chain_spec::tss_account_id::BOB.clone(),
crate::chain_spec::tss_account_id::CHARLIE.clone(),
]
];

for address in externally_endowed_accounts {
inital_accounts.push(
AccountId::from_string(&address).unwrap_or_else(|_| {
panic!("failed to convert a testnet_address address: {}", address)
}),
)
}

inital_accounts
}