@@ -678,14 +678,16 @@ private void WriteAction(MemoryStream ms, Core.Api.v1.Action action, Abi abi)
678678
679679 private void WriteAbiType ( MemoryStream ms , object value , string type , Abi abi )
680680 {
681+ var uwtype = UnwrapTypeDef ( abi , type ) ;
682+
681683 //optional type
682- if ( type . EndsWith ( "?" ) )
684+ if ( uwtype . EndsWith ( "?" ) )
683685 {
684686 WriteByte ( ms , value != null ? 1 : 0 ) ;
685687 if ( value != null )
686688 {
687689 WriteByte ( ms , 1 ) ;
688- type . Substring ( 0 , type . Length - 1 ) ;
690+ uwtype . Substring ( 0 , uwtype . Length - 1 ) ;
689691 }
690692 else
691693 {
@@ -695,10 +697,10 @@ private void WriteAbiType(MemoryStream ms, object value, string type, Abi abi)
695697 }
696698
697699 // array type
698- if ( type . EndsWith ( "[]" ) )
700+ if ( uwtype . EndsWith ( "[]" ) )
699701 {
700702 var items = ( ICollection ) value ;
701- var arrayType = type . Substring ( 0 , type . Length - 2 ) ;
703+ var arrayType = uwtype . Substring ( 0 , uwtype . Length - 2 ) ;
702704
703705 WriteVarUint32 ( ms , items . Count ) ;
704706 foreach ( var item in items )
@@ -715,7 +717,7 @@ private void WriteAbiType(MemoryStream ms, object value, string type, Abi abi)
715717 }
716718 else
717719 {
718- var abiStruct = GetTypeAbiStruct ( abi , type ) ;
720+ var abiStruct = abi . structs . FirstOrDefault ( s => s . name == uwtype ) ;
719721 if ( abiStruct != null )
720722 {
721723 WriteAbiStruct ( ms , value , abiStruct , abi ) ;
@@ -773,6 +775,17 @@ private void WriteAbiStruct(MemoryStream ms, object value, AbiStruct abiStruct,
773775 }
774776 }
775777
778+ private string UnwrapTypeDef ( Abi abi , string type )
779+ {
780+ var wtype = abi . types . FirstOrDefault ( t => t . new_type_name == type ) ;
781+ if ( wtype != null && wtype . type != type )
782+ {
783+ return UnwrapTypeDef ( abi , wtype . type ) ;
784+ }
785+
786+ return type ;
787+ }
788+
776789 private TSerializer GetTypeSerializerAndCache < TSerializer > ( string type , Dictionary < string , TSerializer > typeSerializers , Abi abi )
777790 {
778791 TSerializer nativeSerializer ;
@@ -781,11 +794,11 @@ private TSerializer GetTypeSerializerAndCache<TSerializer>(string type, Dictiona
781794 return nativeSerializer ;
782795 }
783796
784- var abiType = abi . types . FirstOrDefault ( t => t . new_type_name == type ) ;
797+ var abiTypeDef = abi . types . FirstOrDefault ( t => t . new_type_name == type ) ;
785798
786- if ( abiType != null )
799+ if ( abiTypeDef != null )
787800 {
788- var serializer = GetTypeSerializerAndCache ( abiType . type , typeSerializers , abi ) ;
801+ var serializer = GetTypeSerializerAndCache ( abiTypeDef . type , typeSerializers , abi ) ;
789802
790803 if ( serializer != null )
791804 {
@@ -796,29 +809,6 @@ private TSerializer GetTypeSerializerAndCache<TSerializer>(string type, Dictiona
796809
797810 return default ( TSerializer ) ;
798811 }
799-
800- private AbiStruct GetTypeAbiStruct ( Abi abi , string type )
801- {
802- var abiType = abi . types . FirstOrDefault ( t => t . new_type_name == type ) ;
803-
804- if ( abiType != null )
805- {
806- var abiStruct = abi . structs . FirstOrDefault ( s => s . name == abiType . type ) ;
807- if ( abiStruct != null )
808- {
809- return abiStruct ;
810- }
811- else
812- {
813- return GetTypeAbiStruct ( abi , abiType . type ) ;
814- }
815- }
816- else
817- {
818- return abi . structs . FirstOrDefault ( s => s . name == type ) ;
819- }
820- }
821-
822812 #endregion
823813
824814 #region Reader Functions
@@ -1227,9 +1217,10 @@ private List<AbiTable> ReadAbiTableList(byte[] data, ref int readIndex)
12271217 private object ReadAbiType ( byte [ ] data , string type , Abi abi , ref int readIndex )
12281218 {
12291219 object value = null ;
1220+ var uwtype = UnwrapTypeDef ( abi , type ) ;
12301221
12311222 //optional type
1232- if ( type . EndsWith ( "?" ) )
1223+ if ( uwtype . EndsWith ( "?" ) )
12331224 {
12341225 var opt = ( byte ) ReadByte ( data , ref readIndex ) ;
12351226
@@ -1240,9 +1231,9 @@ private object ReadAbiType(byte[] data, string type, Abi abi, ref int readIndex)
12401231 }
12411232
12421233 // array type
1243- if ( type . EndsWith ( "[]" ) )
1234+ if ( uwtype . EndsWith ( "[]" ) )
12441235 {
1245- var arrayType = type . Substring ( 0 , type . Length - 2 ) ;
1236+ var arrayType = uwtype . Substring ( 0 , uwtype . Length - 2 ) ;
12461237 var size = Convert . ToInt32 ( ReadVarUint32 ( data , ref readIndex ) ) ;
12471238 var items = new List < object > ( size ) ;
12481239
@@ -1262,7 +1253,7 @@ private object ReadAbiType(byte[] data, string type, Abi abi, ref int readIndex)
12621253 }
12631254 else
12641255 {
1265- var abiStruct = GetTypeAbiStruct ( abi , type ) ;
1256+ var abiStruct = abi . structs . FirstOrDefault ( s => s . name == uwtype ) ;
12661257 if ( abiStruct != null )
12671258 {
12681259 value = ReadAbiStruct ( data , abiStruct , abi , ref readIndex ) ;
0 commit comments