-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
5,825 additions
and
2,484 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
[package] | ||
name = "bifrost-salp" | ||
version = "0.8.0" | ||
authors = ["Edwin Wang <lark930@gmail.com>", "Ron yang<yrong1997@gmail.com>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
parity-scale-codec = { workspace = true, features = ["derive"] } | ||
scale-info = { workspace = true, features = ["derive"] } | ||
log = { workspace = true } | ||
bifrost-primitives = { workspace = true } | ||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
frame-benchmarking = { workspace = true, optional = true } | ||
sp-std = { workspace = true } | ||
sp-io = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
sp-arithmetic = { workspace = true } | ||
orml-traits = { workspace = true } | ||
orml-tokens = { workspace = true } | ||
bifrost-xcm-interface = { workspace = true } | ||
zenlink-protocol = { workspace = true } | ||
cumulus-primitives-core = { workspace = true } | ||
pallet-xcm = { workspace = true } | ||
xcm = { workspace = true } | ||
xcm-builder = { workspace = true } | ||
bifrost-stable-pool = { workspace = true } | ||
bifrost-stable-asset = { workspace = true } | ||
bifrost-vtoken-minting = { workspace = true } | ||
|
||
[dev-dependencies] | ||
pallet-multisig = { workspace = true } | ||
pallet-sudo = { workspace = true } | ||
pallet-collective = { workspace = true } | ||
sp-core = { workspace = true } | ||
bifrost-currencies = { workspace = true } | ||
orml-xtokens = { workspace = true } | ||
pallet-balances = { workspace = true } | ||
bifrost-asset-registry = { workspace = true } | ||
xcm-executor = { workspace = true } | ||
|
||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"parity-scale-codec/std", | ||
"scale-info/std", | ||
"log/std", | ||
"bifrost-primitives/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"sp-std/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
"sp-arithmetic/std", | ||
"orml-traits/std", | ||
"bifrost-xcm-interface/std", | ||
"xcm-builder/std", | ||
"zenlink-protocol/std", | ||
"bifrost-asset-registry/std", | ||
"cumulus-primitives-core/std", | ||
"pallet-xcm/std", | ||
"pallet-sudo/std", | ||
"xcm/std", | ||
"pallet-multisig/std", | ||
"pallet-collective/std", | ||
"orml-xtokens/std", | ||
] | ||
|
||
runtime-benchmarks = [ | ||
"frame-benchmarking", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"xcm-builder/runtime-benchmarks", | ||
"pallet-xcm/runtime-benchmarks", | ||
"pallet-collective/runtime-benchmarks", | ||
] | ||
try-runtime = [ "frame-support/try-runtime" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "bifrost-salp-rpc" | ||
version = "0.8.0" | ||
authors = ["Ron Yang <yrong1997@gmail.com>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
parity-scale-codec = { workspace = true, features = ["derive"] } | ||
jsonrpsee = { workspace = true, features = ["server", "macros"] } | ||
sp-api = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
sp-blockchain = { workspace = true } | ||
sp-core = { workspace = true } | ||
sp-rpc = { workspace = true } | ||
bifrost-primitives = { workspace = true } | ||
bifrost-salp-rpc-runtime-api = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "bifrost-salp-rpc-runtime-api" | ||
version = "0.8.0" | ||
authors = ["Ron Yang<yrong1997@gmail.com>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
parity-scale-codec = { workspace = true, features = ["derive"] } | ||
sp-api = { workspace = true } | ||
bifrost-primitives = { workspace = true } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"parity-scale-codec/std", | ||
"sp-api/std", | ||
"bifrost-primitives/std", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// This file is part of Bifrost. | ||
|
||
// Copyright (C) Liebi Technologies PTE. LTD. | ||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
use bifrost_primitives::{Balance, RpcContributionStatus}; | ||
use parity_scale_codec::Codec; | ||
use sp_api::decl_runtime_apis; | ||
|
||
decl_runtime_apis! { | ||
pub trait SalpRuntimeApi<ParaId,AccountId> where | ||
ParaId: Codec, | ||
AccountId: Codec, | ||
{ | ||
fn get_contribution( | ||
index: ParaId, | ||
who: AccountId | ||
) -> (Balance,RpcContributionStatus); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// This file is part of Bifrost. | ||
|
||
// Copyright (C) Liebi Technologies PTE. LTD. | ||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
use std::{marker::PhantomData, sync::Arc}; | ||
|
||
use bifrost_primitives::{Balance, RpcContributionStatus}; | ||
pub use bifrost_salp_rpc_runtime_api::{self as runtime_api, SalpRuntimeApi}; | ||
use jsonrpsee::{ | ||
core::{async_trait, RpcResult}, | ||
proc_macros::rpc, | ||
types::error::{ErrorCode, ErrorObject}, | ||
}; | ||
use parity_scale_codec::Codec; | ||
use sp_api::ProvideRuntimeApi; | ||
use sp_blockchain::HeaderBackend; | ||
use sp_rpc::number::NumberOrHex; | ||
use sp_runtime::{sp_std::convert::TryInto, traits::Block as BlockT}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct SalpRpc<C, Block> { | ||
client: Arc<C>, | ||
_marker: PhantomData<Block>, | ||
} | ||
|
||
impl<C, Block> SalpRpc<C, Block> { | ||
pub fn new(client: Arc<C>) -> Self { | ||
Self { client, _marker: PhantomData } | ||
} | ||
} | ||
|
||
fn convert_rpc_params(value: Balance) -> RpcResult<NumberOrHex> { | ||
value.try_into().map_err(|e| { | ||
ErrorObject::owned( | ||
ErrorCode::InvalidParams.code(), | ||
format!("{} doesn't fit in NumberOrHex representation", value), | ||
Some(format!("{:?}", e)), | ||
) | ||
}) | ||
} | ||
|
||
#[rpc(client, server)] | ||
pub trait SalpRpcApi<BlockHash, ParaId, AccountId> { | ||
/// rpc method for getting current contribution | ||
#[method(name = "salp_getContribution")] | ||
fn get_contribution( | ||
&self, | ||
index: ParaId, | ||
who: AccountId, | ||
at: Option<BlockHash>, | ||
) -> RpcResult<(NumberOrHex, RpcContributionStatus)>; | ||
} | ||
|
||
#[async_trait] | ||
impl<C, Block, ParaId, AccountId> SalpRpcApiServer<<Block as BlockT>::Hash, ParaId, AccountId> | ||
for SalpRpc<C, Block> | ||
where | ||
Block: BlockT, | ||
C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>, | ||
C::Api: SalpRuntimeApi<Block, ParaId, AccountId>, | ||
ParaId: Codec, | ||
AccountId: Codec, | ||
{ | ||
fn get_contribution( | ||
&self, | ||
index: ParaId, | ||
account: AccountId, | ||
at: Option<<Block as BlockT>::Hash>, | ||
) -> RpcResult<(NumberOrHex, RpcContributionStatus)> { | ||
let salp_rpc_api = self.client.runtime_api(); | ||
let at = at.unwrap_or_else(|| self.client.info().best_hash); | ||
|
||
let rs = salp_rpc_api.get_contribution(at, index, account); | ||
|
||
match rs { | ||
Ok((val, status)) => match convert_rpc_params(val) { | ||
Ok(value) => Ok((value, status)), | ||
Err(e) => Err(e), | ||
}, | ||
Err(e) => Err(ErrorObject::owned( | ||
ErrorCode::InternalError.code(), | ||
"Failed to get salp contribution.", | ||
Some(format!("{:?}", e)), | ||
)), | ||
} | ||
} | ||
} |
Oops, something went wrong.