Skip to content

Commit

Permalink
Added Price to Order, Remove eth address (buyer & seller) from Order
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjanada committed Jun 26, 2021
1 parent 3956ab4 commit ae72aae
Show file tree
Hide file tree
Showing 18 changed files with 79 additions and 69 deletions.
3 changes: 2 additions & 1 deletion pallets/certifications/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sp-std = { default-features = false, version = '3.0.0' }
traits-certifications = { path = '../../traits/certifications', default-features = false }

[dev-dependencies]
serde = { version = "1.0.119" }
serde = { default-features = false, version = "1.0.119" }
sp-core = { default-features = false, version = '3.0.0' }
sp-io = { default-features = false, version = '3.0.0' }
sp-runtime = { default-features = false, version = '3.0.0' }
Expand All @@ -36,5 +36,6 @@ std = [
'codec/std',
'frame-support/std',
'frame-system/std',
'sp-io/std',
'traits-certifications/std',
]
4 changes: 3 additions & 1 deletion pallets/doctor-certifications/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sp-std = { default-features = false, version = '3.0.0' }
traits-doctor-certifications = { path = '../../traits/doctor-certifications', default-features = false }

[dev-dependencies]
serde = { version = "1.0.119" }
serde = { default-features = false, version = "1.0.119" }
sp-core = { default-features = false, version = '3.0.0' }
sp-io = { default-features = false, version = '3.0.0' }
sp-runtime = { default-features = false, version = '3.0.0' }
Expand All @@ -34,6 +34,8 @@ sp-runtime = { default-features = false, version = '3.0.0' }
default = ['std']
std = [
'codec/std',
'sp-std/std',
'sp-io/std',
'frame-support/std',
'frame-system/std',
'traits-doctor-certifications/std',
Expand Down
3 changes: 2 additions & 1 deletion pallets/doctors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ traits-user-profile = { path = '../../traits/user-profile', default-features = f
traits-doctor-certifications = { path = '../../traits/doctor-certifications', default-features = false }

[dev-dependencies]
serde = { version = "1.0.119" }
serde = { default-features = false, version = "1.0.119" }
sp-core = { default-features = false, version = '3.0.0' }
sp-io = { default-features = false, version = '3.0.0' }
sp-runtime = { default-features = false, version = '3.0.0' }
Expand All @@ -38,6 +38,7 @@ std = [
'frame-support/std',
'frame-system/std',
'sp-std/std',
'sp-io/std',
'traits-user-profile/std',
'traits-doctor-certifications/std',
]
5 changes: 4 additions & 1 deletion pallets/electronic-medical-record/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ pallet-timestamp = { default-features = false, version = '3.0.0' }
traits-electronic-medical-record = { path = '../../traits/electronic-medical-record', default-features = false }

[dev-dependencies]
serde = { version = "1.0.119" }
serde = { default-features = false, version = "1.0.119" }
sp-core = { default-features = false, version = '3.0.0' }
sp-io = { default-features = false, version = '3.0.0' }
sp-runtime = { default-features = false, version = '3.0.0' }

[features]
default = ['std']
std = [

'codec/std',
'frame-support/std',
'frame-system/std',
'sp-std/std',
'sp-io/std',
'pallet-timestamp/std',
'traits-electronic-medical-record/std',
]
3 changes: 2 additions & 1 deletion pallets/genetic-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ traits-genetic-testing = { path = '../../traits/genetic-testing', default-featur
traits-order = { path = '../../traits/order', default-features = false }

[dev-dependencies]
serde = { version = "1.0.119" }
serde = { default-features = false, version = "1.0.119" }
sp-core = { default-features = false, version = '3.0.0' }
sp-io = { default-features = false, version = '3.0.0' }
sp-runtime = { default-features = false, version = '3.0.0' }
Expand All @@ -35,6 +35,7 @@ std = [
'codec/std',
'frame-support/std',
'frame-system/std',
'pallet-timestamp/std',
'sp-std/std',
'traits-genetic-testing/std',
'traits-order/std',
Expand Down
4 changes: 3 additions & 1 deletion pallets/hospital-certifications/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sp-std = { default-features = false, version = '3.0.0' }
traits-hospital-certifications = { path = '../../traits/hospital-certifications', default-features = false }

[dev-dependencies]
serde = { version = "1.0.119" }
serde = { default-features = false, version = "1.0.119" }
sp-core = { default-features = false, version = '3.0.0' }
sp-io = { default-features = false, version = '3.0.0' }
sp-runtime = { default-features = false, version = '3.0.0' }
Expand All @@ -36,5 +36,7 @@ std = [
'codec/std',
'frame-support/std',
'frame-system/std',
'sp-std/std',
'sp-io/std',
'traits-hospital-certifications/std',
]
3 changes: 2 additions & 1 deletion pallets/hospitals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ traits-user-profile = { path = '../../traits/user-profile', default-features = f
traits-hospital-certifications = { path = '../../traits/hospital-certifications', default-features = false }

[dev-dependencies]
serde = { version = "1.0.119" }
serde = { default-features = false, version = "1.0.119" }
sp-core = { default-features = false, version = '3.0.0' }
sp-io = { default-features = false, version = '3.0.0' }
sp-runtime = { default-features = false, version = '3.0.0' }
Expand All @@ -38,6 +38,7 @@ std = [
'frame-support/std',
'frame-system/std',
'sp-std/std',
'sp-io/std',
'traits-user-profile/std',
'traits-hospital-certifications/std',
]
3 changes: 2 additions & 1 deletion pallets/labs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ traits-certifications = { path = '../../traits/certifications', default-features
traits-user-profile = { path = '../../traits/user-profile', default-features = false }

[dev-dependencies]
serde = { version = "1.0.119" }
serde = { default-features = false, version = "1.0.119" }
sp-core = { default-features = false, version = '3.0.0' }
sp-io = { default-features = false, version = '3.0.0' }
sp-runtime = { default-features = false, version = '3.0.0' }
Expand All @@ -39,6 +39,7 @@ std = [
'frame-support/std',
'frame-system/std',
'sp-std/std',
'sp-io/std',
'traits-services/std',
'traits-certifications/std',
'traits-user-profile/std',
Expand Down
6 changes: 4 additions & 2 deletions pallets/labs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub mod pallet {
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type Currency: Currency<Self::AccountId>;
type Services: ServicesProvider<Self>;
type Services: ServicesProvider<Self, BalanceOf<Self>>;
type Certifications: CertificationsProvider<Self>;
type EthereumAddress: Clone + Copy + PartialEq + Eq + Encode + EncodeLike + Decode + Default + sp_std::fmt::Debug;
type UserProfile: UserProfileProvider<Self, Self::EthereumAddress>;
Expand All @@ -194,6 +194,8 @@ pub mod pallet {
pub type LabOf<T> = Lab<AccountIdOf<T>, HashOf<T>>;
pub type CountryRegionCode = Vec<u8>; // country_code-region_code -> XX-YYYY
pub type CityCode = Vec<u8>; // city_code -> ZZZZ
pub type CurrencyOf<T> = <T as self::Config>::Currency;
pub type BalanceOf<T> = <CurrencyOf<T> as Currency<AccountIdOf<T>>>::Balance;

// ----- Storage ------------------
/// Get Lab by account id
Expand Down Expand Up @@ -518,4 +520,4 @@ impl<T: Config> CertificationOwner<T> for Pallet<T> {
}
});
}
}
}
5 changes: 3 additions & 2 deletions pallets/orders/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package = 'parity-scale-codec'
version = '2.0.0'

[dependencies]
serde = { version = "1.0.101", optional = true }
serde = { default-features = false, version = "1.0.119", features = ["derive"] }
frame-support = { default-features = false, version = '3.0.0' }
frame-system = { default-features = false, version = '3.0.0' }
pallet-timestamp = { default-features = false, version = '3.0.0' }
Expand All @@ -41,12 +41,13 @@ sp-runtime = { default-features = false, version = '3.0.0' }
[features]
default = ['std']
std = [
'serde',
'serde/std',
'codec/std',
'frame-support/std',
'frame-system/std',
'sp-std/std',
'sp-core/std',
'sp-io/std',
'pallet-timestamp/std',
'services/std',
'chrono/std',
Expand Down
43 changes: 14 additions & 29 deletions pallets/orders/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ pub mod interface;
use interface::OrderInterface;

pub use pallet::*;
use frame_support::traits::{ Currency };
use frame_support::codec::{Encode, Decode};
use frame_support::pallet_prelude::*;
use sp_std::prelude::*;
use traits_services::{ServicesProvider, ServiceInfo};
use traits_genetic_testing::{GeneticTestingProvider, DnaSampleTracking};
use traits_user_profile::{UserProfileProvider};
use traits_order::{OrderEventEmitter};


Expand All @@ -26,29 +26,27 @@ impl Default for OrderStatus {
}

#[derive(Encode, Decode, Clone, Default, RuntimeDebug, PartialEq, Eq)]
pub struct Order<Hash, AccountId, Moment, EthAddress> {
pub struct Order<Hash, AccountId, Balance, Moment> {
pub id: Hash,
pub service_id: Hash,
pub customer_id: AccountId,
pub customer_box_public_key: Hash,
pub seller_id: AccountId,
pub customer_eth_address: EthAddress,
pub seller_eth_address: EthAddress,
pub dna_sample_tracking_id: Vec<u8>,
pub price: Balance,
pub status: OrderStatus,
pub created_at: Moment,
pub updated_at: Moment,
}
impl<Hash, AccountId, Moment, EthAddress> Order<Hash, AccountId, Moment, EthAddress> {
impl<Hash, AccountId, Balance, Moment> Order<Hash, AccountId, Balance, Moment> {
pub fn new(
id: Hash,
service_id: Hash,
customer_id: AccountId,
customer_box_public_key: Hash,
seller_id: AccountId,
customer_eth_address: EthAddress,
seller_eth_address: EthAddress,
dna_sample_tracking_id: Vec<u8>,
price: Balance,
created_at: Moment,
updated_at: Moment,
)
Expand All @@ -60,9 +58,8 @@ impl<Hash, AccountId, Moment, EthAddress> Order<Hash, AccountId, Moment, EthAddr
customer_id,
customer_box_public_key,
seller_id,
customer_eth_address,
seller_eth_address,
dna_sample_tracking_id,
price,
status: OrderStatus::default(),
created_at,
updated_at,
Expand Down Expand Up @@ -94,10 +91,9 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config + pallet_timestamp::Config {
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type Services: ServicesProvider<Self>;
type Services: ServicesProvider<Self, BalanceOf<Self>>;
type GeneticTesting: GeneticTestingProvider<Self>;
type EthereumAddress: Clone + Copy + PartialEq + Eq + Encode + Decode + Default + sp_std::fmt::Debug;
type UserProfile: UserProfileProvider<Self, Self::EthereumAddress>;
type Currency: Currency<<Self as frame_system::Config>::AccountId>;
}


Expand All @@ -114,8 +110,9 @@ pub mod pallet {
type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type MomentOf<T> = <T as pallet_timestamp::Config>::Moment;
pub type HashOf<T> = <T as frame_system::Config>::Hash;
type EthereumAddressOf<T> = <T as Config>::EthereumAddress;
pub type OrderOf<T> = Order<HashOf<T>, AccountIdOf<T>, MomentOf<T>, EthereumAddressOf<T>>;
pub type CurrencyOf<T> = <T as self::Config>::Currency;
pub type BalanceOf<T> = <CurrencyOf<T> as Currency<AccountIdOf<T>>>::Balance;
pub type OrderOf<T> = Order<HashOf<T>, AccountIdOf<T>, BalanceOf<T>, MomentOf<T>>;
type OrderIdsOf<T> = Vec<HashOf<T>>;
// -------------------------------------------------------

Expand Down Expand Up @@ -299,6 +296,7 @@ impl<T: Config> OrderInterface<T> for Pallet<T> {
let service = service.unwrap();
let order_id = Self::generate_order_id(customer_id, service_id);
let seller_id = service.get_owner_id();
let price = service.get_price();
let now = pallet_timestamp::Pallet::<T>::get();

// Initialize DnaSample
Expand All @@ -308,27 +306,14 @@ impl<T: Config> OrderInterface<T> for Pallet<T> {
}
let dna_sample = dna_sample.ok().unwrap();

let customer_eth_address = T::UserProfile::get_eth_address_by_account_id(customer_id);
if customer_eth_address.is_none() {
return Err(Error::<T>::CustomerEthAddressNotFound);
}
let customer_eth_address = customer_eth_address.unwrap();

let seller_eth_address = T::UserProfile::get_eth_address_by_account_id(seller_id);
if seller_eth_address.is_none() {
return Err(Error::<T>::SellerEthAddressNotFound);
}
let seller_eth_address = seller_eth_address.unwrap();

let order = Order::new(
order_id.clone(),
service_id.clone(),
customer_id.clone(),
customer_box_public_key.clone(),
seller_id.clone(),
customer_eth_address as T::EthereumAddress,
seller_eth_address as T::EthereumAddress,
dna_sample.get_tracking_id().clone(),
price.clone(),
now,
now
);
Expand Down Expand Up @@ -429,7 +414,7 @@ impl<T: Config> Pallet<T> {
}

pub fn update_order_status(order_id: &T::Hash, status: OrderStatus)
-> Option<Order<T::Hash, T::AccountId, T::Moment, T::EthereumAddress>>
-> Option<Order<T::Hash, T::AccountId, BalanceOf<T>, T::Moment>>
{
Orders::<T>::mutate(order_id, |order| {
match order {
Expand Down
4 changes: 3 additions & 1 deletion pallets/services/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sp-std = { default-features = false, version = '3.0.0' }
traits-services = { path = '../../traits/services', default-features = false }

[dev-dependencies]
serde = { version = "1.0.119" }
serde = { default-features = false, version = "1.0.119" }
sp-core = { default-features = false, version = '3.0.0' }
sp-io = { default-features = false, version = '3.0.0' }
sp-runtime = { default-features = false, version = '3.0.0' }
Expand All @@ -34,6 +34,8 @@ sp-runtime = { default-features = false, version = '3.0.0' }
default = ['std']
std = [
'codec/std',
'sp-std/std',
'sp-io/std',
'frame-support/std',
'frame-system/std',
'traits-services/std',
Expand Down
12 changes: 8 additions & 4 deletions pallets/services/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ impl<AccountId, Hash, Balance> Service<AccountId, Hash, Balance> {
}
}

impl<T, AccountId, Hash, Balance> ServiceInfoT<T> for Service<AccountId, Hash, Balance>
where T: frame_system::Config<AccountId = AccountId, Hash = Hash>
impl<T, AccountId, Hash, Balance> ServiceInfoT<T, Balance> for Service<AccountId, Hash, Balance>
where T: frame_system::Config<AccountId = AccountId, Hash = Hash>,
{
fn get_id(&self) -> &Hash {
self.get_id()
}
fn get_owner_id(&self) -> &AccountId {
self.get_owner_id()
}
fn get_price(&self) -> &Balance {
self.get_price()
}
}

#[frame_support::pallet]
Expand Down Expand Up @@ -318,9 +321,10 @@ impl<T: Config> Pallet<T> {
}

/// ServicesProvider Trait Implementation
impl<T: Config> ServicesProvider<T> for Pallet<T> {
impl<T: Config, Balance> ServicesProvider<T, Balance> for Pallet<T>
where ServiceOf<T>: traits_services::ServiceInfo<T, Balance>
{
type Error = Error<T>;
type Balance = pallet::BalanceOf<T>;
type Service = ServiceOf<T>;

fn service_by_id(id: &T::Hash) -> Option<ServiceOf<T>> {
Expand Down
3 changes: 2 additions & 1 deletion pallets/user-profile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ version = '2.0.0'
frame-support = { default-features = false, version = '3.0.0' }
frame-system = { default-features = false, version = '3.0.0' }
sp-std = { default-features = false, version = '3.0.0' }
serde = { version = "1.0.123" }
serde = { default-features = false, version = "1.0.119", features = ["derive"] }
rustc-hex = { version = "2.1.0", default-features = false }
traits-user-profile = { path = '../../traits/user-profile', default-features = false }

Expand All @@ -34,6 +34,7 @@ std = [
'frame-support/std',
'frame-system/std',
'sp-std/std',
'sp-io/std',
'serde/std',
'rustc-hex/std',
'traits-user-profile/std',
Expand Down
Loading

0 comments on commit ae72aae

Please sign in to comment.