-
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.
Merge pull request #189 from KogarashiNetwork/feature/shot-fix
Add pallet nova sample
- Loading branch information
Showing
12 changed files
with
556 additions
and
13 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 |
---|---|---|
|
@@ -5,7 +5,8 @@ members = [ | |
"grumpkin", | ||
"nova", | ||
"zkstd", | ||
"pallet/nova" | ||
"pallet/nova", | ||
"sample" | ||
] | ||
|
||
[profile.release] | ||
|
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,37 @@ | ||
[package] | ||
name = "zk-storage" | ||
version = "3.0.0" | ||
edition = "2018" | ||
authors = ['Substrate DevHub <https://github.com/substrate-developer-hub>'] | ||
repository = "https://github.com/substrate-developer-hub/recipes" | ||
description = "A pallet with two storage items whose sum is exposed via a custom runtime API" | ||
license = "GPL-3.0-or-later" | ||
|
||
[dependencies] | ||
parity-scale-codec = { version = "2.0", default-features = false, features = ["derive"] } | ||
|
||
# Substrate packages | ||
frame-support = { branch = 'v3.0.0', default-features = false, git = "https://github.com/KogarashiNetwork/zksubstrate" } | ||
frame-system = { branch = 'v3.0.0', default-features = false, git = "https://github.com/KogarashiNetwork/zksubstrate" } | ||
sp-runtime = { branch = 'v3.0.0', default-features = false, git = "https://github.com/KogarashiNetwork/zksubstrate" } | ||
sp-std = { branch = 'v3.0.0', default-features = false, git = "https://github.com/KogarashiNetwork/zksubstrate" } | ||
|
||
# nova pallet | ||
pallet-nova = { git = "https://github.com/KogarashiNetwork/Kogarashi", branch = "master", default-features = false } | ||
rand_core = {version="0.6", default-features = false } | ||
|
||
[dev-dependencies] | ||
serde = { version = "1.0.102", default-features = false, features = ["derive"] } | ||
sp-io = { branch = 'v3.0.0', default-features = false, git = "https://github.com/KogarashiNetwork/zksubstrate" } | ||
sp-core = { branch = 'v3.0.0', default-features = false, git = "https://github.com/KogarashiNetwork/zksubstrate" } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"parity-scale-codec/std", | ||
"sp-std/std", | ||
"sp-runtime/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"pallet-nova/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 @@ | ||
[package] | ||
name = "sum-storage-rpc" | ||
version = "2.0.0" | ||
edition = "2018" | ||
authors = ['Substrate DevHub <https://github.com/substrate-developer-hub>'] | ||
repository = 'https://github.com/substrate-developer-hub/recipes' | ||
description = "A pallet that demonstrates simple RPC for summing numbers" | ||
license = "GPL-3.0-or-later" | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "1.3.0" } | ||
jsonrpc-core = "15.0" | ||
jsonrpc-core-client = "15.0" | ||
jsonrpc-derive = "15.0" | ||
serde = { version = "1.0", features = ["derive"], optional = true } | ||
|
||
# Substrate packages | ||
|
||
sp-api = { version = '3.0', default-features = false } | ||
sp-blockchain = { version = '3.0', default-features = false} | ||
sp-rpc = { version = '3.0', default-features = false} | ||
sp-runtime = { version = '3.0', default-features = false} | ||
|
||
# local packages | ||
|
||
sum-storage-runtime-api = { version = "2.0.0", path = "../runtime-api", default-features = false } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"serde", | ||
"sp-api/std", | ||
"sp-runtime/std", | ||
"sum-storage-runtime-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,73 @@ | ||
//! RPC interface for the transaction payment module. | ||
|
||
use jsonrpc_core::{Error as RpcError, ErrorCode, Result}; | ||
use jsonrpc_derive::rpc; | ||
use sp_api::ProvideRuntimeApi; | ||
use sp_blockchain::HeaderBackend; | ||
use sp_runtime::{generic::BlockId, traits::Block as BlockT}; | ||
use std::sync::Arc; | ||
use sum_storage_runtime_api::SumStorageApi as SumStorageRuntimeApi; | ||
|
||
#[rpc] | ||
pub trait SumStorageApi<BlockHash> { | ||
#[rpc(name = "sumStorage_getSum")] | ||
fn get_sum(&self, at: Option<BlockHash>) -> Result<u32>; | ||
} | ||
|
||
/// A struct that implements the `SumStorageApi`. | ||
pub struct SumStorage<C, M> { | ||
// If you have more generics, no need to SumStorage<C, M, N, P, ...> | ||
// just use a tuple like SumStorage<C, (M, N, P, ...)> | ||
client: Arc<C>, | ||
_marker: std::marker::PhantomData<M>, | ||
} | ||
|
||
impl<C, M> SumStorage<C, M> { | ||
/// Create new `SumStorage` instance with the given reference to the client. | ||
pub fn new(client: Arc<C>) -> Self { | ||
Self { | ||
client, | ||
_marker: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
/// Error type of this RPC api. | ||
// pub enum Error { | ||
// /// The transaction was not decodable. | ||
// DecodeError, | ||
// /// The call to runtime failed. | ||
// RuntimeError, | ||
// } | ||
// | ||
// impl From<Error> for i64 { | ||
// fn from(e: Error) -> i64 { | ||
// match e { | ||
// Error::RuntimeError => 1, | ||
// Error::DecodeError => 2, | ||
// } | ||
// } | ||
// } | ||
|
||
impl<C, Block> SumStorageApi<<Block as BlockT>::Hash> for SumStorage<C, Block> | ||
where | ||
Block: BlockT, | ||
C: Send + Sync + 'static, | ||
C: ProvideRuntimeApi<Block>, | ||
C: HeaderBackend<Block>, | ||
C::Api: SumStorageRuntimeApi<Block>, | ||
{ | ||
fn get_sum(&self, at: Option<<Block as BlockT>::Hash>) -> Result<u32> { | ||
let api = self.client.runtime_api(); | ||
let at = BlockId::hash(at.unwrap_or_else(|| | ||
// If the block hash is not supplied assume the best block. | ||
self.client.info().best_hash)); | ||
|
||
let runtime_api_result = api.get_sum(&at); | ||
runtime_api_result.map_err(|e| RpcError { | ||
code: ErrorCode::ServerError(9876), // No real reason for this value | ||
message: "Something wrong".into(), | ||
data: Some(format!("{:?}", e).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,18 @@ | ||
[package] | ||
name = "sum-storage-runtime-api" | ||
version = "2.0.0" | ||
authors = ['Substrate DevHub <https://github.com/substrate-developer-hub>'] | ||
edition = "2018" | ||
license = "GPL-3.0-or-later" | ||
|
||
[dependencies] | ||
sp-api = { version = '3.0', default-features = false} | ||
|
||
[dev-dependencies] | ||
serde_json = "1.0" | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"sp-api/std", | ||
] |
Oops, something went wrong.