Skip to content
This repository was archived by the owner on Feb 28, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,635 changes: 2,009 additions & 1,626 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ci/run
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fi
TIMEFORMAT='elapsed time: %R (user: %U, system: %S)'

echo "--- Load cache"
declare -i cache_version=11
declare -i cache_version=12
target_cache=/cache/target-v${cache_version}
target_cache_key_file="$target_cache/_key"
cache_key="$(sha256sum Cargo.lock | cut -f 1 -d ' ')"
Expand Down
24 changes: 12 additions & 12 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ log = "0.4"
parity-scale-codec = "1.0"
tokio = "0.1"

[dependencies.paint-system]
[dependencies.frame-system]
git = "https://github.com/paritytech/substrate"
rev = "dc4a8329b9c47790c25429a5df272b3648275c1b"
rev = "3d17cbd2fbcc337af49c861896ab4936b161bcee"

[dependencies.paint-support]
[dependencies.frame-support]
git = "https://github.com/paritytech/substrate"
rev = "dc4a8329b9c47790c25429a5df272b3648275c1b"
rev = "3d17cbd2fbcc337af49c861896ab4936b161bcee"

[dependencies.paint-transaction-payment]
[dependencies.pallet-transaction-payment]
git = "https://github.com/paritytech/substrate"
rev = "dc4a8329b9c47790c25429a5df272b3648275c1b"
rev = "3d17cbd2fbcc337af49c861896ab4936b161bcee"

[dependencies.substrate-primitives]
[dependencies.sp-core]
git = "https://github.com/paritytech/substrate"
rev = "dc4a8329b9c47790c25429a5df272b3648275c1b"
rev = "3d17cbd2fbcc337af49c861896ab4936b161bcee"

[dependencies.sr-primitives]
[dependencies.sp-runtime]
git = "https://github.com/paritytech/substrate"
rev = "dc4a8329b9c47790c25429a5df272b3648275c1b"
rev = "3d17cbd2fbcc337af49c861896ab4936b161bcee"

[dependencies.sr-io]
[dependencies.sp-io]
git = "https://github.com/paritytech/substrate"
rev = "dc4a8329b9c47790c25429a5df272b3648275c1b"
rev = "3d17cbd2fbcc337af49c861896ab4936b161bcee"
25 changes: 13 additions & 12 deletions client/src/backend/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use futures01::future;
use std::sync::{Arc, Mutex};

use sr_primitives::{traits::Hash as _, BuildStorage as _};
use sp_runtime::{traits::Hash as _, BuildStorage as _};

use radicle_registry_runtime::{BalancesConfig, Executive, GenesisConfig, Hash, Hashing, Runtime};

Expand All @@ -21,14 +21,14 @@ use crate::interface::*;
/// The responses returned from the client never result in an [Error].
#[derive(Clone)]
pub struct Emulator {
test_ext: Arc<Mutex<sr_io::TestExternalities>>,
test_ext: Arc<Mutex<sp_io::TestExternalities>>,
genesis_hash: Hash,
}

