Skip to content

Commit

Permalink
move payment types to pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
stanly-johnson authored and olanod committed Dec 14, 2021
1 parent 088ea68 commit b50d02d
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 20 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pallets/payment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
parity-scale-codec = { default-features = false, features = ['derive'], version = "2.0.0" }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false, optional = true }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.13", default-features = false }
virto-primitives = { version = "0.3.0", path = "../../primitives" }
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }

[dev-dependencies]
Expand All @@ -31,7 +30,7 @@ orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-li
[features]
default = ['std']
std = [
'codec/std',
'parity-scale-codec/std',
'frame-support/std',
'frame-system/std',
'sp-runtime/std',
Expand Down
7 changes: 3 additions & 4 deletions pallets/payment/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use super::*;

use crate::Pallet as Payment;
use crate::{Pallet as Payment, PaymentState};
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_system::RawOrigin;
use orml_traits::MultiCurrency;
use virto_primitives::{Asset, NetworkAsset, PaymentState};

const SEED: u32 = 0;
const CURRENCY_ID: Asset = Asset::Network(NetworkAsset::KSM);
const CURRENCY_ID: u32 = 1u32;
const INITIAL_AMOUNT: u32 = 100;
const SOME_AMOUNT: u32 = 80;

Expand All @@ -22,7 +21,7 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
benchmarks! {
where_clause { where T::Asset: MultiCurrency<
<T as frame_system::Config>::AccountId,
CurrencyId = Asset, Balance = u32
CurrencyId = u32, Balance = u32
>
}
// create a new payment succesfully
Expand Down
4 changes: 3 additions & 1 deletion pallets/payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ mod tests;
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

mod types;

#[frame_support::pallet]
pub mod pallet {
pub use crate::types::{DisputeResolver, PaymentDetail, PaymentHandler, PaymentState};
use frame_support::{dispatch::DispatchResultWithPostInfo, pallet_prelude::*};
use frame_system::pallet_prelude::*;
use orml_traits::{MultiCurrency, MultiReservableCurrency};
use sp_runtime::Percent;
use virto_primitives::{DisputeResolver, PaymentDetail, PaymentHandler, PaymentState};

type BalanceOf<T> =
<<T as Config>::Asset as MultiCurrency<<T as frame_system::Config>::AccountId>>::Balance;
Expand Down
9 changes: 4 additions & 5 deletions pallets/payment/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
Percent,
};
use virto_primitives::{Asset, DisputeResolver, NetworkAsset};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
pub type AccountId = u8;
pub const PAYMENT_CREATOR: AccountId = 10;
pub const PAYMENT_RECIPENT: AccountId = 11;
pub const CURRENCY_ID: Asset = Asset::Network(NetworkAsset::KSM);
pub const CURRENCY_ID: u32 = 1u32;
pub const RESOLVER_ACCOUNT: AccountId = 12;

frame_support::construct_runtime!(
Expand Down Expand Up @@ -65,7 +64,7 @@ impl system::Config for Test {
}

parameter_type_with_key! {
pub ExistentialDeposits: |_currency_id: Asset| -> u32 {
pub ExistentialDeposits: |_currency_id: u32| -> u32 {
0u32
};
}
Expand All @@ -83,7 +82,7 @@ impl Contains<AccountId> for MockDustRemovalWhitelist {
impl orml_tokens::Config for Test {
type Amount = i64;
type Balance = u32;
type CurrencyId = Asset;
type CurrencyId = u32;
type Event = Event;
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
Expand All @@ -93,7 +92,7 @@ impl orml_tokens::Config for Test {
}

pub struct MockDisputeResolver;
impl DisputeResolver<AccountId> for MockDisputeResolver {
impl crate::types::DisputeResolver<AccountId> for MockDisputeResolver {
fn get_origin() -> AccountId {
RESOLVER_ACCOUNT
}
Expand Down
7 changes: 5 additions & 2 deletions pallets/payment/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{mock::*, Payment as PaymentStore};
use crate::{
mock::*,
types::{PaymentDetail, PaymentState},
Payment as PaymentStore,
};
use frame_support::{assert_noop, assert_ok};
use orml_traits::MultiCurrency;
use virto_primitives::{PaymentDetail, PaymentState};

#[test]
fn test_create_payment_works() {
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@
#![cfg_attr(not(feature = "std"), no_std)]

mod asset;
mod payment;

pub use asset::*;
pub use payment::*;
4 changes: 2 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ mod proxy_type;
use currency_id_convert::CurrencyIdConvert;
use orml_traits::{arithmetic::Zero, parameter_type_with_key};
use proxy_type::ProxyType;
use virto_primitives::{Asset, DisputeResolver};
use virto_primitives::Asset;

/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
pub type Signature = MultiSignature;
Expand Down Expand Up @@ -596,7 +596,7 @@ impl orml_unknown_tokens::Config for Runtime {
}

pub struct VirtoDisputeResolver;
impl DisputeResolver<AccountId> for VirtoDisputeResolver {
impl virto_payment::DisputeResolver<AccountId> for VirtoDisputeResolver {
fn get_origin() -> AccountId {
Sudo::key()
}
Expand Down

0 comments on commit b50d02d

Please sign in to comment.