@@ -13,6 +13,8 @@ import { knownOrigins } from '../../interfaces/runtime/definitions';
1313
1414interface MapDef {
1515 hashers : StorageHasherV13 [ ] ;
16+ isLinked : boolean ;
17+ isOptional : boolean ;
1618 keys : Type [ ] ;
1719 value : Type ;
1820}
@@ -211,7 +213,7 @@ function convertEvents (specs: TypeSpec[], registry: Registry, modName: Text, ev
211213 } ] ) ;
212214}
213215
214- function createMapEntry ( specs : TypeSpec [ ] , registry : Registry , sectionTypes : OverrideModuleType , { hashers, keys, value } : MapDef ) : StorageEntryTypeV14 {
216+ function createMapEntry ( specs : TypeSpec [ ] , registry : Registry , sectionTypes : OverrideModuleType , { hashers, isLinked , isOptional , keys, value } : MapDef ) : StorageEntryTypeV14 {
215217 setTypeOverride ( sectionTypes , [ value , ...( Array . isArray ( keys ) ? keys : [ keys ] ) ] ) ;
216218
217219 return registry . createTypeUnsafe ( 'StorageEntryTypeV14' , [ {
@@ -220,7 +222,11 @@ function createMapEntry (specs: TypeSpec[], registry: Registry, sectionTypes: Ov
220222 key : hashers . length === 1
221223 ? compatType ( specs , keys [ 0 ] )
222224 : makeTupleType ( specs , keys . map ( ( t ) => compatType ( specs , t ) ) ) ,
223- value : compatType ( specs , value )
225+ value : isLinked
226+ // For previous-generation linked-map support, the actual storage result
227+ // is a Tuple with the value and the Linkage (Option appears in teh value-part only)
228+ ? compatType ( specs , `(${ isOptional ? `Option<${ value . toString ( ) } >` : value . toString ( ) } , Linkage<${ keys [ 0 ] . toString ( ) } >)` )
229+ : compatType ( specs , value )
224230 }
225231 } ] ) ;
226232}
@@ -247,6 +253,8 @@ function convertStorage (specs: TypeSpec[], registry: Registry, { items, prefix
247253
248254 entryType = createMapEntry ( specs , registry , sectionTypes , {
249255 hashers : [ map . hasher ] ,
256+ isLinked : map . linked . isTrue ,
257+ isOptional : modifier . isOptional ,
250258 keys : [ map . key ] ,
251259 value : map . value
252260 } ) ;
@@ -255,6 +263,8 @@ function convertStorage (specs: TypeSpec[], registry: Registry, { items, prefix
255263
256264 entryType = createMapEntry ( specs , registry , sectionTypes , {
257265 hashers : [ dm . hasher , dm . key2Hasher ] ,
266+ isLinked : false ,
267+ isOptional : modifier . isOptional ,
258268 keys : [ dm . key1 , dm . key2 ] ,
259269 value : dm . value
260270 } ) ;
@@ -263,6 +273,8 @@ function convertStorage (specs: TypeSpec[], registry: Registry, { items, prefix
263273
264274 entryType = createMapEntry ( specs , registry , sectionTypes , {
265275 hashers : nm . hashers ,
276+ isLinked : false ,
277+ isOptional : modifier . isOptional ,
266278 keys : nm . keyVec ,
267279 value : nm . value
268280 } ) ;
0 commit comments