Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
change(serializer): on serialize_compact use self.resolve to resolve …
Browse files Browse the repository at this point in the history
…types
  • Loading branch information
pandres95 committed Dec 14, 2022
1 parent b989583 commit d5b3a26
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::prelude::*;
use bytes::BufMut;
use codec::Encode;
use core::fmt;
use scale_info::{PortableRegistry, TypeDefPrimitive, TypeInfo};
use scale_info::{PortableRegistry, TypeInfo};
use serde::{ser, Serialize};

use crate::{EnumVariant, SpecificType, TupleOrArray};
Expand Down Expand Up @@ -136,20 +136,14 @@ where
}

fn serialize_compact(&mut self, ty: u32, v: u128) -> Result<()> {
let type_def = self
.registry
.expect("registry not present")
.resolve(ty)
.expect("type T for Compact<T> not found in registry")
.type_def();

use scale_info::TypeDef::Primitive;
let type_def = self.resolve(ty);

use codec::Compact;
let compact_buffer = if matches!(type_def, Primitive(TypeDefPrimitive::U32)) {
let compact_buffer = if matches!(type_def, SpecificType::U32) {
Compact(v as u32).encode()
} else if matches!(type_def, Primitive(TypeDefPrimitive::U64)) {
} else if matches!(type_def, SpecificType::U64) {
Compact(v as u64).encode()
} else if matches!(type_def, Primitive(TypeDefPrimitive::U128)) {
} else if matches!(type_def, SpecificType::U128) {
Compact(v).encode()
} else {
todo!()
Expand Down

0 comments on commit d5b3a26

Please sign in to comment.