Skip to content

Commit

Permalink
Merge pull request #130 from galacticcouncil/payment_migration
Browse files Browse the repository at this point in the history
fix!: Multi Payment storage migration
  • Loading branch information
mrq1911 authored Mar 7, 2021
2 parents 332a747 + ffee851 commit ac45b0f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
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'
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
} 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

0 comments on commit ac45b0f

Please sign in to comment.