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

bugfix: Fix claims pallet #394

Merged
merged 6 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 0 additions & 1 deletion node/src/chainspec/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ pub fn local_mainnet_config(chain_id: u64) -> Result<ChainSpec, String> {
mainnet::get_edgeware_genesis_balance_distribution(),
mainnet::get_leaderboard_balance_distribution(),
mainnet::get_substrate_balance_distribution(),
mainnet::get_local_balance_distribution(),
]),
// Genesis investor / team distribution (pallet-balances + pallet-vesting)
combine_distributions(vec![
Expand Down
4 changes: 4 additions & 0 deletions node/src/chainspec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +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(),
true,
)
},
Expand Down Expand Up @@ -202,6 +203,7 @@ pub fn tangle_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
testnet::get_evm_balance_distribution(),
]),
testnet::get_substrate_balance_distribution(),
vec![],
true,
)
},
Expand Down Expand Up @@ -231,6 +233,7 @@ fn testnet_genesis(
chain_id: u64,
genesis_evm_distribution: Vec<(H160, fp_evm::GenesisAccount)>,
genesis_substrate_distribution: Vec<(AccountId, Balance)>,
claims: Vec<(MultiAddress, Balance)>,
_enable_println: bool,
) -> RuntimeGenesisConfig {
const ENDOWMENT: Balance = 10_000_000 * UNIT;
Expand Down Expand Up @@ -258,6 +261,7 @@ fn testnet_genesis(
let claims: 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))))
.collect();
let vesting_claims: Vec<(
MultiAddress,
Expand Down
19 changes: 19 additions & 0 deletions node/src/distributions/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,26 @@
use std::str::FromStr;

use fp_evm::GenesisAccount;
use pallet_airdrop_claims::MultiAddress;
use sp_core::{H160, U256};
use tangle_primitives::Balance;

pub fn get_evm_claims() -> Vec<(MultiAddress, Balance)> {
vec![
// Test account with a simple menmonic
// Mnemonic: "test test test test test test test test test test test junk"
// Path: m/44'/60'/0'/0/0
// Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
(
MultiAddress::EVM(
H160::from_str("f39Fd6e51aad88F6F4ce6aB8827279cffFb92266")
.expect("internal H160 is valid; qed")
.into(),
),
1_000_000_000_000_000_000_000_000u128,
),
]
}

pub fn get_evm_balance_distribution() -> Vec<(H160, GenesisAccount)> {
vec![
Expand Down
39 changes: 0 additions & 39 deletions node/src/distributions/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,45 +165,6 @@ pub fn get_leaderboard_balance_distribution() -> DistributionResult {
)
}

/// Used for testing purposes
///
/// DO NOT USE IN MAINNET
pub fn get_local_balance_distribution() -> DistributionResult {
let list = vec![
// Test account with a simple menmonic
// Mnemonic: "test test test test test test test test test test test junk"
// Path: m/44'/60'/0'/0/0
// Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
H160::from_str("f39Fd6e51aad88F6F4ce6aB8827279cffFb92266")
.expect("internal H160 is valid; qed"),
// Test account with a simple menmonic
// Mnemonic: "test test test test test test test test test test test junk"
// Path: m/44'/60'/0'/0/1
// Private Key: 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
H160::from_str("70997970C51812dc3A010C7d01b50e0d17dc79C8")
.expect("internal H160 is valid; qed"),
// H160 address of Alice dev account
// Derived from SS58 (42 prefix) address
// SS58: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
// hex: 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d
// Using the full hex key, truncating to the first 20 bytes (the first 40 hex
// chars)
H160::from_str("d43593c715fdd31c61141abd04a99fd6822c8558")
.expect("internal H160 is valid; qed"),
];
let endowment = ONE_PERCENT_TOTAL_SUPPLY / list.len() as u128;
let local_list: Vec<(MultiAddress, u128)> = list
.into_iter()
.map(|address| (MultiAddress::EVM(EthereumAddress(address.0)), endowment))
.collect();
get_distribution_for(
local_list,
Some(StatementKind::Regular),
ONE_MONTH_BLOCKS,
TWO_YEARS_BLOCKS,
)
}

pub fn get_substrate_balance_distribution() -> DistributionResult {
let arr = get_edgeware_snapshot_list()
.into_iter()
Expand Down
39 changes: 32 additions & 7 deletions pallets/claims/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,12 @@ pub mod pallet {
signature: MultiAddressSignature,
) -> DispatchResult {
ensure_none(origin)?;

let data = dest.using_encoded(to_ascii_hex);
let data = match dest {
Some(MultiAddress::EVM(ref evm)) => evm.using_encoded(to_ascii_hex),
Some(MultiAddress::Native(ref native)) => native.using_encoded(to_ascii_hex),
// no dest, no data.
None => Vec::new(),
};
let signer = Self::get_signer_multi_address(signer.clone(), signature, data, vec![])?;
ensure!(Signing::<T>::get(&signer).is_none(), Error::<T>::InvalidStatement);
Self::process_claim(signer, dest)?;
Expand Down Expand Up @@ -407,8 +411,12 @@ pub mod pallet {
statement: Vec<u8>,
) -> DispatchResult {
ensure_none(origin)?;

let data = dest.using_encoded(to_ascii_hex);
let data = match dest {
Some(MultiAddress::EVM(ref evm)) => evm.using_encoded(to_ascii_hex),
Some(MultiAddress::Native(ref native)) => native.using_encoded(to_ascii_hex),
// no dest, no data.
None => Vec::new(),
};
let signer =
Self::get_signer_multi_address(signer.clone(), signature, data, statement.clone())?;
if let Some(s) = Signing::<T>::get(signer.clone()) {
Expand Down Expand Up @@ -460,7 +468,13 @@ pub mod pallet {
// The weight of this logic is included in the `claim` dispatchable.
// </weight>
Call::claim { dest: account, signer, signature } => {
let data = account.using_encoded(to_ascii_hex);
let data = match account {
Some(MultiAddress::EVM(ref evm)) => evm.using_encoded(to_ascii_hex),
Some(MultiAddress::Native(ref native)) =>
native.using_encoded(to_ascii_hex),
// no dest, no data.
None => Vec::new(),
};
match Self::get_signer_multi_address(
signer.clone(),
signature.clone(),
Expand All @@ -475,7 +489,13 @@ pub mod pallet {
// The weight of this logic is included in the `claim_attest` dispatchable.
// </weight>
Call::claim_attest { dest: account, signer, signature, statement } => {
let data = account.using_encoded(to_ascii_hex);
let data = match account {
shekohex marked this conversation as resolved.
Show resolved Hide resolved
Some(MultiAddress::EVM(ref evm)) => evm.using_encoded(to_ascii_hex),
Some(MultiAddress::Native(ref native)) =>
native.using_encoded(to_ascii_hex),
// no dest, no data.
None => Vec::new(),
};
match Self::get_signer_multi_address(
signer.clone(),
signature.clone(),
Expand Down Expand Up @@ -554,10 +574,15 @@ 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>";
shekohex marked this conversation as resolved.
Show resolved Hide resolved
let prefix = T::Prefix::get();
let mut v = prefix.to_vec();
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 Down
Loading
Loading