From 5a385b3e604cc90cbe71d02a4b9885c687e5fbd1 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 18 Apr 2024 14:06:06 -0400 Subject: [PATCH 1/5] Add testnet account json --- node/cli/src/endowed_accounts.rs | 23 ++++++++++++++++++----- testnet_accounts.json | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 testnet_accounts.json diff --git a/node/cli/src/endowed_accounts.rs b/node/cli/src/endowed_accounts.rs index ee4e0c567..55b6499e1 100644 --- a/node/cli/src/endowed_accounts.rs +++ b/node/cli/src/endowed_accounts.rs @@ -14,13 +14,19 @@ // along with this program. If not, see . //! 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 sp_core::{crypto::Ss58Codec, sr25519}; +use std::{fs::File, io::Read}; pub fn endowed_accounts_dev() -> Vec { - vec![ + // handle user submitted file for tokens + let mut file = File::open("testnet_accounts.json").expect("file should open read only"); + let mut data = String::new(); + file.read_to_string(&mut data).expect("Unable to read file"); + let accounts: Vec = serde_json::from_str(&data).expect("JSON parse error"); + + let mut inital_accounts = vec![ get_account_id_from_seed::("Alice"), get_account_id_from_seed::("Bob"), get_account_id_from_seed::("Charlie"), @@ -40,5 +46,12 @@ pub fn endowed_accounts_dev() -> Vec { 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 accounts { + inital_accounts + .push(AccountId::from_string(&address).expect("failed to convert a testnet_address")) + } + + inital_accounts } diff --git a/testnet_accounts.json b/testnet_accounts.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/testnet_accounts.json @@ -0,0 +1 @@ +[] From 88d6b62364ed07faebdaebe3a62e3390b2355299 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 18 Apr 2024 14:08:14 -0400 Subject: [PATCH 2/5] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33ff97331..2169f1924 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ At the moment this project **does not** adhere to and sr25519 keypairs will be different what they were before. ### Added +- Add testnet account json ([#769](https://github.com/entropyxyz/entropy-core/pull/769)) ### Changed - Derive the threshold account keypair and x25519 keypair from mnemonic using HKDF ([#709](https://github.com/entropyxyz/entropy-core/pull/709)) From def1f1f083018d65d2e79dc21d3b41c0321006a5 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 18 Apr 2024 15:47:47 -0400 Subject: [PATCH 3/5] fix --- Cargo.lock | 1 + node/cli/Cargo.toml | 1 + node/cli/src/endowed_accounts.rs | 7 ++++++- testnet_accounts.json => testnet-accounts.json | 0 4 files changed, 8 insertions(+), 1 deletion(-) rename testnet_accounts.json => testnet-accounts.json (100%) diff --git a/Cargo.lock b/Cargo.lock index f1283f61e..ef8e2c114 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2378,6 +2378,7 @@ dependencies = [ "pallet-transaction-payment", "pallet-transaction-payment-rpc", "parity-scale-codec", + "project-root", "rand", "sc-authority-discovery", "sc-basic-authorship", diff --git a/node/cli/Cargo.toml b/node/cli/Cargo.toml index a0ee46fd1..cd8699d74 100644 --- a/node/cli/Cargo.toml +++ b/node/cli/Cargo.toml @@ -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 } diff --git a/node/cli/src/endowed_accounts.rs b/node/cli/src/endowed_accounts.rs index 55b6499e1..50fa8fffa 100644 --- a/node/cli/src/endowed_accounts.rs +++ b/node/cli/src/endowed_accounts.rs @@ -16,12 +16,17 @@ //! Pre-endowed accounts used for the development network 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 { // handle user submitted file for tokens - let mut file = File::open("testnet_accounts.json").expect("file should open read only"); + let mut file = File::open(format!( + "{}/testnet-accounts.json", + get_project_root().expect("Error getting project root").to_string_lossy() + )) + .expect("file should open read only"); let mut data = String::new(); file.read_to_string(&mut data).expect("Unable to read file"); let accounts: Vec = serde_json::from_str(&data).expect("JSON parse error"); diff --git a/testnet_accounts.json b/testnet-accounts.json similarity index 100% rename from testnet_accounts.json rename to testnet-accounts.json From 02ad0e1ad4b590d496d49ca3952bdc5040dbb9c2 Mon Sep 17 00:00:00 2001 From: JesseAbram <33698952+JesseAbram@users.noreply.github.com> Date: Tue, 23 Apr 2024 07:41:04 -0700 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Hernando Castano --- CHANGELOG.md | 1 - node/cli/src/endowed_accounts.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2169f1924..33ff97331 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,6 @@ At the moment this project **does not** adhere to and sr25519 keypairs will be different what they were before. ### Added -- Add testnet account json ([#769](https://github.com/entropyxyz/entropy-core/pull/769)) ### Changed - Derive the threshold account keypair and x25519 keypair from mnemonic using HKDF ([#709](https://github.com/entropyxyz/entropy-core/pull/709)) diff --git a/node/cli/src/endowed_accounts.rs b/node/cli/src/endowed_accounts.rs index 50fa8fffa..f9923ddeb 100644 --- a/node/cli/src/endowed_accounts.rs +++ b/node/cli/src/endowed_accounts.rs @@ -29,7 +29,7 @@ pub fn endowed_accounts_dev() -> Vec { .expect("file should open read only"); let mut data = String::new(); file.read_to_string(&mut data).expect("Unable to read file"); - let accounts: Vec = serde_json::from_str(&data).expect("JSON parse error"); + let externally_endowed_accounts: Vec = serde_json::from_str(&data).expect("JSON parse error"); let mut inital_accounts = vec![ get_account_id_from_seed::("Alice"), From 9960dc1c7bd5c7da390331b7e0372f699079a415 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Tue, 23 Apr 2024 10:58:05 -0400 Subject: [PATCH 5/5] clean --- .../cli/src/chain_spec/testnet-accounts.json | 0 node/cli/src/endowed_accounts.rs | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) rename testnet-accounts.json => node/cli/src/chain_spec/testnet-accounts.json (100%) diff --git a/testnet-accounts.json b/node/cli/src/chain_spec/testnet-accounts.json similarity index 100% rename from testnet-accounts.json rename to node/cli/src/chain_spec/testnet-accounts.json diff --git a/node/cli/src/endowed_accounts.rs b/node/cli/src/endowed_accounts.rs index f9923ddeb..0c7284c91 100644 --- a/node/cli/src/endowed_accounts.rs +++ b/node/cli/src/endowed_accounts.rs @@ -22,14 +22,16 @@ use std::{fs::File, io::Read}; pub fn endowed_accounts_dev() -> Vec { // handle user submitted file for tokens - let mut file = File::open(format!( - "{}/testnet-accounts.json", - get_project_root().expect("Error getting project root").to_string_lossy() - )) - .expect("file should open read only"); + 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 = serde_json::from_str(&data).expect("JSON parse error"); + let externally_endowed_accounts: Vec = + serde_json::from_str(&data).expect("JSON parse error"); let mut inital_accounts = vec![ get_account_id_from_seed::("Alice"), @@ -53,9 +55,12 @@ pub fn endowed_accounts_dev() -> Vec { crate::chain_spec::tss_account_id::CHARLIE.clone(), ]; - for address in accounts { - inital_accounts - .push(AccountId::from_string(&address).expect("failed to convert a testnet_address")) + 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