Skip to content

Commit 8053ddb

Browse files
authored
Don't deposit failure event in orml-unknown-tokens. (#440)
* Don't deposit failure event in orml-unknown-tokens. * Patch substrate/polkadot/cumulus. * Fix patch.
1 parent d1749f0 commit 8053ddb

File tree

3 files changed

+72
-93
lines changed

3 files changed

+72
-93
lines changed

Cargo.dev.toml

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,67 @@ members = [
2323
]
2424
resolver = "2"
2525

26-
[patch.crates-io]
27-
frame-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
28-
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
29-
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
30-
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
31-
pallet-elections-phragmen = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
32-
pallet-scheduler = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
33-
pallet-treasury = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
34-
sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
35-
sp-application-crypto = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
36-
sp-arithmetic = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
37-
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
38-
sp-inherents = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
39-
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
40-
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
41-
sp-runtime-interface = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
42-
sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
43-
sp-trie = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
44-
sp-version = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
26+
[patch.'https://github.com/paritytech/substrate']
27+
frame-benchmarking = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
28+
frame-support = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
29+
frame-system = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
30+
pallet-balances = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
31+
pallet-elections-phragmen = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
32+
pallet-scheduler = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
33+
pallet-treasury = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
34+
pallet-authorship = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
35+
pallet-vesting = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
36+
pallet-timestamp = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
37+
pallet-session = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
38+
pallet-staking = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
39+
pallet-offences = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
40+
pallet-authority-discovery = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
41+
sp-api = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
42+
sp-application-crypto = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
43+
sp-arithmetic = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
44+
sp-core = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
45+
sp-inherents = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
46+
sp-io = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
47+
sp-runtime = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
48+
sp-runtime-interface = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
49+
sp-std = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
50+
sp-trie = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
51+
sp-version = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
52+
sp-externalities = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
53+
sp-state-machine = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
54+
sp-wasm-interface = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
55+
sp-keystore = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
56+
sp-staking = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
57+
sp-storage = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
58+
sp-panic-handler = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
59+
sp-npos-elections = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
60+
sp-npos-elections-compact = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
61+
sp-debug-derive = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
62+
sp-allocator = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
63+
sp-authority-discovery = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
64+
sc-executor-common = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
65+
sc-executor-wasmi = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
66+
sc-executor = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
67+
sc-client-api = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
68+
sp-tasks = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
69+
sp-authorship = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
70+
sp-consensus = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
71+
sp-timestamp = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
72+
sp-session = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
73+
sp-blockchain = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
74+
sp-transaction-pool = { git = "https://github.com/paritytech//substrate", rev = "3ec97a31b285181fb1beab426ee2a8e2cb1188ab" }
75+
76+
[patch.'https://github.com/paritytech/cumulus']
77+
cumulus-primitives-core = { git = "https://github.com/paritytech//cumulus", rev = "c5be7306f425be9fcf3c6e0bc598c0f481588cd9" }
78+
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech//cumulus", rev = "c5be7306f425be9fcf3c6e0bc598c0f481588cd9" }
79+
parachain-info = { git = "https://github.com/paritytech//cumulus", rev = "c5be7306f425be9fcf3c6e0bc598c0f481588cd9" }
80+
cumulus-pallet-xcm-handler = { git = "https://github.com/paritytech//cumulus", rev = "c5be7306f425be9fcf3c6e0bc598c0f481588cd9" }
81+
82+
[patch.'https://github.com/paritytech/polkadot']
83+
xcm = { git = "https://github.com/paritytech//polkadot", rev = "6b5b4a58a3f6a3fb647fec926609e04b7d5a336a" }
84+
xcm-executor = { git = "https://github.com/paritytech//polkadot", rev = "6b5b4a58a3f6a3fb647fec926609e04b7d5a336a" }
85+
xcm-builder = { git = "https://github.com/paritytech//polkadot", rev = "6b5b4a58a3f6a3fb647fec926609e04b7d5a336a" }
86+
polkadot-core-primitives = { git = "https://github.com/paritytech//polkadot", rev = "6b5b4a58a3f6a3fb647fec926609e04b7d5a336a" }
87+
polkadot-runtime-parachains = { git = "https://github.com/paritytech//polkadot", rev = "6b5b4a58a3f6a3fb647fec926609e04b7d5a336a" }
88+
polkadot-parachain = { git = "https://github.com/paritytech//polkadot", rev = "6b5b4a58a3f6a3fb647fec926609e04b7d5a336a" }
89+
polkadot-primitives = { git = "https://github.com/paritytech//polkadot", rev = "6b5b4a58a3f6a3fb647fec926609e04b7d5a336a" }

