Skip to content

Commit 8096ad3

Browse files
authored
Merge pull request #76 from HashWarlock/feat/nft-lock-logic
NFT Lock Mechanism
2 parents 0bcc42a + f5155fc commit 8096ad3

File tree

28 files changed

+2051
-1398
lines changed

28 files changed

+2051
-1398
lines changed

Cargo.lock

Lines changed: 1553 additions & 1207 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/pallets/rmrk-market.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Buy a listed NFT. Ensure that the NFT is available for purchase and has not rece
99
```rust
1010
collection_id: CollectionId,
1111
nft_id: NftId
12+
amount: Option<BalanceOf<T>>
1213
```
1314

1415
### **list**

node/Cargo.toml

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,57 @@ targets = ["x86_64-unknown-linux-gnu"]
1919
[dependencies]
2020
clap = { version = "3.0", features = ["derive"] }
2121

22-
sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18", features = ["wasmtime"] }
23-
sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
24-
sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18", features = ["wasmtime"] }
25-
sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18", features = ["wasmtime"] }
26-
sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
27-
sc-keystore = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
28-
sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
29-
sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
30-
sc-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
31-
sp-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
32-
sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
33-
sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
34-
sc-finality-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
35-
sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
36-
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
37-
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
38-
sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
22+
sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22", features = ["wasmtime"] }
23+
sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
24+
sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22", features = ["wasmtime"] }
25+
sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22", features = ["wasmtime"] }
26+
sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
27+
sc-keystore = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
28+
sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
29+
sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
30+
sc-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
31+
sp-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
32+
sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
33+
sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
34+
sc-finality-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
35+
sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
36+
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
37+
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
38+
sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
39+
sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
40+
sp-keyring = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
41+
frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
42+
pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
3943

4044
# These dependencies are used for the node template"s RPCs
41-
jsonrpc-core = "18.0.0"
42-
sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
43-
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
44-
sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
45-
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
46-
sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
47-
sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
48-
substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
49-
pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
45+
jsonrpsee = { version = "0.13.0", features = ["server"] }
46+
sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
47+
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
48+
sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
49+
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
50+
sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
51+
sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
52+
substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
53+
pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
5054

5155
# These dependencies are used for runtime benchmarking
52-
frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
53-
frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
56+
frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
57+
frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
5458

5559
# Local Dependencies
5660
rmrk-substrate-runtime = { version = "4.0.0-dev", path = "../runtime" }
5761

62+
# CLI-specific dependencies
63+
try-runtime-cli = { version = "0.10.0-dev", optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
64+
5865
[build-dependencies]
59-
substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
66+
substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" }
6067

6168
[features]
6269
default = []
6370
runtime-benchmarks = [
6471
"rmrk-substrate-runtime/runtime-benchmarks",
65-
]
72+
]
73+
# Enable features that allow the runtime to be tried and debugged. Name might be subject to change
74+
# in the near future.
75+
try-runtime = ["try-runtime-cli"]

node/src/chain_spec.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ pub fn development_config() -> Result<ChainSpec, String> {
7676
))
7777
}
7878

79-
8079
pub fn local_testnet_config() -> Result<ChainSpec, String> {
8180
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
8281

node/src/cli.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ pub enum Subcommand {
3737
Revert(sc_cli::RevertCmd),
3838

3939
/// The custom benchmark subcommand benchmarking runtime pallets.
40-
#[clap(name = "benchmark", about = "Benchmark runtime pallets.")]
40+
#[clap(subcommand)]
4141
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
42-
}
42+
43+
/// Try some command against runtime state.
44+
#[cfg(feature = "try-runtime")]
45+
TryRuntime(try_runtime_cli::TryRuntimeCmd),
46+
47+
/// Try some command against runtime state. Note: `try-runtime` feature must be enabled.
48+
#[cfg(not(feature = "try-runtime"))]
49+
TryRuntime,
50+
51+
/// Db meta columns information.
52+
ChainInfo(sc_cli::ChainInfoCmd),
53+
}

node/src/command.rs

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
use crate::{
22
chain_spec,
33
cli::{Cli, Subcommand},
4+
command_helper::{inherent_benchmark_data, BenchmarkExtrinsicBuilder},
45
service,
56
};
7+
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
68
use rmrk_substrate_runtime::Block;
79
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
810
use sc_service::PartialComponents;
11+
use std::sync::Arc;
912

