Partial fee estimates for SubmittableExtrinsic (#910)

* add partial_fee estimation to submittable extrinsic

* add integration test

* make functions immune to doctest

* add doc test

* inline encoded_with_len, fix tests

* fix test fmt

* remove unused imoort

* Bump h2 from 0.3.16 to 0.3.17 (#911)

Bumps [h2](https://github.com/hyperium/h2) from 0.3.16 to 0.3.17.
- [Release notes](https://github.com/hyperium/h2/releases)
- [Changelog](https://github.com/hyperium/h2/blob/master/CHANGELOG.md)
- [Commits](https://github.com/hyperium/h2/compare/v0.3.16...v0.3.17)

---
updated-dependencies:
- dependency-name: h2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* call_raw returns Res: Decode

* remove import

* remove struct

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
Tadeo Hepperle
2023-04-17 10:40:48 +02:00
committed by GitHub
parent e642740081
commit 2997b1bdc3
7 changed files with 138 additions and 69 deletions
+25 -5
View File
@@ -2,17 +2,18 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use super::TxPayload;
use std::borrow::Cow;
use codec::{Compact, Encode};
use derivative::Derivative;
use crate::{
client::{OfflineClientT, OnlineClientT},
config::{Config, ExtrinsicParams, Hasher},
error::Error,
tx::{Signer as SignerT, TxProgress},
tx::{Signer as SignerT, TxPayload, TxProgress},
utils::{Encoded, PhantomDataSendSync},
};
use codec::{Compact, Encode};
use derivative::Derivative;
use std::borrow::Cow;
// This is returned from an API below, so expose it here.
pub use crate::rpc::types::DryRunResult;
@@ -465,4 +466,23 @@ where
let dry_run_bytes = self.client.rpc().dry_run(self.encoded(), at).await?;
dry_run_bytes.into_dry_run_result(&self.client.metadata())
}
/// This returns an estimate for what the extrinsic is expected to cost to execute, less any tips.
/// The actual amount paid can vary from block to block based on node traffic and other factors.
pub async fn partial_fee_estimate(&self) -> Result<u128, Error> {
let mut params = self.encoded().to_vec();
(self.encoded().len() as u32).encode_to(&mut params);
// destructuring RuntimeDispatchInfo, see type information <https://paritytech.github.io/substrate/master/pallet_transaction_payment_rpc_runtime_api/struct.RuntimeDispatchInfo.html>
// data layout: {weight_ref_time: Compact<u64>, weight_proof_size: Compact<u64>, class: u8, partial_fee: u128}
let (_, _, _, partial_fee) = self
.client
.rpc()
.state_call::<(Compact<u64>, Compact<u64>, u8, u128)>(
"TransactionPaymentApi_query_info",
Some(&params),
None,
)
.await?;
Ok(partial_fee)
}
}