Add borsh impls for SignedEmbeddedEllipticCurveKeys

This commit is contained in:
Luke Parker
2025-09-05 07:21:07 -04:00
parent 28dbef8a1c
commit 2077e485bb
4 changed files with 101 additions and 78 deletions

View File

@@ -252,35 +252,7 @@ mod substrate {
}
impl Decode for Transaction {
fn decode<I: scale::Input>(input: &mut I) -> Result<Self, scale::Error> {
struct ScaleRead<'a, I: scale::Input>(&'a mut I, Option<scale::Error>);
impl<I: scale::Input> borsh::io::Read for ScaleRead<'_, I> {
fn read(&mut self, buf: &mut [u8]) -> borsh::io::Result<usize> {
let remaining_len = self.0.remaining_len().map_err(|err| {
self.1 = Some(err);
#[allow(clippy::io_other_error)]
borsh::io::Error::new(borsh::io::ErrorKind::Other, "")
})?;
// If we're still calling `read`, we try to read at least one more byte
let to_read = buf.len().min(remaining_len.unwrap_or(1));
// This may not be _allocated_ making this over-zealous, but it's the best we can do
self.0.on_before_alloc_mem(to_read).map_err(|err| {
self.1 = Some(err);
#[allow(clippy::io_other_error)]
borsh::io::Error::new(borsh::io::ErrorKind::Other, "")
})?;
self.0.read(&mut buf[.. to_read]).map_err(|err| {
self.1 = Some(err);
#[allow(clippy::io_other_error)]
borsh::io::Error::new(borsh::io::ErrorKind::Other, "")
})?;
Ok(to_read)
}
}
let mut input = ScaleRead(input, None);
match Self::deserialize_reader(&mut input) {
Ok(res) => Ok(res),
Err(_) => Err(input.1.unwrap()),
}
serai_primitives::read_scale_as_borsh(input)
}
}

View File

@@ -1,9 +1,7 @@
use borsh::{BorshSerialize, BorshDeserialize};
use sp_core::{ConstU32, bounded::BoundedVec};
use serai_primitives::{
crypto::{ExternalKey, EmbeddedEllipticCurveKeys, KeyPair, Signature},
crypto::{SignedEmbeddedEllipticCurveKeys, KeyPair, Signature},
address::SeraiAddress,
balance::Amount,
network_id::*,
@@ -40,14 +38,8 @@ pub enum Call {
},
/// Set a validator's keys on embedded elliptic curves for a specific network.
set_embedded_elliptic_curve_keys {
/// The network the origin is setting their embedded elliptic curve keys for.
network: ExternalNetworkId,
/// The keys on the embedded elliptic curves.
#[borsh(
serialize_with = "serai_primitives::sp_borsh::borsh_serialize_bounded_vec",
deserialize_with = "serai_primitives::sp_borsh::borsh_deserialize_bounded_vec"
)]
keys: EmbeddedEllipticCurveKeys,
keys: SignedEmbeddedEllipticCurveKeys,
},
/// Allocate stake to a network.
allocate {