Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make api and primitives generic over Runtime #340

Merged
merged 31 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4679f17
add interface traits
haerdib Nov 22, 2022
91c76d0
fix rebase changes
haerdib Nov 29, 2022
af921dd
add missing contracts
haerdib Nov 29, 2022
a44d07a
amke staking generic over BalanceType
haerdib Nov 29, 2022
b173d7c
cargo fmt
haerdib Nov 29, 2022
b433e91
make these types truly generic
haerdib Nov 29, 2022
6ab7914
cargo fmt
haerdib Nov 29, 2022
2cb2d7d
fix tests
haerdib Nov 30, 2022
e8fa803
Merge branch 'master' into bh/make-api-generic-over-runtime
haerdib Nov 30, 2022
1cd4c1e
fix staking payout example
haerdib Dec 1, 2022
1bf2524
Merge branch 'master' into bh/make-api-generic-over-runtime
haerdib Dec 1, 2022
972a777
Merge branch 'master' into bh/make-api-generic-over-runtime
haerdib Dec 1, 2022
b2bf4aa
Merge branch 'master' into bh/make-api-generic-over-runtime
haerdib Dec 2, 2022
72fffe2
add pallets trait
haerdib Dec 5, 2022
6abdeed
add no_std traits
haerdib Dec 5, 2022
cea2b99
remove obsoltete sp_std
haerdib Dec 5, 2022
8657599
Merge branch 'bh/make-api-generic-over-runtime' of https://github.com…
haerdib Dec 5, 2022
043d5fb
add missing re-export
haerdib Dec 5, 2022
1bb52e7
remove frame-support and frame-system from node-api
haerdib Dec 5, 2022
bfa7d1e
add pallet contracts
haerdib Dec 6, 2022
974034b
add pallets contracts
haerdib Dec 6, 2022
8829d45
add std impl for pallet traits
haerdib Dec 6, 2022
8fcb8ce
add pallet staking
haerdib Dec 6, 2022
c1b7368
remove pallet dependencies
haerdib Dec 6, 2022
d34f317
add tpyes.rs
haerdib Dec 6, 2022
f467b05
cargo fmt
haerdib Dec 6, 2022
cfc7fe2
fix taplo
haerdib Dec 6, 2022
634f9af
remove substrate comment
haerdib Dec 6, 2022
10c2d5c
fix toml formatting
haerdib Dec 6, 2022
4b26c5c
fix taplo
haerdib Dec 6, 2022
7df61e7
add links to the types where taken from substrate
haerdib Dec 6, 2022
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
426 changes: 293 additions & 133 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 10 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features =
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
log = { version = "0.4.14", default-features = false }
primitive-types = { version = "0.12.1", optional = true, features = ["codec"] }
serde = { version = "1.0.136", optional = true, features = ["derive"] }
serde_json = { version = "1.0.79", optional = true }
serde = { version = "1.0.136", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.79", default-features = false }
thiserror = { version = "1.0.30", optional = true }
ws = { version = "0.9.2", optional = true, features = ["ssl"] }

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

[dev-dependencies]
env_logger = "0.9.0"
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
kitchensink-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
pallet-identity = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
pallet-staking = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
wabt = "0.10.0"
pallet-identity = { git = "https://github.com/paritytech/substrate.git", branch = "master" }

[features]
default = ["std", "ws-client"]
Expand All @@ -63,14 +62,11 @@ std = [
"log/std",
"primitive-types",
"serde/std",
"serde_json",
"serde_json/std",
"thiserror",
# substrate
"frame-metadata/std",
"frame-support/std",
"frame-system",
"pallet-balances",
"pallet-transaction-payment/std",
"frame-support",
"sp-core/std",
"sp-rpc",
"sp-runtime/std",
Expand All @@ -83,4 +79,4 @@ std = [
"ac-primitives/std",
]
ws-client = ["ws"]
staking-xt = ["std", "pallet-staking"]
staking-xt = ["std"]
2 changes: 0 additions & 2 deletions compose-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ log = { version = "0.4.14", default-features = false }
# substrate
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }

# need to add this for the app_crypto macro
sp-application-crypto = { default-features = false, git = "https://github.com/paritytech/substrate.git", features = ["full_crypto"], branch = "master" }
Expand All @@ -28,7 +27,6 @@ std = [
# substrate
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
"sp-application-crypto/std",
# local
"ac-primitives/std",
Expand Down
11 changes: 9 additions & 2 deletions examples/batch_payout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(feature = "staking-xt")]
use codec::{Decode, Encode};
#[cfg(feature = "staking-xt")]
use kitchensink_runtime::Runtime;
#[cfg(feature = "staking-xt")]
use pallet_staking::{ActiveEraInfo, Exposure};
#[cfg(feature = "staking-xt")]
use serde_json::Value;
Expand All @@ -17,7 +19,7 @@ fn main() {

let from = AccountKeyring::Alice.pair();
let client = WsRpcClient::new("ws://127.0.0.1:9944");
let mut api = Api::<_, _, PlainTipExtrinsicParams>::new(client).unwrap();
let mut api = Api::<_, _, PlainTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
api.set_signer(from);
let grace_period: GracePeriod = GracePeriod { enabled: false, eras: 0 };
let mut results: Vec<Value> = Vec::new();
Expand Down Expand Up @@ -86,7 +88,12 @@ fn main() {
#[cfg(feature = "staking-xt")]
pub fn get_last_reward(
validator_address: &str,
api: &substrate_api_client::Api<sp_core::sr25519::Pair, WsRpcClient, PlainTipExtrinsicParams>,
api: &substrate_api_client::Api<
sp_core::sr25519::Pair,
WsRpcClient,
PlainTipExtrinsicParams<Runtime>,
Runtime,
>,
) -> u32 {
let account = match AccountId32::from_ss58check(validator_address) {
Ok(address) => address,
Expand Down
6 changes: 2 additions & 4 deletions examples/benchmark_bulk_xt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// run this against test node with
// > substrate-test-node --dev --execution native --ws-port 9979 -ltxpool=debug

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

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

// define the recipient
let to = AccountKeyring::Bob.to_account_id();

Expand Down
6 changes: 3 additions & 3 deletions examples/compose_extrinsic_offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! without asking the node for nonce and does not need to know the metadata

use ac_primitives::AssetTipExtrinsicParamsBuilder;
use kitchensink_runtime::{BalancesCall, Header, RuntimeCall};
use kitchensink_runtime::{BalancesCall, Header, Runtime, RuntimeCall};
use sp_keyring::AccountKeyring;
use sp_runtime::{generic::Era, MultiAddress};
use substrate_api_client::{
Expand All @@ -32,14 +32,14 @@ fn main() {
let from = AccountKeyring::Alice.pair();
let client = WsRpcClient::new("ws://127.0.0.1:9944");

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

// Information for Era for mortal transactions.
let head = api.get_finalized_head().unwrap().unwrap();
let h: Header = api.get_header(Some(head)).unwrap().unwrap();
let period = 5;
let tx_params = AssetTipExtrinsicParamsBuilder::new()
let tx_params = AssetTipExtrinsicParamsBuilder::<Runtime>::new()
.era(Era::mortal(period, h.number.into()), head)
.tip(0);

Expand Down
3 changes: 2 additions & 1 deletion examples/contract_instantiate_with_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//! This example is community maintained and not CI tested, therefore it may not work as is.

use codec::Decode;
use kitchensink_runtime::Runtime;
use sp_keyring::AccountKeyring;
use std::sync::mpsc::channel;
use substrate_api_client::{
Expand All @@ -40,7 +41,7 @@ fn main() {
// initialize api and set the signer (sender) that is used to sign the extrinsics
let from = AccountKeyring::Alice.pair();
let client = WsRpcClient::new("ws://127.0.0.1:9944");
let mut api = Api::<_, _, PlainTipExtrinsicParams>::new(client).unwrap();
let mut api = Api::<_, _, PlainTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
api.set_signer(from);

println!("[+] Alice's Account Nonce is {}", api.get_nonce().unwrap());
Expand Down
6 changes: 3 additions & 3 deletions examples/custom_nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! without asking the node for nonce and does not need to know the metadata

use ac_primitives::AssetTipExtrinsicParamsBuilder;
use kitchensink_runtime::{BalancesCall, Header, RuntimeCall};
use kitchensink_runtime::{BalancesCall, Header, Runtime, RuntimeCall};
use sp_keyring::AccountKeyring;
use sp_runtime::{generic::Era, MultiAddress};
use substrate_api_client::{
Expand All @@ -32,14 +32,14 @@ fn main() {
let from = AccountKeyring::Alice.pair();
let client = WsRpcClient::new("ws://127.0.0.1:9944");

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

// Information for Era for mortal transactions.
let head = api.get_finalized_head().unwrap().unwrap();
let h: Header = api.get_header(Some(head)).unwrap().unwrap();
let period = 5;
let tx_params = AssetTipExtrinsicParamsBuilder::new()
let tx_params = AssetTipExtrinsicParamsBuilder::<Runtime>::new()
.era(Era::mortal(period, h.number.into()), head)
.tip(0);

Expand Down
8 changes: 5 additions & 3 deletions examples/event_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
limitations under the License.
*/

///! Very simple example that shows how to subscribe to events.
use std::sync::mpsc::channel;
//! Very simple example that shows how to subscribe to events.

use codec::Decode;
use kitchensink_runtime::Runtime;
use log::debug;
use sp_core::{sr25519, H256 as Hash};
use std::sync::mpsc::channel;

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

let client = WsRpcClient::new("ws://127.0.0.1:9944");
let api = Api::<sr25519::Pair, _, AssetTipExtrinsicParams>::new(client).unwrap();
let api =
Api::<sr25519::Pair, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();

println!("Subscribe to events");
let (events_in, events_out) = channel();
Expand Down
3 changes: 2 additions & 1 deletion examples/event_error_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License.
*/

use codec::Decode;
use kitchensink_runtime::Runtime;
use sp_core::crypto::Pair;
use sp_keyring::AccountKeyring;
use sp_runtime::{AccountId32 as AccountId, MultiAddress};
Expand Down Expand Up @@ -42,7 +43,7 @@ fn main() {
let from = AccountKeyring::Alice.pair();

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

let from_account_id = AccountKeyring::Alice.to_account_id();
Expand Down
3 changes: 2 additions & 1 deletion examples/generic_event_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//! implying no runtime needs to be imported

use codec::Decode;
use kitchensink_runtime::Runtime;
use sp_keyring::AccountKeyring;
use sp_runtime::{AccountId32 as AccountId, MultiAddress};
use std::{sync::mpsc::channel, thread};
Expand All @@ -41,7 +42,7 @@ fn main() {
// Initialize api and set the signer (sender) that is used to sign the extrinsics.
let alice = AccountKeyring::Alice.pair();
let client = WsRpcClient::new("ws://127.0.0.1:9944");
let mut api = Api::<_, _, AssetTipExtrinsicParams>::new(client).unwrap();
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
api.set_signer(alice);

println!("Subscribe to events");
Expand Down
3 changes: 2 additions & 1 deletion examples/generic_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//! This examples shows how to use the compose_extrinsic macro to create an extrinsic for any (custom)
//! module, whereas the desired module and call are supplied as a string.

use kitchensink_runtime::Runtime;
use sp_keyring::AccountKeyring;
use substrate_api_client::{
compose_extrinsic, rpc::WsRpcClient, Api, AssetTipExtrinsicParams, GenericAddress,
Expand All @@ -28,7 +29,7 @@ fn main() {
// initialize api and set the signer (sender) that is used to sign the extrinsics
let from = AccountKeyring::Alice.pair();
let client = WsRpcClient::new("ws://127.0.0.1:9944");
let mut api = Api::<_, _, AssetTipExtrinsicParams>::new(client).unwrap();
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
api.set_signer(from);
// set the recipient
let to = AccountKeyring::Bob.to_account_id();
Expand Down
4 changes: 3 additions & 1 deletion examples/get_account_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ fn main() {
// Create the node-api client and set the signer.
let client = WsRpcClient::new("ws://127.0.0.1:9944");
let alice = AccountKeyring::Alice.pair();
let mut api = Api::<_, _, AssetTipExtrinsicParams>::new(client).unwrap();
let mut api =
Api::<_, _, AssetTipExtrinsicParams<KitchensinkRuntime>, KitchensinkRuntime>::new(client)
.unwrap();
api.set_signer(alice.clone());

// Fill Identity storage
Expand Down
5 changes: 3 additions & 2 deletions examples/get_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! Very simple example that shows how to pretty print the metadata. Has proven to be a helpful
//! debugging tool.

use kitchensink_runtime::{Block, Header};
use kitchensink_runtime::{Block, Header, Runtime};
use sp_core::sr25519;
use sp_runtime::generic::SignedBlock as SignedBlockG;
use std::sync::mpsc::channel;
Expand All @@ -28,7 +28,8 @@ fn main() {
env_logger::init();

let client = WsRpcClient::new("ws://127.0.0.1:9944");
let api = Api::<sr25519::Pair, _, AssetTipExtrinsicParams>::new(client).unwrap();
let api =
Api::<sr25519::Pair, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();

let head = api.get_finalized_head().unwrap().unwrap();

Expand Down
7 changes: 5 additions & 2 deletions examples/get_existential_deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

///! Very simple example that shows how to get some simple storage values.
//! Very simple example that shows how to get some simple storage values.

use kitchensink_runtime::Runtime;
use sp_runtime::app_crypto::sp_core::sr25519;
use substrate_api_client::{rpc::WsRpcClient, Api, AssetTipExtrinsicParams};

fn main() {
env_logger::init();

let client = WsRpcClient::new("ws://127.0.0.1:9944");
let api = Api::<sr25519::Pair, _, AssetTipExtrinsicParams>::new(client).unwrap();
let api =
Api::<sr25519::Pair, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();

// get existential deposit
let min_balance = api.get_existential_deposit().unwrap();
Expand Down
14 changes: 11 additions & 3 deletions examples/get_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,23 @@
limitations under the License.
*/

///! Very simple example that shows how to get some simple storage values.
//! Very simple example that shows how to get some simple storage values.

use frame_system::AccountInfo as GenericAccountInfo;
use kitchensink_runtime::Runtime;
use sp_keyring::AccountKeyring;
use substrate_api_client::{rpc::WsRpcClient, AccountInfo, Api, AssetTipExtrinsicParams};
use substrate_api_client::{rpc::WsRpcClient, Api, AssetTipExtrinsicParams};

type IndexFor<T> = <T as frame_system::Config>::Index;
type AccountDataFor<T> = <T as frame_system::Config>::AccountData;

type AccountInfo = GenericAccountInfo<IndexFor<Runtime>, AccountDataFor<Runtime>>;

fn main() {
env_logger::init();

let client = WsRpcClient::new("ws://127.0.0.1:9944");
let mut api = Api::<_, _, AssetTipExtrinsicParams>::new(client).unwrap();
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();

// get some plain storage value
let result: u128 = api.get_storage_value("Balances", "TotalIssuance", None).unwrap().unwrap();
Expand Down
10 changes: 6 additions & 4 deletions examples/print_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
limitations under the License.
*/

///! Very simple example that shows how to pretty print the metadata. Has proven to be a helpful
///! debugging tool.
use sp_core::sr25519;
//! Very simple example that shows how to pretty print the metadata. Has proven to be a helpful
//! debugging tool.

use kitchensink_runtime::Runtime;
use sp_core::sr25519;
use substrate_api_client::{rpc::WsRpcClient, Api, AssetTipExtrinsicParams, Metadata};

fn main() {
env_logger::init();

let client = WsRpcClient::new("ws://127.0.0.1:9944");
let mut api = Api::<sr25519::Pair, _, AssetTipExtrinsicParams>::new(client).unwrap();
let mut api =
Api::<sr25519::Pair, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();

let meta = api.metadata().clone();

Expand Down
Loading