From e00aa3031cd404bcc82fc99e19e3a4221866feea Mon Sep 17 00:00:00 2001 From: Luke Parker <lukeparker5132@gmail.com> Date: Wed, 26 Jul 2023 14:00:30 -0400 Subject: [PATCH] Have Shorthand::Raw contain RefundableInInstruction, not an encoded RII --- docs/integrations/Instructions.md | 5 ++--- .../in-instructions/primitives/src/lib.rs | 13 ++++++++++++- .../primitives/src/shorthand.rs | 18 +++++------------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/docs/integrations/Instructions.md b/docs/integrations/Instructions.md index e92e49ff..43516214 100644 --- a/docs/integrations/Instructions.md +++ b/docs/integrations/Instructions.md @@ -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 diff --git a/substrate/in-instructions/primitives/src/lib.rs b/substrate/in-instructions/primitives/src/lib.rs index c2bb1783..62dd54d6 100644 --- a/substrate/in-instructions/primitives/src/lib.rs +++ b/substrate/in-instructions/primitives/src/lib.rs @@ -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>, diff --git a/substrate/in-instructions/primitives/src/shorthand.rs b/substrate/in-instructions/primitives/src/shorthand.rs index 7a86167d..a382d052 100644 --- a/substrate/in-instructions/primitives/src/shorthand.rs +++ b/substrate/in-instructions/primitives/src/shorthand.rs @@ -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!(), })