Skip to content
Merged
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
68 changes: 40 additions & 28 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1236,19 +1236,19 @@ dependencies = [

[[package]]
name = "futures-channel"
version = "0.3.13"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939"
checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2"
dependencies = [
"futures-core",
"futures-sink",
]

[[package]]
name = "futures-core"
version = "0.3.13"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94"
checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1"

[[package]]
name = "futures-executor"
Expand All @@ -1264,9 +1264,9 @@ dependencies = [

[[package]]
name = "futures-io"
version = "0.3.13"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59"
checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1"

[[package]]
name = "futures-lite"
Expand All @@ -1285,10 +1285,11 @@ dependencies = [

[[package]]
name = "futures-macro"
version = "0.3.13"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea405816a5139fb39af82c2beb921d52143f556038378d6db21183a5c37fbfb7"
checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121"
dependencies = [
"autocfg 1.0.1",
"proc-macro-hack",
"proc-macro2",
"quote 1.0.9",
Expand All @@ -1297,15 +1298,15 @@ dependencies = [

[[package]]
name = "futures-sink"
version = "0.3.13"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85754d98985841b7d4f5e8e6fbfa4a4ac847916893ec511a2917ccd8525b8bb3"
checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282"

[[package]]
name = "futures-task"
version = "0.3.13"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80"
checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae"

[[package]]
name = "futures-timer"
Expand All @@ -1315,10 +1316,11 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c"

[[package]]
name = "futures-util"
version = "0.3.13"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1"
checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967"
dependencies = [
"autocfg 1.0.1",
"futures 0.1.31",
"futures-channel",
"futures-core",
Expand Down Expand Up @@ -1463,7 +1465,7 @@ dependencies = [
"http",
"indexmap",
"slab",
"tokio 1.4.0",
"tokio 1.6.1",
"tokio-util 0.6.5",
"tracing",
]
Expand Down Expand Up @@ -1671,7 +1673,7 @@ dependencies = [
"itoa",
"pin-project 1.0.6",
"socket2",
"tokio 1.4.0",
"tokio 1.6.1",
"tower-service",
"tracing",
"want",
Expand Down Expand Up @@ -1699,7 +1701,7 @@ dependencies = [
"bytes 1.0.1",
"hyper 0.14.5",
"native-tls",
"tokio 1.4.0",
"tokio 1.6.1",
"tokio-native-tls",
]

Expand Down Expand Up @@ -1844,7 +1846,7 @@ dependencies = [
"serde",
"serde_json",
"serde_urlencoded",
"tokio 1.4.0",
"tokio 1.6.1",
"tokio-util 0.6.5",
"tracing",
"typed-builder",
Expand Down Expand Up @@ -5038,6 +5040,18 @@ dependencies = [
"wasm-gc-api",
]

[[package]]
name = "substratee-api-client-extensions"
version = "0.8.0"
dependencies = [
"parity-scale-codec 2.0.1",
"sp-core",
"sp-finality-grandpa",
"sp-runtime",
"substrate-api-client",
"substratee-node-primitives",
]

[[package]]
name = "substratee-client"
version = "0.8.0"
Expand Down Expand Up @@ -5067,6 +5081,8 @@ dependencies = [
"substrate-api-client",
"substrate-bip39 0.3.1",
"substrate-client-keystore",
"substratee-api-client-extensions",
"substratee-node-primitives",
"substratee-node-runtime",
"substratee-stf",
"substratee-worker-api",
Expand All @@ -5079,14 +5095,9 @@ dependencies = [
name = "substratee-node-primitives"
version = "0.8.0"
dependencies = [
"base58",
"log 0.4.14 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-scale-codec 2.0.1",
"primitive-types 0.9.0",
"sgx_tstd",
"sp-core",
"sp-runtime",
"substrate-api-client",
"substratee-node-runtime",
]

Expand Down Expand Up @@ -5191,6 +5202,7 @@ dependencies = [
"sp-keyring",
"sp-runtime",
"substrate-api-client",
"substratee-api-client-extensions",
"substratee-node-primitives",
"substratee-node-runtime",
"substratee-settings",
Expand Down Expand Up @@ -5461,9 +5473,9 @@ dependencies = [

[[package]]
name = "tokio"
version = "1.4.0"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134af885d758d645f0f0505c9a8b3f9bf8a348fd822e112ab5248138348f1722"
checksum = "0a38d31d7831c6ed7aad00aa4c12d9375fd225a6dd77da1d25b707346319a975"
dependencies = [
"autocfg 1.0.1",
"bytes 1.0.1",
Expand Down Expand Up @@ -5491,7 +5503,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b"
dependencies = [
"native-tls",
"tokio 1.4.0",
"tokio 1.6.1",
]

[[package]]
Expand Down Expand Up @@ -5519,7 +5531,7 @@ dependencies = [
"futures-sink",
"log 0.4.14 (registry+https://github.com/rust-lang/crates.io-index)",
"pin-project-lite 0.2.6",
"tokio 1.4.0",
"tokio 1.6.1",
]

[[package]]
Expand Down Expand Up @@ -5658,7 +5670,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04f8ab788026715fa63b31960869617cba39117e520eb415b0139543e325ab59"
dependencies = [
"cfg-if 0.1.10",
"rand 0.6.5",
"rand 0.7.3",
"static_assertions",
]

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"client",
"primitives/api-client-extensions",
"primitives/settings",
"primitives/node",
"primitives/worker",
Expand Down
6 changes: 6 additions & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ package = "substratee-node-runtime"
[dependencies.substratee-worker-primitives]
path = "../primitives/worker"

[dependencies.substratee-node-primitives]
path = "../primitives/node"

[dependencies.substratee-api-client-extensions]
path = "../primitives/api-client-extensions"

[dependencies.substratee-stf]
path = "../stf"

Expand Down
24 changes: 5 additions & 19 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ use clap_nested::{Command, Commander};
use codec::{Decode, Encode};
use log::*;
use my_node_runtime::{
substratee_registry::{Enclave, Request},
substratee_registry::Request,
AccountId, BalancesCall, Call, Event, Hash, Signature,
};

use sp_core::{crypto::Ss58Codec, sr25519 as sr25519_core, Pair, H256};
use sp_runtime::{
traits::{IdentifyAccount, Verify},
Expand All @@ -64,6 +65,7 @@ use substrate_api_client::{
use substrate_client_keystore::LocalKeystore;
use substratee_stf::{ShardIdentifier, TrustedCallSigned, TrustedOperation};
use substratee_worker_api::direct_client::DirectApi as DirectWorkerApi;
use substratee_api_client_extensions::SubstrateeRegistryApi;
use substratee_worker_primitives::{DirectRequestStatus, RpcRequest, RpcResponse, RpcReturnValue};

type AccountPublic = <Signature as Verify>::Signer;
Expand Down Expand Up @@ -293,10 +295,10 @@ fn main() {
.description("query enclave registry and list all workers")
.runner(|_args: &str, matches: &ArgMatches<'_>| {
let api = get_chain_api(matches);
let wcount = get_enclave_count(&api);
let wcount = api.enclave_count().unwrap();
println!("number of workers registered: {}", wcount);
for w in 1..=wcount {
let enclave = get_enclave(&api, w);
let enclave = api.enclave(w).unwrap();
if enclave.is_none() {
println!("error reading enclave data");
continue;
Expand Down Expand Up @@ -865,19 +867,3 @@ fn get_pair_from_str(account: &str) -> sr25519::AppPair {
}
}
}

fn get_enclave_count(api: &Api<sr25519::Pair>) -> u64 {
if let Some(count) = api
.get_storage_value("SubstrateeRegistry", "EnclaveCount", None)
.unwrap()
{
count
} else {
0
}
}

fn get_enclave(api: &Api<sr25519::Pair>, eindex: u64) -> Option<Enclave<AccountId, Vec<u8>>> {
api.get_storage_map("SubstrateeRegistry", "EnclaveRegistry", eindex, None)
.unwrap()
}
1 change: 0 additions & 1 deletion enclave/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2495,7 +2495,6 @@ name = "substratee-node-primitives"
version = "0.8.0"
dependencies = [
"parity-scale-codec",
"primitive-types",
"sgx_tstd",
"sp-core",
]
Expand Down
19 changes: 19 additions & 0 deletions primitives/api-client-extensions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "substratee-api-client-extensions"
version = "0.8.0"
authors = ["clangenbacher <christian.langenbacher@scs.ch>"]
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"] }

# substrate
sp-core = { version = "3.0.0", git = "https://github.com/paritytech/substrate.git" }
sp-finality-grandpa = { version = "3.0.0", git = "https://github.com/paritytech/substrate.git" }
sp-runtime = { version = "3.0.0", git = "https://github.com/paritytech/substrate.git" }

# scs
substrate-api-client = { git = "https://github.com/scs/substrate-api-client" }

# substratee
substratee-node-primitives = { path = "../node"}
28 changes: 28 additions & 0 deletions primitives/api-client-extensions/src/account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use sp_core::crypto::Pair;
use substrate_api_client::Api;
use sp_runtime::MultiSignature;

use substratee_node_primitives::AccountId;

use crate::ApiResult;

/// ApiClient extension that contains some convenience methods around accounts.
pub trait AccountApi {
fn get_nonce_of(&self, who: &AccountId) -> ApiResult<u32>;
fn get_free_balance(&self, who: &AccountId) -> ApiResult<u128>;
}

impl<P: Pair> AccountApi for Api<P>
where
MultiSignature: From<P::Signature>
{
fn get_nonce_of(&self, who: &AccountId) -> ApiResult<u32> {
Ok(self.get_account_info(who)?
.map_or_else(|| 0, |info| info.nonce))
}

fn get_free_balance(&self, who: &AccountId) -> ApiResult<u128> {
Ok(self.get_account_data(who)?
.map_or_else(|| 0, |data| data.free))
}
}
53 changes: 53 additions & 0 deletions primitives/api-client-extensions/src/chain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use sp_core::{Pair, H256, storage::StorageKey};
use sp_finality_grandpa::{AuthorityList, VersionedAuthorityList, GRANDPA_AUTHORITIES_KEY};
use sp_runtime::MultiSignature;
use substrate_api_client::Api;

use substratee_node_primitives::SignedBlock;

use crate::ApiResult;

pub type StorageProof = Vec<Vec<u8>>;

/// ApiClient extension that simplifies chain data access.
pub trait ChainApi {
fn last_finalized_block(&self) -> ApiResult<Option<SignedBlock>>;
fn signed_block(&self, hash: Option<H256>) -> ApiResult<Option<SignedBlock>>;
fn grandpa_authorities(&self, hash: Option<H256>) -> ApiResult<AuthorityList>;
fn grandpa_authorities_proof(&self, hash: Option<H256>) -> ApiResult<StorageProof>;
}

impl<P: Pair> ChainApi for Api<P>
where
MultiSignature: From<P::Signature>
{
fn last_finalized_block(&self) -> ApiResult<Option<SignedBlock>> {
self.get_finalized_head()?
.map_or_else(|| Ok(None), |hash| self.signed_block(Some(hash)))
}

fn signed_block(&self, hash: Option<H256>) -> ApiResult<Option<SignedBlock>> {
// Even though this is only a wrapper here, we want to have this in the trait
// to be able to be generic over the trait and mock the `signed_block` method
// in tests.
self.get_signed_block(hash)
}

fn grandpa_authorities(&self, at_block: Option<H256>) -> ApiResult<AuthorityList> {
Ok(self.get_storage_by_key_hash(
StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec()),
at_block,
)?
.map(|g: VersionedAuthorityList| g.into())
.unwrap()) // todo: Introduce an error instead of unwrap: See: https://github.com/scs/substrate-api-client/issues/123
}

fn grandpa_authorities_proof(&self, at_block: Option<H256>) -> ApiResult<StorageProof> {
Ok(self.get_storage_proof_by_keys(
vec![StorageKey(GRANDPA_AUTHORITIES_KEY.to_vec())],
at_block,
)?
.map(|read_proof| read_proof.proof.into_iter().map(|bytes| bytes.0).collect())
.unwrap()) // todo: Introduce an error instead of unwrap: See: https://github.com/scs/substrate-api-client/issues/123
}
}
Loading