From b4e8905053760a1c7bcd833bfc0d3230dbd356f6 Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Mon, 4 Nov 2019 16:00:54 +0100 Subject: [PATCH] Event arguments are Vec not HashSet (#27) Event arguments in the metadata are treated as `Vec` instead of `HashSet`. This fixes an issue with event arguments of the same name. For example the `Balances::Transfer` event has four arguments: `AccountId` (from), `AccountId` (to), `Balance` (value), `Balance` (fee). Before this change the code would only try to parse the two distinct arguments `AccountId` and `Balance` and decoding would fail. --- src/metadata.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/metadata.rs b/src/metadata.rs index f6d014ce1e..8f8e46fe92 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -13,10 +13,7 @@ use runtime_metadata::{ META_RESERVED, }; use std::{ - collections::{ - HashMap, - HashSet, - }, + collections::HashMap, convert::TryFrom, marker::PhantomData, str::FromStr, @@ -197,7 +194,7 @@ impl StorageMap { #[derive(Clone, Debug)] pub struct ModuleEventMetadata { pub name: String, - arguments: HashSet, + arguments: Vec, } impl ModuleEventMetadata { @@ -355,10 +352,10 @@ fn convert_event( event: runtime_metadata::EventMetadata, ) -> Result { let name = convert(event.name)?; - let mut arguments = HashSet::new(); + let mut arguments = Vec::new(); for arg in convert(event.arguments)? { let arg = arg.parse::()?; - arguments.insert(arg); + arguments.push(arg); } Ok(ModuleEventMetadata { name, arguments }) }