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 e85c5af
Showing
11 changed files
with
205 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.
Empty file.
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.25" } | ||
sp-blockchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } | ||
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } | ||
|
||
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,65 @@ | ||
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_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).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() | ||
} |
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,50 @@ | ||
//! The Substrate runtime. This can be compiled with `#[no_std]`, ready for Wasm. | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
pub use pallet::*; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use frame_support::pallet_prelude::*; | ||
use frame_system::pallet_prelude::*; | ||
use sp_runtime::traits::AtLeast32BitUnsigned; | ||
|
||
/// Configure the pallet by specifying the parameters and types on which it depends. | ||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
/// Because this pallet emits events, it depends on the runtime's definition of an event. | ||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>; | ||
|
||
// The type used to store balances. | ||
type Balance: MaxEncodedLen + Member + Parameter + AtLeast32BitUnsigned + Default + Copy; | ||
} | ||
|
||
#[pallet::pallet] | ||
#[pallet::generate_store(pub(super) trait Store)] | ||
pub struct Pallet<T>(_); | ||
|
||
/// Storage item for balances to accounts mapping. | ||
#[pallet::storage] | ||
#[pallet::getter(fn get_balance)] | ||
pub(super) type BalanceToAccount<T: Config> = | ||
StorageMap<_, Blake2_128Concat, T::AccountId, T::Balance, ValueQuery>; | ||
|
||
/// Token mint can emit two Event types. | ||
#[pallet::event] | ||
#[pallet::generate_deposit(pub(super) fn deposit_event)] | ||
pub enum Event<T: Config> { | ||
/// New token supply was minted. | ||
MintedNewSupply(T::AccountId), | ||
/// Tokens were successfully transferred between accounts. [from, to, value] | ||
Transferred(T::AccountId, T::AccountId, T::Balance), | ||
} | ||
|
||
#[pallet::hooks] | ||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {} | ||
} | ||
|
||
impl<T: Config> Pallet<T> { | ||
pub fn get_7() -> u64 { | ||
7 | ||
} | ||
} |