Skip to content

Commit

Permalink
A0-4099: New pallets API in aleph-client (#1629)
Browse files Browse the repository at this point in the history
# Description

Recently we added the feature control and vk storage pallet - in order
to test them in e2e tests, we need its API covered by aleph-client.

## Type of change

- New feature (non-breaking change which adds functionality)

# Checklist:

- I have created new documentation
- I have bumped aleph-client version if relevant
  • Loading branch information
pmikolajczyk41 authored Feb 23, 2024
1 parent f7b05cf commit 06bf402
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 6 deletions.
2 changes: 1 addition & 1 deletion aleph-client/Cargo.lock

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

2 changes: 1 addition & 1 deletion aleph-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph_client"
version = "3.9.0"
version = "3.10.0"
edition = "2021"
authors = ["Cardinal"]
documentation = "https://docs.rs/aleph_client"
Expand Down
41 changes: 41 additions & 0 deletions aleph-client/src/pallets/feature_control.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::{
api, pallet_feature_control::Feature, BlockHash, ConnectionApi, RootConnection,
SignedConnectionApi, TxInfo, TxStatus,
};

/// Read only pallet feature control API.
#[async_trait::async_trait]
pub trait FeatureControlApi {
/// Check if a feature is active.
async fn is_feature_active(&self, feature: Feature, at: Option<BlockHash>) -> bool;
}

/// Pallet feature control API that requires sudo.
#[async_trait::async_trait]
pub trait FeatureControlSudoApi {
/// Enable a feature.
async fn enable_feature(&self, feature: Feature, status: TxStatus) -> anyhow::Result<TxInfo>;
/// Disable a feature.
async fn disable_feature(&self, feature: Feature, status: TxStatus) -> anyhow::Result<TxInfo>;
}

#[async_trait::async_trait]
impl<C: ConnectionApi> FeatureControlApi for C {
async fn is_feature_active(&self, feature: Feature, at: Option<BlockHash>) -> bool {
let addrs = api::storage().feature_control().active_features(feature);
self.get_storage_entry_maybe(&addrs, at).await.is_some()
}
}

#[async_trait::async_trait]
impl FeatureControlSudoApi for RootConnection {
async fn enable_feature(&self, feature: Feature, status: TxStatus) -> anyhow::Result<TxInfo> {
let tx = api::tx().feature_control().enable(feature);
self.send_tx(tx, status).await
}

async fn disable_feature(&self, feature: Feature, status: TxStatus) -> anyhow::Result<TxInfo> {
let tx = api::tx().feature_control().disable(feature);
self.send_tx(tx, status).await
}
}
2 changes: 2 additions & 0 deletions aleph-client/src/pallets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub mod committee_management;
pub mod contract;
/// Pallet elections API
pub mod elections;
/// Pallet feature control API
pub mod feature_control;
/// Pallet transaction payment API
pub mod fee;
/// Pallet multisig API
Expand Down
22 changes: 20 additions & 2 deletions aleph-client/src/pallets/vk_storage.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
use anyhow::Result;

use crate::{api, SignedConnection, SignedConnectionApi, TxInfo, TxStatus};
use crate::{
api, sp_core::H256, BlockHash, ConnectionApi, SignedConnection, SignedConnectionApi, TxInfo,
TxStatus,
};

/// Read only pallet vk storage API.
#[async_trait::async_trait]
pub trait VkStorageApi {
/// Get verification key from pallet's storage.
async fn get_verification_key(&self, key_hash: H256, at: Option<BlockHash>) -> Vec<u8>;
}

/// Pallet vk storage API.
#[async_trait::async_trait]
pub trait VkStorageUserApi {
/// Store verifying key in pallet's storage.
/// Store a verifying key in pallet's storage.
async fn store_key(&self, key: Vec<u8>, status: TxStatus) -> Result<TxInfo>;
}

#[async_trait::async_trait]
impl<C: ConnectionApi> VkStorageApi for C {
async fn get_verification_key(&self, key_hash: H256, at: Option<BlockHash>) -> Vec<u8> {
let addrs = api::storage().vk_storage().verification_keys(key_hash);
self.get_storage_entry(&addrs, at).await.0
}
}

#[async_trait::async_trait]
impl VkStorageUserApi for SignedConnection {
async fn store_key(&self, key: Vec<u8>, status: TxStatus) -> Result<TxInfo> {
Expand Down
2 changes: 1 addition & 1 deletion bin/cliain/Cargo.lock

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

2 changes: 1 addition & 1 deletion e2e-tests/Cargo.lock

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

0 comments on commit 06bf402

Please sign in to comment.