-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup refactor
- Loading branch information
Showing
20 changed files
with
2,253 additions
and
633 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.
Large diffs are not rendered by default.
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 |
---|---|---|
|
@@ -545,5 +545,6 @@ fn mangata_genesis( | |
.collect(), | ||
}, | ||
vesting: Default::default(), | ||
rolldown: Default::default(), | ||
} | ||
} |
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
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
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,40 @@ | ||
[package] | ||
authors = ['Mangata team'] | ||
name = "rolldown-rpc" | ||
version = "2.0.0" | ||
edition = "2018" | ||
description = "RPC calls for Proof of Stake" | ||
license = "GPL-3.0-or-later" | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "3.0.0" } | ||
jsonrpsee = { version = "0.16.2", features = ["server", "client", "macros"] } | ||
serde = { version = "1.0.126", features = ["derive"], optional = true } | ||
|
||
# Substrate packages | ||
|
||
sp-api = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false } | ||
sp-blockchain = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false } | ||
sp-rpc = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false } | ||
sp-core = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false } | ||
sp-std = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false } | ||
sp-runtime = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false } | ||
mangata-types = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false } | ||
|
||
# local packages | ||
|
||
rolldown-runtime-api = { version = "2.0.0", path = "../runtime-api", default-features = false } | ||
|
||
[features] | ||
default = ["std"] | ||
|
||
std = [ | ||
"serde", | ||
"sp-api/std", | ||
"sp-core/std", | ||
"sp-std/std", | ||
"sp-runtime/std", | ||
"rolldown-runtime-api/std", | ||
"mangata-types/std", | ||
"codec/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,74 @@ | ||
// Copyright (C) 2021 Mangata team | ||
|
||
use jsonrpsee::{ | ||
core::{async_trait, Error as JsonRpseeError, RpcResult}, | ||
proc_macros::rpc, | ||
types::error::{CallError, ErrorObject}, | ||
}; | ||
use rolldown_runtime_api::RolldownRuntimeApi; | ||
pub use sp_api::ProvideRuntimeApi; | ||
use sp_blockchain::HeaderBackend; | ||
use sp_runtime::traits::Block as BlockT; | ||
use std::sync::Arc; | ||
|
||
#[rpc(client, server)] | ||
pub trait RolldownApi<BlockHash> { | ||
/// Calculates amount of available native rewards | ||
/// | ||
/// * `account` - user account address | ||
/// * `liquidity_token` - liquidity token id | ||
/// * `at` - optional block hash | ||
#[method(name = "rolldown_pending_updates_hash")] | ||
fn pending_updates_hash(&self, at: Option<BlockHash>) -> RpcResult<sp_core::H256>; | ||
|
||
#[method(name = "rolldown_pending_updates")] | ||
fn pending_updates(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>; | ||
} | ||
|
||
pub struct Rolldown<C, M> { | ||
client: Arc<C>, | ||
_marker: std::marker::PhantomData<M>, | ||
} | ||
|
||
impl<C, P> Rolldown<C, P> { | ||
pub fn new(client: Arc<C>) -> Self { | ||
Self { client, _marker: Default::default() } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<C, Block> RolldownApiServer<<Block as BlockT>::Hash> for Rolldown<C, Block> | ||
where | ||
Block: BlockT, | ||
C: Send + Sync + 'static, | ||
C: ProvideRuntimeApi<Block>, | ||
C: HeaderBackend<Block>, | ||
C::Api: RolldownRuntimeApi<Block>, | ||
{ | ||
fn pending_updates_hash( | ||
&self, | ||
at: Option<<Block as BlockT>::Hash>, | ||
) -> RpcResult<sp_core::H256> { | ||
let api = self.client.runtime_api(); | ||
let at = at.unwrap_or(self.client.info().best_hash); | ||
api.get_pending_updates_hash(at).map_err(|e| { | ||
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned( | ||
1, | ||
"Unable to serve the request", | ||
Some(format!("{:?}", e)), | ||
))) | ||
}) | ||
} | ||
|
||
fn pending_updates(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> { | ||
let api = self.client.runtime_api(); | ||
let at = at.unwrap_or(self.client.info().best_hash); | ||
api.get_pending_updates(at).map_err(|e| { | ||
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned( | ||
1, | ||
"Unable to serve the request", | ||
Some(format!("{:?}", e)), | ||
))) | ||
}) | ||
} | ||
} |
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,21 @@ | ||
[package] | ||
authors = ['Mangata team'] | ||
name = "rolldown-runtime-api" | ||
version = "2.0.0" | ||
edition = "2018" | ||
license = "GPL-3.0-or-later" | ||
|
||
[dependencies] | ||
|
||
sp-api = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false } | ||
sp-std = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false } | ||
sp-core = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false } | ||
|
||
[features] | ||
default = ["std"] | ||
|
||
std = [ | ||
"sp-api/std", | ||
"sp-std/std", | ||
"sp-core/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,10 @@ | ||
// Copyright (C) 2021 Mangata team | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
use sp_std::vec::Vec; | ||
sp_api::decl_runtime_apis! { | ||
pub trait RolldownRuntimeApi{ | ||
fn get_pending_updates_hash() -> sp_core::H256; | ||
fn get_pending_updates() -> Vec<u8>; | ||
} | ||
} |
Oops, something went wrong.