difftreelog
allow conflicting type names
in: master
1 file changed
.docker/forkless-config/typeNames.jsonnetdiffbeforeafterboth1function(chain)2local3 typeName(id) = local4 ty = chain._meta.types.types[id],5 name = if std.objectHas(ty.type, "path") then6 std.join('::', ty.type.path)7 else if std.objectHas(ty.type.def, "primitive") then ty.type.def.primitive8 else if std.objectHas(ty.type.def, "tuple") then "(" + std.join(', ', std.map(typeName, ty.type.def.tuple)) + ")"9 else if std.objectHas(ty.type.def, "sequence") then "Vec<" + typeName(ty.type.def.sequence.type) + ">"10 else if std.objectHas(ty.type.def, "array") then "[" + typeName(ty.type.def.array.type) + "; " + ty.type.def.array.len + "]"11 else if std.objectHas(ty.type.def, "compact") then "Compact<" + typeName(ty.type.def.compact.type) + ">"12 else error "Can't generate useable name for " + ty.type,13 generics = if std.objectHas(ty.type, "params") then14 '<' + std.join(', ', std.map(function(p) if p.type == null then 'Spec#'+id else typeName(p.type), ty.type.params)) + '>'15 else ''16 ; name + generics,17 shortenPrefix(obj, prefix, short) = {18 [short]: obj[field]19 for field in std.objectFields(obj)20 // There should be at most one element with this prefix21 if std.startsWith(field, prefix)22 },23;2425local typesRaw = {26 [typeName(id)]: id27 for id in std.range(0, std.length(chain._meta.types.types)-1)28};2930local types = typesRaw + shortenPrefix(typesRaw, 'frame_system::AccountInfo<', 'AccountInfo');3132types33// local34// ;3536// local encoded = chain._encode(types['AccountInfo'], {37// nonce: 0,38// consumers: 3,39// providers: 1,40// sufficients: 0,41// data: {42// free: Munique,43// reserved: "0",44// misc_frozen: "0",45// fee_frozen: "0",46// },47// });4849// local systemAccount = chain._decode(types['AccountInfo'], encoded);5051// chain.System._encodeKey.Account(['0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'])1function(chain)2local3 typeName(id) = local4 ty = chain._meta.types.types[id],5 name = if std.objectHas(ty.type, "path") then6 std.join('::', ty.type.path)7 else if std.objectHas(ty.type.def, "primitive") then ty.type.def.primitive8 else if std.objectHas(ty.type.def, "tuple") then "(" + std.join(', ', std.map(typeName, ty.type.def.tuple)) + ")"9 else if std.objectHas(ty.type.def, "sequence") then "Vec<" + typeName(ty.type.def.sequence.type) + ">"10 else if std.objectHas(ty.type.def, "array") then "[" + typeName(ty.type.def.array.type) + "; " + ty.type.def.array.len + "]"11 else if std.objectHas(ty.type.def, "compact") then "Compact<" + typeName(ty.type.def.compact.type) + ">"12 else error "Can't generate useable name for " + ty.type,13 generics = if std.objectHas(ty.type, "params") then14 '<' + std.join(', ', std.map(function(p) if p.type == null then 'Spec#'+id else typeName(p.type), ty.type.params)) + '>'15 else ''16 ; name + generics,17 shortenPrefix(obj, prefix, short) = {18 [short]: obj[field]19 for field in std.objectFields(obj)20 // There should be at most one element with this prefix21 if std.startsWith(field, prefix)22 },23 makeObject(keyValues) = std.foldl(function(o, kv) if kv[0] in o then o else o + {[kv[0]]: kv[1]}, keyValues, {}),24;2526local typesRaw = makeObject([27 [typeName(id), id]28 for id in std.range(0, std.length(chain._meta.types.types)-1)29]);3031local types = typesRaw + shortenPrefix(typesRaw, 'frame_system::AccountInfo<', 'AccountInfo');3233types34// local35// ;3637// local encoded = chain._encode(types['AccountInfo'], {38// nonce: 0,39// consumers: 3,40// providers: 1,41// sufficients: 0,42// data: {43// free: Munique,44// reserved: "0",45// misc_frozen: "0",46// fee_frozen: "0",47// },48// });4950// local systemAccount = chain._decode(types['AccountInfo'], encoded);5152// chain.System._encodeKey.Account(['0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'])