This repository has been archived by the owner on Aug 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
cd55e72
commit d34f3be
Showing
10 changed files
with
157 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
[workspace] | ||
members = [ | ||
"meta/meta-consensus", | ||
"meta/meta-defichain", | ||
"meta/meta-defichain/rpc", | ||
"meta/meta-defichain/rpc/runtime-api", | ||
"meta/meta-runtime", | ||
"meta/meta-node", | ||
] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "meta-defichain" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
codec = { default-features = false, version = "3.1.5", features = ["derive", "max-encoded-len"], package = "parity-scale-codec" } | ||
scale-info = { default-features = false, version = "2.1.2", features = ["derive"] } | ||
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
|
||
serde = { version = "1.0.144", features = ["derive"], optional = true } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"codec/std", | ||
"scale-info/std", | ||
"serde", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"sp-api/std", | ||
"sp-runtime/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,13 @@ | ||
[package] | ||
name = "meta-defichain-rpc" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
jsonrpsee = { version = "0.14.0", features = ["server", "macros"] } | ||
|
||
sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
sp-blockchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
|
||
meta-defichain-rpc-runtime-api = { path = "./runtime-api", package = "meta-defichain-rpc-runtime-api"} |
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,13 @@ | ||
[package] | ||
name = "meta-defichain-rpc-runtime-api" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"sp-api/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,7 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
sp_api::decl_runtime_apis! { | ||
pub trait DefichainApi { | ||
fn get_7() -> u64; | ||
} | ||
} |
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,67 @@ | ||
use codec::Codec; | ||
use jsonrpsee::{ | ||
core::{async_trait, Error as JsonRpseeError, RpcResult}, | ||
proc_macros::rpc, | ||
types::error::{CallError, ErrorObject}, | ||
}; | ||
use sp_api::ProvideRuntimeApi; | ||
use sp_blockchain::HeaderBackend; | ||
use sp_rpc::number::NumberOrHex; | ||
use sp_runtime::{ | ||
generic::BlockId, | ||
traits::{Block as BlockT, Header as HeaderT}, | ||
}; | ||
use std::{marker::PhantomData, sync::Arc}; | ||
|
||
pub use meta_defichain_rpc_runtime_api::DefichainApi as DefichainRuntimeApi; | ||
|
||
const RUNTIME_ERROR: i32 = 1; | ||
|
||
#[rpc(client, server)] | ||
pub trait DefichainApi<BlockHash> { | ||
#[method(name = "defichain_get7")] | ||
fn get_7(&self, at: Option<BlockHash>) -> RpcResult<u64>; | ||
} | ||
|
||
/// A struct that implements the `DefichainApi` | ||
pub struct Defichain<Client, Block> { | ||
client: Arc<Client>, | ||
_marker: PhantomData<Block>, | ||
} | ||
|
||
impl<Client, Block> Defichain<Client, Block> { | ||
/// Create new `Defichain` instance with the given reference to the client | ||
pub fn new(client: Arc<Client>) -> Self { | ||
Self { | ||
client, | ||
_marker: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<Client, Block> DefichainApiServer<<Block as BlockT>::Hash> for Defichain<Client, Block> | ||
where | ||
Block: BlockT, | ||
Client: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>, | ||
Client::Api: DefichainRuntimeApi<Block>, | ||
{ | ||
fn get_7(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<u64> { | ||
let api = self.client.runtime_api(); | ||
// to calling the runtime at specific block | ||
let at = BlockId::hash(at.unwrap_or_else(|| | ||
// If the block hash is not supplied assume the best block. | ||
self.client.info().best_hash)); | ||
api.get_7(&at, a, b).map_err(runtime_error_into_rpc_err) | ||
} | ||
} | ||
|
||
/// Converts a runtime trap into an RPC error. | ||
fn runtime_error_into_rpc_err(err: impl std::fmt::Debug) -> JsonRpseeError { | ||
CallError::Custom(ErrorObject::owned( | ||
RUNTIME_ERROR, | ||
"Runtime error", | ||
Some(format!("{:?}", err)), | ||
)) | ||
.into() | ||
} |
File renamed without changes.