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
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
FROM rust:buster as builder

RUN apt-get update && apt-get install time clang libclang-dev llvm -y
RUN rustup toolchain install nightly
RUN rustup target add wasm32-unknown-unknown --toolchain nightly
RUN rustup toolchain install nightly-2021-06-17
RUN rustup target add wasm32-unknown-unknown --toolchain nightly-2021-06-17

WORKDIR /app
COPY . /app
Expand Down
2 changes: 1 addition & 1 deletion node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
C: Send + Sync + 'static,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: FeeRuntimeApi<Block, AccountId>,
C::Api: SalpRuntimeApi<Block, ParaId, AccountId, Balance>,
C::Api: SalpRuntimeApi<Block, ParaId, AccountId>,
P: TransactionPool + 'static,
{
let FullDeps { client, .. } = deps;
Expand Down
8 changes: 3 additions & 5 deletions node/service/src/collator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ use cumulus_client_service::{
prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,
};
use cumulus_primitives_core::ParaId;
use node_primitives::{AccountId, Balance, ParaId as BifrostParaId};
use node_primitives::{AccountId, ParaId as BifrostParaId};
use sc_client_api::ExecutorProvider;
use sc_consensus_aura::ImportQueueParams;
pub use sc_executor::NativeExecutor;
use sc_executor::{native_executor_instance, NativeExecutionDispatch};
use sc_network::NetworkService;
Expand All @@ -43,7 +42,6 @@ use sp_consensus::SlotData;
use sp_consensus_aura::sr25519::{AuthorityId as AuraId, AuthorityPair as AuraPair};
use sp_keystore::SyncCryptoStorePtr;
use substrate_prometheus_endpoint::Registry;
use zenlink_protocol_runtime_api::ZenlinkProtocolApi as ZenlinkProtocolRuntimeApi;

use crate::RuntimeApiCollection;

Expand Down Expand Up @@ -212,7 +210,7 @@ where
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
RuntimeApi::RuntimeApi: sp_consensus_aura::AuraApi<Block, AuraId>,
RuntimeApi::RuntimeApi: FeeRuntimeApi<Block, AccountId>,
RuntimeApi::RuntimeApi: SalpRuntimeApi<Block, BifrostParaId, AccountId, Balance>,
RuntimeApi::RuntimeApi: SalpRuntimeApi<Block, BifrostParaId, AccountId>,
Executor: NativeExecutionDispatch + 'static,
BIC: FnOnce(
Arc<TFullClient<Block, RuntimeApi, Executor>>,
Expand Down Expand Up @@ -371,7 +369,7 @@ where
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
RuntimeApi::RuntimeApi: sp_consensus_aura::AuraApi<Block, AuraId>,
RuntimeApi::RuntimeApi: FeeRuntimeApi<Block, AccountId>,
RuntimeApi::RuntimeApi: SalpRuntimeApi<Block, BifrostParaId, AccountId, Balance>,
RuntimeApi::RuntimeApi: SalpRuntimeApi<Block, BifrostParaId, AccountId>,
Executor: NativeExecutionDispatch + 'static,
{
start_node_impl(
Expand Down
2 changes: 2 additions & 0 deletions pallets/salp/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ jsonrpc-derive = "15.1.0"
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
node-primitives = { path = "../../../node/primitives", default-features = false }
bifrost-salp-rpc-runtime-api = { path = "./runtime-api" }
2 changes: 2 additions & 0 deletions pallets/salp/rpc/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ edition = "2018"
[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
node-primitives = { path = "../../../../node/primitives", default-features = false }

[features]
default = ["std"]
std = [
"codec/std",
"sp-api/std",
"node-primitives/std",
]
4 changes: 2 additions & 2 deletions pallets/salp/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#![cfg_attr(not(feature = "std"), no_std)]

use codec::Codec;
use node_primitives::Balance;
use sp_api::decl_runtime_apis;

decl_runtime_apis! {
pub trait SalpRuntimeApi<ParaId,AccountId, Balance> where
pub trait SalpRuntimeApi<ParaId,AccountId> where
ParaId: Codec,
AccountId: Codec,
Balance: Codec,
{
fn get_contribution(
index: ParaId,
Expand Down
31 changes: 18 additions & 13 deletions pallets/salp/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use jsonrpc_core::{Error as RpcError, ErrorCode, Result as JsonRpcResult};
use jsonrpc_derive::rpc;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
use sp_rpc::number::NumberOrHex;
use sp_runtime::{generic::BlockId, traits::Block as BlockT, SaturatedConversion};

pub use self::gen_client::Client as SalpClient;

Expand All @@ -41,40 +42,44 @@ impl<C, Block> SalpRpcWrapper<C, Block> {
}

#[rpc]
pub trait SalpRpcApi<BlockHash, ParaId, AccountId, Balance> {
pub trait SalpRpcApi<BlockHash, ParaId, AccountId> {
/// rpc method for getting current contribution
#[rpc(name = "salp_getContribution")]
fn get_contribution(
&self,
index: ParaId,
who: AccountId,
at: Option<BlockHash>,
) -> JsonRpcResult<Balance>;
) -> JsonRpcResult<NumberOrHex>;
}

impl<C, Block, ParaId, AccountId, Balance>
SalpRpcApi<<Block as BlockT>::Hash, ParaId, AccountId, Balance> for SalpRpcWrapper<C, Block>
impl<C, Block, ParaId, AccountId> SalpRpcApi<<Block as BlockT>::Hash, ParaId, AccountId>
for SalpRpcWrapper<C, Block>
where
Block: BlockT,
C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
C::Api: SalpRuntimeApi<Block, ParaId, AccountId, Balance>,
C::Api: SalpRuntimeApi<Block, ParaId, AccountId>,
ParaId: Codec,
AccountId: Codec,
Balance: Codec,
{
fn get_contribution(
&self,
index: ParaId,
account: AccountId,
at: Option<<Block as BlockT>::Hash>,
) -> JsonRpcResult<Balance> {
) -> JsonRpcResult<NumberOrHex> {
let salp_rpc_api = self.client.runtime_api();
let at = BlockId::<Block>::hash(at.unwrap_or_else(|| self.client.info().best_hash));

salp_rpc_api.get_contribution(&at, index, account).map_err(|e| RpcError {
code: ErrorCode::InternalError,
message: "Failed to get salp contribution.".to_owned(),
data: Some(format!("{:?}", e).into()),
})
let rs = salp_rpc_api.get_contribution(&at, index, account);

match rs {
Ok(val) => Ok(NumberOrHex::Number(val.saturated_into())),
Err(e) => Err(RpcError {
code: ErrorCode::InternalError,
message: "Failed to get salp contribution.".to_owned(),
data: Some(format!("{:?}", e).into()),
}),
}
}
}
2 changes: 1 addition & 1 deletion runtime/asgard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ impl_runtime_apis! {
}
}

impl bifrost_salp_rpc_runtime_api::SalpRuntimeApi<Block, ParaId, AccountId,Balance> for Runtime {
impl bifrost_salp_rpc_runtime_api::SalpRuntimeApi<Block, ParaId, AccountId> for Runtime {
fn get_contribution(index: ParaId, who: AccountId) -> Balance {
let rs = Salp::contribution_by_fund(index, &who);
match rs {
Expand Down
2 changes: 1 addition & 1 deletion runtime/bifrost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ impl_runtime_apis! {
}
}

impl bifrost_salp_rpc_runtime_api::SalpRuntimeApi<Block, ParaId, AccountId,Balance> for Runtime {
impl bifrost_salp_rpc_runtime_api::SalpRuntimeApi<Block, ParaId, AccountId> for Runtime {
fn get_contribution(index: ParaId, who: AccountId) -> Balance {
let rs = Salp::contribution_by_fund(index, &who);
match rs {
Expand Down