mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-08 21:48:02 +00:00
integrate new primitives with native-runtime
This commit is contained in:
@@ -229,7 +229,7 @@ mod test {
|
||||
let pair = Pair::from_seed(b"12345678901234567890123456789012");
|
||||
let public = pair.public();
|
||||
assert_eq!(public, "2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee".into());
|
||||
let message: Vec<u8> = FromHex::from_hex("2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee00000000000000000228000000d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a4500000000000000").unwrap();
|
||||
let message: Vec<u8> = FromHex::from_hex("2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee000000000000000002d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a4500000000000000").unwrap();
|
||||
let signature = pair.sign(&message[..]);
|
||||
assert!(signature.verify(&message[..], &public));
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ pub type BlockNumber = u64;
|
||||
pub type TxOrder = u64;
|
||||
|
||||
/// A hash of some data.
|
||||
pub type Hash = [u8; 32];
|
||||
pub type Hash = hash::H256;
|
||||
|
||||
/// Alias to 520-bit hash when used in the context of a signature.
|
||||
pub type Signature = hash::H512;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Transaction type.
|
||||
|
||||
use bytes::{self, Vec};
|
||||
use bytes::Vec;
|
||||
use codec::Slicable;
|
||||
use runtime_function::Function;
|
||||
|
||||
@@ -35,9 +35,30 @@ pub struct Transaction {
|
||||
pub nonce: ::TxOrder,
|
||||
/// The function that should be called.
|
||||
pub function: Function,
|
||||
/// Serialised input data to the function.
|
||||
#[serde(with = "bytes")]
|
||||
pub input_data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Slicable for Transaction {
|
||||
fn from_slice(value: &mut &[u8]) -> Option<Self> {
|
||||
Some(Transaction {
|
||||
signed: try_opt!(Slicable::from_slice(value)),
|
||||
nonce: try_opt!(Slicable::from_slice(value)),
|
||||
function: try_opt!(Slicable::from_slice(value)),
|
||||
})
|
||||
}
|
||||
|
||||
fn to_vec(&self) -> Vec<u8> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
self.signed.as_slice_then(|s| v.extend(s));
|
||||
self.nonce.as_slice_then(|s| v.extend(s));
|
||||
self.function.as_slice_then(|s| v.extend(s));
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
fn as_slice_then<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
f(self.to_vec().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
/// A transactions right from the external world. Unchecked.
|
||||
@@ -52,12 +73,7 @@ pub struct UncheckedTransaction {
|
||||
impl Slicable for UncheckedTransaction {
|
||||
fn from_slice(value: &mut &[u8]) -> Option<Self> {
|
||||
Some(UncheckedTransaction {
|
||||
transaction: Transaction {
|
||||
signed: try_opt!(Slicable::from_slice(value)),
|
||||
nonce: try_opt!(Slicable::from_slice(value)),
|
||||
function: try_opt!(Slicable::from_slice(value)),
|
||||
input_data: try_opt!(Slicable::from_slice(value)),
|
||||
},
|
||||
transaction: try_opt!(Transaction::from_slice(value)),
|
||||
signature: try_opt!(Slicable::from_slice(value)),
|
||||
})
|
||||
}
|
||||
@@ -68,7 +84,6 @@ impl Slicable for UncheckedTransaction {
|
||||
self.transaction.signed.as_slice_then(|s| v.extend(s));
|
||||
self.transaction.nonce.as_slice_then(|s| v.extend(s));
|
||||
self.transaction.function.as_slice_then(|s| v.extend(s));
|
||||
self.transaction.input_data.as_slice_then(|s| v.extend(s));
|
||||
self.signature.as_slice_then(|s| v.extend(s));
|
||||
|
||||
v
|
||||
@@ -92,3 +107,25 @@ impl fmt::Debug for UncheckedTransaction {
|
||||
write!(f, "UncheckedTransaction({:?})", self.transaction)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ::codec::Slicable;
|
||||
use runtime_function::Function;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn serialize_unchecked() {
|
||||
let tx = UncheckedTransaction {
|
||||
transaction: Transaction {
|
||||
signed: [1; 32],
|
||||
nonce: 999u64,
|
||||
function: Function::TimestampSet(135135),
|
||||
},
|
||||
signature: ::hash::H512([0; 64]),
|
||||
};
|
||||
|
||||
let v = Slicable::to_vec(&tx);
|
||||
assert_eq!(UncheckedTransaction::from_slice(&mut &v[..]).unwrap(), tx);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user