From 521c54a835e79f9046f1963f3bbf7ce8f3e5c368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Gawrya=C5=82?= Date: Wed, 16 Aug 2023 14:09:41 +0200 Subject: [PATCH] Small polishing --- .../docker/subxt-integration-entrypoint.sh | 6 ++---- aleph-client/src/lib.rs | 2 +- aleph-client/src/pallets/multisig.rs | 2 +- aleph-client/src/pallets/staking.rs | 15 +++++++++------ 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/aleph-client/docker/subxt-integration-entrypoint.sh b/aleph-client/docker/subxt-integration-entrypoint.sh index a60bb03acd..f4b8b95322 100644 --- a/aleph-client/docker/subxt-integration-entrypoint.sh +++ b/aleph-client/docker/subxt-integration-entrypoint.sh @@ -1,13 +1,11 @@ #!/usr/bin/env bash - -subxt codegen --derive Clone --derive Debug --derive Eq --derive PartialEq | rustfmt --edition=2021 --config-path aleph-node/rustfmt.toml > aleph_zero.rs +../generate_interface.sh diff -y -W 200 --suppress-common-lines aleph_zero.rs aleph-node/aleph-client/src/aleph_zero.rs diff_exit_code=$? if [[ ! $diff_exit_code -eq 0 ]]; then echo "Current runtime metadata is different than versioned in git!" - echo "Run subxt codegen --derive Clone --derive Debug --derive Eq --derive PartialEq | rustfmt --edition=2021 >" \ -"src/aleph_zero.rs from aleph-client directory and commit to git." + echo "Run ./generate_interface.sh from aleph-client directory and commit to git." exit 1 fi echo "Current runtime metadata and versioned in git matches." diff --git a/aleph-client/src/lib.rs b/aleph-client/src/lib.rs index c044a88754..f8c25931b3 100644 --- a/aleph-client/src/lib.rs +++ b/aleph-client/src/lib.rs @@ -62,7 +62,7 @@ pub type AlephKeyPair = ed25519::Pair; /// An alias for a type of a key pair that signs chain transactions. pub type RawKeyPair = sr25519::Pair; /// An alias for an account id type. -pub type AccountId = sp_runtime::AccountId32; +pub type AccountId = subxt::ext::sp_core::crypto::AccountId32; /// An alias for a hash type. pub type CodeHash = H256; /// An alias for a block hash type. diff --git a/aleph-client/src/pallets/multisig.rs b/aleph-client/src/pallets/multisig.rs index 441de340ab..2983ed4628 100644 --- a/aleph-client/src/pallets/multisig.rs +++ b/aleph-client/src/pallets/multisig.rs @@ -372,7 +372,7 @@ impl Context { self.call_hash } /// Read approvers set. - pub fn approvers(&self) -> &HashSet + From> { + pub fn approvers(&self) -> &HashSet { &self.approvers } } diff --git a/aleph-client/src/pallets/staking.rs b/aleph-client/src/pallets/staking.rs index 3c77e0608f..930923ef43 100644 --- a/aleph-client/src/pallets/staking.rs +++ b/aleph-client/src/pallets/staking.rs @@ -440,6 +440,11 @@ impl StakingSudoApi for RootConnection { } } +fn extend_with_twox64_concat_hash(key: &mut Vec, value_to_hash: T) { + key.extend(subxt::ext::sp_core::twox_64(&value_to_hash.encode())); + key.extend(&value_to_hash.encode()); +} + #[async_trait::async_trait] impl StakingRawApi for C { async fn get_stakers_storage_keys( @@ -449,8 +454,8 @@ impl StakingRawApi for C { ) -> anyhow::Result> { let key_addrs = api::storage().staking().eras_stakers_root(); let mut key = key_addrs.to_root_bytes(); - key.extend(subxt::ext::sp_core::twox_64(&era.encode())); - key.extend(&era.encode()); + extend_with_twox64_concat_hash(&mut key, era); + let storage = self.as_connection().as_client().storage(); let block = match at { Some(block_hash) => storage.at(block_hash), @@ -467,14 +472,12 @@ impl StakingRawApi for C { ) -> Vec { let key_addrs = api::storage().staking().eras_stakers_root(); let mut key = key_addrs.to_root_bytes(); - key.extend(subxt::ext::sp_core::twox_64(&era.encode())); - key.extend(&era.encode()); + extend_with_twox64_concat_hash(&mut key, era); accounts .iter() .map(|account| { let mut key = key.clone(); - key.extend(subxt::ext::sp_core::twox_64(&account.encode())); - key.extend(&account.encode()); + extend_with_twox64_concat_hash(&mut key, account); StorageKey(key) })