mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
fix parse_transaction on Rialto+Millau (#1360)
This commit is contained in:
committed by
Bastian Köcher
parent
c29bfcccc3
commit
133934df7c
@@ -27,7 +27,7 @@ use sp_runtime::{
|
|||||||
use sp_std::{convert::TryFrom, fmt::Debug, hash::Hash, str::FromStr, vec, vec::Vec};
|
use sp_std::{convert::TryFrom, fmt::Debug, hash::Hash, str::FromStr, vec, vec::Vec};
|
||||||
|
|
||||||
/// Chain call, that is either SCALE-encoded, or decoded.
|
/// Chain call, that is either SCALE-encoded, or decoded.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum EncodedOrDecodedCall<ChainCall> {
|
pub enum EncodedOrDecodedCall<ChainCall> {
|
||||||
/// The call that is SCALE-encoded.
|
/// The call that is SCALE-encoded.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ use std::time::Duration;
|
|||||||
pub type HeaderId = relay_utils::HeaderId<millau_runtime::Hash, millau_runtime::BlockNumber>;
|
pub type HeaderId = relay_utils::HeaderId<millau_runtime::Hash, millau_runtime::BlockNumber>;
|
||||||
|
|
||||||
/// Millau chain definition.
|
/// Millau chain definition.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Millau;
|
pub struct Millau;
|
||||||
|
|
||||||
impl ChainBase for Millau {
|
impl ChainBase for Millau {
|
||||||
@@ -154,8 +154,8 @@ impl TransactionSignScheme for Millau {
|
|||||||
let extra = &tx.signature.as_ref()?.2;
|
let extra = &tx.signature.as_ref()?.2;
|
||||||
Some(UnsignedTransaction {
|
Some(UnsignedTransaction {
|
||||||
call: tx.function.into(),
|
call: tx.function.into(),
|
||||||
nonce: Compact::<IndexOf<Self::Chain>>::decode(&mut &extra.4.encode()[..]).ok()?.into(),
|
nonce: Compact::<IndexOf<Self::Chain>>::decode(&mut &extra.5.encode()[..]).ok()?.into(),
|
||||||
tip: Compact::<BalanceOf<Self::Chain>>::decode(&mut &extra.6.encode()[..])
|
tip: Compact::<BalanceOf<Self::Chain>>::decode(&mut &extra.7.encode()[..])
|
||||||
.ok()?
|
.ok()?
|
||||||
.into(),
|
.into(),
|
||||||
})
|
})
|
||||||
@@ -167,3 +167,32 @@ pub type SigningParams = sp_core::sr25519::Pair;
|
|||||||
|
|
||||||
/// Millau header type used in headers sync.
|
/// Millau header type used in headers sync.
|
||||||
pub type SyncHeader = relay_substrate_client::SyncHeader<millau_runtime::Header>;
|
pub type SyncHeader = relay_substrate_client::SyncHeader<millau_runtime::Header>;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use relay_substrate_client::TransactionEra;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_transaction_works() {
|
||||||
|
let unsigned = UnsignedTransaction {
|
||||||
|
call: millau_runtime::Call::System(millau_runtime::SystemCall::remark {
|
||||||
|
remark: b"Hello world!".to_vec(),
|
||||||
|
})
|
||||||
|
.into(),
|
||||||
|
nonce: 777,
|
||||||
|
tip: 888,
|
||||||
|
};
|
||||||
|
let signed_transaction = Millau::sign_transaction(SignParam {
|
||||||
|
spec_version: 42,
|
||||||
|
transaction_version: 50000,
|
||||||
|
genesis_hash: [42u8; 64].into(),
|
||||||
|
signer: sp_core::sr25519::Pair::from_seed_slice(&[1u8; 32]).unwrap(),
|
||||||
|
era: TransactionEra::immortal(),
|
||||||
|
unsigned: unsigned.clone(),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
let parsed_transaction = Millau::parse_transaction(signed_transaction).unwrap();
|
||||||
|
assert_eq!(parsed_transaction, unsigned);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ use std::time::Duration;
|
|||||||
pub type HeaderId = relay_utils::HeaderId<rialto_runtime::Hash, rialto_runtime::BlockNumber>;
|
pub type HeaderId = relay_utils::HeaderId<rialto_runtime::Hash, rialto_runtime::BlockNumber>;
|
||||||
|
|
||||||
/// Rialto chain definition
|
/// Rialto chain definition
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Rialto;
|
pub struct Rialto;
|
||||||
|
|
||||||
impl ChainBase for Rialto {
|
impl ChainBase for Rialto {
|
||||||
@@ -152,8 +152,8 @@ impl TransactionSignScheme for Rialto {
|
|||||||
let extra = &tx.signature.as_ref()?.2;
|
let extra = &tx.signature.as_ref()?.2;
|
||||||
Some(UnsignedTransaction {
|
Some(UnsignedTransaction {
|
||||||
call: tx.function.into(),
|
call: tx.function.into(),
|
||||||
nonce: Compact::<IndexOf<Self::Chain>>::decode(&mut &extra.4.encode()[..]).ok()?.into(),
|
nonce: Compact::<IndexOf<Self::Chain>>::decode(&mut &extra.5.encode()[..]).ok()?.into(),
|
||||||
tip: Compact::<BalanceOf<Self::Chain>>::decode(&mut &extra.6.encode()[..])
|
tip: Compact::<BalanceOf<Self::Chain>>::decode(&mut &extra.7.encode()[..])
|
||||||
.ok()?
|
.ok()?
|
||||||
.into(),
|
.into(),
|
||||||
})
|
})
|
||||||
@@ -165,3 +165,32 @@ pub type SigningParams = sp_core::sr25519::Pair;
|
|||||||
|
|
||||||
/// Rialto header type used in headers sync.
|
/// Rialto header type used in headers sync.
|
||||||
pub type SyncHeader = relay_substrate_client::SyncHeader<rialto_runtime::Header>;
|
pub type SyncHeader = relay_substrate_client::SyncHeader<rialto_runtime::Header>;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use relay_substrate_client::TransactionEra;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_transaction_works() {
|
||||||
|
let unsigned = UnsignedTransaction {
|
||||||
|
call: rialto_runtime::Call::System(rialto_runtime::SystemCall::remark {
|
||||||
|
remark: b"Hello world!".to_vec(),
|
||||||
|
})
|
||||||
|
.into(),
|
||||||
|
nonce: 777,
|
||||||
|
tip: 888,
|
||||||
|
};
|
||||||
|
let signed_transaction = Rialto::sign_transaction(SignParam {
|
||||||
|
spec_version: 42,
|
||||||
|
transaction_version: 50000,
|
||||||
|
genesis_hash: [42u8; 32].into(),
|
||||||
|
signer: sp_core::sr25519::Pair::from_seed_slice(&[1u8; 32]).unwrap(),
|
||||||
|
era: TransactionEra::immortal(),
|
||||||
|
unsigned: unsigned.clone(),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
let parsed_transaction = Rialto::parse_transaction(signed_transaction).unwrap();
|
||||||
|
assert_eq!(parsed_transaction, unsigned);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ pub trait BlockWithJustification<Header> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Transaction before it is signed.
|
/// Transaction before it is signed.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct UnsignedTransaction<C: Chain> {
|
pub struct UnsignedTransaction<C: Chain> {
|
||||||
/// Runtime call of this transaction.
|
/// Runtime call of this transaction.
|
||||||
pub call: EncodedOrDecodedCall<C::Call>,
|
pub call: EncodedOrDecodedCall<C::Call>,
|
||||||
|
|||||||
Reference in New Issue
Block a user