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

fix!: Multi Payment storage migration #130

Merged
merged 7 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 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 pallets/transaction-multi-payment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = '2018'
homepage = 'https://github.com/galacticcouncil/hydra-dx'
license = 'Unlicense'
repository = 'https://github.com/galacticcouncil/hydra-dx'
version = '2.0.0'
mrq1911 marked this conversation as resolved.
Show resolved Hide resolved
version = '3.0.0'

[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
Expand Down
4 changes: 2 additions & 2 deletions pallets/transaction-multi-payment/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = 'https://github.com/galacticcouncil/hydra-dx'
license = 'Unlicense'
name = 'pallet-multi-payment-benchmarking'
repository = 'https://github.com/galacticcouncil/hydra-dx'
version = '2.0.0'
version = '3.0.0'

[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
Expand All @@ -28,7 +28,7 @@ serde = { features = ['derive'], optional = true, version = '1.0.101' }
primitives = { path = '../../../primitives', default-features = false, version = '2.0.0' }
pallet-asset-registry= { path = '../../asset-registry', default-features = false, version = '2.0.0' }
pallet-amm = { path = '../../amm', default-features = false, version = '2.0.0' }
pallet-transaction-multi-payment = { path = '../../transaction-multi-payment', default-features = false, version = '2.0.0' }
pallet-transaction-multi-payment = { path = '../../transaction-multi-payment', default-features = false, version = '3.0.0' }

# ORML dependencies
orml-traits = { default-features = false, version = "0.3.3-dev" }
Expand Down
35 changes: 33 additions & 2 deletions pallets/transaction-multi-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use frame_support::{
decl_error, decl_event, decl_module, decl_storage,
dispatch::DispatchResult,
ensure,
traits::{Currency, ExistenceRequirement, Get, Imbalance, OnUnbalanced, WithdrawReasons},
traits::{
Currency, ExistenceRequirement, Get, GetPalletVersion, Imbalance, OnUnbalanced, PalletVersion, WithdrawReasons,
},
weights::DispatchClass,
weights::WeightToFeePolynomial,
};
Expand Down Expand Up @@ -248,6 +250,26 @@ decl_module! {

Ok(())
}

fn on_runtime_upgrade() -> frame_support::weights::Weight {
mod previous {
pub struct Module<T>(sp_std::marker::PhantomData<T>);
frame_support::decl_storage! {
trait Store for Module<T: super::Config> as TransactionPayment {
pub AcceptedCurrencies get(fn currencies) config(): super::Vec<super::AssetId>;
}
}
}
let version = <Self as GetPalletVersion>::storage_version();

if version == None || version == Some(PalletVersion::new(2, 0, 0)) {
previous::AcceptedCurrencies::kill();
AcceptedCurrencies::put(OrderedSet::<AssetId>::new());
T::BlockWeights::get().max_block
mrq1911 marked this conversation as resolved.
Show resolved Hide resolved
} else {
0
}
}
}
}
impl<T: Config> Module<T> {
Expand All @@ -260,7 +282,16 @@ impl<T: Config> Module<T> {

// If not native currency, let's buy CORE asset first and then pay with that.
if fee_currency != CORE_ASSET_ID {
T::AMMPool::buy(&who, AssetPair{asset_out: CORE_ASSET_ID, asset_in: fee_currency}, fee, 2u128 * fee, false)?;
T::AMMPool::buy(
&who,
AssetPair {
asset_out: CORE_ASSET_ID,
asset_in: fee_currency,
},
fee,
2u128 * fee,
false,
)?;
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pallet-asset-registry = {path = '../pallets/asset-registry', default-features =
pallet-exchange = {path = '../pallets/exchange', default-features = false, version = '2.0.0'}
pallet-exchange-benchmarking = {path = '../pallets/exchange/benchmarking', default-features = false, optional = true, version = '2.0.0'}
pallet-faucet = {path = '../pallets/faucet', default-features = false, version = '2.0.0'}
pallet-multi-payment-benchmarking = {path = '../pallets/transaction-multi-payment/benchmarking', default-features = false, optional = true, version = '2.0.0'}
pallet-transaction-multi-payment = {path = '../pallets/transaction-multi-payment', default-features = false, version = '2.0.0'}
pallet-multi-payment-benchmarking = {path = '../pallets/transaction-multi-payment/benchmarking', default-features = false, optional = true, version = '3.0.0'}
pallet-transaction-multi-payment = {path = '../pallets/transaction-multi-payment', default-features = false, version = '3.0.0'}
primitives = {path = '../primitives', default-features = false, version = '2.0.0'}

# ORML dependencies
Expand Down