Skip to content

Commit

Permalink
Add signed claim extrinsic (#631)
Browse files Browse the repository at this point in the history
* Add signed claim extrinsic

* Version bujmp

* Fix clippy

* fix clippy and lower fees again

---------

Co-authored-by: 1xstj <[email protected]>
  • Loading branch information
drewstone and 1xstj authored May 7, 2024
1 parent 3a021da commit e909dea
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 35 deletions.
46 changes: 23 additions & 23 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "1.0.1"
version = "1.0.2"
authors = ["Webb Technologies Inc."]
edition = "2021"
license = "Unlicense"
Expand Down
15 changes: 14 additions & 1 deletion pallets/claims/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use sp_io::{
use sp_runtime::{
traits::{CheckedSub, Zero},
transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction},
RuntimeDebug,
AccountId32, RuntimeDebug,
};
use sp_std::{convert::TryInto, prelude::*, vec};
use utils::Sr25519Signature;
Expand Down Expand Up @@ -420,6 +420,19 @@ pub mod pallet {
ExpiryConfig::<T>::set(Some((expiry_block, dest)));
Ok(())
}

/// Claim from signed origin
#[pallet::weight(T::WeightInfo::claim())]
#[pallet::call_index(6)]
pub fn claim_signed(origin: OriginFor<T>, dest: Option<MultiAddress>) -> DispatchResult {
let origin = ensure_signed(origin)?;
let account_id_32 = AccountId32::decode(&mut origin.encode().as_ref())
.map_err(|_| Error::<T>::InvalidNativeAccount)?;
let signer = MultiAddress::Native(account_id_32);
ensure!(Signing::<T>::get(&signer).is_none(), Error::<T>::InvalidStatement);
Self::process_claim(signer, dest)?;
Ok(())
}
}

#[pallet::validate_unsigned]
Expand Down
16 changes: 16 additions & 0 deletions pallets/claims/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use hex_literal::hex;
use parity_scale_codec::Encode;
use secp_utils::*;
use sp_core::ConstU32;
use sp_core::Pair;
use sp_runtime::{BoundedVec, TokenError::Frozen};

// The testing primitives are very useful for avoiding having to work with signatures
Expand Down Expand Up @@ -898,6 +899,21 @@ fn test_claim_from_substrate_address_to_evm() {
});
}

#[test]
fn test_claim_alice_signed_extrinsic() {
new_test_ext().execute_with(|| {
let original_total_claims = Total::<Test>::get();
let claim_of_alice = 500;
let alice_account_id_32 = AccountId32::from(alice_sr25519().public());
assert_ok!(ClaimsPallet::claim_signed(
RuntimeOrigin::signed(alice_account_id_32.clone()),
None,
));
assert_eq!(Total::<Test>::get(), original_total_claims - claim_of_alice);
assert_eq!(Balances::free_balance(alice_account_id_32), 500);
});
}

#[test]
fn test_double_claim_fails_for_substrate_account() {
new_test_ext().execute_with(|| {
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub mod currency {
/// Lets assume 100 TNT = 1USD
/// This assumption forms the base of all fee calculations, revisit this
/// if the assumption is no longer true.
pub const DOLLAR: Balance = UNIT * 100;
pub const DOLLAR: Balance = UNIT * 10;
pub const CENT: Balance = DOLLAR / 100;
pub const MILLICENT: Balance = CENT / 1000;
/// The existential deposit.
Expand Down
9 changes: 4 additions & 5 deletions runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("tangle"),
impl_name: create_runtime_str!("tangle"),
authoring_version: 1,
spec_version: 1001, // v1.0.1
spec_version: 1002, // v1.0.2
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -1043,10 +1043,9 @@ impl pallet_tx_pause::Config for Runtime {
}

parameter_types! {
pub const BasicDeposit: Balance = deposit(0, 200);
pub const ByteDeposit: Balance = deposit(0, 50);
pub const FieldDeposit: Balance = deposit(0, 33);
pub const SubAccountDeposit: Balance = deposit(1, 53);
pub const BasicDeposit: Balance = deposit(0, 100);
pub const ByteDeposit: Balance = deposit(0, 100);
pub const SubAccountDeposit: Balance = deposit(1, 1);
pub const MaxSubAccounts: u32 = 100;
#[derive(Serialize, Deserialize)]
pub const MaxAdditionalFields: u32 = 100;
Expand Down
8 changes: 4 additions & 4 deletions runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("tangle-testnet"),
impl_name: create_runtime_str!("tangle-testnet"),
authoring_version: 1,
spec_version: 1001, // v1.0.1
spec_version: 1002, // v1.0.2
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -1041,9 +1041,9 @@ impl pallet_tx_pause::Config for Runtime {
}

parameter_types! {
pub const BasicDeposit: Balance = deposit(0, 100); // purposely set low, do not copy for mainnet
pub const ByteDeposit: Balance = deposit(0, 100); // purposely set low, do not copy for mainnet
pub const SubAccountDeposit: Balance = deposit(1, 1); // purposely set low, do not copy for mainnet
pub const BasicDeposit: Balance = deposit(0, 100);
pub const ByteDeposit: Balance = deposit(0, 100);
pub const SubAccountDeposit: Balance = deposit(1, 1);
pub const MaxSubAccounts: u32 = 100;
#[derive(Serialize, Deserialize)]
pub const MaxAdditionalFields: u32 = 100;
Expand Down

0 comments on commit e909dea

Please sign in to comment.