Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
S0c5 committed Apr 19, 2024
1 parent cbb8a1a commit 616f261
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
3 changes: 0 additions & 3 deletions scales/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,9 @@ impl SpecificType {
A: AsRef<[u8]> + PartialEq + core::fmt::Debug,
B: AsRef<[u8]> + PartialEq + core::fmt::Debug,
{


match self {
SpecificType::Variant(_, _, Some(_)) => Some(self),
SpecificType::Variant(_, ref mut variants, idx @ None) => {

let (vf, _) = variants
.iter()
.map(|v| (v.index, get_field(&v)))
Expand Down
20 changes: 2 additions & 18 deletions scales/src/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use core::fmt::{self, Debug};
use scale_info::{PortableRegistry, TypeInfo};
use serde::{ser, Serialize};


use crate::{EnumVariant, SpecificType, TupleOrArray};

type TypeId = u32;
Expand Down Expand Up @@ -441,7 +440,6 @@ where
Some(SpecificType::Str) | None => Ok(None),
// { "foo": "Bar" } => "Bar" might be an enum variant
Some(ref mut var @ SpecificType::Variant(_, _, None)) => {

var.pick_mut(to_vec(val)?, |k| to_vec(k.name()).unwrap())
.ok_or_else(|| Error::BadInput("Invalid ".into()))?;
self.out.put_u8(var.variant_id());
Expand Down Expand Up @@ -591,12 +589,9 @@ where
where
T: Serialize,
{


match self {
TypedSerializer::Enum(ser) => {
if let Some(ref mut var @ SpecificType::Variant(_, _, None)) = ser.ty {

let key_data = to_vec(key)?;

// assume the key is the name of the variant
Expand All @@ -618,26 +613,19 @@ where
where
T: Serialize,
{

//
match self {
TypedSerializer::Composite(ser, types) => {



let mut ty = ser.resolve(types.remove(0));
// serde_json unwraps newtypes
if let SpecificType::StructNewType(ty_id) = ty {
ty = ser.resolve(ty_id)
}


ser.ty = Some(ty);
}
TypedSerializer::Enum(ser) => {

if let Some(var @ SpecificType::Variant(_, _, Some(_))) = &ser.ty {

if let EnumVariant::NewType(_, _, ty_id) = var.into() {
let ty = ser.resolve(ty_id);

Expand Down Expand Up @@ -1316,11 +1304,8 @@ mod tests {
}
});


let call_data = to_vec_with_info(
&transfer_call,
(&registry, 106u32).into(),
).expect("call data");
let call_data =
to_vec_with_info(&transfer_call, (&registry, 106u32).into()).expect("call data");

let encooded = hex::encode(&call_data);

Expand All @@ -1329,7 +1314,6 @@ mod tests {
format!("0x04{}", encooded)
);


Ok(())
}
}

0 comments on commit 616f261

Please sign in to comment.