mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 01:05:41 +00:00
Impl From<UncheckedExtrinsic> for OpaqueExtrinsic (#6522)
This commit is contained in:
@@ -424,13 +424,12 @@ mod tests {
|
||||
use node_primitives::{Block, DigestItem, Signature};
|
||||
use node_runtime::{BalancesCall, Call, UncheckedExtrinsic, Address};
|
||||
use node_runtime::constants::{currency::CENTS, time::SLOT_DURATION};
|
||||
use codec::{Encode, Decode};
|
||||
use codec::Encode;
|
||||
use sp_core::{crypto::Pair as CryptoPair, H256};
|
||||
use sp_runtime::{
|
||||
generic::{BlockId, Era, Digest, SignedPayload},
|
||||
traits::{Block as BlockT, Header as HeaderT},
|
||||
traits::Verify,
|
||||
OpaqueExtrinsic,
|
||||
};
|
||||
use sp_timestamp;
|
||||
use sp_finality_tracker;
|
||||
@@ -605,16 +604,13 @@ mod tests {
|
||||
signer.sign(payload)
|
||||
});
|
||||
let (function, extra, _) = raw_payload.deconstruct();
|
||||
let xt = UncheckedExtrinsic::new_signed(
|
||||
index += 1;
|
||||
UncheckedExtrinsic::new_signed(
|
||||
function,
|
||||
from.into(),
|
||||
signature.into(),
|
||||
extra,
|
||||
).encode();
|
||||
let v: Vec<u8> = Decode::decode(&mut xt.as_slice()).unwrap();
|
||||
|
||||
index += 1;
|
||||
OpaqueExtrinsic(v)
|
||||
).into()
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ use crate::{
|
||||
},
|
||||
generic::CheckedExtrinsic,
|
||||
transaction_validity::{TransactionValidityError, InvalidTransaction},
|
||||
OpaqueExtrinsic,
|
||||
};
|
||||
|
||||
const TRANSACTION_VERSION: u8 = 4;
|
||||
@@ -316,6 +317,23 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<Address, Call, Signature, Extra> From<UncheckedExtrinsic<Address, Call, Signature, Extra>>
|
||||
for OpaqueExtrinsic
|
||||
where
|
||||
Address: Encode,
|
||||
Signature: Encode,
|
||||
Call: Encode,
|
||||
Extra: SignedExtension,
|
||||
{
|
||||
fn from(extrinsic: UncheckedExtrinsic<Address, Call, Signature, Extra>) -> Self {
|
||||
OpaqueExtrinsic::from_bytes(extrinsic.encode().as_slice())
|
||||
.expect(
|
||||
"both OpaqueExtrinsic and UncheckedExtrinsic have encoding that is compatible with \
|
||||
raw Vec<u8> encoding; qed"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -424,4 +442,13 @@ mod tests {
|
||||
let as_vec: Vec<u8> = Decode::decode(&mut encoded.as_slice()).unwrap();
|
||||
assert_eq!(as_vec.encode(), encoded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn conversion_to_opaque() {
|
||||
let ux = Ex::new_unsigned(vec![0u8; 0]);
|
||||
let encoded = ux.encode();
|
||||
let opaque: OpaqueExtrinsic = ux.into();
|
||||
let opaque_encoded = opaque.encode();
|
||||
assert_eq!(opaque_encoded, encoded);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -714,7 +714,14 @@ macro_rules! assert_eq_error_rate {
|
||||
/// Simple blob to hold an extrinsic without committing to its format and ensure it is serialized
|
||||
/// correctly.
|
||||
#[derive(PartialEq, Eq, Clone, Default, Encode, Decode)]
|
||||
pub struct OpaqueExtrinsic(pub Vec<u8>);
|
||||
pub struct OpaqueExtrinsic(Vec<u8>);
|
||||
|
||||
impl OpaqueExtrinsic {
|
||||
/// Convert an encoded extrinsic to an `OpaqueExtrinsic`.
|
||||
pub fn from_bytes(mut bytes: &[u8]) -> Result<Self, codec::Error> {
|
||||
OpaqueExtrinsic::decode(&mut bytes)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl parity_util_mem::MallocSizeOf for OpaqueExtrinsic {
|
||||
|
||||
Reference in New Issue
Block a user