1013
impl SubstrateCli for Cli {
1114
fn impl_name() -> String {
@@ -95,19 +98,75 @@ pub fn run() -> sc_cli::Result<()> {
9598
runner.async_run(|config| {
9699
let PartialComponents { client, task_manager, backend, .. } =
97100
service::new_partial(&config)?;
98-
Ok((cmd.run(client, backend), task_manager))
101+
let aux_revert = Box::new(|client, _, blocks| {
102+
sc_finality_grandpa::revert(client, blocks)?;
103+
Ok(())
104+
});
105+
Ok((cmd.run(client, backend, Some(aux_revert)), task_manager))
99106
})
100107
},
101-
Some(Subcommand::Benchmark(cmd)) =>
102-
if cfg!(feature = "runtime-benchmarks") {
103-
let runner = cli.create_runner(cmd)?;
108+
Some(Subcommand::Benchmark(cmd)) => {
109+
let runner = cli.create_runner(cmd)?;
110+
111+
runner.sync_run(|config| {
112+
// This switch needs to be in the client, since the client decides
113+
// which sub-commands it wants to support.
114+
match cmd {
115+
BenchmarkCmd::Pallet(cmd) => {
116+
if !cfg!(feature = "runtime-benchmarks") {
117+
return Err(
118+
"Runtime benchmarking wasn't enabled when building the node. \
119+
You can enable it with `--features runtime-benchmarks`."
120+
.into(),
121+
)
122+
}
123+
124+
cmd.run::<Block, service::ExecutorDispatch>(config)
125+
},
126+
BenchmarkCmd::Block(cmd) => {
127+
let PartialComponents { client, .. } = service::new_partial(&config)?;
128+
cmd.run(client)
129+
},
130+
BenchmarkCmd::Storage(cmd) => {
131+
let PartialComponents { client, backend, .. } =
132+
service::new_partial(&config)?;
133+
let db = backend.expose_db();
134+
let storage = backend.expose_storage();
104135

105-
runner.sync_run(|config| cmd.run::<Block, service::ExecutorDispatch>(config))
106-
} else {
107-
Err("Benchmarking wasn't enabled when building the node. You can enable it with \
108-
`--features runtime-benchmarks`."
109-
.into())
110-
},
136+
cmd.run(config, client, db, storage)
137+
},
138+
BenchmarkCmd::Overhead(cmd) => {
139+
let PartialComponents { client, .. } = service::new_partial(&config)?;
140+
let ext_builder = BenchmarkExtrinsicBuilder::new(client.clone());
141+
142+
cmd.run(config, client, inherent_benchmark_data()?, Arc::new(ext_builder))
143+
},
144+
BenchmarkCmd::Machine(cmd) =>
145+
cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()),
146+
}
147+
})
148+
},
149+
#[cfg(feature = "try-runtime")]
150+
Some(Subcommand::TryRuntime(cmd)) => {
151+
let runner = cli.create_runner(cmd)?;
152+
runner.async_run(|config| {
153+
// we don't need any of the components of new_partial, just a runtime, or a task
154+
// manager to do `async_run`.
155+
let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry);
156+
let task_manager =
157+
sc_service::TaskManager::new(config.tokio_handle.clone(), registry)
158+
.map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?;
159+
Ok((cmd.run::<Block, service::ExecutorDispatch>(config), task_manager))
160+
})
161+
},
162+
#[cfg(not(feature = "try-runtime"))]
163+
Some(Subcommand::TryRuntime) => Err("TryRuntime wasn't enabled when building the node. \
164+
You can enable it with `--features try-runtime`."
165+
.into()),
166+
Some(Subcommand::ChainInfo(cmd)) => {
167+
let runner = cli.create_runner(cmd)?;
168+
runner.sync_run(|config| cmd.run::<Block>(&config))
169+
},
111170
None => {
112171
let runner = cli.create_runner(&cli.run)?;
113172
runner.run_node_until_exit(|config| async move {

node/src/command_helper.rs

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) 2022 Parity Technologies (UK) Ltd.
4+
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5+
6+
// This program is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 3 of the License, or
9+
// (at your option) any later version.
10+
11+
// This program is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
16+
// You should have received a copy of the GNU General Public License
17+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
19+
//! Contains code to setup the command invocations in [`super::command`] which would
20+
//! otherwise bloat that module.
21+
22+
use crate::service::FullClient;
23+
24+
use rmrk_substrate_runtime as runtime;
25+
use runtime::SystemCall;
26+
use sc_cli::Result;
27+
use sc_client_api::BlockBackend;
28+
use sp_core::{Encode, Pair};
29+
use sp_inherents::{InherentData, InherentDataProvider};
30+
use sp_keyring::Sr25519Keyring;
31+
use sp_runtime::{OpaqueExtrinsic, SaturatedConversion};
32+
33+
use std::{sync::Arc, time::Duration};
34+
35+
/// Generates extrinsics for the `benchmark overhead` command.
36+
///
37+
/// Note: Should only be used for benchmarking.
38+
pub struct BenchmarkExtrinsicBuilder {
39+
client: Arc<FullClient>,
40+
}
41+
42+
impl BenchmarkExtrinsicBuilder {
43+
/// Creates a new [`Self`] from the given client.
44+
pub fn new(client: Arc<FullClient>) -> Self {
45+
Self { client }
46+
}
47+
}
48+
49+
impl frame_benchmarking_cli::ExtrinsicBuilder for BenchmarkExtrinsicBuilder {
50+
fn remark(&self, nonce: u32) -> std::result::Result<OpaqueExtrinsic, &'static str> {
51+
let acc = Sr25519Keyring::Bob.pair();
52+
let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic(
53+
self.client.as_ref(),
54+
acc,
55+
SystemCall::remark { remark: vec![] }.into(),
56+
nonce,
57+
)
58+
.into();
59+
60+
Ok(extrinsic)
61+
}
62+
}
63+
64+
/// Create a transaction using the given `call`.
65+
///
66+
/// Note: Should only be used for benchmarking.
67+
pub fn create_benchmark_extrinsic(
68+
client: &FullClient,
69+
sender: sp_core::sr25519::Pair,
70+
call: runtime::Call,
71+
nonce: u32,
72+
) -> runtime::UncheckedExtrinsic {
73+
let genesis_hash = client.block_hash(0).ok().flatten().expect("Genesis block exists; qed");
74+
let best_hash = client.chain_info().best_hash;
75+
let best_block = client.chain_info().best_number;
76+
77+
let period = runtime::BlockHashCount::get()
78+
.checked_next_power_of_two()
79+
.map(|c| c / 2)
80+
.unwrap_or(2) as u64;
81+
let extra: runtime::SignedExtra = (
82+
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
83+
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
84+
frame_system::CheckGenesis::<runtime::Runtime>::new(),
85+
frame_system::CheckEra::<runtime::Runtime>::from(sp_runtime::generic::Era::mortal(
86+
period,
87+
best_block.saturated_into(),
88+
)),
89+
frame_system::CheckNonce::<runtime::Runtime>::from(nonce),
90+
frame_system::CheckWeight::<runtime::Runtime>::new(),
91+
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
92+
);
93+
94+
let raw_payload = runtime::SignedPayload::from_raw(
95+
call.clone(),
96+
extra.clone(),
97+
(
98+
runtime::VERSION.spec_version,
99+
runtime::VERSION.transaction_version,
100+
genesis_hash,
101+
best_hash,
102+
(),
103+
(),
104+
(),
105+
),
106+
);
107+
let signature = raw_payload.using_encoded(|e| sender.sign(e));
108+
109+
runtime::UncheckedExtrinsic::new_signed(
110+
call.clone(),
111+
sp_runtime::AccountId32::from(sender.public()).into(),
112+
runtime::Signature::Sr25519(signature.clone()),
113+
extra.clone(),
114+
)
115+
}
116+
117+
/// Generates inherent data for the `benchmark overhead` command.
118+
///
119+
/// Note: Should only be used for benchmarking.
120+
pub fn inherent_benchmark_data() -> Result<InherentData> {
121+
let mut inherent_data = InherentData::new();
122+
let d = Duration::from_millis(0);
123+
let timestamp = sp_timestamp::InherentDataProvider::new(d.into());
124+
125+
timestamp
126+
.provide_inherent_data(&mut inherent_data)
127+
.map_err(|e| format!("creating inherent data: {:?}", e))?;
128+
Ok(inherent_data)
129+
}

node/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod chain_spec;
66
mod service;
77
mod cli;
88
mod command;
9+
mod command_helper;
910
mod rpc;
1011

1112
fn main() -> sc_cli::Result<()> {

0 commit comments

Comments
 (0)