Skip to content

Commit d540964

Browse files
authored
Make api and primitives generic over Runtime (#340)
* add interface traits add traits add balanes impl add Runtime trait make api generic over Runtime remove interfaces fix clippy fix staking feature fix doc make RuntimeVersion generic over Runtime revert last commit fix examples * fix rebase changes * add missing contracts * amke staking generic over BalanceType * cargo fmt * make these types truly generic * cargo fmt * fix tests * fix staking payout example * add pallets trait * add no_std traits * remove obsoltete sp_std * add missing re-export * remove frame-support and frame-system from node-api * add pallet contracts * add pallets contracts * add std impl for pallet traits * add pallet staking * remove pallet dependencies * add tpyes.rs * cargo fmt * fix taplo * remove substrate comment * fix toml formatting * fix taplo * add links to the types where taken from substrate
1 parent 7ff294c commit d540964

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1353
-412
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features =
1919
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
2020
log = { version = "0.4.14", default-features = false }
2121
primitive-types = { version = "0.12.1", optional = true, features = ["codec"] }
22-
serde = { version = "1.0.136", optional = true, features = ["derive"] }
23-
serde_json = { version = "1.0.79", optional = true }
22+
serde = { version = "1.0.136", default-features = false, features = ["derive"] }
23+
serde_json = { version = "1.0.79", default-features = false }
2424
thiserror = { version = "1.0.30", optional = true }
2525
ws = { version = "0.9.2", optional = true, features = ["ssl"] }
2626

2727
# Substrate dependencies
2828
frame-metadata = { default-features = false, git = "https://github.com/paritytech/frame-metadata", features = ["v14", "serde_full", "decode"] }
29-
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
30-
frame-system = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
31-
pallet-balances = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
32-
pallet-staking = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
33-
pallet-transaction-payment = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
29+
frame-support = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
3430
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
3531
sp-rpc = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
3632
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
@@ -45,10 +41,13 @@ ac-primitives = { path = "primitives", default-features = false }
4541

4642
[dev-dependencies]
4743
env_logger = "0.9.0"
44+
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
4845
kitchensink-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
46+
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
47+
pallet-identity = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
48+
pallet-staking = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
4949
sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
5050
wabt = "0.10.0"
51-
pallet-identity = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
5251

5352
[features]
5453
default = ["std", "ws-client"]
@@ -63,14 +62,11 @@ std = [
6362
"log/std",
6463
"primitive-types",
6564
"serde/std",
66-
"serde_json",
65+
"serde_json/std",
6766
"thiserror",
6867
# substrate
6968
"frame-metadata/std",
70-
"frame-support/std",
71-
"frame-system",
72-
"pallet-balances",
73-
"pallet-transaction-payment/std",
69+
"frame-support",
7470
"sp-core/std",
7571
"sp-rpc",
7672
"sp-runtime/std",
@@ -83,4 +79,4 @@ std = [
8379
"ac-primitives/std",
8480
]
8581
ws-client = ["ws"]
86-
staking-xt = ["std", "pallet-staking"]
82+
staking-xt = ["std"]

compose-macros/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ log = { version = "0.4.14", default-features = false }
1212
# substrate
1313
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
1414
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
15-
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
1615

1716
# need to add this for the app_crypto macro
1817
sp-application-crypto = { default-features = false, git = "https://github.com/paritytech/substrate.git", features = ["full_crypto"], branch = "master" }
@@ -28,7 +27,6 @@ std = [
2827
# substrate
2928
"sp-core/std",
3029
"sp-runtime/std",
31-
"sp-std/std",
3230
"sp-application-crypto/std",
3331
# local
3432
"ac-primitives/std",

examples/batch_payout.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#[cfg(feature = "staking-xt")]
22
use codec::{Decode, Encode};
33
#[cfg(feature = "staking-xt")]
4+
use kitchensink_runtime::Runtime;
5+
#[cfg(feature = "staking-xt")]
46
use pallet_staking::{ActiveEraInfo, Exposure};
57
#[cfg(feature = "staking-xt")]
68
use serde_json::Value;
@@ -17,7 +19,7 @@ fn main() {
1719

1820
let from = AccountKeyring::Alice.pair();
1921
let client = WsRpcClient::new("ws://127.0.0.1:9944");
20-
let mut api = Api::<_, _, PlainTipExtrinsicParams>::new(client).unwrap();
22+
let mut api = Api::<_, _, PlainTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
2123
api.set_signer(from);
2224
let grace_period: GracePeriod = GracePeriod { enabled: false, eras: 0 };
2325
let mut results: Vec<Value> = Vec::new();
@@ -86,7 +88,12 @@ fn main() {
8688
#[cfg(feature = "staking-xt")]
8789
pub fn get_last_reward(
8890
validator_address: &str,
89-
api: &substrate_api_client::Api<sp_core::sr25519::Pair, WsRpcClient, PlainTipExtrinsicParams>,
91+
api: &substrate_api_client::Api<
92+
sp_core::sr25519::Pair,
93+
WsRpcClient,
94+
PlainTipExtrinsicParams<Runtime>,
95+
Runtime,
96+
>,
9097
) -> u32 {
9198
let account = match AccountId32::from_ss58check(validator_address) {
9299
Ok(address) => address,

examples/benchmark_bulk_xt.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// run this against test node with
1919
// > substrate-test-node --dev --execution native --ws-port 9979 -ltxpool=debug
2020

21-
use kitchensink_runtime::{BalancesCall, RuntimeCall};
21+
use kitchensink_runtime::{BalancesCall, Runtime, RuntimeCall};
2222
use sp_keyring::AccountKeyring;
2323
use substrate_api_client::{
2424
compose_extrinsic_offline, rpc::WsRpcClient, Api, AssetTipExtrinsicParams,
@@ -31,11 +31,9 @@ fn main() {
3131
// initialize api and set the signer (sender) that is used to sign the extrinsics
3232
let from = AccountKeyring::Alice.pair();
3333
let client = WsRpcClient::new("ws://127.0.0.1:9944");
34-
let mut api = Api::<_, _, AssetTipExtrinsicParams>::new(client).unwrap();
34+
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
3535
api.set_signer(from);
3636

37-
println!("[+] Alice's Account Nonce is {}\n", api.get_nonce().unwrap());
38-
3937
// define the recipient
4038
let to = AccountKeyring::Bob.to_account_id();
4139

examples/compose_extrinsic_offline.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! without asking the node for nonce and does not need to know the metadata
1818
1919
use ac_primitives::AssetTipExtrinsicParamsBuilder;
20-
use kitchensink_runtime::{BalancesCall, Header, RuntimeCall};
20+
use kitchensink_runtime::{BalancesCall, Header, Runtime, RuntimeCall};
2121
use sp_keyring::AccountKeyring;
2222
use sp_runtime::{generic::Era, MultiAddress};
2323
use substrate_api_client::{
@@ -32,14 +32,14 @@ fn main() {
3232
let from = AccountKeyring::Alice.pair();
3333
let client = WsRpcClient::new("ws://127.0.0.1:9944");
3434

35-
let mut api = Api::<_, _, AssetTipExtrinsicParams>::new(client).unwrap();
35+
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
3636
api.set_signer(from);
3737

3838
// Information for Era for mortal transactions.
3939
let head = api.get_finalized_head().unwrap().unwrap();
4040
let h: Header = api.get_header(Some(head)).unwrap().unwrap();
4141
let period = 5;
42-
let tx_params = AssetTipExtrinsicParamsBuilder::new()
42+
let tx_params = AssetTipExtrinsicParamsBuilder::<Runtime>::new()
4343
.era(Era::mortal(period, h.number.into()), head)
4444
.tip(0);
4545

examples/contract_instantiate_with_code.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//! This example is community maintained and not CI tested, therefore it may not work as is.
1717
1818
use codec::Decode;
19+
use kitchensink_runtime::Runtime;
1920
use sp_keyring::AccountKeyring;
2021
use std::sync::mpsc::channel;
2122
use substrate_api_client::{
@@ -40,7 +41,7 @@ fn main() {
4041
// initialize api and set the signer (sender) that is used to sign the extrinsics
4142
let from = AccountKeyring::Alice.pair();
4243
let client = WsRpcClient::new("ws://127.0.0.1:9944");
43-
let mut api = Api::<_, _, PlainTipExtrinsicParams>::new(client).unwrap();
44+
let mut api = Api::<_, _, PlainTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
4445
api.set_signer(from);
4546

4647
println!("[+] Alice's Account Nonce is {}", api.get_nonce().unwrap());

examples/custom_nonce.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! without asking the node for nonce and does not need to know the metadata
1818
1919
use ac_primitives::AssetTipExtrinsicParamsBuilder;
20-
use kitchensink_runtime::{BalancesCall, Header, RuntimeCall};
20+
use kitchensink_runtime::{BalancesCall, Header, Runtime, RuntimeCall};
2121
use sp_keyring::AccountKeyring;
2222
use sp_runtime::{generic::Era, MultiAddress};
2323
use substrate_api_client::{
@@ -32,14 +32,14 @@ fn main() {
3232
let from = AccountKeyring::Alice.pair();
3333
let client = WsRpcClient::new("ws://127.0.0.1:9944");
3434

35-
let mut api = Api::<_, _, AssetTipExtrinsicParams>::new(client).unwrap();
35+
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
3636
api.set_signer(from);
3737

3838
// Information for Era for mortal transactions.
3939
let head = api.get_finalized_head().unwrap().unwrap();
4040
let h: Header = api.get_header(Some(head)).unwrap().unwrap();
4141
let period = 5;
42-
let tx_params = AssetTipExtrinsicParamsBuilder::new()
42+
let tx_params = AssetTipExtrinsicParamsBuilder::<Runtime>::new()
4343
.era(Era::mortal(period, h.number.into()), head)
4444
.tip(0);
4545

examples/event_callback.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
limitations under the License.
1414
*/
1515

16-
///! Very simple example that shows how to subscribe to events.
17-
use std::sync::mpsc::channel;
16+
//! Very simple example that shows how to subscribe to events.
1817
1918
use codec::Decode;
19+
use kitchensink_runtime::Runtime;
2020
use log::debug;
2121
use sp_core::{sr25519, H256 as Hash};
22+
use std::sync::mpsc::channel;
2223

2324
// This module depends on node_runtime.
2425
// To avoid dependency collisions, node_runtime has been removed from the substrate-api-client library.
@@ -31,7 +32,8 @@ fn main() {
3132
env_logger::init();
3233

3334
let client = WsRpcClient::new("ws://127.0.0.1:9944");
34-
let api = Api::<sr25519::Pair, _, AssetTipExtrinsicParams>::new(client).unwrap();
35+
let api =
36+
Api::<sr25519::Pair, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
3537

3638
println!("Subscribe to events");
3739
let (events_in, events_out) = channel();

examples/event_error_details.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ limitations under the License.
1414
*/
1515

1616
use codec::Decode;
17+
use kitchensink_runtime::Runtime;
1718
use sp_core::crypto::Pair;
1819
use sp_keyring::AccountKeyring;
1920
use sp_runtime::{AccountId32 as AccountId, MultiAddress};
@@ -42,7 +43,7 @@ fn main() {
4243
let from = AccountKeyring::Alice.pair();
4344

4445
let client = WsRpcClient::new("ws://127.0.0.1:9944");
45-
let mut api = Api::<_, _, AssetTipExtrinsicParams>::new(client).unwrap();
46+
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
4647
api.set_signer(from.clone());
4748

4849
let from_account_id = AccountKeyring::Alice.to_account_id();

0 commit comments

Comments
 (0)