Skip to content

Commit

Permalink
feat : add jobs pallet rpc calls
Browse files Browse the repository at this point in the history
  • Loading branch information
1xstj committed Jan 3, 2024
1 parent a89445d commit c8685fb
Show file tree
Hide file tree
Showing 19 changed files with 656 additions and 304 deletions.
511 changes: 292 additions & 219 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ pallet-jobs = { path = "pallets/jobs", default-features = false }
pallet-roles = { path = "pallets/roles", default-features = false }
pallet-dkg = { path = "pallets/dkg", default-features = false }
pallet-zksaas = { path = "pallets/zksaas", default-features = false }
pallet-jobs-rpc-runtime-api = { path = "pallets/jobs/rpc/runtime-api", default-features = false }
pallet-jobs-rpc = { path = "pallets/jobs/rpc" }

# Substrate dependencies
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
Expand Down
85 changes: 43 additions & 42 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "tangle"
build = "build.rs"
description = "Tangle Standalone chain node"
version = { workspace = true }
authors = { workspace = true }
build = "build.rs"
edition = { workspace = true }
license = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
description = "Tangle Standalone chain node"

[package.metadata.wasm-pack.profile.release]
# `wasm-opt` has some problems on linux, see
Expand All @@ -24,52 +24,53 @@ targets = ["x86_64-unknown-linux-gnu"]
substrate-build-script-utils = { workspace = true }

[dependencies]
serde_json = { workspace = true }
tokio = { workspace = true }
clap = { workspace = true }
parity-scale-codec = { workspace = true }
futures = { workspace = true }
hex-literal = { workspace = true }
log = { workspace = true }
parity-scale-codec = { workspace = true }
rand = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }

# Substrate dependencies
sc-cli = { workspace = true }
sc-executor = { workspace = true }
sc-offchain = { workspace = true }
sc-keystore = { workspace = true }
sc-service = { workspace = true }
sp-core = { workspace = true }
frame-benchmarking = { workspace = true }
frame-benchmarking-cli = { workspace = true }
frame-system = { workspace = true }
sc-basic-authorship = { workspace = true }
sc-cli = { workspace = true }
sc-client-api = { workspace = true }
sc-consensus = { workspace = true }
sc-consensus-babe = { workspace = true }
sc-consensus-grandpa = { workspace = true }
sc-executor = { workspace = true }
sc-keystore = { workspace = true }
sc-network = { workspace = true }
sc-network-sync = { workspace = true }
sc-offchain = { workspace = true }
sc-service = { workspace = true }
sc-telemetry = { workspace = true }
sc-transaction-pool = { workspace = true }
sp-consensus-babe = { workspace = true }
sp-core = { workspace = true }
sp-inherents = { workspace = true }
sp-keyring = { workspace = true }
sp-runtime = { workspace = true }
sp-trie = { workspace = true }
sc-consensus-grandpa = { workspace = true }
sc-network-sync = { workspace = true }
webb-consensus-types = { workspace = true }
webb-proposals = { workspace = true }

pallet-airdrop-claims = { workspace = true }
pallet-jobs-rpc = { workspace = true }
sc-chain-spec = { workspace = true }
sc-rpc = { workspace = true }
sc-rpc-api = { workspace = true }
sp-api = { workspace = true }
sp-block-builder = { workspace = true }
sp-blockchain = { workspace = true }
sp-timestamp = { workspace = true }
substrate-prometheus-endpoint = { workspace = true }
substrate-frame-rpc-system = { workspace = true }
pallet-airdrop-claims = { workspace = true }
substrate-prometheus-endpoint = { workspace = true }

# RPC related dependencies
jsonrpsee = { workspace = true }
Expand All @@ -80,6 +81,7 @@ sc-transaction-pool-api = { workspace = true }
wasmer = { version = "2.3" }

# Frontier
fc-api = { workspace = true }
fc-cli = { workspace = true }
fc-consensus = { workspace = true }
fc-db = { workspace = true }
Expand All @@ -88,52 +90,51 @@ fc-rpc = { workspace = true, features = ["rpc-binary-search-estimate"] }
fc-rpc-core = { workspace = true }
fc-storage = { workspace = true }
fp-account = { workspace = true }
fc-api = { workspace = true }
fp-dynamic-fee = { workspace = true, features = ["default"] }
fp-evm = { workspace = true, features = ["default"] }
fp-rpc = { workspace = true, features = ["default"] }