unknown-tokens/src/lib.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ pub mod module {
2626
pub enum Event {
2727
/// Deposit success. [asset, to]
2828
Deposited(MultiAsset, MultiLocation),
29-
/// Deposit failed. [asset, to, error]
30-
DepositFailed(MultiAsset, MultiLocation, DispatchError),
3129
/// Withdraw success. [asset, from]
3230
Withdrawn(MultiAsset, MultiLocation),
33-
/// Withdraw failed. [asset, from, error]
34-
WithdrawFailed(MultiAsset, MultiLocation, DispatchError),
3531
}
3632

3733
#[pallet::error]
@@ -74,7 +70,7 @@ pub mod module {
7470

7571
impl<T: Config> UnknownAsset for Pallet<T> {
7672
fn deposit(asset: &MultiAsset, to: &MultiLocation) -> DispatchResult {
77-
let result = match asset {
73+
match asset {
7874
MultiAsset::ConcreteFungible { id, amount } => {
7975
ConcreteFungibleBalances::<T>::try_mutate(to, id, |b| -> DispatchResult {
8076
*b = b.checked_add(*amount).ok_or(Error::<T>::BalanceOverflow)?;
@@ -88,19 +84,15 @@ impl<T: Config> UnknownAsset for Pallet<T> {
8884
})
8985
}
9086
_ => Err(Error::<T>::UnhandledAsset.into()),
91-
};
87+
}?;
9288

93-
if let Err(err) = result {
94-
Self::deposit_event(Event::DepositFailed(asset.clone(), to.clone(), err));
95-
} else {
96-
Self::deposit_event(Event::Deposited(asset.clone(), to.clone()));
97-
}
89+
Self::deposit_event(Event::Deposited(asset.clone(), to.clone()));
9890

99-
result
91+
Ok(())
10092
}
10193

10294
fn withdraw(asset: &MultiAsset, from: &MultiLocation) -> DispatchResult {
103-
let result = match asset {
95+
match asset {
10496
MultiAsset::ConcreteFungible { id, amount } => {
10597
ConcreteFungibleBalances::<T>::try_mutate(from, id, |b| -> DispatchResult {
10698
*b = b.checked_sub(*amount).ok_or(Error::<T>::BalanceTooLow)?;
@@ -114,14 +106,10 @@ impl<T: Config> UnknownAsset for Pallet<T> {
114106
})
115107
}
116108
_ => Err(Error::<T>::UnhandledAsset.into()),
117-
};
109+
}?;
118110

119-
if let Err(err) = result {
120-
Self::deposit_event(Event::WithdrawFailed(asset.clone(), from.clone(), err));
121-
} else {
122-
Self::deposit_event(Event::Withdrawn(asset.clone(), from.clone()));
123-
}
111+
Self::deposit_event(Event::Withdrawn(asset.clone(), from.clone()));
124112

125-
result
113+
Ok(())
126114
}
127115
}

unknown-tokens/src/tests.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,6 @@ fn deposit_concrete_fungible_asset_works() {
4848
UnknownTokens::deposit(&max_asset, &MOCK_RECIPIENT),
4949
Error::<Runtime>::BalanceOverflow
5050
);
51-
52-
let deposit_failed_event = Event::unknown_tokens(crate::Event::DepositFailed(
53-
max_asset,
54-
MOCK_RECIPIENT,
55-
Error::<Runtime>::BalanceOverflow.into(),
56-
));
57-
assert!(System::events()
58-
.iter()
59-
.any(|record| record.event == deposit_failed_event));
6051
});
6152
}
6253

@@ -83,15 +74,6 @@ fn deposit_abstract_fungible_asset() {
8374
UnknownTokens::abstract_fungible_balances(&MOCK_RECIPIENT, &mock_abstract_fungible_id()),
8475
3
8576
);
86-
87-
let deposit_failed_event = Event::unknown_tokens(crate::Event::DepositFailed(
88-
max_asset,
89-
MOCK_RECIPIENT,
90-
Error::<Runtime>::BalanceOverflow.into(),
91-
));
92-
assert!(System::events()
93-
.iter()
94-
.any(|record| record.event == deposit_failed_event));
9577
});
9678
}
9779

@@ -102,15 +84,6 @@ fn deposit_unhandled_asset_should_fail() {
10284
UnknownTokens::deposit(&MultiAsset::All, &MOCK_RECIPIENT),
10385
Error::<Runtime>::UnhandledAsset
10486
);
105-
106-
let deposit_failed_event = Event::unknown_tokens(crate::Event::DepositFailed(
107-
MultiAsset::All,
108-
MOCK_RECIPIENT,
109-
Error::<Runtime>::UnhandledAsset.into(),
110-
));
111-
assert!(System::events()
112-
.iter()
113-
.any(|record| record.event == deposit_failed_event));
11487
});
11588
}
11689

@@ -134,15 +107,6 @@ fn withdraw_concrete_fungible_asset_works() {
134107
UnknownTokens::withdraw(&asset, &MOCK_RECIPIENT),
135108
Error::<Runtime>::BalanceTooLow
136109
);
137-
138-
let withdraw_failed_event = Event::unknown_tokens(crate::Event::WithdrawFailed(
139-
asset,
140-
MOCK_RECIPIENT,
141-
Error::<Runtime>::BalanceTooLow.into(),
142-
));
143-
assert!(System::events()
144-
.iter()
145-
.any(|record| record.event == withdraw_failed_event));
146110
});
147111
}
148112

@@ -166,15 +130,6 @@ fn withdraw_abstract_fungible_asset_works() {
166130
UnknownTokens::withdraw(&asset, &MOCK_RECIPIENT),
167131
Error::<Runtime>::BalanceTooLow
168132
);
169-
170-
let withdraw_failed_event = Event::unknown_tokens(crate::Event::WithdrawFailed(
171-
asset,
172-
MOCK_RECIPIENT,
173-
Error::<Runtime>::BalanceTooLow.into(),
174-
));
175-
assert!(System::events()
176-
.iter()
177-
.any(|record| record.event == withdraw_failed_event));
178133
});
179134
}
180135

@@ -185,14 +140,5 @@ fn withdraw_unhandled_asset_should_fail() {
185140
UnknownTokens::withdraw(&MultiAsset::All, &MOCK_RECIPIENT),
186141
Error::<Runtime>::UnhandledAsset
187142
);
188-
189-
let withdraw_failed_event = Event::unknown_tokens(crate::Event::WithdrawFailed(
190-
MultiAsset::All,
191-
MOCK_RECIPIENT,
192-
Error::<Runtime>::UnhandledAsset.into(),
193-
));
194-
assert!(System::events()
195-
.iter()
196-
.any(|record| record.event == withdraw_failed_event));
197143
});
198144
}

0 commit comments

Comments
 (0)