Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ exclude = [
]

members = [
'node/*',
'pallets/*',
"node/*",
"pallets/*",
]

resolver = "2"
3 changes: 1 addition & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ bench pallet exection="wasm":


run +args='--dev --tmp':
cargo run --release \
-- \
./target/release/deer-node \
{{args}} \
--port 30333 \
--ws-port 9944 \
Expand Down
2 changes: 2 additions & 0 deletions node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ targets = ["x86_64-unknown-linux-gnu"]
jsonrpc-core = "18.0.0"
node-primitives = { package = "deer-primitives", path = "../primitives" }
pallet-transaction-payment-rpc = { path = "../../substrate/frame/transaction-payment/rpc/" }
pallet-nft-rpc = { path = "../../pallets/nft/rpc/" }
pallet-storage-rpc = { path = "../../pallets/storage/rpc/" }
sc-client-api = { path = "../../substrate/client/api" }
sc-consensus-babe = { path = "../../substrate/client/consensus/babe" }
sc-consensus-babe-rpc = { path = "../../substrate/client/consensus/babe/rpc" }
Expand Down
9 changes: 9 additions & 0 deletions node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,17 @@ where
+ 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: pallet_nft_rpc::NFTRuntimeApi<Block, Balance>,
C::Api: pallet_storage_rpc::FileStorageRuntimeApi<Block, AccountId, Balance, BlockNumber>,
C::Api: BabeApi<Block>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + 'static,
SC: SelectChain<Block> + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
{
use pallet_nft_rpc::{NFTApi, NFT};
use pallet_storage_rpc::{FileStorage, FileStorageApi};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
use substrate_frame_rpc_system::{FullSystem, SystemApi};

Expand All @@ -135,6 +139,11 @@ where
io.extend_with(SystemApi::to_delegate(FullSystem::new(client.clone(), pool, deny_unsafe)));

io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone())));

io.extend_with(NFTApi::to_delegate(NFT::new(client.clone())));

io.extend_with(FileStorageApi::to_delegate(FileStorage::new(client.clone())));