rpc-trace = { workspace = true }
frame-system-rpc-runtime-api = { workspace = true }
mmr-rpc = { workspace = true }
primitives-ext = { workspace = true }
rpc-debug = { workspace = true }
rpc-txpool = { workspace = true }
rpc-primitives-debug = { workspace = true }
rpc-primitives-txpool = { workspace = true }
primitives-ext = { workspace = true }
sp-transaction-storage-proof = { workspace = true }
sc-statement-store = { workspace = true }
sp-statement-store = { workspace = true }
sc-consensus-slots = { workspace = true }
sp-consensus = { workspace = true }
sp-keystore = { workspace = true }
rpc-trace = { workspace = true }
rpc-txpool = { workspace = true }
sc-authority-discovery = { workspace = true }
sc-consensus-babe-rpc = { workspace = true }
sc-consensus-grandpa-rpc = { workspace = true }
mmr-rpc = { workspace = true }
sc-consensus-slots = { workspace = true }
sc-network-common = { workspace = true }
sc-network-statement = { workspace = true }
sc-rpc-spec-v2 = { workspace = true }
substrate-state-trie-migration-rpc = { workspace = true }
sc-statement-store = { workspace = true }
sc-storage-monitor = { workspace = true }
sc-sync-state-rpc = { workspace = true }
sc-sysinfo = { workspace = true }
sc-authority-discovery = { workspace = true }
sc-storage-monitor = { workspace = true }
sc-network-statement = { workspace = true }
sc-network-common = { workspace = true }
frame-system-rpc-runtime-api = { workspace = true }
tangle-testnet-runtime = { workspace = true, optional = true }
tangle-runtime = { workspace = true }
tangle-primitives = { workspace = true }
sp-consensus = { workspace = true }
sp-keystore = { workspace = true }
sp-statement-store = { workspace = true }
sp-transaction-storage-proof = { workspace = true }
substrate-state-trie-migration-rpc = { workspace = true }
tangle-crypto-primitives = { workspace = true }
tangle-primitives = { workspace = true }
tangle-runtime = { workspace = true }
tangle-testnet-runtime = { workspace = true, optional = true }

[features]
default = ["with-rocksdb-weights", "rocksdb", "sql"]
runtime-benchmarks = ["tangle-testnet-runtime/runtime-benchmarks"]
with-rocksdb-weights = ["tangle-testnet-runtime/with-rocksdb-weights"]
with-paritydb-weights = ["tangle-testnet-runtime/with-paritydb-weights"]
rocksdb = [
"sc-cli/rocksdb",
"sc-service/rocksdb",
"fc-cli/rocksdb",
"fc-db/rocksdb",
"fc-mapping-sync/rocksdb",
"fc-rpc/rocksdb",
"sc-cli/rocksdb",
"sc-service/rocksdb",
"fc-cli/rocksdb",
"fc-db/rocksdb",
"fc-mapping-sync/rocksdb",
"fc-rpc/rocksdb",
]
sql = ["fc-db/sql", "fc-mapping-sync/sql"]
testnet = ["tangle-testnet-runtime"]
Expand Down
86 changes: 86 additions & 0 deletions node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,92 @@ where
}

