mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 15:27:57 +00:00
payment_queryInfo: Make it work with WeightV2 (#12633)
* `payment_queryInfo`: Make it work with `WeighV2` The runtime api for querying the payment info depends on the `Weight` type and broke for old runtimes that still use the `WeighV1`. This pull requests fixes this by: 1. Bumping the version of the runtime api. 2. Making the node side code use the correct runtime api function depending on the version of the runtime api. 3. Make the RPC always return `WeighV1`. Users of the api should switch to `state_call` and decide based on the version of the runtime api which `Weight` type is being returned. * Fix tests * Review comment
This commit is contained in:
@@ -26,7 +26,7 @@ use jsonrpsee::{
|
||||
types::error::{CallError, ErrorCode, ErrorObject},
|
||||
};
|
||||
use pallet_transaction_payment_rpc_runtime_api::{FeeDetails, InclusionFee, RuntimeDispatchInfo};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_api::{ApiExt, ProvideRuntimeApi};
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_core::Bytes;
|
||||
use sp_rpc::number::NumberOrHex;
|
||||
@@ -82,8 +82,10 @@ impl From<Error> for i32 {
|
||||
}
|
||||
|
||||
impl<C, Block, Balance>
|
||||
TransactionPaymentApiServer<<Block as BlockT>::Hash, RuntimeDispatchInfo<Balance>>
|
||||
for TransactionPayment<C, Block>
|
||||
TransactionPaymentApiServer<
|
||||
<Block as BlockT>::Hash,
|
||||
RuntimeDispatchInfo<Balance, sp_weights::OldWeight>,
|
||||
> for TransactionPayment<C, Block>
|
||||
where
|
||||
Block: BlockT,
|
||||
C: ProvideRuntimeApi<Block> + HeaderBackend<Block> + Send + Sync + 'static,
|
||||
@@ -94,7 +96,7 @@ where
|
||||
&self,
|
||||
encoded_xt: Bytes,
|
||||
at: Option<Block::Hash>,
|
||||
) -> RpcResult<RuntimeDispatchInfo<Balance>> {
|
||||
) -> RpcResult<RuntimeDispatchInfo<Balance, sp_weights::OldWeight>> {
|
||||
let api = self.client.runtime_api();
|
||||
let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash));
|
||||
|
||||
@@ -107,14 +109,41 @@ where
|
||||
Some(format!("{:?}", e)),
|
||||
))
|
||||
})?;
|
||||
api.query_info(&at, uxt, encoded_len).map_err(|e| {
|
||||
|
||||
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
|
||||
CallError::Custom(ErrorObject::owned(
|
||||
Error::RuntimeError.into(),
|
||||
"Unable to query dispatch info.",
|
||||
Some(e.to_string()),
|
||||
desc,
|
||||
Some(error.to_string()),
|
||||
))
|
||||
.into()
|
||||
})
|
||||
}
|
||||
|
||||
let api_version = api
|
||||
.api_version::<dyn TransactionPaymentRuntimeApi<Block, Balance>>(&at)
|
||||
.map_err(|e| map_err(e, "Failed to get transaction payment runtime api version"))?
|
||||
.ok_or_else(|| {
|
||||
CallError::Custom(ErrorObject::owned(
|
||||
Error::RuntimeError.into(),
|
||||
"Transaction payment runtime api wasn't found in the runtime",
|
||||
None::<String>,
|
||||
))
|
||||
})?;
|
||||
|
||||
if api_version < 2 {
|
||||
#[allow(deprecated)]
|
||||
api.query_info_before_version_2(&at, uxt, encoded_len)
|
||||
.map_err(|e| map_err(e, "Unable to query dispatch info.").into())
|
||||
} else {
|
||||
let res = api
|
||||
.query_info(&at, uxt, encoded_len)
|
||||
.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
|
||||
|
||||
Ok(RuntimeDispatchInfo {
|
||||
weight: sp_weights::OldWeight(res.weight.ref_time()),
|
||||
class: res.class,
|
||||
partial_fee: res.partial_fee,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn query_fee_details(
|
||||
|
||||
Reference in New Issue
Block a user