io.extend_with(sc_consensus_babe_rpc::BabeApi::to_delegate(BabeRpcHandler::new(
client.clone(),
shared_epoch_changes.clone(),
Expand Down
4 changes: 4 additions & 0 deletions node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ pallet-vesting = { path = "../../substrate/frame/vesting", default-features = fa

# node pallets
pallet-nft = { path = "../../pallets/nft", default-features = false }
pallet-nft-rpc-runtime-api = { path = "../../pallets/nft/rpc/runtime-api", default-features = false }
pallet-nft-order = { path = "../../pallets/nft-order", default-features = false }
pallet-nft-auction = { path = "../../pallets/nft-auction", default-features = false }
pallet-storage = { path = "../../pallets/storage", default-features = false }
pallet-storage-rpc-runtime-api = { path = "../../pallets/storage/rpc/runtime-api", default-features = false }
pallet-bridge = { path = "../../pallets/bridge", default-features = false }
pallet-bridge-transfer = { path = "../../pallets/bridge-transfer", default-features = false }

Expand Down Expand Up @@ -161,9 +163,11 @@ std = [
"sp-npos-elections/std",
"sp-io/std",
"pallet-nft/std",
"pallet-nft-rpc-runtime-api/std",
"pallet-nft-order/std",
"pallet-nft-auction/std",
"pallet-storage/std",
"pallet-storage-rpc-runtime-api/std",
"pallet-bridge/std",
"pallet-bridge-transfer/std",
]
Expand Down
33 changes: 33 additions & 0 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,39 @@ impl_runtime_apis! {
}
}

impl pallet_nft_rpc_runtime_api::NFTApi<
Block,
Balance
> for Runtime {
fn create_class_deposit(bytes_len: u32) -> pallet_nft_rpc_runtime_api::BalanceInfo<Balance> {
pallet_nft_rpc_runtime_api::BalanceInfo {
amount: NFT::create_class_deposit(bytes_len)
}
}
fn mint_token_deposit(bytes_len: u32) -> pallet_nft_rpc_runtime_api::BalanceInfo<Balance> {
pallet_nft_rpc_runtime_api::BalanceInfo {
amount: NFT::mint_token_deposit(bytes_len)
}
}
}

impl pallet_storage_rpc_runtime_api::FileStorageApi<
Block,
AccountId,
Balance,
BlockNumber
> for Runtime {
fn store_fee(file_size: u64, time: BlockNumber) -> pallet_storage_rpc_runtime_api::StoreFeeInfo<Balance> {
pallet_storage_rpc_runtime_api::StoreFeeInfo {
fee: FileStorage::store_fee(file_size, time)
}
}
fn node_deposit(controller: &AccountId) -> pallet_storage_rpc_runtime_api::NodeDepositInfo<Balance> {
FileStorage::node_deposit(controller)
}
}


impl sp_session::SessionKeys<Block> for Runtime {
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
SessionKeys::generate(seed)
Expand Down
21 changes: 21 additions & 0 deletions pallets/nft/rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "pallet-nft-rpc"
version = "0.4.0"
edition = "2018"
license = "Apache 2.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "2" }
jsonrpc-core = "18.0.0"
jsonrpc-core-client = "18.0.0"
jsonrpc-derive = "18.0.0"

pallet-nft-rpc-runtime-api = { path = "./runtime-api" }

sp-api = { path = "../../../substrate/primitives/api" }
sp-rpc = { path = "../../../substrate/primitives/rpc" }
sp-runtime = { path = "../../../substrate/primitives/runtime" }
sp-blockchain = { path = "../../../substrate/primitives/blockchain" }
29 changes: 29 additions & 0 deletions pallets/nft/rpc/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "pallet-nft-rpc-runtime-api"
version = "0.4.0"
edition = "2018"
license = "Apache 2.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false, features = ["derive"] }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.126", optional = true, features = ["derive"] }
sp-api = { path = "../../../../substrate/primitives/api", default-features = false }
sp-std = { path = "../../../../substrate/primitives/std", default-features = false }
sp-core = { path = "../../../../substrate/primitives/core", default-features = false }
sp-runtime = { path = "../../../../substrate/primitives/runtime", default-features = false }

[features]
default = ["std"]
std = [
"codec/std",
"scale-info/std",
"serde",
"sp-api/std",
"sp-std/std",
"sp-core/std",
"sp-runtime/std",
]
47 changes: 47 additions & 0 deletions pallets/nft/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Codec, Decode, Encode};
use scale_info::TypeInfo;
use sp_runtime::traits::{MaybeDisplay, MaybeFromStr};
use sp_std::prelude::*;

#[cfg(feature = "std")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[derive(Eq, PartialEq, Encode, Decode, Default, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
pub struct BalanceInfo<Balance> {
#[cfg_attr(feature = "std", serde(bound(serialize = "Balance: std::fmt::Display")))]
#[cfg_attr(feature = "std", serde(serialize_with = "serialize_as_string"))]
#[cfg_attr(feature = "std", serde(bound(deserialize = "Balance: std::str::FromStr")))]
#[cfg_attr(feature = "std", serde(deserialize_with = "deserialize_from_string"))]
pub amount: Balance,
}

#[cfg(feature = "std")]
fn serialize_as_string<S: Serializer, T: std::fmt::Display>(
t: &T,
serializer: S,
) -> Result<S::Ok, S::Error> {
serializer.serialize_str(&t.to_string())
}

#[cfg(feature = "std")]
fn deserialize_from_string<'de, D: Deserializer<'de>, T: std::str::FromStr>(
deserializer: D,
) -> Result<T, D::Error> {
let s = String::deserialize(deserializer)?;
s.parse::<T>().map_err(|_| serde::de::Error::custom("Parse from string failed"))
}

sp_api::decl_runtime_apis! {
pub trait NFTApi<Balance> where
Balance: Codec + MaybeDisplay + MaybeFromStr,
{
/// Get deposit for create nft class.
fn create_class_deposit(bytes_len: u32) -> BalanceInfo<Balance>;
/// Get deposit for mint nft token.
fn mint_token_deposit(bytes_len: u32) -> BalanceInfo<Balance>;
}
}
Loading