Skip to content

Commit 434dc1d

Browse files
authored
chore: upgraded subxt version (#483)
* chore: upgrade subxt dependency to 0.29.0
1 parent eaf5838 commit 434dc1d

File tree

28 files changed

+1097
-627
lines changed

28 files changed

+1097
-627
lines changed

Cargo.lock

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

faucet/src/http.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use lazy_static::lazy_static;
1010
use parity_scale_codec::{Decode, Encode};
1111
use reqwest::Url;
1212
use runtime::{
13-
AccountId, CollateralBalancesPallet, CurrencyId, Error as RuntimeError, InterBtcParachain, RuntimeCurrencyInfo,
14-
Ss58Codec, TryFromSymbol, VaultRegistryPallet, SS58_PREFIX,
13+
sp_core::crypto::Ss58Codec, AccountId, CollateralBalancesPallet, CurrencyId, Error as RuntimeError,
14+
InterBtcParachain, RuntimeCurrencyInfo, TryFromSymbol, VaultRegistryPallet, SS58_PREFIX,
1515
};
1616
use serde::{Deserialize, Deserializer, Serialize};
1717
use std::{net::SocketAddr, time::Duration};
@@ -225,12 +225,13 @@ struct GetSignatureData {
225225
}
226226

227227
async fn ensure_signature_exists(auth_url: &str, account_id: &AccountId) -> Result<(), Error> {
228+
let account_id = runtime::sp_core::crypto::AccountId32::from(account_id.0);
228229
reqwest::get(Url::parse(auth_url)?.join(&account_id.to_ss58check_with_version(SS58_PREFIX.into()))?)
229230
.await?
230231
.json::<GetSignatureData>()
231232
.await?
232233
.exists
233-
.then(|| ())
234+
.then_some(())
234235
.ok_or(Error::SignatureMissing)
235236
}
236237

@@ -262,7 +263,7 @@ async fn atomic_faucet_funding(
262263
let transfers = amounts
263264
.into_iter()
264265
.map(|AllowanceAmount { symbol, amount }| {
265-
let currency_id = CurrencyId::try_from_symbol(symbol.clone())?;
266+
let currency_id = CurrencyId::try_from_symbol(symbol)?;
266267
log::info!(
267268
"AccountId: {}, Currency: {:?} Type: {:?}, Amount: {}",
268269
account_id,
@@ -418,12 +419,12 @@ mod tests {
418419
.flat_map(|account_id| {
419420
vec![DEFAULT_TESTING_CURRENCY, DEFAULT_GOVERNANCE_CURRENCY]
420421
.into_iter()
421-
.map(move |currency_id| (account_id.clone(), 1 << 60, 0, currency_id))
422+
.map(move |currency_id| (account_id.clone().into(), 1 << 60, 0, currency_id))
422423
})
423-
.collect(),
424+
.collect::<Vec<(runtime::utils_accountid::AccountId32, u128, u128, CurrencyId)>>(),
424425
)
425426
.await
426-
.expect("Should endow accounts")
427+
.expect("Should endow accounts");
427428
}
428429

429430
async fn set_exchange_rate(client: SubxtClient) {
@@ -534,7 +535,7 @@ mod tests {
534535
endow_accounts(client.clone()).await;
535536

536537
// Bob's account is prefunded with lots of DOT
537-
let bob_account_id: AccountId = AccountKeyring::Bob.to_account_id();
538+
let bob_account_id: AccountId = AccountKeyring::Bob.to_account_id().into();
538539
let user_allowance: Allowance = vec![
539540
AllowanceAmount::new(DEFAULT_TESTING_CURRENCY.symbol().unwrap(), 100),
540541
AllowanceAmount::new(DEFAULT_GOVERNANCE_CURRENCY.symbol().unwrap(), 100),
@@ -568,7 +569,7 @@ mod tests {
568569
set_exchange_rate(client.clone()).await;
569570
endow_accounts(client.clone()).await;
570571

571-
let bob_account_id = AccountKeyring::Bob.to_account_id();
572+
let bob_account_id: AccountId = AccountKeyring::Bob.to_account_id().into();
572573
let bob_vault_id = VaultId::new(
573574
bob_account_id.clone(),
574575
DEFAULT_TESTING_CURRENCY,
@@ -593,13 +594,14 @@ mod tests {
593594
let alice_provider = setup_provider(client.clone(), AccountKeyring::Alice).await;
594595
let bob_provider = setup_provider(client.clone(), AccountKeyring::Bob).await;
595596
// Drain the amount Bob was prefunded by, so he is eligible to receive Faucet funding
596-
let bob_prefunded_amount = get_multi_currency_balance(&bob_account_id, &user_allowance, &bob_provider).await;
597+
let bob_prefunded_amount =
598+
get_multi_currency_balance(&bob_account_id.clone().into(), &user_allowance, &bob_provider).await;
597599
drain_multi_currency(&bob_prefunded_amount, &bob_provider, &drain_account_id, 1)
598600
.await
599601
.expect("Unable to transfer funds");
600602

601603
let req = FundAccountJsonRpcRequest {
602-
account_id: bob_account_id.clone(),
604+
account_id: bob_account_id.clone().into(),
603605
currency_id: DEFAULT_TESTING_CURRENCY,
604606
};
605607
fund_account(
@@ -614,11 +616,13 @@ mod tests {
614616
bob_provider.register_public_key(dummy_public_key()).await.unwrap();
615617
bob_provider.register_vault(&bob_vault_id, 3 * KSM.one()).await.unwrap();
616618

617-
let bob_funds_before = get_multi_currency_balance(&bob_account_id, &user_allowance, &alice_provider).await;
619+
let bob_funds_before =
620+
get_multi_currency_balance(&bob_account_id.clone().into(), &user_allowance, &alice_provider).await;
618621
fund_account(&Arc::from(alice_provider.clone()), req, store, allowance_config)
619622
.await
620623
.expect("Funding the account failed");
621-
let bob_funds_after = get_multi_currency_balance(&bob_account_id, &user_allowance, &alice_provider).await;
624+
let bob_funds_after =
625+
get_multi_currency_balance(&bob_account_id.clone().into(), &user_allowance, &alice_provider).await;
622626
assert_allowance_emitted(&bob_funds_before, &bob_funds_after, &vault_allowance);
623627
}
624628

@@ -677,7 +681,7 @@ mod tests {
677681

678682
for currency_id in [Token(KINT), Token(KSM)] {
679683
kv.clear().unwrap();
680-
let bob_account_id: AccountId = AccountKeyring::Bob.to_account_id();
684+
let bob_account_id: AccountId = AccountKeyring::Bob.to_account_id().into();
681685
let bob_vault_id = VaultId::new(bob_account_id.clone(), currency_id, DEFAULT_WRAPPED_CURRENCY);
682686
let drain_account_id: AccountId = [3; 32].into();
683687

@@ -709,7 +713,7 @@ mod tests {
709713

710714
let bob_funds_before = get_multi_currency_balance(&bob_account_id, &user_allowance, &bob_provider).await;
711715
let req = FundAccountJsonRpcRequest {
712-
account_id: bob_account_id.clone(),
716+
account_id: bob_account_id.clone().into(),
713717
currency_id,
714718
};
715719

@@ -729,7 +733,7 @@ mod tests {
729733
set_exchange_rate(client.clone()).await;
730734
endow_accounts(client.clone()).await;
731735

732-
let bob_account_id: AccountId = AccountKeyring::Bob.to_account_id();
736+
let bob_account_id: AccountId = AccountKeyring::Bob.to_account_id().into();
733737
let bob_vault_id = VaultId::new(
734738
bob_account_id.clone(),
735739
DEFAULT_TESTING_CURRENCY,

oracle/src/feeds/dia.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::single_char_pattern)]
12
use super::{get_http, PriceFeed};
23
use crate::{config::CurrencyStore, currency::*, Error};
34
use async_trait::async_trait;
@@ -33,7 +34,7 @@ fn extract_response(value: Value) -> Option<f64> {
3334

3435
fn set_token_path(base: &mut Url, token_path: &str) {
3536
let base_path = base.path().trim_end_matches("/");
36-
let new_path = format!("{}/assetQuotation/{}", base_path, token_path);
37+
let new_path = format!("{base_path}/assetQuotation/{token_path}");
3738
base.set_path(&new_path);
3839
}
3940

runner/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ signal-hook = "0.3.14"
2424
signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] }
2525
futures = "0.3.21"
2626
backoff = { version = "0.3.0", features = ["tokio"] }
27-
subxt = "0.25.0"
27+
subxt = { version = "0.29.0", default_features = false, features = ["jsonrpsee-ws"] }
2828
sha2 = "0.8.2"
2929

3030
[dev-dependencies]

runner/src/runner.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,12 @@ impl Runner {
277277
CURRENT_RELEASES_STORAGE_ITEM,
278278
vec![Value::from_bytes(client_type.to_string().as_bytes())],
279279
);
280-
let lookup_bytes = subxt::storage::utils::storage_address_bytes(&storage_address, &subxt_api.metadata())?;
280+
let lookup_bytes = subxt_api.storage().address_bytes(&storage_address)?;
281281
let enc_res = subxt_api
282282
.storage()
283-
.fetch_raw(&lookup_bytes, None)
283+
.at_latest()
284+
.await?
285+
.fetch_raw(&lookup_bytes)
284286
.await?
285287
.map(Bytes::from);
286288
enc_res
@@ -758,7 +760,7 @@ mod tests {
758760
&runner,
759761
"https://github.com/interlay/interbtc-clients/releases/download/1.17.2/vault-parachain-metadata-kintsugi",
760762
)
761-
.unwrap();
763+
.unwrap();
762764
assert_eq!(bin_name, "vault-parachain-metadata-kintsugi");
763765
assert_eq!(bin_path, mock_path.join(bin_name));
764766
}

runtime/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,22 @@ url = "2"
3131
cfg-if = "1.0"
3232
prometheus = { version = "0.12.0", features = ["process"] }
3333
lazy_static = "1.4.0"
34+
base58 = { version = "0.2.0" }
35+
blake2 = { version = "0.10.4", default-features = false }
36+
scale-decode = { version = "0.7.0", features = ["derive"] }
37+
scale-encode = { version = "0.3.0", features = ["derive"] }
3438

3539
# Substrate dependencies
3640
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
41+
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
3742
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
3843
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
3944
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
4045

4146
# Subxt dependencies
42-
subxt = "0.25.0"
47+
subxt = { version = "0.29.0", default_features = false, features = ["jsonrpsee-ws"] }
4348
subxt-client = { path = "./client", optional = true }
44-
jsonrpsee = { version = "0.16.2", features = ["async-client", "client-ws-transport", "macros", "jsonrpsee-types", "client", "jsonrpsee-ws-client", "jsonrpsee-client-transport"] }
49+
jsonrpsee = { version = "0.16", features = ["async-client", "client-ws-transport", "macros", "jsonrpsee-types", "client", "jsonrpsee-ws-client", "jsonrpsee-client-transport"] }
4550

4651
bitcoin = { path = "../bitcoin" }
4752

runtime/client/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ keywords = ["parity", "substrate", "blockchain"]
1515
tokio = { version = "1.10", features = ["time", "rt-multi-thread"] }
1616
futures = { version = "0.3.9", features = ["compat"], package = "futures" }
1717
futures01 = { package = "futures", version = "0.1.29" }
18-
jsonrpsee = "0.16.2"
19-
jsonrpsee-types = "0.16.2"
20-
jsonrpsee-core = { version = "0.16.2", features = ["async-client"] }
18+
jsonrpsee = "0.16"
19+
jsonrpsee-types = "0.16"
20+
jsonrpsee-core = { version = "0.16", features = ["async-client"] }
2121

2222
log = "0.4.13"
2323
serde_json = "1.0.61"
@@ -29,4 +29,4 @@ sc-network-common = { git = "https://github.com/paritytech/substrate", branch =
2929
sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
3030
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
3131

32-
subxt = "0.25.0"
32+
subxt = { version = "0.29.0", default_features = false, features = ["jsonrpsee-ws"] }

runtime/src/assets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl TryFromSymbol for CurrencyId {
157157
fn from_lend_token_symbol(symbol: &str) -> Option<Self> {
158158
let uppercase_symbol = symbol.to_uppercase();
159159
// Does the first character match the lend token prefix?
160-
if uppercase_symbol.as_str().chars().next() == Some(LEND_TOKEN_SYMBOL_PREFIX) {
160+
if uppercase_symbol.as_str().starts_with(LEND_TOKEN_SYMBOL_PREFIX) {
161161
return Self::try_from_symbol(uppercase_symbol[1..].to_string())
162162
.ok()
163163
.and_then(|underlying_id| LendingAssets::get_lend_token_id(underlying_id).ok());

runtime/src/cli.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::{
44
InterBtcParachain, InterBtcSigner,
55
};
66
use clap::Parser;
7+
use sp_core::{sr25519, Pair};
78
use sp_keyring::AccountKeyring;
89
use std::{collections::HashMap, num::ParseIntError, str::FromStr, time::Duration};
9-
use subxt::ext::sp_core::{sr25519::Pair, Pair as _};
1010

1111
#[derive(Parser, Debug, Clone)]
1212
pub struct ProviderUserOpts {
@@ -31,7 +31,7 @@ pub struct ProviderUserOpts {
3131

3232
impl ProviderUserOpts {
3333
/// Get the key pair and the username, the latter of which is used for wallet selection.
34-
pub fn get_key_pair(&self) -> Result<(Pair, String), Error> {
34+
pub fn get_key_pair(&self) -> Result<(sr25519::Pair, String), Error> {
3535
// Load parachain credentials
3636
let (pair, user_name) = match (
3737
self.keyfile.as_ref(), // Check if keyfile is provided
@@ -66,8 +66,8 @@ impl ProviderUserOpts {
6666
/// # Arguments
6767
///
6868
/// * `keyuri` - secret phrase to generate pair
69-
fn get_pair_from_phrase(keyuri: &String) -> Result<Pair, KeyLoadingError> {
70-
Pair::from_string(keyuri, None).map_err(KeyLoadingError::SecretStringError)
69+
fn get_pair_from_phrase(keyuri: &str) -> Result<sr25519::Pair, KeyLoadingError> {
70+
sr25519::Pair::from_string(keyuri, None).map_err(KeyLoadingError::SecretStringError)
7171
}
7272

7373
/// Loads the credentials for the given user from the keyfile
@@ -76,7 +76,7 @@ fn get_pair_from_phrase(keyuri: &String) -> Result<Pair, KeyLoadingError> {
7676
///
7777
/// * `file_path` - path to the json file containing the credentials
7878
/// * `keyname` - name of the key to get
79-
fn get_credentials_from_file(file_path: &str, keyname: &str) -> Result<Pair, KeyLoadingError> {
79+
fn get_credentials_from_file(file_path: &str, keyname: &str) -> Result<sr25519::Pair, KeyLoadingError> {
8080
let file = std::fs::File::open(file_path)?;
8181
let reader = std::io::BufReader::new(file);
8282
let map: HashMap<String, String> = serde_json::from_reader(reader)?;

runtime/src/error.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ use jsonrpsee::{
88
};
99
use prometheus::Error as PrometheusError;
1010
use serde_json::Error as SerdeJsonError;
11+
use sp_core::crypto::SecretStringError;
1112
use std::{array::TryFromSliceError, fmt::Debug, io::Error as IoError, num::TryFromIntError, str::Utf8Error};
12-
use subxt::{
13-
error::{DispatchError, ModuleError, TransactionError},
14-
ext::sp_core::crypto::SecretStringError,
15-
};
13+
use subxt::error::{DispatchError, TransactionError};
14+
pub use subxt::{error::RpcError, Error as SubxtError};
1615
use thiserror::Error;
1716
use tokio::time::error::Elapsed;
1817
use url::ParseError as UrlParseError;
1918

20-
pub use subxt::{error::RpcError, Error as SubxtError};
21-
2219
#[derive(Error, Debug)]
2320
pub enum Error {
2421
#[error("Could not get exchange rate info")]
@@ -103,7 +100,7 @@ pub enum Error {
103100

104101
impl From<module_bitcoin::Error> for Error {
105102
fn from(value: module_bitcoin::Error) -> Self {
106-
Self::BitcoinError(format!("{:?}", value))
103+
Self::BitcoinError(format!("{value:?}"))
107104
}
108105
}
109106

@@ -116,12 +113,12 @@ impl Error {
116113
}
117114

118115
fn is_module_err(&self, pallet_name: &str, error_name: &str) -> bool {
119-
matches!(
120-
self,
121-
Error::SubxtRuntimeError(SubxtError::Runtime(DispatchError::Module(ModuleError{
122-
pallet, error, ..
123-
}))) if pallet == pallet_name && error == error_name,
124-
)
116+
if let Error::SubxtRuntimeError(SubxtError::Runtime(DispatchError::Module(module_error))) = self {
117+
if let Ok(details) = module_error.details() {
118+
return details.pallet.name() == pallet_name && details.variant.name == error_name;
119+
}
120+
}
121+
false
125122
}
126123

127124
pub fn is_duplicate_block(&self) -> bool {
@@ -203,7 +200,7 @@ impl Error {
203200
pub fn is_block_hash_not_found_error(&self) -> bool {
204201
matches!(
205202
self,
206-
Error::SubxtRuntimeError(SubxtError::Transaction(TransactionError::BlockHashNotFound))
203+
Error::SubxtRuntimeError(SubxtError::Transaction(TransactionError::BlockNotFound))
207204
)
208205
}
209206

0 commit comments

Comments
 (0)