Skip to content

Commit

Permalink
support channel_relationship (paritytech#113)
Browse files Browse the repository at this point in the history
* support channel_relationship
  • Loading branch information
toxotguo authored Nov 21, 2018
1 parent 954bbef commit 88b3b65
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
13 changes: 12 additions & 1 deletion cxrml/associations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ decl_event!(
{
InitAccount(AccountId, AccountId, Balance),
InitExchangeAccount(AccountId, AccountId),
InitChannelRelationship(Vec<u8>, AccountId),
}
);

Expand All @@ -84,7 +85,7 @@ impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
decl_storage! {
trait Store for Module<T: Trait> as Associations {
pub Relationship get(relationship): map T::AccountId => Option<T::AccountId>;
pub TokenRelationship get(token_relationship): map (Vec<u8>, T::AccountId) => Vec<u8>;
pub ChannelRelationship get(channel_relationship): map Vec<u8> => Option< T::AccountId >;
pub ExchangeRelationship get(exchange_relationship): map T::AccountId => Option<T::AccountId>;
// fee
pub InitFee get(init_fee) config(): T::Balance;
Expand Down Expand Up @@ -163,4 +164,14 @@ impl<T: Trait> Module<T> {
Self::deposit_event(RawEvent::InitExchangeAccount(from, who));
Ok(())
}
pub fn init_channel_relationship( channel: Vec<u8>,who: &T::AccountId) -> Result {

if Self::channel_relationship(&channel).is_some() {
return Err("has register this channel");
}

ChannelRelationship::<T>::insert(channel.clone(), who.clone());
Self::deposit_event(RawEvent::InitChannelRelationship(channel, who.clone()));
Ok(())
}
}
10 changes: 6 additions & 4 deletions cxrml/exchange/pendingorders/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extern crate srml_system as system;
extern crate cxrml_support as cxsupport;
extern crate cxrml_tokenbalances as tokenbalances;

#[cfg(test)]

extern crate cxrml_associations as associations;
#[cfg(test)]
extern crate cxrml_system as cxsystem;
Expand Down Expand Up @@ -362,9 +362,11 @@ impl<T: Trait> Module<T> {
return Err("channel name too long");
}
let transactor = ensure_signed(origin)?;
//TODO
let channel: T::AccountId = transactor.clone(); //从channel模块获得channel_name对应的account

//从channel模块获得channel_name对应的account
let channel: T::AccountId = match <associations::Module<T>>::channel_relationship(&channel_name) {
Some(relation)=>relation,
None=>transactor.clone(),
};
Self::do_put_order(&transactor, &pair, ordertype, amount, price, &channel)
}
pub fn update_command_of(command_id: u64, bid: u128) {
Expand Down
1 change: 1 addition & 0 deletions src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate cxrml_tokenbalances;
extern crate keys;
extern crate primitives as btc_primitives;


use self::base58::FromBase58;
use self::cxrml_exchange_pendingorders::OrderPair;
use chainx_runtime::{
Expand Down

0 comments on commit 88b3b65

Please sign in to comment.