Skip to content

Commit

Permalink
use ValidateUnsigned to validate unsigned tx (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjj9219 authored Feb 29, 2020
1 parent d6212fe commit cf8666d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 9 additions & 2 deletions modules/cdp_engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,19 @@ impl<T: Trait> Module<T> {
if let Some((_, account_id)) = key {
// TODO: liquidate unsafe cdp before emergency shutdown, settle cdp with debit when emergency shutdown occurs.
if Self::is_unsafe_cdp(currency_id, &account_id) {
if let Err(e) = Self::submit_unsigned_liquidation_tx(currency_id, account_id) {
if let Err(e) = Self::submit_unsigned_liquidation_tx(currency_id, account_id.clone()) {
debug::debug!(
target: "cdp-engine offchain worker",
"faild to submit unsigned liquidation tx: {:?}",
e,
);
} else {
debug::info!(
target: "cdp-engine offchain worker",
"successfully submit unsigned liquidation tx for CDP: \n AccountId - {:?} \n CurrencyId: {:?}",
account_id,
currency_id,
);
}
}
}
Expand Down Expand Up @@ -700,7 +707,7 @@ impl<T: Trait> frame_support::unsigned::ValidateUnsigned for Module<T> {
Ok(ValidTransaction {
priority: TransactionPriority::max_value(),
requires: vec![],
provides: vec![],
provides: vec![(<system::Module<T>>::block_number(), currency_id, who).encode()],
longevity: 64_u64,
propagate: true,
})
Expand Down
4 changes: 1 addition & 3 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@ impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtim
system::CheckWeight::<Runtime>::new(),
orml_oracle::CheckOperator::<Runtime>::new(),
module_accounts::ChargeTransactionPayment::<Runtime>::from(tip),
module_cdp_engine::AutomaticLiquidationValidation::<Runtime>::new(),
);
let raw_payload = SignedPayload::new(call, extra)
.map_err(|e| {
Expand Down Expand Up @@ -686,7 +685,7 @@ construct_runtime!(
Auction: orml_auction::{Module, Storage, Call, Event<T>},
AuctionManager: module_auction_manager::{Module, Storage, Call, Event<T>},
Loans: module_loans::{Module, Storage, Call, Event<T>},
CdpEngine: module_cdp_engine::{Module, Storage, Call, Event<T>, Config<T>},
CdpEngine: module_cdp_engine::{Module, Storage, Call, Event<T>, Config<T>, ValidateUnsigned},
Honzon: module_honzon::{Module, Storage, Call, Event<T>},
Dex: module_dex::{Module, Storage, Call, Event<T>},
CdpTreasury: module_cdp_treasury::{Module, Storage, Call, Config<T>, Event<T>},
Expand Down Expand Up @@ -715,7 +714,6 @@ pub type SignedExtra = (
system::CheckWeight<Runtime>,
orml_oracle::CheckOperator<Runtime>,
module_accounts::ChargeTransactionPayment<Runtime>,
module_cdp_engine::AutomaticLiquidationValidation<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
Expand Down

0 comments on commit cf8666d

Please sign in to comment.