/// Instantiate all Full RPC extensions.
#[cfg(feature = "testnet")]
pub fn create_full<C, P, BE, A, CT, SC, B, CIDP>(
deps: FullDeps<C, P, A, CT, SC, B, CIDP>,
subscription_task_executor: SubscriptionTaskExecutor,
pubsub_notification_sinks: Arc<
fc_mapping_sync::EthereumBlockNotificationSinks<
fc_mapping_sync::EthereumBlockNotification<Block>,
>,
>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
C: CallApiAt<Block> + ProvideRuntimeApi<Block>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: sp_block_builder::BlockBuilder<Block>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: pallet_jobs_rpc::JobsRuntimeApi<Block, AccountId>,
C::Api: fp_rpc::ConvertTransactionRuntimeApi<Block>,
C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,
C::Api: rpc_primitives_debug::DebugRuntimeApi<Block>,
C::Api: rpc_primitives_txpool::TxPoolRuntimeApi<Block>,
C::Api: BabeApi<Block>,
C: BlockchainEvents<Block> + 'static,
C: HeaderBackend<Block>
+ HeaderMetadata<Block, Error = BlockChainError>
+ StorageProvider<Block, BE>,
BE: Backend<Block> + 'static,
P: TransactionPool<Block = Block> + 'static,
A: ChainApi<Block = Block> + 'static,
CT: fp_rpc::ConvertTransaction<<Block as BlockT>::Extrinsic> + Send + Sync + 'static,
SC: SelectChain<Block> + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::BlakeTwo256>,
CIDP: sp_inherents::CreateInherentDataProviders<Block, ()> + Send + Sync + 'static,
{
use pallet_jobs_rpc::{JobsApiServer, JobsClient};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_consensus_babe_rpc::{Babe, BabeApiServer};
use sc_consensus_grandpa_rpc::{Grandpa, GrandpaApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};

let mut io = RpcModule::new(());
let FullDeps { client, pool, deny_unsafe, eth, babe, select_chain, grandpa } = deps;

let BabeDeps { keystore, babe_worker_handle } = babe;

let GrandpaDeps {
shared_voter_state,
shared_authority_set,
justification_stream,
subscription_executor,
finality_provider,
} = grandpa;

io.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
io.merge(TransactionPayment::new(client.clone()).into_rpc())?;
io.merge(JobsClient::new(client.clone()).into_rpc())?;

io.merge(
Babe::new(client.clone(), babe_worker_handle.clone(), keystore, select_chain, deny_unsafe)
.into_rpc(),
)?;

io.merge(
Grandpa::new(
subscription_executor,
shared_authority_set.clone(),
shared_voter_state,
justification_stream,
finality_provider,
)
.into_rpc(),
)?;

// Ethereum compatibility RPCs
let io = create_eth::<_, _, _, _, _, _, _, DefaultEthConfig<C, BE>>(
io,
eth,
subscription_task_executor,
pubsub_notification_sinks,
)?;

Ok(io)
}

/// Instantiate all Full RPC extensions.
#[cfg(not(feature = "testnet"))]
pub fn create_full<C, P, BE, A, CT, SC, B, CIDP>(
deps: FullDeps<C, P, A, CT, SC, B, CIDP>,
subscription_task_executor: SubscriptionTaskExecutor,
Expand Down
4 changes: 2 additions & 2 deletions pallets/dkg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
tangle-primitives = { workspace = true, default-features = false }
tangle-crypto-primitives = { workspace = true, default-features = false }
tangle-primitives = { workspace = true, default-features = false }

[dev-dependencies]
pallet-balances = { workspace = true }
Expand All @@ -38,6 +38,6 @@ std = [
"tangle-crypto-primitives/std",
"pallet-balances/std",
"sp-io/std",
"sp-keystore/std"
"sp-keystore/std",
]
try-runtime = ["frame-support/try-runtime"]
2 changes: 1 addition & 1 deletion pallets/jobs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ scale-info = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
tangle-primitives = { workspace = true, default-features = false }
tangle-crypto-primitives = { workspace = true, default-features = false }
tangle-primitives = { workspace = true, default-features = false }

[dev-dependencies]
ethereum = { workspace = true, features = ["with-codec"] }
Expand Down
2 changes: 1 addition & 1 deletion pallets/jobs/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
jsonrpsee = { version = "0.16.2", features = ["client-core", "server", "macros"] }
pallet-jobs-rpc-runtime-api = { path = "./runtime-api" }
pallet-jobs-rpc-runtime-api = { path = "./runtime-api", default-features = false }
parity-scale-codec = { workspace = true }
sp-api = { workspace = true }
sp-blockchain = { workspace = true }
Expand Down
10 changes: 4 additions & 6 deletions pallets/jobs/rpc/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ repository = { workspace = true }
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
pallet-jobs = { default-features = false, path = "../../../jobs" }
parity-scale-codec = { workspace = true }
parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive"] }
sp-api = { workspace = true }
sp-runtime = { workspace = true }
sp-weights = { workspace = true }
tangle-primitives = { workspace = true }
sp-std = { workspace = true }
tangle-primitives = { workspace = true, default-features = false }

[features]
default = ["std"]
std = [
"parity-scale-codec/std",
"pallet-jobs/std",
"sp-api/std",
"sp-runtime/std",
"sp-weights/std",
"tangle-primitives/std",
"sp-std/std",
]
7 changes: 3 additions & 4 deletions pallets/jobs/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use parity_scale_codec::Codec;
use sp_runtime::{traits::MaybeDisplay, Serialize};

use sp_std::vec::Vec;
use tangle_primitives::{
jobs::{JobId, RpcResponseJobsData, RpcResponsePhaseOneResult},
roles::RoleType,
Expand All @@ -42,9 +42,8 @@ sp_api::decl_runtime_apis! {
///
/// # Returns
///
/// Returns a `Result` containing a vector of `RpcResponseJobsData<AccountId>` if the
/// operation is successful
fn query_jobs_by_validator(validator: AccountId) -> Result<Vec<RpcResponseJobsData<AccountId>>, String>;
/// An optional vec of `RpcResponseJobsData` of jobs assigned to validator
fn query_jobs_by_validator(validator: AccountId) -> Option<Vec<RpcResponseJobsData<AccountId>>>;
/// Queries a job by its key and ID.
///
/// # Arguments
Expand Down
Loading

0 comments on commit c8685fb

Please sign in to comment.