impl Emulator {
pub fn new() -> Self {
let genesis_config = make_genesis_config();
let mut test_ext = sr_io::TestExternalities::new(genesis_config.build_storage().unwrap());
let mut test_ext = sp_io::TestExternalities::new(genesis_config.build_storage().unwrap());
let genesis_hash = init_runtime(&mut test_ext);
Emulator {
test_ext: Arc::new(Mutex::new(test_ext)),
Expand All @@ -45,11 +45,11 @@ impl backend::Backend for Emulator {
let tx_hash = Hashing::hash_of(&extrinsic);
let test_ext = &mut self.test_ext.lock().unwrap();
let events = test_ext.execute_with(move || {
let event_start_index = paint_system::Module::<Runtime>::event_count();
let event_start_index = frame_system::Module::<Runtime>::event_count();
// We ignore the dispatch result. It is provided through the system event
// TODO Pass on apply errors instead of unwrapping.
let _dispatch_result = Executive::apply_extrinsic(extrinsic).unwrap();
paint_system::Module::<Runtime>::events()
frame_system::Module::<Runtime>::events()
.into_iter()
.skip(event_start_index as usize)
.map(|event_record| event_record.event)
Expand All @@ -64,7 +64,7 @@ impl backend::Backend for Emulator {

fn fetch(&self, key: &[u8]) -> Response<Option<Vec<u8>>, Error> {
let test_ext = &mut self.test_ext.lock().unwrap();
let maybe_data = test_ext.execute_with(|| sr_io::storage::get(key));
let maybe_data = test_ext.execute_with(|| sp_io::storage::get(key));
Box::new(future::ok(maybe_data))
}

Expand All @@ -78,8 +78,8 @@ impl backend::Backend for Emulator {
/// Initializes the balance of the `//Alice` account with `2^60` tokens.
fn make_genesis_config() -> GenesisConfig {
GenesisConfig {
paint_aura: None,
paint_balances: Some(BalancesConfig {
pallet_aura: None,
pallet_balances: Some(BalancesConfig {
balances: vec![(
ed25519::Pair::from_string("//Alice", None)
.unwrap()
Expand All @@ -88,23 +88,24 @@ fn make_genesis_config() -> GenesisConfig {
)],
vesting: vec![],
}),
paint_sudo: None,
pallet_sudo: None,
grandpa: None,
system: None,
}
}

/// Initialize the runtime state so that it is usable and return the genesis hash.
fn init_runtime(test_ext: &mut sr_io::TestExternalities) -> Hash {
fn init_runtime(test_ext: &mut sp_io::TestExternalities) -> Hash {
test_ext.execute_with(|| {
// Insert the genesis block (number `1`) into the system. We don’t care about the
// other parameters, they are not relevant.
paint_system::Module::<Runtime>::initialize(
frame_system::Module::<Runtime>::initialize(
&1,
&[0u8; 32].into(),
&[0u8; 32].into(),
&Default::default(),
);
// Now we can retrieve the block hash. But here the block number is zero-based.
paint_system::Module::<Runtime>::block_hash(0)
frame_system::Module::<Runtime>::block_hash(0)
})
}
7 changes: 3 additions & 4 deletions client/src/backend/remote_node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! [backend::Backend] implementation for a remote full node
use futures01::future::Future;
use sr_primitives::traits::Hash as _;
use substrate_primitives::storage::StorageKey;
use sp_core::storage::StorageKey;
use sp_runtime::traits::Hash as _;

use radicle_registry_runtime::{opaque::Block as OpaqueBlock, Event, Hash, Hashing, Runtime};

Expand Down Expand Up @@ -112,7 +111,7 @@ fn extract_events(block: OpaqueBlock, ext_success: ExtrinsicSuccess) -> Option<V
.events
.iter()
.filter_map(|event_record| match event_record.phase {
paint_system::Phase::ApplyExtrinsic(i) if i == xt_index as u32 => {
frame_system::Phase::ApplyExtrinsic(i) if i == xt_index as u32 => {
Some(event_record.event.clone())
}
_ => None,
Expand Down
37 changes: 22 additions & 15 deletions client/src/call.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Defines [Call] trait and implementations for all transaction parameters.

use radicle_registry_runtime::{
balances, registry, registry::CheckpointId, Call as RuntimeCall, Event,
};
use sr_primitives::DispatchError;
use frame_support::weights::DispatchInfo;
use radicle_registry_runtime::{balances, registry, Call as RuntimeCall, Event};
use sp_runtime::DispatchError;

/// Indicates that parsing the events into the approriate call result failed.
type EventParseError = String;
Expand Down Expand Up @@ -31,7 +30,7 @@ impl Call for registry::RegisterProjectParams {
fn result_from_events(events: Vec<Event>) -> Result<Self::Result, EventParseError> {
let dispatch_result = get_dispatch_result(&events)?;
match dispatch_result {
Ok(()) => find_event(&events, "ProjectRegistered", |event| match event {
Ok(_dispatch_info) => find_event(&events, "ProjectRegistered", |event| match event {
Event::registry(registry::Event::ProjectRegistered(_project_id, _account_id)) => {
Some(Ok(()))
}
Expand All @@ -47,12 +46,12 @@ impl Call for registry::RegisterProjectParams {
}

impl Call for registry::CreateCheckpointParams {
type Result = Result<CheckpointId, Option<&'static str>>;
type Result = Result<registry::CheckpointId, Option<&'static str>>;

fn result_from_events(events: Vec<Event>) -> Result<Self::Result, EventParseError> {
let dispatch_result = get_dispatch_result(&events)?;
match dispatch_result {
Ok(()) => find_event(&events, "CheckpointCreated", |event| match event {
Ok(_dispatch_info) => find_event(&events, "CheckpointCreated", |event| match event {
Event::registry(registry::Event::CheckpointCreated(checkpoint_id)) => {
Some(Ok(*checkpoint_id))
}
Expand All @@ -73,7 +72,7 @@ impl Call for registry::SetCheckpointParams {
fn result_from_events(events: Vec<Event>) -> Result<Self::Result, EventParseError> {
let dispatch_result = get_dispatch_result(&events)?;
match dispatch_result {
Ok(()) => find_event(&events, "CheckpointSet", |event| match event {
Ok(_dispatch_info) => find_event(&events, "CheckpointSet", |event| match event {
Event::registry(registry::Event::CheckpointSet(_project_id, _checkpoint_id)) => {
Some(Ok(()))
}
Expand All @@ -93,7 +92,9 @@ impl Call for crate::TransferParams {

fn result_from_events(events: Vec<Event>) -> Result<Self::Result, EventParseError> {
let dispatch_result = get_dispatch_result(&events)?;
Ok(dispatch_result.map_err(|dispatch_error| dispatch_error.message))
Ok(dispatch_result
.map_err(|dispatch_error| dispatch_error.message)
.map(|_| ()))
}

fn into_runtime_call(self) -> RuntimeCall {
Expand All @@ -106,7 +107,9 @@ impl Call for registry::TransferFromProjectParams {

fn result_from_events(events: Vec<Event>) -> Result<Self::Result, EventParseError> {
let dispatch_result = get_dispatch_result(&events)?;
Ok(dispatch_result.map_err(|dispatch_error| dispatch_error.message))
Ok(dispatch_result
.map_err(|dispatch_error| dispatch_error.message)
.map(|_| ()))
}

fn into_runtime_call(self) -> RuntimeCall {
Expand All @@ -116,17 +119,21 @@ impl Call for registry::TransferFromProjectParams {

/// Extract the dispatch result of an extrinsic from the extrinsic events.
///
/// Looks for the [paint_system::Event] in the list of events and returns the inner result based on
/// Looks for the [frame_system::Event] in the list of events and returns the inner result based on
/// the event.
///
/// Returns an outer [EventParseError] if no [paint_system::Event] was present in `events`.
/// Returns an outer [EventParseError] if no [frame_system::Event] was present in `events`.
///
/// Because of an issue with substrate the `message` field of [DispatchError] will always be `None`
fn get_dispatch_result(events: &[Event]) -> Result<Result<(), DispatchError>, EventParseError> {
fn get_dispatch_result(
events: &[Event],
) -> Result<Result<DispatchInfo, DispatchError>, EventParseError> {
find_event(events, "System", |event| match event {
Event::system(system_event) => match system_event {
paint_system::Event::ExtrinsicSuccess => Some(Ok(())),
paint_system::Event::ExtrinsicFailed(ref dispatch_error) => Some(Err(*dispatch_error)),
frame_system::Event::ExtrinsicSuccess(ref dispatch_info) => Some(Ok(*dispatch_info)),
frame_system::Event::ExtrinsicFailed(ref dispatch_error, _) => {
Some(Err(*dispatch_error))
}
},
_ => None,
})
Expand Down
4 changes: 2 additions & 2 deletions client/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub use radicle_registry_runtime::{
},
AccountId, Balance, Event, Hashing, Index, String32,
};
pub use substrate_primitives::crypto::{Pair as CryptoPair, Public as CryptoPublic};
pub use substrate_primitives::{ed25519, H256};
pub use sp_core::crypto::{Pair as CryptoPair, Public as CryptoPublic};
pub use sp_core::{ed25519, H256};

pub use crate::call::Call;
pub use crate::transaction::{Transaction, TransactionExtra};
Expand Down
6 changes: 3 additions & 3 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use std::sync::Arc;

use parity_scale_codec::{Decode, FullCodec};

use paint_support::storage::generator::{StorageMap, StorageValue};
use frame_support::storage::generator::{StorageMap, StorageValue};
use radicle_registry_runtime::{balances, registry, Runtime};
use sr_primitives::traits::Hash as _;
use sp_runtime::traits::Hash as _;

mod backend;
mod call;
Expand Down Expand Up @@ -195,7 +195,7 @@ impl ClientT for Client {
}

fn account_nonce(&self, account_id: &AccountId) -> Response<Index, Error> {
Box::new(self.fetch_map_value::<paint_system::AccountNonce<Runtime>, _, _>(*account_id))
Box::new(self.fetch_map_value::<frame_system::AccountNonce<Runtime>, _, _>(*account_id))
}

fn transfer(
Expand Down
37 changes: 19 additions & 18 deletions client/src/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//! Provides [Transaction] and [TransactionExtra].
use parity_scale_codec::Encode;
use radicle_registry_runtime::UncheckedExtrinsic;
use sr_primitives::generic::{Era, SignedPayload};
use sr_primitives::traits::SignedExtension;
use sp_runtime::generic::{Era, SignedPayload};
use sp_runtime::traits::SignedExtension;
use std::marker::PhantomData;

pub use radicle_registry_runtime::{
registry::{Project, ProjectId},
AccountId, Balance,
};
pub use substrate_primitives::crypto::{Pair as CryptoPair, Public as CryptoPublic};
pub use substrate_primitives::ed25519;
pub use sp_core::crypto::{Pair as CryptoPair, Public as CryptoPublic};
pub use sp_core::ed25519;

pub use crate::call::Call;
pub use radicle_registry_runtime::{Call as RuntimeCall, Hash, Index, SignedExtra};
Expand Down Expand Up @@ -82,12 +82,12 @@ fn transaction_extra_to_runtime_extra(
SignedExtra,
<SignedExtra as SignedExtension>::AdditionalSigned,
) {
let check_version = paint_system::CheckVersion::new();
let check_genesis = paint_system::CheckGenesis::new();
let check_era = paint_system::CheckEra::from(Era::Immortal);
let check_nonce = paint_system::CheckNonce::from(extra.nonce);
let check_weight = paint_system::CheckWeight::new();
let charge_transaction_payment = paint_transaction_payment::ChargeTransactionPayment::from(0);
let check_version = frame_system::CheckVersion::new();
let check_genesis = frame_system::CheckGenesis::new();
let check_era = frame_system::CheckEra::from(Era::Immortal);
let check_nonce = frame_system::CheckNonce::from(extra.nonce);
let check_weight = frame_system::CheckWeight::new();
let charge_transaction_payment = pallet_transaction_payment::ChargeTransactionPayment::from(0);

let additional_signed = (
check_version
Expand Down Expand Up @@ -124,22 +124,23 @@ fn transaction_extra_to_runtime_extra(
mod test {
use super::*;
use radicle_registry_runtime::{GenesisConfig, Runtime};
use sr_primitives::traits::{Checkable, IdentityLookup};
use sr_primitives::BuildStorage as _;
use sp_runtime::traits::{Checkable, IdentityLookup};
use sp_runtime::BuildStorage as _;

#[test]
/// Assert that extrinsics created with [create_and_sign] are validated by the runtime.
fn check_extrinsic() {
let genesis_config = GenesisConfig {
paint_aura: None,
paint_balances: None,
paint_sudo: None,
pallet_aura: None,
pallet_balances: None,
pallet_sudo: None,
system: None,
grandpa: None,
};
let mut test_ext = sr_io::TestExternalities::new(genesis_config.build_storage().unwrap());
let mut test_ext = sp_io::TestExternalities::new(genesis_config.build_storage().unwrap());
let (key_pair, _) = ed25519::Pair::generate();

type System = paint_system::Module<Runtime>;
type System = frame_system::Module<Runtime>;
let genesis_hash = test_ext.execute_with(|| {
System::initialize(
&1,
Expand All @@ -152,7 +153,7 @@ mod test {

let xt = signed_extrinsic(
&key_pair,
paint_system::Call::fill_block().into(),
frame_system::Call::fill_block().into(),
TransactionExtra {
nonce: 0,
genesis_hash,
Expand Down
Loading