Get all processors to compile again

Requires splitting `serai-cosign` into `serai-cosign` and `serai-cosign-types`
so the processor don't require `serai-client/serai` (not correct yet).
This commit is contained in:
Luke Parker
2025-09-02 02:16:21 -04:00
parent 75240ed327
commit ada94e8c5d
87 changed files with 413 additions and 301 deletions

View File

@@ -23,7 +23,7 @@ thiserror = { version = "2", default-features = false, optional = true }
bitvec = { version = "1", default-features = false, features = ["alloc", "serde"] }
hex = "0.4"
scale = { package = "parity-scale-codec", version = "3" }
scale = { package = "parity-scale-codec", version = "3", optional = true }
borsh = { version = "1", features = ["derive"] }
serde = { version = "1", features = ["derive"], optional = true }
serde_json = { version = "1", optional = true }
@@ -64,7 +64,7 @@ dockertest = "0.5"
serai-docker-tests = { path = "../../tests/docker" }
[features]
serai = ["thiserror/std", "serde", "serde_json", "multiaddr", "sp-core", "sp-runtime", "frame-system", "simple-request"]
serai = ["thiserror/std", "scale", "serde", "serde_json", "multiaddr", "sp-core", "sp-runtime", "frame-system", "simple-request"]
networks = []
bitcoin = ["networks", "dep:bitcoin"]
@@ -73,4 +73,4 @@ monero = ["networks", "dalek-ff-group", "ciphersuite", "monero-address"]
# Assumes the default usage is to use Serai as a DEX, which doesn't actually
# require connecting to a Serai node
default = ["bitcoin", "monero"]
default = ["bitcoin", "ethereum", "monero"]

View File

@@ -8,20 +8,6 @@ pub use serai::*;
#[cfg(not(feature = "serai"))]
pub use serai_abi::primitives;
#[cfg(not(feature = "serai"))]
mod other_primitives {
pub mod coins {
pub use serai_abi::coins::primitives;
}
pub mod validator_sets {
pub use serai_abi::validator_sets::primitives;
}
pub mod in_instructions {
pub use serai_abi::in_instructions::primitives;
}
}
#[cfg(not(feature = "serai"))]
pub use other_primitives::*;
#[cfg(test)]
mod tests;

View File

@@ -1,6 +1,5 @@
use core::{str::FromStr, fmt};
use scale::{Encode, Decode};
use borsh::{BorshSerialize, BorshDeserialize};
use bitcoin::{
@@ -11,10 +10,10 @@ use bitcoin::{
address::{AddressType, NetworkChecked, Address as BAddress},
};
use crate::primitives::ExternalAddress;
use crate::primitives::address::ExternalAddress;
// SCALE-encodable representation of Bitcoin addresses, used internally.
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, BorshSerialize, BorshDeserialize)]
#[derive(Clone, PartialEq, Eq, Debug, BorshSerialize, BorshDeserialize)]
enum EncodedAddress {
P2PKH([u8; 20]),
P2SH([u8; 20]),
@@ -124,7 +123,7 @@ impl TryFrom<ExternalAddress> for Address {
fn try_from(data: ExternalAddress) -> Result<Address, ()> {
// Decode as an EncodedAddress, then map to a ScriptBuf
let mut data = data.as_ref();
let encoded = EncodedAddress::decode(&mut data).map_err(|_| ())?;
let encoded = EncodedAddress::deserialize_reader(&mut data).map_err(|_| ())?;
if !data.is_empty() {
Err(())?
}
@@ -141,8 +140,8 @@ impl From<Address> for EncodedAddress {
impl From<Address> for ExternalAddress {
fn from(addr: Address) -> ExternalAddress {
// Safe since all variants are fixed-length and fit into MAX_ADDRESS_LEN
ExternalAddress::new(EncodedAddress::from(addr).encode()).unwrap()
// Safe since all variants are fixed-length and fit into `MAX_ADDRESS_LEN`
ExternalAddress::try_from(borsh::to_vec(&EncodedAddress::from(addr)).unwrap()).unwrap()
}
}

View File

@@ -3,7 +3,7 @@ use std::io::Read;
use borsh::{BorshSerialize, BorshDeserialize};
use crate::primitives::{MAX_ADDRESS_LEN, ExternalAddress};
use crate::primitives::address::ExternalAddress;
/// THe maximum amount of gas an address is allowed to specify as its gas limit.
///
@@ -33,7 +33,8 @@ impl ContractDeployment {
}
// The max address length, minus the type byte, minus the size of the gas
const MAX_CODE_LEN: usize = (MAX_ADDRESS_LEN as usize) - (1 + core::mem::size_of::<u32>());
const MAX_CODE_LEN: usize =
(ExternalAddress::MAX_LEN as usize) - (1 + core::mem::size_of::<u32>());
if code.len() > MAX_CODE_LEN {
None?;
}
@@ -111,7 +112,7 @@ impl From<Address> for ExternalAddress {
}
}
// We only construct addresses whose code is small enough this can safely be constructed
ExternalAddress::new(res).unwrap()
ExternalAddress::try_from(res).unwrap()
}
}

View File

@@ -5,7 +5,7 @@ use ciphersuite::Ciphersuite;
use monero_address::{Network, AddressType as MoneroAddressType, MoneroAddress};
use crate::primitives::ExternalAddress;
use crate::primitives::address::ExternalAddress;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
enum AddressType {
@@ -123,7 +123,7 @@ impl TryFrom<ExternalAddress> for Address {
impl From<Address> for ExternalAddress {
fn from(address: Address) -> ExternalAddress {
// This is 65 bytes which is less than MAX_ADDRESS_LEN
ExternalAddress::new(borsh::to_vec(&address).unwrap()).unwrap()
ExternalAddress::try_from(borsh::to_vec(&address).unwrap()).unwrap()
}
}

View File

@@ -25,16 +25,18 @@ scale-info = { version = "2", default-features = false, features = ["derive"], o
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "2bfdaed4b3614de2fe7d10e4ece3e6a912833e90", default-features = false }
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["alloc"] }
dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = false }
dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = false, features = ["alloc"] }
dkg = { package = "dkg-musig", path = "../../crypto/dkg/musig", default-features = false }
schnorrkel = { version = "0.11", default-features = false }
bech32 = { version = "0.11", default-features = false }
[dev-dependencies]
rand_core = { version = "0.6", default-features = false, features = ["std"] }
[features]
std = ["zeroize/std", "borsh/std", "bitvec/std", "scale/std", "scale-info/std", "sp-core/std", "ciphersuite/std", "dalek-ff-group/std", "dkg/std", "bech32/std"]
std = ["zeroize/std", "borsh/std", "bitvec/std", "scale?/std", "scale-info?/std", "sp-core/std", "ciphersuite/std", "dalek-ff-group/std", "dkg/std", "schnorrkel/std", "bech32/std"]
serde = []
non_canonical_scale_derivations = ["scale", "scale-info"]
default = ["std"]

