mirror of
https://github.com/serai-dex/serai.git
synced 2025-02-02 11:16:41 +00:00
Have Shorthand::Raw contain RefundableInInstruction, not an encoded RII
This commit is contained in:
parent
f8afb040dc
commit
e00aa3031c
3 changed files with 19 additions and 17 deletions
|
@ -67,9 +67,8 @@ Shorthand is an enum which expands to an Refundable In Instruction.
|
|||
|
||||
##### Raw
|
||||
|
||||
Raw Shorthand encodes a raw Refundable In Instruction in a Data, with no further
|
||||
processing. This is a verbose fallback option for infrequent use cases not
|
||||
covered by Shorthand.
|
||||
Raw Shorthand contains a Refundable In Instruction directly. This is a verbose
|
||||
fallback option for infrequent use cases not covered by Shorthand.
|
||||
|
||||
##### Swap
|
||||
|
||||
|
|
|
@ -30,7 +30,18 @@ pub enum InInstruction {
|
|||
Dex(Data),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Encode, Decode, TypeInfo, RuntimeDebug)]
|
||||
#[derive(
|
||||
Clone,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Encode,
|
||||
Decode,
|
||||
MaxEncodedLen,
|
||||
TypeInfo,
|
||||
RuntimeDebug,
|
||||
)]
|
||||
#[cfg_attr(feature = "std", derive(Zeroize))]
|
||||
pub struct RefundableInInstruction {
|
||||
pub origin: Option<ExternalAddress>,
|
||||
|
|
|
@ -6,7 +6,7 @@ use serde::{Serialize, Deserialize};
|
|||
use scale::{Encode, Decode, MaxEncodedLen};
|
||||
use scale_info::TypeInfo;
|
||||
|
||||
use serai_primitives::{Coin, Amount, SeraiAddress, ExternalAddress, Data};
|
||||
use serai_primitives::{Coin, Amount, SeraiAddress, ExternalAddress};
|
||||
|
||||
use tokens_primitives::OutInstruction;
|
||||
|
||||
|
@ -19,7 +19,7 @@ use crate::InInstruction;
|
|||
)]
|
||||
#[cfg_attr(feature = "std", derive(Zeroize))]
|
||||
pub enum Shorthand {
|
||||
Raw(Data),
|
||||
Raw(RefundableInInstruction),
|
||||
Swap {
|
||||
origin: Option<ExternalAddress>,
|
||||
coin: Coin,
|
||||
|
@ -36,14 +36,8 @@ pub enum Shorthand {
|
|||
|
||||
impl Shorthand {
|
||||
#[cfg(feature = "std")]
|
||||
pub fn transfer(origin: Option<ExternalAddress>, address: SeraiAddress) -> Option<Self> {
|
||||
Some(Self::Raw(
|
||||
Data::new(
|
||||
(RefundableInInstruction { origin, instruction: InInstruction::Transfer(address) })
|
||||
.encode(),
|
||||
)
|
||||
.ok()?,
|
||||
))
|
||||
pub fn transfer(origin: Option<ExternalAddress>, address: SeraiAddress) -> Self {
|
||||
Self::Raw(RefundableInInstruction { origin, instruction: InInstruction::Transfer(address) })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,9 +45,7 @@ impl TryFrom<Shorthand> for RefundableInInstruction {
|
|||
type Error = &'static str;
|
||||
fn try_from(shorthand: Shorthand) -> Result<RefundableInInstruction, &'static str> {
|
||||
Ok(match shorthand {
|
||||
Shorthand::Raw(raw) => {
|
||||
RefundableInInstruction::decode(&mut raw.data()).map_err(|_| "invalid raw instruction")?
|
||||
}
|
||||
Shorthand::Raw(instruction) => instruction,
|
||||
Shorthand::Swap { .. } => todo!(),
|
||||
Shorthand::AddLiquidity { .. } => todo!(),
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue