Skip to content

Commit

Permalink
chore: upgraded subxt version (#483)
Browse files Browse the repository at this point in the history
* chore: upgrade subxt dependency to 0.29.0
  • Loading branch information
nakul1010 authored Jul 19, 2023
1 parent eaf5838 commit 434dc1d
Show file tree
Hide file tree
Showing 28 changed files with 1,097 additions and 627 deletions.
641 changes: 353 additions & 288 deletions Cargo.lock

Large diffs are not rendered by default.

36 changes: 20 additions & 16 deletions faucet/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use lazy_static::lazy_static;
use parity_scale_codec::{Decode, Encode};
use reqwest::Url;
use runtime::{
AccountId, CollateralBalancesPallet, CurrencyId, Error as RuntimeError, InterBtcParachain, RuntimeCurrencyInfo,
Ss58Codec, TryFromSymbol, VaultRegistryPallet, SS58_PREFIX,
sp_core::crypto::Ss58Codec, AccountId, CollateralBalancesPallet, CurrencyId, Error as RuntimeError,
InterBtcParachain, RuntimeCurrencyInfo, TryFromSymbol, VaultRegistryPallet, SS58_PREFIX,
};
use serde::{Deserialize, Deserializer, Serialize};
use std::{net::SocketAddr, time::Duration};
Expand Down Expand Up @@ -225,12 +225,13 @@ struct GetSignatureData {
}

async fn ensure_signature_exists(auth_url: &str, account_id: &AccountId) -> Result<(), Error> {
let account_id = runtime::sp_core::crypto::AccountId32::from(account_id.0);
reqwest::get(Url::parse(auth_url)?.join(&account_id.to_ss58check_with_version(SS58_PREFIX.into()))?)
.await?
.json::<GetSignatureData>()
.await?
.exists
.then(|| ())
.then_some(())
.ok_or(Error::SignatureMissing)
}

Expand Down Expand Up @@ -262,7 +263,7 @@ async fn atomic_faucet_funding(
let transfers = amounts
.into_iter()
.map(|AllowanceAmount { symbol, amount }| {
let currency_id = CurrencyId::try_from_symbol(symbol.clone())?;
let currency_id = CurrencyId::try_from_symbol(symbol)?;
log::info!(
"AccountId: {}, Currency: {:?} Type: {:?}, Amount: {}",
account_id,
Expand Down Expand Up @@ -418,12 +419,12 @@ mod tests {
.flat_map(|account_id| {
vec![DEFAULT_TESTING_CURRENCY, DEFAULT_GOVERNANCE_CURRENCY]
.into_iter()
.map(move |currency_id| (account_id.clone(), 1 << 60, 0, currency_id))
.map(move |currency_id| (account_id.clone().into(), 1 << 60, 0, currency_id))
})
.collect(),
.collect::<Vec<(runtime::utils_accountid::AccountId32, u128, u128, CurrencyId)>>(),
)
.await
.expect("Should endow accounts")
.expect("Should endow accounts");
}

async fn set_exchange_rate(client: SubxtClient) {
Expand Down Expand Up @@ -534,7 +535,7 @@ mod tests {
endow_accounts(client.clone()).await;

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

let bob_account_id = AccountKeyring::Bob.to_account_id();
let bob_account_id: AccountId = AccountKeyring::Bob.to_account_id().into();
let bob_vault_id = VaultId::new(
bob_account_id.clone(),
DEFAULT_TESTING_CURRENCY,
Expand All @@ -593,13 +594,14 @@ mod tests {
let alice_provider = setup_provider(client.clone(), AccountKeyring::Alice).await;
let bob_provider = setup_provider(client.clone(), AccountKeyring::Bob).await;
// Drain the amount Bob was prefunded by, so he is eligible to receive Faucet funding
let bob_prefunded_amount = get_multi_currency_balance(&bob_account_id, &user_allowance, &bob_provider).await;
let bob_prefunded_amount =
get_multi_currency_balance(&bob_account_id.clone().into(), &user_allowance, &bob_provider).await;
drain_multi_currency(&bob_prefunded_amount, &bob_provider, &drain_account_id, 1)
.await
.expect("Unable to transfer funds");

let req = FundAccountJsonRpcRequest {
account_id: bob_account_id.clone(),
account_id: bob_account_id.clone().into(),
currency_id: DEFAULT_TESTING_CURRENCY,
};
fund_account(
Expand All @@ -614,11 +616,13 @@ mod tests {
bob_provider.register_public_key(dummy_public_key()).await.unwrap();
bob_provider.register_vault(&bob_vault_id, 3 * KSM.one()).await.unwrap();

let bob_funds_before = get_multi_currency_balance(&bob_account_id, &user_allowance, &alice_provider).await;
let bob_funds_before =
get_multi_currency_balance(&bob_account_id.clone().into(), &user_allowance, &alice_provider).await;
fund_account(&Arc::from(alice_provider.clone()), req, store, allowance_config)
.await
.expect("Funding the account failed");
let bob_funds_after = get_multi_currency_balance(&bob_account_id, &user_allowance, &alice_provider).await;
let bob_funds_after =
get_multi_currency_balance(&bob_account_id.clone().into(), &user_allowance, &alice_provider).await;
assert_allowance_emitted(&bob_funds_before, &bob_funds_after, &vault_allowance);
}

Expand Down Expand Up @@ -677,7 +681,7 @@ mod tests {

for currency_id in [Token(KINT), Token(KSM)] {
kv.clear().unwrap();
let bob_account_id: AccountId = AccountKeyring::Bob.to_account_id();
let bob_account_id: AccountId = AccountKeyring::Bob.to_account_id().into();
let bob_vault_id = VaultId::new(bob_account_id.clone(), currency_id, DEFAULT_WRAPPED_CURRENCY);
let drain_account_id: AccountId = [3; 32].into();

Expand Down Expand Up @@ -709,7 +713,7 @@ mod tests {

let bob_funds_before = get_multi_currency_balance(&bob_account_id, &user_allowance, &bob_provider).await;
let req = FundAccountJsonRpcRequest {
account_id: bob_account_id.clone(),
account_id: bob_account_id.clone().into(),
currency_id,
};

Expand All @@ -729,7 +733,7 @@ mod tests {
set_exchange_rate(client.clone()).await;
endow_accounts(client.clone()).await;

let bob_account_id: AccountId = AccountKeyring::Bob.to_account_id();
let bob_account_id: AccountId = AccountKeyring::Bob.to_account_id().into();
let bob_vault_id = VaultId::new(
bob_account_id.clone(),
DEFAULT_TESTING_CURRENCY,
Expand Down
3 changes: 2 additions & 1 deletion oracle/src/feeds/dia.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::single_char_pattern)]
use super::{get_http, PriceFeed};
use crate::{config::CurrencyStore, currency::*, Error};
use async_trait::async_trait;
Expand Down Expand Up @@ -33,7 +34,7 @@ fn extract_response(value: Value) -> Option<f64> {

fn set_token_path(base: &mut Url, token_path: &str) {
let base_path = base.path().trim_end_matches("/");
let new_path = format!("{}/assetQuotation/{}", base_path, token_path);
let new_path = format!("{base_path}/assetQuotation/{token_path}");
base.set_path(&new_path);
}

Expand Down
2 changes: 1 addition & 1 deletion runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ signal-hook = "0.3.14"
signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] }
futures = "0.3.21"
backoff = { version = "0.3.0", features = ["tokio"] }
subxt = "0.25.0"
subxt = { version = "0.29.0", default_features = false, features = ["jsonrpsee-ws"] }
sha2 = "0.8.2"

[dev-dependencies]
Expand Down
8 changes: 5 additions & 3 deletions runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,12 @@ impl Runner {
CURRENT_RELEASES_STORAGE_ITEM,
vec![Value::from_bytes(client_type.to_string().as_bytes())],
);
let lookup_bytes = subxt::storage::utils::storage_address_bytes(&storage_address, &subxt_api.metadata())?;
let lookup_bytes = subxt_api.storage().address_bytes(&storage_address)?;
let enc_res = subxt_api
.storage()
.fetch_raw(&lookup_bytes, None)
.at_latest()
.await?
.fetch_raw(&lookup_bytes)
.await?
.map(Bytes::from);
enc_res
Expand Down Expand Up @@ -758,7 +760,7 @@ mod tests {
&runner,
"https://github.com/interlay/interbtc-clients/releases/download/1.17.2/vault-parachain-metadata-kintsugi",
)
.unwrap();
.unwrap();
assert_eq!(bin_name, "vault-parachain-metadata-kintsugi");
assert_eq!(bin_path, mock_path.join(bin_name));
}
Expand Down
9 changes: 7 additions & 2 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,22 @@ url = "2"
cfg-if = "1.0"
prometheus = { version = "0.12.0", features = ["process"] }
lazy_static = "1.4.0"
base58 = { version = "0.2.0" }
blake2 = { version = "0.10.4", default-features = false }
scale-decode = { version = "0.7.0", features = ["derive"] }
scale-encode = { version = "0.3.0", features = ["derive"] }

# Substrate dependencies
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }

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

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

Expand Down
8 changes: 4 additions & 4 deletions runtime/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ keywords = ["parity", "substrate", "blockchain"]
tokio = { version = "1.10", features = ["time", "rt-multi-thread"] }
futures = { version = "0.3.9", features = ["compat"], package = "futures" }
futures01 = { package = "futures", version = "0.1.29" }
jsonrpsee = "0.16.2"
jsonrpsee-types = "0.16.2"
jsonrpsee-core = { version = "0.16.2", features = ["async-client"] }
jsonrpsee = "0.16"
jsonrpsee-types = "0.16"
jsonrpsee-core = { version = "0.16", features = ["async-client"] }

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

subxt = "0.25.0"
subxt = { version = "0.29.0", default_features = false, features = ["jsonrpsee-ws"] }
2 changes: 1 addition & 1 deletion runtime/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl TryFromSymbol for CurrencyId {
fn from_lend_token_symbol(symbol: &str) -> Option<Self> {
let uppercase_symbol = symbol.to_uppercase();
// Does the first character match the lend token prefix?
if uppercase_symbol.as_str().chars().next() == Some(LEND_TOKEN_SYMBOL_PREFIX) {
if uppercase_symbol.as_str().starts_with(LEND_TOKEN_SYMBOL_PREFIX) {
return Self::try_from_symbol(uppercase_symbol[1..].to_string())
.ok()
.and_then(|underlying_id| LendingAssets::get_lend_token_id(underlying_id).ok());
Expand Down
10 changes: 5 additions & 5 deletions runtime/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::{
InterBtcParachain, InterBtcSigner,
};
use clap::Parser;
use sp_core::{sr25519, Pair};
use sp_keyring::AccountKeyring;
use std::{collections::HashMap, num::ParseIntError, str::FromStr, time::Duration};
use subxt::ext::sp_core::{sr25519::Pair, Pair as _};

#[derive(Parser, Debug, Clone)]
pub struct ProviderUserOpts {
Expand All @@ -31,7 +31,7 @@ pub struct ProviderUserOpts {

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

/// Loads the credentials for the given user from the keyfile
Expand All @@ -76,7 +76,7 @@ fn get_pair_from_phrase(keyuri: &String) -> Result<Pair, KeyLoadingError> {
///
/// * `file_path` - path to the json file containing the credentials
/// * `keyname` - name of the key to get
fn get_credentials_from_file(file_path: &str, keyname: &str) -> Result<Pair, KeyLoadingError> {
fn get_credentials_from_file(file_path: &str, keyname: &str) -> Result<sr25519::Pair, KeyLoadingError> {
let file = std::fs::File::open(file_path)?;
let reader = std::io::BufReader::new(file);
let map: HashMap<String, String> = serde_json::from_reader(reader)?;
Expand Down
25 changes: 11 additions & 14 deletions runtime/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ use jsonrpsee::{
};
use prometheus::Error as PrometheusError;
use serde_json::Error as SerdeJsonError;
use sp_core::crypto::SecretStringError;
use std::{array::TryFromSliceError, fmt::Debug, io::Error as IoError, num::TryFromIntError, str::Utf8Error};
use subxt::{
error::{DispatchError, ModuleError, TransactionError},
ext::sp_core::crypto::SecretStringError,
};
use subxt::error::{DispatchError, TransactionError};
pub use subxt::{error::RpcError, Error as SubxtError};
use thiserror::Error;
use tokio::time::error::Elapsed;
use url::ParseError as UrlParseError;

pub use subxt::{error::RpcError, Error as SubxtError};

#[derive(Error, Debug)]
pub enum Error {
#[error("Could not get exchange rate info")]
Expand Down Expand Up @@ -103,7 +100,7 @@ pub enum Error {

impl From<module_bitcoin::Error> for Error {
fn from(value: module_bitcoin::Error) -> Self {
Self::BitcoinError(format!("{:?}", value))
Self::BitcoinError(format!("{value:?}"))
}
}

Expand All @@ -116,12 +113,12 @@ impl Error {
}

fn is_module_err(&self, pallet_name: &str, error_name: &str) -> bool {
matches!(
self,
Error::SubxtRuntimeError(SubxtError::Runtime(DispatchError::Module(ModuleError{
pallet, error, ..
}))) if pallet == pallet_name && error == error_name,
)
if let Error::SubxtRuntimeError(SubxtError::Runtime(DispatchError::Module(module_error))) = self {
if let Ok(details) = module_error.details() {
return details.pallet.name() == pallet_name && details.variant.name == error_name;
}
}
false
}

pub fn is_duplicate_block(&self) -> bool {
Expand Down Expand Up @@ -203,7 +200,7 @@ impl Error {
pub fn is_block_hash_not_found_error(&self) -> bool {
matches!(
self,
Error::SubxtRuntimeError(SubxtError::Transaction(TransactionError::BlockHashNotFound))
Error::SubxtRuntimeError(SubxtError::Transaction(TransactionError::BlockNotFound))
)
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/integration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub async fn assert_issue(
.unwrap();

parachain_rpc
.execute_issue(issue.issue_id, &metadata.proof, &metadata.raw_tx)
.execute_issue(*issue.issue_id, &metadata.proof, &metadata.raw_tx)
.await
.unwrap();
}
Expand Down
Loading

0 comments on commit 434dc1d

Please sign in to comment.