Skip to content

Commit

Permalink
Migrating to v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hbulgarini committed Aug 16, 2023
1 parent 3d0dfc1 commit d2186a5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 41 deletions.
20 changes: 11 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }

frame-benchmarking = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42", optional = true }
frame-support = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
frame-system = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0", optional = true }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }

pallet-assets = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-assets = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
sp-std = { default-features = false, version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }

[dev-dependencies]
pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-core = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-io = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-runtime = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }

[features]
default = ["std"]
std = [
"codec/std",
"scale-info/std",
"sp-std/std",
"sp-runtime/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
Expand Down
10 changes: 5 additions & 5 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jsonrpsee = { version = "0.16.2", features = ["server", "macros"] }

pallet-dex-rpc-runtime-api = { version = "0.0.1", path = "./runtime-api" }

sp-api = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-blockchain = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-runtime = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-blockchain = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }

[dev-dependencies]
pallet-dex = { version = "0.0.1", path = ".." }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
tokio = { version = "1.21.2", features = ["macros", "time", "parking_lot"] }
6 changes: 3 additions & 3 deletions rpc/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }

pallet-dex = { version = "0.0.1", default-features = false, path = "../.." }
sp-api = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-runtime = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-dex = { version = "0.0.2", default-features = false, path = "../.." }
sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }

[features]
default = ["std"]
Expand Down
15 changes: 7 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,14 @@ pub mod pallet {
pub exchanges: Vec<GenesisExchangeInfo<T>>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> GenesisConfig<T> {
GenesisConfig { exchanges: vec![] }
}
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
let pallet_account = T::pallet_account();
for (provider, asset_id, liquidity_token_id, currency_amount, token_amount) in
Expand Down Expand Up @@ -472,7 +471,7 @@ pub mod pallet {
currency_amount: BalanceOf<T>,
min_liquidity: AssetBalanceOf<T>,
max_tokens: AssetBalanceOf<T>,
deadline: T::BlockNumber,
deadline: BlockNumberFor<T>,
) -> DispatchResult {
// -------------------------- Validation part --------------------------
let caller = ensure_signed(origin)?;
Expand Down Expand Up @@ -541,7 +540,7 @@ pub mod pallet {
liquidity_amount: AssetBalanceOf<T>,
min_currency: BalanceOf<T>,
min_tokens: AssetBalanceOf<T>,
deadline: T::BlockNumber,
deadline: BlockNumberFor<T>,
) -> DispatchResult {
// -------------------------- Validation part --------------------------
let caller = ensure_signed(origin)?;
Expand Down Expand Up @@ -606,7 +605,7 @@ pub mod pallet {
origin: OriginFor<T>,
asset_id: AssetIdOf<T>,
amount: TradeAmount<BalanceOf<T>, AssetBalanceOf<T>>,
deadline: T::BlockNumber,
deadline: BlockNumberFor<T>,
recipient: Option<AccountIdOf<T>>,
) -> DispatchResult {
// -------------------------- Validation part --------------------------
Expand Down Expand Up @@ -662,7 +661,7 @@ pub mod pallet {
origin: OriginFor<T>,
asset_id: AssetIdOf<T>,
amount: TradeAmount<AssetBalanceOf<T>, BalanceOf<T>>,
deadline: T::BlockNumber,
deadline: BlockNumberFor<T>,
recipient: Option<AccountIdOf<T>>,
) -> DispatchResult {
// -------------------------- Validation part --------------------------
Expand Down Expand Up @@ -718,7 +717,7 @@ pub mod pallet {
sold_asset_id: AssetIdOf<T>,
bought_asset_id: AssetIdOf<T>,
amount: TradeAmount<AssetBalanceOf<T>, AssetBalanceOf<T>>,
deadline: T::BlockNumber,
deadline: BlockNumberFor<T>,
recipient: Option<AccountIdOf<T>>,
) -> DispatchResult {
// -------------------------- Validation part --------------------------
Expand Down Expand Up @@ -756,7 +755,7 @@ pub mod pallet {
<Exchanges<T>>::get(asset_id.clone()).ok_or(Error::<T>::ExchangeNotFound)
}

fn check_deadline(deadline: &T::BlockNumber) -> Result<(), Error<T>> {
fn check_deadline(deadline: &BlockNumberFor<T>) -> Result<(), Error<T>> {
ensure!(deadline >= &<frame_system::Pallet<T>>::block_number(), Error::DeadlinePassed);
Ok(())
}
Expand Down
29 changes: 13 additions & 16 deletions src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
use crate as dex;
use frame_support::traits::{
AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, Everything, GenesisBuild,
AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, ConstU64, Everything,
};
use frame_support::{parameter_types, PalletId};
use frame_system::{EnsureRoot, EnsureSigned};
use sp_core::H256;
use sp_runtime::traits::{BlakeTwo256, Identity, IdentityLookup};
use sp_runtime::{
traits::{BlakeTwo256, Identity, IdentityLookup},
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
type Header = sp_runtime::generic::Header<u32, BlakeTwo256>;

frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Assets: pallet_assets::{Pallet, Call, Storage, Config<T>, Event<T>},
Dex: dex::{Pallet, Call, Storage, Event<T>},
Expand All @@ -30,15 +28,12 @@ impl frame_system::Config for Test {
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u32;
type BlockNumber = u32;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU32<250>;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
Expand All @@ -49,6 +44,8 @@ impl frame_system::Config for Test {
type SS58Prefix = ConstU16<42>;
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
type Nonce = u64;
type Block = Block;
}

impl pallet_balances::Config for Test {
Expand All @@ -63,7 +60,7 @@ impl pallet_balances::Config for Test {
type ReserveIdentifier = [u8; 8];
type FreezeIdentifier = ();
type MaxFreezes = ();
type HoldIdentifier = ();
type RuntimeHoldReason = ();
type MaxHolds = ();
}

Expand Down Expand Up @@ -121,8 +118,8 @@ pub(crate) const LIQ_TOKEN_A: u32 = 200;
pub(crate) const LIQ_TOKEN_B: u32 = 201;

pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
let mut storage = frame_system::GenesisConfig::default()
.build_storage::<Test>()
let mut storage = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();

pallet_balances::GenesisConfig::<Test> {
Expand Down

0 comments on commit d2186a5

Please sign in to comment.