Skip to content

Commit

Permalink
Change address for conflicting at API side (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
badkk committed May 19, 2020
1 parent b335134 commit f2b8538
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 26 deletions.
26 changes: 11 additions & 15 deletions cstrml/market/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//! The Substrate Node runtime. This can be compiled with `#[no_std]`, ready for Wasm.

#![cfg_attr(not(feature = "std"), no_std)]
#![feature(option_result_contains)]

Expand All @@ -18,7 +16,7 @@ use serde::{Deserialize, Serialize};

// Crust runtime modules
use primitives::{
Address, MerkleRoot, Balance, BlockNumber,
AddressInfo, MerkleRoot, Balance, BlockNumber,
constants::tee::REPORT_SLOT
};

Expand Down Expand Up @@ -58,8 +56,8 @@ impl Default for OrderStatus {
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, Default)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct Provision<Hash> {
/// Vendor's address
pub address: Address,
/// Provider's address
pub address_info: AddressInfo,

/// Mapping from `file_id` to `order_id`, this mapping only add when user place the order
pub file_map: BTreeMap<MerkleRoot, Hash>,
Expand Down Expand Up @@ -143,27 +141,25 @@ decl_error! {
}
}

// The module's dispatchable functions.
decl_module! {
/// The module declaration.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
type Error = Error<T>;

// Initializing events
// this is needed only if you are using events in your module
fn deposit_event() = default;

type Error = Error<T>;

/// Register to be a provider, you should provide your Karst's address{ip, port}
/// Register to be a provider, you should provide your storage layer's address info
#[weight = SimpleDispatchInfo::default()]
fn register(origin, address: Address) -> DispatchResult {
fn register(origin, address_info: AddressInfo) -> DispatchResult {
let who = ensure_signed(origin)?;

// 1. Make sure you have works
ensure!(T::OrderInspector::check_works(&who, 0), Error::<T>::NoWorkload);

// 2. Insert provision
<Providers<T>>::insert(who.clone(), Provision {
address,
address_info,
file_map: BTreeMap::new()
});

Expand All @@ -173,19 +169,19 @@ decl_module! {
Ok(())
}

/// TODO: organize these parameters into a struct.
/// Place a storage order, make sure
#[weight = SimpleDispatchInfo::default()]
fn place_storage_order(
origin,
dest: <T::Lookup as StaticLookup>::Source,
provider: <T::Lookup as StaticLookup>::Source,
#[compact] value: Balance,
file_identifier: MerkleRoot,
file_size: u64,
duration: u32
) -> DispatchResult
{
let who = ensure_signed(origin)?;
let provider = T::Lookup::lookup(dest)?;
let provider = T::Lookup::lookup(provider)?;

// 1. Expired should be greater than created
ensure!(duration > REPORT_SLOT.try_into().unwrap(), Error::<T>::DurationTooShort);
Expand Down
6 changes: 3 additions & 3 deletions cstrml/market/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ fn test_for_storage_order_should_work() {
let file_size = 16; // should less than provider
let duration = 360; // file should store at least 30 minutes
let fee = 10;
let address = "ws://127.0.0.1:8855".as_bytes().to_vec();
let address_info = "ws://127.0.0.1:8855".as_bytes().to_vec();

assert_ok!(Market::register(Origin::signed(provider), address.clone()));
assert_ok!(Market::register(Origin::signed(provider), address_info.clone()));
assert_ok!(Market::place_storage_order(
Origin::signed(source), provider, fee,
file_identifier.clone(), file_size, duration
));

let order_id = H256::default();
assert_eq!(Market::providers(100).unwrap(), Provision {
address,
address_info,
file_map: vec![(file_identifier.clone(), order_id.clone())].into_iter().collect()
});
assert_eq!(Market::clients(0).unwrap(), vec![order_id.clone()]);
Expand Down
4 changes: 0 additions & 4 deletions cstrml/tee/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//! The Substrate Node runtime. This can be compiled with `#[no_std]`, ready for Wasm.

#![cfg_attr(not(feature = "std"), no_std)]
#![feature(option_result_contains)]

Expand Down Expand Up @@ -166,9 +164,7 @@ decl_storage! {
}
}

// The module's dispatchable functions.
decl_module! {
/// The module declaration.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
// Initializing events
// this is needed only if you are using events in your module
Expand Down
2 changes: 1 addition & 1 deletion cstrml/tee/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub fn upsert_sorder_to_provider(who: &AccountId, f_id: &MerkleRoot, rd: u8, os:
};
file_map.insert(f_id.clone(), sorder_id.clone());
let provision = Provision {
address: vec![],
address_info: vec![],
file_map
};
<market::Providers<Test>>::insert(who, provision);
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ pub type MerkleRoot = Vec<u8>;
pub type ReportSlot = u64;

/// Market vendor's address info
pub type Address = Vec<u8>;
pub type AddressInfo = Vec<u8>;
2 changes: 0 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ pub use timestamp::Call as TimestampCall;
/// Crust primitives
use primitives::{constants::{time::*, currency::*}, *};

use market;

#[cfg(feature = "std")]
pub use staking::StakerStatus;

Expand Down

0 comments on commit f2b8538

Please sign in to comment.