mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 23:15:42 +00:00
Check signatures as "Compact" in statement distribution (#5071)
* allow converting payloads _up_ * convert to superpayload in statement-distribution * Update primitives/src/v2/signed.rs Co-authored-by: Andronik <write@reusable.software> Co-authored-by: Andronik <write@reusable.software>
This commit is contained in:
committed by
GitHub
parent
22a7fad75f
commit
8a17c614f0
@@ -660,6 +660,8 @@ impl From<BitVec<u8, bitvec::order::Lsb0>> for AvailabilityBitfield {
|
||||
|
||||
/// A signed compact statement, suitable to be sent to the chain.
|
||||
pub type SignedStatement = Signed<CompactStatement>;
|
||||
/// A signed compact statement, with signature not yet checked.
|
||||
pub type UncheckedSignedStatement = UncheckedSigned<CompactStatement>;
|
||||
|
||||
/// A bitfield signed by a particular validator about the availability of pending candidates.
|
||||
pub type SignedAvailabilityBitfield = Signed<AvailabilityBitfield>;
|
||||
|
||||
@@ -148,6 +148,30 @@ impl<Payload: EncodeAs<RealPayload>, RealPayload: Encode> Signed<Payload, RealPa
|
||||
{
|
||||
Signed(self.0.unchecked_convert_payload())
|
||||
}
|
||||
|
||||
/// Convert `Payload` into some claimed `SuperPayload` if the encoding matches.
|
||||
///
|
||||
/// Succeeds if and only if the super-payload provided actually encodes as
|
||||
/// the expected payload.
|
||||
pub fn convert_to_superpayload<SuperPayload>(
|
||||
self,
|
||||
claimed: SuperPayload,
|
||||
) -> Result<Signed<SuperPayload, RealPayload>, (Self, SuperPayload)>
|
||||
where
|
||||
SuperPayload: EncodeAs<RealPayload>,
|
||||
Payload: Encode,
|
||||
{
|
||||
if claimed.encode_as() == self.0.payload.encode_as() {
|
||||
Ok(Signed(UncheckedSigned {
|
||||
payload: claimed,
|
||||
validator_index: self.0.validator_index,
|
||||
signature: self.0.signature,
|
||||
real_payload: sp_std::marker::PhantomData,
|
||||
}))
|
||||
} else {
|
||||
Err((self, claimed))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We can't bound this on `Payload: Into<RealPayload>` because that conversion consumes
|
||||
|
||||
Reference in New Issue
Block a user