mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 05:09:22 +00:00
* Add SignalsConfig to chain_spec * Correct multiexp feature flagging for rand_core std * Remove bincode for borsh Replaces a non-canonical encoding with a canonical encoding which additionally should be faster. Also fixes an issue where we used bincode in transcripts where it cannot be trusted. This ended up fixing a myriad of other bugs observed, unfortunately. Accordingly, it either has to be merged or the bug fixes from it must be ported to a new PR. * Make serde optional, minimize usage * Make borsh an optional dependency of substrate/ crates * Remove unused dependencies * Use [u8; 64] where possible in the processor messages * Correct borsh feature flagging
57 lines
1.6 KiB
Rust
57 lines
1.6 KiB
Rust
#[cfg(feature = "std")]
|
|
use zeroize::Zeroize;
|
|
|
|
#[cfg(feature = "borsh")]
|
|
use borsh::{BorshSerialize, BorshDeserialize};
|
|
#[cfg(feature = "serde")]
|
|
use serde::{Serialize, Deserialize};
|
|
|
|
use scale::{Encode, Decode, MaxEncodedLen};
|
|
use scale_info::TypeInfo;
|
|
|
|
use serai_primitives::{Coin, Amount, SeraiAddress, ExternalAddress};
|
|
|
|
use coins_primitives::OutInstruction;
|
|
|
|
use crate::RefundableInInstruction;
|
|
#[cfg(feature = "std")]
|
|
use crate::InInstruction;
|
|
|
|
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
|
|
#[cfg_attr(feature = "std", derive(Zeroize))]
|
|
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
pub enum Shorthand {
|
|
Raw(RefundableInInstruction),
|
|
Swap {
|
|
origin: Option<ExternalAddress>,
|
|
coin: Coin,
|
|
minimum: Amount,
|
|
out: OutInstruction,
|
|
},
|
|
SwapAndAddLiquidity {
|
|
origin: Option<ExternalAddress>,
|
|
minimum: Amount,
|
|
gas: Amount,
|
|
address: SeraiAddress,
|
|
},
|
|
}
|
|
|
|
impl Shorthand {
|
|
#[cfg(feature = "std")]
|
|
pub fn transfer(origin: Option<ExternalAddress>, address: SeraiAddress) -> Self {
|
|
Self::Raw(RefundableInInstruction { origin, instruction: InInstruction::Transfer(address) })
|
|
}
|
|
}
|
|
|
|
impl TryFrom<Shorthand> for RefundableInInstruction {
|
|
type Error = &'static str;
|
|
fn try_from(shorthand: Shorthand) -> Result<RefundableInInstruction, &'static str> {
|
|
Ok(match shorthand {
|
|
Shorthand::Raw(instruction) => instruction,
|
|
Shorthand::Swap { .. } => todo!(),
|
|
Shorthand::SwapAndAddLiquidity { .. } => todo!(),
|
|
})
|
|
}
|
|
}
|