Skip to content
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
15 changes: 11 additions & 4 deletions node/src/chainspec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub fn local_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
testnet::get_evm_balance_distribution(),
]),
testnet::get_substrate_balance_distribution(),
develop::get_evm_claims(),
develop::get_local_claims(),
true,
)
},
Expand Down Expand Up @@ -258,11 +258,13 @@ fn testnet_genesis(
.collect::<Vec<_>>();

let num_endowed_accounts = endowed_accounts.len();
let claims: Vec<(MultiAddress, Balance, Option<StatementKind>)> = endowed_accounts

let claims_list: Vec<(MultiAddress, Balance, Option<StatementKind>)> = endowed_accounts
.iter()
.map(|x| (MultiAddress::Native(x.clone()), ENDOWMENT, Some(StatementKind::Regular)))
.chain(claims.into_iter().map(|(a, b)| (a, b, Some(StatementKind::Regular))))
.chain(claims.clone().into_iter().map(|(a, b)| (a, b, Some(StatementKind::Regular))))
.collect();

let vesting_claims: Vec<(
MultiAddress,
BoundedVec<(Balance, Balance, BlockNumber), MaxVestingSchedules>,
Expand All @@ -273,6 +275,11 @@ fn testnet_genesis(
bounded_vec.try_push((ENDOWMENT, ENDOWMENT, 0)).unwrap();
(MultiAddress::Native(x.clone()), bounded_vec)
})
.chain(claims.into_iter().map(|(a, b)| {
let mut bounded_vec = BoundedVec::new();
bounded_vec.try_push((b, b, 0)).unwrap();
(a, bounded_vec)
}))
.collect();

RuntimeGenesisConfig {
Expand Down Expand Up @@ -355,7 +362,7 @@ fn testnet_genesis(
phantom: PhantomData,
},
claims: ClaimsConfig {
claims,
claims: claims_list,
vesting: vesting_claims,
expiry: Some((
200u64,
Expand Down
27 changes: 26 additions & 1 deletion node/src/distributions/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ use std::str::FromStr;
use fp_evm::GenesisAccount;
use pallet_airdrop_claims::MultiAddress;
use sp_core::{H160, U256};
use sp_runtime::AccountId32;
use tangle_primitives::Balance;

pub fn get_evm_claims() -> Vec<(MultiAddress, Balance)> {
pub fn get_local_claims() -> Vec<(MultiAddress, Balance)> {
vec![
// Test account with a simple menmonic
// Mnemonic: "test test test test test test test test test test test junk"
Expand All @@ -34,6 +35,30 @@ pub fn get_evm_claims() -> Vec<(MultiAddress, Balance)> {
),
1_000_000_000_000_000_000_000_000u128,
),
(
MultiAddress::EVM(
H160::from_str("2DFA35bd8C59C38FB3eC4e71b0106160E130A40E")
.expect("internal H160 is valid; qed")
.into(),
),
1_000_000_000_000_000_000_000_000u128,
),
(
MultiAddress::Native(
AccountId32::from_str("5EbkKKTdRJzP1j3aM3S7q178du6tW7ZVWK9Dtjx9CbTFEpGf")
.expect("internal AccountId32 is valid; qed")
.into(),
),
1_000_000_000_000_000_000_000_000u128,
),
(
MultiAddress::Native(
AccountId32::from_str("5DLXgUoVVeCZKHduaVhkH4RvLcyG1GdQwLqYLd4aFuYX1qve")
.expect("internal AccountId32 is valid; qed")
.into(),
),
1_000_000_000_000_000_000_000_000u128,
),
]
}

Expand Down
24 changes: 19 additions & 5 deletions pallets/claims/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,11 @@ impl<T: Config> Pallet<T> {
// Constructs the message that PolkadotJS would sign.
fn polkadotjs_signable_message(what: &[u8], extra: &[u8]) -> Vec<u8> {
let mut v = Vec::new();
let polkadotjs_prefix = b"<Bytes>";
let polkadotjs_suffix = b"</Bytes>";
let prefix = T::Prefix::get();
v.extend_from_slice(polkadotjs_prefix);

v.extend_from_slice(prefix);
v.extend_from_slice(what);
v.extend_from_slice(extra);
v.extend_from_slice(polkadotjs_suffix);
v
}

Expand All @@ -579,6 +576,7 @@ impl<T: Config> Pallet<T> {
extra: &[u8],
) -> Option<MultiAddress> {
let msg = keccak_256(&Self::polkadotjs_signable_message(what, extra));

let public: Public = match addr.clone() {
MultiAddress::EVM(_) => return None,
MultiAddress::Native(a) => {
Expand All @@ -587,9 +585,25 @@ impl<T: Config> Pallet<T> {
Public(bytes)
},
};

match sr25519_verify(&s.0, &msg, &public) {
true => Some(addr),
false => None,
false => {
// If the signature verification fails, we try to wrap the hashed msg in a
// `<Bytes></Bytes>` tag and try again.
let polkadotjs_prefix = b"<Bytes>";
let polkadotjs_suffix = b"</Bytes>";

let mut wrapped_msg = Vec::new();
wrapped_msg.extend_from_slice(polkadotjs_prefix);
wrapped_msg.extend_from_slice(&msg);
wrapped_msg.extend_from_slice(polkadotjs_suffix);

match sr25519_verify(&s.0, &wrapped_msg, &public) {
true => Some(addr),
false => None,
}
},
}
}

Expand Down