View File

@@ -1,3 +1,4 @@
use core::convert::AsRef;
use alloc::vec::Vec;
use zeroize::Zeroize;
@@ -150,13 +151,18 @@ impl TryFrom<Vec<u8>> for ExternalAddress {
vec.try_into().map(ExternalAddress).map_err(|_| FromVecError::TooLong)
}
}
impl From<ExternalAddress> for Vec<u8> {
fn from(ext: ExternalAddress) -> Vec<u8> {
ext.0.into_inner()
}
}
impl AsRef<[u8]> for ExternalAddress {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}
impl zeroize::Zeroize for ExternalAddress {
fn zeroize(&mut self) {
self.0.as_mut().zeroize();

View File

@@ -40,6 +40,11 @@ impl From<Public> for sp_core::sr25519::Public {
)
)]
pub struct Signature(pub [u8; 64]);
impl From<schnorrkel::Signature> for Signature {
fn from(signature: schnorrkel::Signature) -> Self {
Self(signature.to_bytes())
}
}
impl From<sp_core::sr25519::Signature> for Signature {
fn from(signature: sp_core::sr25519::Signature) -> Self {
Self(signature.0)
@@ -71,6 +76,12 @@ pub struct ExternalKey(
pub BoundedVec<u8, ConstU32<{ ExternalKey::MAX_LEN }>>,
);
impl AsRef<[u8]> for ExternalKey {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}
impl Zeroize for ExternalKey {
fn zeroize(&mut self) {
self.0.as_mut().zeroize();

View File

@@ -93,6 +93,7 @@ impl BorshDeserialize for Batch {
}
/// An error incurred while pushing an instruction onto a `Batch`.
#[derive(Debug)]
pub enum PushInstructionError {
/// The Batch's max size was exceeded.
MaxSizeExceeded,

View File

@@ -80,7 +80,7 @@ pub struct RefundableInInstruction {
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, BorshSerialize, BorshDeserialize)]
pub struct InInstructionWithBalance {
/// The instruction on how to handle coins in.
pub instruction: OutInstruction,
pub instruction: InInstruction,
/// The coins in.
pub balance: ExternalBalance,
}

View File

@@ -1,5 +1,8 @@
mod r#in;
pub use r#in::{InInstruction, InInstructionWithBalance, PushInstructionError, Batch, SignedBatch};
pub use r#in::{
InInstruction, InInstructionWithBalance, RefundableInInstruction, PushInstructionError, Batch,
SignedBatch,
};
mod out;
pub use out::{OutInstruction, OutInstructionWithBalance};

View File

@@ -62,11 +62,11 @@ impl ExternalNetworkId {
}
/// The coins native to this network.
pub fn coins(&self) -> &'static [ExternalCoin] {
pub fn coins(&self) -> impl Iterator<Item = ExternalCoin> {
match self {
Self::Bitcoin => &[ExternalCoin::Bitcoin],
Self::Ethereum => &[ExternalCoin::Ether, ExternalCoin::Dai],
Self::Monero => &[ExternalCoin::Monero],
Self::Bitcoin => [ExternalCoin::Bitcoin].as_slice().iter().copied(),
Self::Ethereum => [ExternalCoin::Ether, ExternalCoin::Dai].as_slice().iter().copied(),
Self::Monero => [ExternalCoin::Monero].as_slice().iter().copied(),
}
}
}
@@ -119,11 +119,11 @@ impl NetworkId {
/// The coins native to this network.
pub fn coins(self) -> impl Iterator<Item = Coin> {
let (coins, external_coins): (&[Coin], &[ExternalCoin]) = match self {
NetworkId::Serai => (&[Coin::Serai], &[]),
NetworkId::External(ext) => (&[], ext.coins()),
let (coins, external_coins): (&[Coin], _) = match self {
NetworkId::Serai => (&[Coin::Serai], None),
NetworkId::External(ext) => (&[], Some(ext.coins())),
};
coins.iter().copied().chain(external_coins.iter().copied().map(Into::into))
coins.iter().copied().chain(external_coins.into_iter().flatten().map(Into::into))
}
}