-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLA-1977] Parses any specVersion of metadata (#38)
- Loading branch information
1 parent
98f9286
commit b7fe8c0
Showing
14 changed files
with
265 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
export 'v100.dart'; | ||
export 'v101.dart'; | ||
export 'v102.dart'; | ||
export 'v103.dart'; | ||
export 'v104.dart'; | ||
export 'v105.dart'; | ||
export 'v106.dart'; | ||
export 'v107.dart'; | ||
export 'v110.dart'; | ||
export 'v120.dart'; | ||
export 'v1021.dart'; | ||
export 'v1022.dart'; | ||
export 'v1023.dart'; | ||
export 'v1024.dart'; | ||
export 'v1025.dart'; | ||
export 'v1026.dart'; | ||
export 'v103.dart'; | ||
export 'v1030.dart'; | ||
export 'v1031.dart'; | ||
export 'v1032.dart'; | ||
export 'v104.dart'; | ||
export 'v105.dart'; | ||
export 'v106.dart'; | ||
export 'v107.dart'; | ||
export 'v110.dart'; | ||
export 'v120.dart'; |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,92 @@ | ||
import 'canary/canary.dart' as c; | ||
import 'production/production.dart' as p; | ||
|
||
String canary() { | ||
String canaryLatest() { | ||
return c.v1032; | ||
} | ||
|
||
String production() { | ||
String productionLatest() { | ||
return p.v1026; | ||
} | ||
|
||
String metadata(network, specVersion) { | ||
if (network == 'canary-relaychain') { | ||
return canarySpec(specVersion); | ||
} | ||
|
||
return productionSpec(specVersion); | ||
} | ||
|
||
String canarySpec(specVersion) { | ||
switch (specVersion) { | ||
case 100: | ||
return c.v100; | ||
case 101: | ||
return c.v101; | ||
case 102: | ||
return c.v102; | ||
case 103: | ||
return c.v103; | ||
case 104: | ||
return c.v104; | ||
case 105: | ||
return c.v105; | ||
case 106: | ||
return c.v106; | ||
case 107: | ||
return c.v107; | ||
case 110: | ||
return c.v110; | ||
case 120: | ||
return c.v120; | ||
case 1021: | ||
return c.v1021; | ||
case 1022: | ||
return c.v1022; | ||
case 1023: | ||
return c.v1023; | ||
case 1024: | ||
return c.v1024; | ||
case 1025: | ||
return c.v1025; | ||
case 1026: | ||
return c.v1026; | ||
case 1030: | ||
return c.v1030; | ||
case 1031: | ||
return c.v1031; | ||
case 1032: | ||
return c.v1032; | ||
default: | ||
return canaryLatest(); | ||
} | ||
} | ||
|
||
String productionSpec(specVersion) { | ||
switch (specVersion) { | ||
case 100: | ||
return p.v100; | ||
case 101: | ||
return p.v101; | ||
case 102: | ||
return p.v102; | ||
case 110: | ||
return p.v110; | ||
case 120: | ||
return p.v120; | ||
case 1021: | ||
return p.v1021; | ||
case 1022: | ||
return p.v1022; | ||
case 1023: | ||
return p.v1023; | ||
case 1024: | ||
return p.v1024; | ||
case 1025: | ||
return p.v1025; | ||
case 1026: | ||
return p.v1026; | ||
default: | ||
return productionLatest(); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,82 @@ | ||
import 'canary/canary.dart' as c; | ||
import 'production/production.dart' as p; | ||
|
||
String canary() { | ||
String canaryLatest() { | ||
return c.v1012; | ||
} | ||
|
||
String production() { | ||
String productionLatest() { | ||
return p.v1006; | ||
} | ||
|
||
String metadata(network, specVersion) { | ||
if (network == 'canary-matrixchain' || network == 'canary') { | ||
return canarySpec(specVersion); | ||
} | ||
|
||
return productionSpec(specVersion); | ||
} | ||
|
||
String canarySpec(specVersion) { | ||
switch (specVersion) { | ||
case 500: | ||
return c.v500; | ||
case 600: | ||
return c.v600; | ||
case 601: | ||
return c.v601; | ||
case 602: | ||
return c.v602; | ||
case 604: | ||
return c.v604; | ||
case 605: | ||
return c.v605; | ||
case 1000: | ||
return c.v1000; | ||
case 1001: | ||
return c.v1001; | ||
case 1002: | ||
return c.v1002; | ||
case 1003: | ||
return c.v1003; | ||
case 1004: | ||
return c.v1004; | ||
case 1005: | ||
return c.v1005; | ||
case 1006: | ||
return c.v1006; | ||
case 1010: | ||
return c.v1010; | ||
case 1011: | ||
return c.v1011; | ||
case 1012: | ||
return c.v1012; | ||
default: | ||
return canaryLatest(); | ||
} | ||
} | ||
|
||
String productionSpec(specVersion) { | ||
switch (specVersion) { | ||
case 603: | ||
return p.v603; | ||
case 604: | ||
return p.v604; | ||
case 605: | ||
return p.v605; | ||
case 1000: | ||
return p.v1000; | ||
case 1002: | ||
return p.v1002; | ||
case 1003: | ||
return p.v1003; | ||
case 1004: | ||
return p.v1004; | ||
case 1005: | ||
return p.v1005; | ||
case 1006: | ||
return p.v1006; | ||
default: | ||
return productionLatest(); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// The first time a metadata is requested we instantiate it and keep it on memory to speed up the decoder | ||
// Otherwise we would have to decode the metadata every time we decode an extrinsic or event | ||
// TODO: Later we can make some kind of LRU cache so it doesn't stays there forever | ||
|
||
import 'package:platform_decoder/consts/enjin/enjin.dart' as enjin; | ||
import 'package:platform_decoder/consts/matrix/matrix.dart' as matrix; | ||
import 'package:substrate_metadata/core/metadata_decoder.dart'; | ||
import 'package:substrate_metadata/models/models.dart'; | ||
|
||
// { | ||
// "enjin-matrixchain": { | ||
// 1000: ChainInfo, | ||
// 1001: ChainInfo, | ||
// } | ||
// } | ||
final Map<String, Map<int, ChainInfo>> chainInfos = {}; | ||
|
||
ChainInfo getChainInfo(network, specVersion) { | ||
final chainInfoMetadata = chainInfos[network]?[specVersion]; | ||
|
||
if (chainInfoMetadata != null) { | ||
return chainInfoMetadata; | ||
} | ||
|
||
// Instantiate a new metadata for relaychains | ||
if (network == 'canary-relaychain' || network == 'enjin-relaychain') { | ||
final metadata = | ||
MetadataDecoder.instance.decode(enjin.metadata(network, specVersion)); | ||
final ChainInfo chain = ChainInfo.fromMetadata(metadata); | ||
|
||
if (chainInfos[network] == null) { | ||
chainInfos[network] = {specVersion: chain}; | ||
} else { | ||
chainInfos[network]![specVersion] = chain; | ||
} | ||
|
||
print("Instantiated new metadata for $network $specVersion"); | ||
|
||
return chain; | ||
} | ||
|
||
// Instantiate a new metadata for matrixchains | ||
final metadata = | ||
MetadataDecoder.instance.decode(matrix.metadata(network, specVersion)); | ||
final ChainInfo chain = ChainInfo.fromMetadata(metadata); | ||
|
||
if (chainInfos[network] == null) { | ||
chainInfos[network] = {specVersion: chain}; | ||
} else { | ||
chainInfos[network]![specVersion] = chain; | ||
} | ||
|
||
print("Instantiated new metadata for $network $specVersion"); | ||
|
||
return chain; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,18 @@ | ||
import 'package:platform_decoder/consts/enjin/enjin.dart' as enjin; | ||
import 'package:platform_decoder/consts/matrix/matrix.dart' as matrix; | ||
import 'package:polkadart_scale_codec/io/io.dart'; | ||
import 'package:substrate_metadata/core/metadata_decoder.dart'; | ||
import 'package:substrate_metadata/models/models.dart'; | ||
import 'package:substrate_metadata/types/metadata_types.dart'; | ||
|
||
final DecodedMetadata matrixMetadata = | ||
MetadataDecoder.instance.decode(matrix.production()); | ||
final ChainInfo matrixChain = ChainInfo.fromMetadata(matrixMetadata); | ||
import 'chain_info.dart'; | ||
|
||
final DecodedMetadata matrixCanaryMetadata = | ||
MetadataDecoder.instance.decode(matrix.canary()); | ||
final ChainInfo matrixCanaryChain = | ||
ChainInfo.fromMetadata(matrixCanaryMetadata); | ||
|
||
final DecodedMetadata enjinMetadata = | ||
MetadataDecoder.instance.decode(enjin.production()); | ||
final ChainInfo enjinChain = ChainInfo.fromMetadata(enjinMetadata); | ||
|
||
final DecodedMetadata enjinCanaryMetadata = | ||
MetadataDecoder.instance.decode(enjin.canary()); | ||
final ChainInfo enjinCanaryChain = ChainInfo.fromMetadata(enjinCanaryMetadata); | ||
|
||
dynamic decodeExtrinsic(raw, network) { | ||
dynamic decodeExtrinsic(raw, network, specVersion) { | ||
final input = Input.fromHex(raw); | ||
final chainInfo = getChainInfo(network, specVersion); | ||
|
||
if (network == 'canary' || network == 'canary-matrixchain') { | ||
final dynamic decoded = | ||
ExtrinsicsCodec(chainInfo: matrixCanaryChain).decode(input); | ||
return decoded; | ||
} | ||
|
||
if (network == 'enjin-relaychain') { | ||
final dynamic decoded = | ||
ExtrinsicsCodec(chainInfo: enjinChain).decode(input); | ||
return decoded; | ||
} | ||
|
||
if (network == 'canary-relaychain') { | ||
final dynamic decoded = | ||
ExtrinsicsCodec(chainInfo: enjinCanaryChain).decode(input); | ||
return decoded; | ||
} | ||
|
||
final dynamic decoded = ExtrinsicsCodec(chainInfo: matrixChain).decode(input); | ||
return decoded; | ||
return ExtrinsicsCodec(chainInfo: chainInfo).decode(input); | ||
} | ||
|
||
dynamic decodeEvents(raw, network) { | ||
dynamic decodeEvents(raw, network, specVersion) { | ||
final input = Input.fromHex(raw); | ||
final chainInfo = getChainInfo(network, specVersion); | ||
|
||
if (network == 'canary' || network == 'canary-matrixchain') { | ||
final List<dynamic> decoded = | ||
matrixCanaryChain.scaleCodec.decode('EventCodec', input); | ||
return decoded; | ||
} | ||
|
||
if (network == 'enjin-relaychain') { | ||
final List<dynamic> decoded = | ||
enjinChain.scaleCodec.decode('EventCodec', input); | ||
return decoded; | ||
} | ||
|
||
if (network == 'canary-relaychain') { | ||
final List<dynamic> decoded = | ||
enjinCanaryChain.scaleCodec.decode('EventCodec', input); | ||
return decoded; | ||
} | ||
|
||
final decoded = matrixChain.scaleCodec.decode('EventCodec', input); | ||
return decoded; | ||
return chainInfo.scaleCodec.decode('EventCodec', input); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters