Skip to content

Commit

Permalink
Added RWS pallet (airalab#77)
Browse files Browse the repository at this point in the history
* Added RWS pallet

* Added RWS tests

* Fix node build

* Fix code style
  • Loading branch information
akru authored Sep 25, 2020
1 parent 02c7175 commit 3776078
Show file tree
Hide file tree
Showing 12 changed files with 612 additions and 148 deletions.
257 changes: 123 additions & 134 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"bin/node/ipci-runtime",
"bin/node/robonomics-runtime",
"bin/node/robonomics-runtime/parachain",
"robonomics/frame/rws",
"robonomics/frame/launch",
"robonomics/frame/datalog",
"robonomics/frame/liability",
Expand Down
2 changes: 2 additions & 0 deletions bin/node/robonomics-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "ro
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
pallet-robonomics-rws = { path = "../../../robonomics/frame/rws", default-features = false }
pallet-robonomics-launch = { path = "../../../robonomics/frame/launch", default-features = false }
pallet-robonomics-datalog = { path = "../../../robonomics/frame/datalog", default-features = false }
pallet-robonomics-liability = { path = "../../../robonomics/frame/liability", default-features = false }
Expand Down Expand Up @@ -119,6 +120,7 @@ std = [
"sp-block-builder/std",
"sp-transaction-pool/std",
"sp-inherents/std",
"pallet-robonomics-rws/std",
"pallet-robonomics-datalog/std",
"pallet-robonomics-liability/std",
]
Expand Down
5 changes: 3 additions & 2 deletions bin/node/robonomics-runtime/parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "ro
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
#pallet-xtokens = { package = "orml-xtokens", git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "rococo", default-features = false }
pallet-robonomics-launch = { path = "../../../../robonomics/frame/launch", default-features = false }
pallet-robonomics-datalog = { path = "../../../../robonomics/frame/datalog", default-features = false }
pallet-robonomics-liability = { path = "../../../../robonomics/frame/liability", default-features = false }
Expand All @@ -56,7 +57,6 @@ cumulus-runtime = { git = "https://github.com/paritytech/cumulus", default-featu
cumulus-upward-message = { git = "https://github.com/paritytech/cumulus", default-features = false }
cumulus-message-broker = { git = "https://github.com/paritytech/cumulus", default-features = false }
cumulus-parachain-upgrade = { git = "https://github.com/paritytech/cumulus", default-features = false }
cumulus-token-dealer = { git = "https://github.com/paritytech/cumulus", default-features = false }
parachain-info = { git = "https://github.com/paritytech/cumulus", default-features = false }

[build-dependencies]
Expand All @@ -74,7 +74,6 @@ std = [
"cumulus-runtime/std",
"cumulus-upward-message/std",
"cumulus-message-broker/std",
"cumulus-token-dealer/std",
"cumulus-parachain-upgrade/std",
"pallet-collective/std",
"pallet-elections-phragmen/std",
Expand Down Expand Up @@ -109,6 +108,8 @@ std = [
"sp-block-builder/std",
"sp-transaction-pool/std",
"sp-inherents/std",
# "pallet-xtokens/std",
"pallet-robonomics-launch/std",
"pallet-robonomics-datalog/std",
"pallet-robonomics-liability/std",
]
Expand Down
42 changes: 35 additions & 7 deletions bin/node/robonomics-runtime/parachain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,20 +345,49 @@ impl pallet_elections_phragmen::Trait for Runtime {

impl cumulus_message_broker::Trait for Runtime {
type Event = Event;
type DownwardMessageHandlers = TokenDealer;
type DownwardMessageHandlers = ();
type UpwardMessage = cumulus_upward_message::RococoUpwardMessage;
type ParachainId = ParachainInfo;
type XCMPMessage = cumulus_token_dealer::XCMPMessage<AccountId, Balance>;
type XCMPMessageHandlers = TokenDealer;
type XCMPMessage = ();
type XCMPMessageHandlers = ();
}

impl cumulus_token_dealer::Trait for Runtime {
/*
parameter_types! {
pub const RelayChainCurrencyId: CurrencyId = CurrencyId::DOT;
}
pub struct RelayToNative;
impl Convert<RelayChainBalance, Balance> for RelayToNative {
fn convert(val: u128) -> Balance {
// native is 9
// relay is 12
val / 1_000
}
}
pub struct NativeToRelay;
impl Convert<Balance, RelayChainBalance> for NativeToRelay {
fn convert(val: u128) -> Balance {
// native is 9
// relay is 12
val * 1_000
}
}
impl pallet_xtokens::Trait for Runtime {
type Event = Event;
type Balance = Balance;
type CurrencyId = CurrencyId;
type Currency = Currencies;
type XCMPMessageSender = MessageBroker;
type RelayChainCurrencyId = RelayChainCurrencyId;
type UpwardMessageSender = MessageBroker;
type FromRelayChainBalance = RelayToNative;
type ToRelayChainBalance = NativeToRelay;
type UpwardMessage = cumulus_upward_message::RococoUpwardMessage;
type Currency = Balances;
type XCMPMessageSender = MessageBroker;
}
*/

impl parachain_info::Trait for Runtime {}

Expand Down Expand Up @@ -480,7 +509,6 @@ construct_runtime! {
ParachainUpgrade: cumulus_parachain_upgrade::{Module, Call, Storage, Inherent, Event},
ParachainInfo: parachain_info::{Module, Storage, Config},
MessageBroker: cumulus_message_broker::{Module, Call, Inherent, Event<T>},
TokenDealer: cumulus_token_dealer::{Module, Call, Event<T>},

// DAO modules
Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
Expand Down
15 changes: 15 additions & 0 deletions bin/node/robonomics-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,20 @@ impl pallet_robonomics_launch::Trait for Runtime {
type Event = Event;
}

parameter_types! {
pub const TotalBandwidth: u64 = 100; // 100 TPS allocated for RWS transactions
pub const WeightLimit: Weight = 1_000_000_000_000_000;
pub const PointsLimit: u64 = 10_000_000_000; // equal to 10 TPS
}

impl pallet_robonomics_rws::Trait for Runtime {
type TotalBandwidth = TotalBandwidth;
type WeightLimit = WeightLimit;
type PointsLimit = PointsLimit;
type Event = Event;
type Call = Call;
}

impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime
where
Call: From<LocalCall>,
Expand Down Expand Up @@ -665,6 +679,7 @@ construct_runtime!(
Liability: pallet_robonomics_liability::{Module, Call, Storage, Event<T>, ValidateUnsigned},
Datalog: pallet_robonomics_datalog::{Module, Call, Storage, Event<T>},
Launch: pallet_robonomics_launch::{Module, Call, Storage, Event<T>},
RWS: pallet_robonomics_rws::{Module, Call, Storage, Event<T>},

// Sudo. Usable initially.
Sudo: pallet_sudo::{Module, Call, Storage, Event<T>, Config<T>},
Expand Down
2 changes: 1 addition & 1 deletion robonomics/frame/datalog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Airalab <[email protected]>"]
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion robonomics/frame/launch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Airalab <[email protected]>"]
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
Expand Down
18 changes: 16 additions & 2 deletions robonomics/frame/launch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@ use sp_std::prelude::*;
pub trait Trait: frame_system::Trait {
/// Robot launch parameter data type.
type Parameter: Codec + EncodeLike + Member;
// This module can send XCMP messages.
//type XCMPMessageSender: XCMPMessageSender<XCMPMessage<Self::AccountId, Self::Balance>>;
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
}

/*
/// Robot launch XCMP message trait.
pub trait LaunchMessage<AccountId, Parameter>: Sized {
#[derive(Encode, Decode)]
pub enum XCMPMessage<AccountId, Parameter> {
/// Launch robot with given launch parameter.
fn launch(from: AccountId, to: AccountId, param: Parameter) -> Self;
fn LaunchRobot(from: AccountId, to: AccountId, param: Parameter),
}
*/

decl_event! {
pub enum Event<T>
Expand Down Expand Up @@ -65,6 +70,15 @@ decl_module! {
}
}

/*
impl<T: Trait> XCMPMessageHandler<XCMPMessage<T::AccountId, T::Balance>> for Module<T> {
fn handle_xcmp_message(src: ParaId, msg: &XCMPMessage<T::AccountId, T::Balance>) {
match msg {
}
}
}
*/

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion robonomics/frame/liability/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Airalab <[email protected]>"]
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
Expand Down
33 changes: 33 additions & 0 deletions robonomics/frame/rws/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "pallet-robonomics-rws"
description = "Robonomics Web Services subscription runtime module."
version = "0.1.0"
authors = ["Airalab <[email protected]>"]
edition = "2018"

[dependencies]
serde = { version = "1.0.101", optional = true }
codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" , default-features = false }

[dev-dependencies]
sp-io = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
node-primitives = { path = "../../../bin/node/primitives" }
pallet-robonomics-datalog = { path = "../datalog" }

[features]
default = ["std"]
std = [
"serde",
"codec/std",
"sp-std/std",
"sp-runtime/std",
"frame-system/std",
"frame-support/std",
"pallet-timestamp/std",
]
Loading

0 comments on commit 3776078

Please sign in to comment.