Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
refactor: Remove unused origin from pre_dispatch_self_contained
Browse files Browse the repository at this point in the history
  • Loading branch information
code0xff committed Sep 12, 2024
1 parent 55ad1ac commit 10e71cb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
8 changes: 2 additions & 6 deletions frame/cosmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ where

pub fn pre_dispatch_self_contained(
&self,
origin: &H160,
dispatch_info: &DispatchInfoOf<T::RuntimeCall>,
len: usize,
) -> Option<Result<(), TransactionValidityError>> {
Expand All @@ -134,7 +133,7 @@ where
return Some(Err(e));
}

Some(Pallet::<T>::validate_transaction_in_block(*origin, tx_bytes))
Some(Pallet::<T>::validate_transaction_in_block(tx_bytes))
} else {
None
}
Expand Down Expand Up @@ -396,10 +395,7 @@ impl<T: Config> Pallet<T> {
///
/// This function must be called during the pre-dispatch phase
/// (just before applying the extrinsic).
pub fn validate_transaction_in_block(
_origin: H160,
tx_bytes: &[u8],
) -> Result<(), TransactionValidityError> {
pub fn validate_transaction_in_block(tx_bytes: &[u8]) -> Result<(), TransactionValidityError> {
let tx = Tx::decode(&mut &*tx_bytes)
.map_err(|_| TransactionValidityError::Invalid(InvalidTransaction::Call))?;

Expand Down
7 changes: 1 addition & 6 deletions frame/cosmos/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,11 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall {

fn pre_dispatch_self_contained(
&self,
info: &Self::SignedInfo,
dispatch_info: &DispatchInfoOf<RuntimeCall>,
len: usize,
) -> Option<Result<(), TransactionValidityError>> {
match self {
RuntimeCall::Cosmos(call) => call.pre_dispatch_self_contained(
&info.to_cosmos_address().unwrap(),
dispatch_info,
len,
),
RuntimeCall::Cosmos(call) => call.pre_dispatch_self_contained(dispatch_info, len),
_ => None,
}
}
Expand Down
14 changes: 7 additions & 7 deletions frame/cosmos/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn pallet_cosmos_msg_send_test() {
};
let dispatch_info = extrinsic.get_dispatch_info();

assert_ok!(call.pre_dispatch_self_contained(&source, &dispatch_info, 0).unwrap());
assert_ok!(call.pre_dispatch_self_contained(&dispatch_info, 0).unwrap());
assert_ok!(extrinsic.function.apply_self_contained(alice).unwrap());

let msg = tx.body.as_ref().unwrap().messages.first().unwrap();
Expand Down Expand Up @@ -87,7 +87,7 @@ fn pallet_cosmos_msg_store_code_test() {
};
let dispatch_info = extrinsic.get_dispatch_info();

assert_ok!(call.pre_dispatch_self_contained(&source, &dispatch_info, 0).unwrap());
assert_ok!(call.pre_dispatch_self_contained(&dispatch_info, 0).unwrap());
assert_ok!(extrinsic.function.apply_self_contained(alice).unwrap());

let (_gas_wanted, _gas_used, events) = System::events()
Expand Down Expand Up @@ -147,7 +147,7 @@ fn pallet_cosmos_msg_instantiate_contract2_test() {
};
let dispatch_info = extrinsic.get_dispatch_info();

assert_ok!(call.pre_dispatch_self_contained(&source, &dispatch_info, 0).unwrap());
assert_ok!(call.pre_dispatch_self_contained(&dispatch_info, 0).unwrap());
assert_ok!(extrinsic.function.apply_self_contained(alice).unwrap());

System::set_block_number(2);
Expand All @@ -165,7 +165,7 @@ fn pallet_cosmos_msg_instantiate_contract2_test() {
};
let dispatch_info = extrinsic.get_dispatch_info();

assert_ok!(call.pre_dispatch_self_contained(&source, &dispatch_info, 0).unwrap());
assert_ok!(call.pre_dispatch_self_contained(&dispatch_info, 0).unwrap());
assert_ok!(extrinsic.function.apply_self_contained(alice).unwrap());
});
}
Expand All @@ -190,7 +190,7 @@ fn pallet_cosmos_msg_execute_contract_test() {
};
let dispatch_info = extrinsic.get_dispatch_info();

assert_ok!(call.pre_dispatch_self_contained(&source, &dispatch_info, 0).unwrap());
assert_ok!(call.pre_dispatch_self_contained(&dispatch_info, 0).unwrap());
assert_ok!(extrinsic.function.apply_self_contained(alice).unwrap());

System::set_block_number(2);
Expand All @@ -208,7 +208,7 @@ fn pallet_cosmos_msg_execute_contract_test() {
};
let dispatch_info = extrinsic.get_dispatch_info();

assert_ok!(call.pre_dispatch_self_contained(&source, &dispatch_info, 0).unwrap());
assert_ok!(call.pre_dispatch_self_contained(&dispatch_info, 0).unwrap());
assert_ok!(extrinsic.function.apply_self_contained(alice).unwrap());

System::set_block_number(3);
Expand All @@ -226,7 +226,7 @@ fn pallet_cosmos_msg_execute_contract_test() {
};
let dispatch_info = extrinsic.get_dispatch_info();

assert_ok!(call.pre_dispatch_self_contained(&source, &dispatch_info, 0).unwrap());
assert_ok!(call.pre_dispatch_self_contained(&dispatch_info, 0).unwrap());
assert_ok!(extrinsic.function.apply_self_contained(alice).unwrap());
});
}
8 changes: 2 additions & 6 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall {

fn pre_dispatch_self_contained(
&self,
info: &Self::SignedInfo,
_info: &Self::SignedInfo,
dispatch_info: &DispatchInfoOf<RuntimeCall>,
len: usize,
) -> Option<Result<(), TransactionValidityError>> {
Expand All @@ -562,11 +562,7 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall {
}
}

call.pre_dispatch_self_contained(
&info.to_cosmos_address().unwrap(),
dispatch_info,
len,
)
call.pre_dispatch_self_contained(dispatch_info, len)
},
_ => None,
}
Expand Down

0 comments on commit 10e71cb

Please sign in to comment.