mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 02:51:08 +00:00
Simplify the TxPayload trait a little (#638)
* Simplify TxPayload trait; don't need to get names unless validating * cargo fmt * Expose a way to create a SubmittableExtrinsic from pre-prepaed tx bytes * remove unneeded refs
This commit is contained in:
+28
-15
@@ -57,14 +57,14 @@ impl<T: Config, C: OfflineClientT<T>> TxClient<T, C> {
|
||||
where
|
||||
Call: TxPayload,
|
||||
{
|
||||
if let Some(actual_hash) = call.validation_hash() {
|
||||
if let Some(details) = call.validation_details() {
|
||||
let metadata = self.client.metadata();
|
||||
let expected_hash =
|
||||
metadata.call_hash(call.pallet_name(), call.call_name())?;
|
||||
if actual_hash != expected_hash {
|
||||
metadata.call_hash(details.pallet_name, details.call_name)?;
|
||||
if details.hash != expected_hash {
|
||||
return Err(crate::metadata::MetadataError::IncompatibleCallMetadata(
|
||||
call.pallet_name().into(),
|
||||
call.call_name().into(),
|
||||
details.pallet_name.into(),
|
||||
details.call_name.into(),
|
||||
)
|
||||
.into())
|
||||
}
|
||||
@@ -114,11 +114,10 @@ impl<T: Config, C: OfflineClientT<T>> TxClient<T, C> {
|
||||
};
|
||||
|
||||
// Wrap in Encoded to ensure that any more "encode" calls leave it in the right state.
|
||||
Ok(SubmittableExtrinsic {
|
||||
client: self.client.clone(),
|
||||
encoded: Encoded(extrinsic),
|
||||
marker: std::marker::PhantomData,
|
||||
})
|
||||
Ok(SubmittableExtrinsic::from_bytes(
|
||||
self.client.clone(),
|
||||
extrinsic,
|
||||
))
|
||||
}
|
||||
|
||||
/// Creates a raw signed extrinsic without submitting it.
|
||||
@@ -202,11 +201,10 @@ impl<T: Config, C: OfflineClientT<T>> TxClient<T, C> {
|
||||
|
||||
// Wrap in Encoded to ensure that any more "encode" calls leave it in the right state.
|
||||
// maybe we can just return the raw bytes..
|
||||
Ok(SubmittableExtrinsic {
|
||||
client: self.client.clone(),
|
||||
encoded: Encoded(extrinsic),
|
||||
marker: std::marker::PhantomData,
|
||||
})
|
||||
Ok(SubmittableExtrinsic::from_bytes(
|
||||
self.client.clone(),
|
||||
extrinsic,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,6 +328,21 @@ where
|
||||
T: Config,
|
||||
C: OfflineClientT<T>,
|
||||
{
|
||||
/// Create a [`SubmittableExtrinsic`] from some already-signed and prepared
|
||||
/// extrinsic bytes, and some client (anything implementing [`OfflineClientT`]
|
||||
/// or [`OnlineClientT`]).
|
||||
///
|
||||
/// Prefer to use [`TxClient`] to create and sign extrinsics. This is simply
|
||||
/// exposed in case you want to skip this process and submit something you've
|
||||
/// already created.
|
||||
pub fn from_bytes(client: C, tx_bytes: Vec<u8>) -> Self {
|
||||
Self {
|
||||
client,
|
||||
encoded: Encoded(tx_bytes),
|
||||
marker: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the SCALE encoded extrinsic bytes.
|
||||
pub fn encoded(&self) -> &[u8] {
|
||||
&self.encoded.0
|
||||
|
||||
Reference in New Issue
Block a user