Skip to content

Commit

Permalink
add NetworkStateData.genesisHash & PluginBasicData.genesisHash
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Apr 20, 2021
1 parent 6644bb7 commit 897812b
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 234 deletions.
23 changes: 15 additions & 8 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.3"
version: "1.1.0"
charcode:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0-nullsafety.3"
version: "1.15.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -151,6 +151,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.12"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
json_annotation:
dependency: transitive
description:
Expand All @@ -171,7 +178,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -255,7 +262,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.1"
version: "0.1.5"
process:
dependency: transitive
description:
Expand Down Expand Up @@ -337,14 +344,14 @@ packages:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.3"
version: "2.1.0"
webview_flutter:
dependency: transitive
description:
Expand All @@ -360,5 +367,5 @@ packages:
source: hosted
version: "0.1.0"
sdks:
dart: ">=2.10.0 <2.11.0"
flutter: ">=1.22.0 <2.0.0"
dart: ">=2.12.0-0 <3.0.0"
flutter: ">=1.22.0"
8 changes: 4 additions & 4 deletions js_api/dist/main.js

Large diffs are not rendered by default.

151 changes: 1 addition & 150 deletions js_api/src/constants/networkSpect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,12 @@ export const UnknownNetworkKeys = Object.freeze({
UNKNOWN: "unknown",
});

// ethereumChainId is used as Network key for Ethereum networks
/* eslint-disable sort-keys */
export const EthereumNetworkKeys = Object.freeze({
FRONTIER: "1",
ROPSTEN: "3",
RINKEBY: "4",
GOERLI: "5",
KOVAN: "42",
CLASSIC: "61",
});

/* eslint-enable sort-keys */

// genesisHash is used as Network key for Substrate networks
export const SubstrateNetworkKeys = Object.freeze({
ACALA_TC4: "0x783c78945a4e4a3118190bcf93002bb2d2903192bed10040eb52d54500aade36",
CENTRIFUGE: "0x67dddf2673b69e5f875f6f25277495834398eafd67f492e09f3f3345e003d1b5", // https://portal.chain.centrifuge.io/#/explorer/query/0
CENTRIFUGE_AMBER: "0x092af6e7d25178ebab1677d15f66e37b30392b44ef442f728a53dd1bf48ec110", // https://portal.chain.centrifuge.io/#/explorer/query/0
EDGEWARE: "0x742a2ca70c2fda6cee4f8df98d64c4c670a052d9568058982dad9d5a7a135c5b", // https://polkascan.io/pre/edgeware/block/0
KULUPU: "0xf7a99d3cb92853d00d5275c971c132c074636256583fee53b3bbe60d7b8769ba",
KUSAMA: "0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe", // https://polkascan.io/pre/kusama-cc3/block/0
KUSAMA_CC2: "0xe3777fa922cafbff200cadeaea1a76bd7898ad5b89f7848999058b50e715f636",
KUSAMA_DEV: "0x5e9679182f658e148f33d3f760f11179977398bb3da8d1f0bf7b267fe6b3ebb0",
POLKADOT: "0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3",
SUBSTRATE_DEV: "0x0d667fd278ec412cd9fccdb066f09ed5b4cfd9c9afa9eb747213acb02b1e70bc", // substrate --dev commit ac6a2a783f0e1f4a814cf2add40275730cd41be1 hosted on wss://dev-node.substrate.dev .
WESTEND: "0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e",
});

const unknownNetworkBase = {
Expand All @@ -77,56 +57,6 @@ const unknownNetworkBase = {
};

const substrateNetworkBase = {
[SubstrateNetworkKeys.ACALA_TC4]: {
color: "#173DC9",
decimals: 18,
genesisHash: SubstrateNetworkKeys.ACALA_TC4,
order: 42,
pathId: "acala_mandala_tc4",
prefix: 42,
title: "Acala Mandala TC4",
unit: "ACA",
},
[SubstrateNetworkKeys.CENTRIFUGE]: {
color: "#FCC367",
decimals: 18,
genesisHash: SubstrateNetworkKeys.CENTRIFUGE,
order: 6,
pathId: "centrifuge",
prefix: 36,
title: "Centrifuge Mainnet",
unit: "RAD",
},
[SubstrateNetworkKeys.CENTRIFUGE_AMBER]: {
color: "#7C6136",
decimals: 18,
genesisHash: SubstrateNetworkKeys.CENTRIFUGE_AMBER,
order: 7,
pathId: "centrifuge_amber",
prefix: 42,
title: "Centrifuge Testnet Amber",
unit: "ARAD",
},
[SubstrateNetworkKeys.EDGEWARE]: {
color: "#0B95E0",
decimals: 18,
genesisHash: SubstrateNetworkKeys.EDGEWARE,
order: 4,
pathId: "edgeware",
prefix: 7,
title: "Edgeware",
unit: "EDG",
},
[SubstrateNetworkKeys.KULUPU]: {
color: "#003366",
decimals: 18,
genesisHash: SubstrateNetworkKeys.KULUPU,
order: 5,
pathId: "kulupu",
prefix: 16,
title: "Kulupu",
unit: "KULU",
},
[SubstrateNetworkKeys.KUSAMA]: {
color: "#000",
decimals: 12,
Expand All @@ -137,26 +67,6 @@ const substrateNetworkBase = {
title: "Kusama",
unit: "KSM",
},
[SubstrateNetworkKeys.KUSAMA_CC2]: {
color: "#000",
decimals: 12,
genesisHash: SubstrateNetworkKeys.KUSAMA,
order: 2,
pathId: "kusama_CC2",
prefix: 2,
title: "Kusama",
unit: "KSM",
},
[SubstrateNetworkKeys.KUSAMA_DEV]: {
color: "#000",
decimals: 12,
genesisHash: SubstrateNetworkKeys.KUSAMA_DEV,
order: 99,
pathId: "kusama_dev",
prefix: 2,
title: "Kusama Development",
unit: "KSM",
},
[SubstrateNetworkKeys.POLKADOT]: {
color: "#E6027A",
decimals: 12,
Expand All @@ -167,64 +77,6 @@ const substrateNetworkBase = {
title: "Polkadot",
unit: "DOT",
},
[SubstrateNetworkKeys.SUBSTRATE_DEV]: {
color: "#18FFB2",
decimals: 12,
genesisHash: SubstrateNetworkKeys.SUBSTRATE_DEV,
order: 100,
pathId: "substrate_dev",
prefix: 42,
title: "Substrate Development",
unit: "UNIT",
},
[SubstrateNetworkKeys.WESTEND]: {
color: "#660D35",
decimals: 12,
genesisHash: SubstrateNetworkKeys.WESTEND,
order: 3,
pathId: "westend",
prefix: 42,
title: "Westend",
unit: "WND",
},
};

const ethereumNetworkBase = {
[EthereumNetworkKeys.FRONTIER]: {
color: "#8B94B3",
ethereumChainId: EthereumNetworkKeys.FRONTIER,
order: 101,
secondaryColor: colors.background.card,
title: "Ethereum",
},
[EthereumNetworkKeys.CLASSIC]: {
color: "#1a4d33",
ethereumChainId: EthereumNetworkKeys.CLASSIC,
order: 102,
secondaryColor: colors.background.card,
title: "Ethereum Classic",
},
[EthereumNetworkKeys.ROPSTEN]: {
ethereumChainId: EthereumNetworkKeys.ROPSTEN,
order: 104,
title: "Ropsten Testnet",
},
[EthereumNetworkKeys.GOERLI]: {
ethereumChainId: EthereumNetworkKeys.GOERLI,
order: 105,
title: "Görli Testnet",
},
[EthereumNetworkKeys.KOVAN]: {
ethereumChainId: EthereumNetworkKeys.KOVAN,
order: 103,
title: "Kovan Testnet",
},
};

const ethereumDefaultValues = {
color: "#434875",
protocol: NetworkProtocols.ETHEREUM,
secondaryColor: colors.background.card,
};

const substrateDefaultValues = {
Expand All @@ -245,7 +97,6 @@ function setDefault(networkBase, defaultProps) {
}, {});
}

export const ETHEREUM_NETWORK_LIST = Object.freeze(setDefault(ethereumNetworkBase, ethereumDefaultValues));
export const SUBSTRATE_NETWORK_LIST = Object.freeze(setDefault(substrateNetworkBase, substrateDefaultValues));
export const UNKNOWN_NETWORK = Object.freeze(unknownNetworkBase);

Expand All @@ -255,7 +106,7 @@ const substrateNetworkMetas = Object.values({
});
export const PATH_IDS_LIST = substrateNetworkMetas.map((meta: any) => meta.pathId);

export const NETWORK_LIST = Object.freeze(Object.assign({}, SUBSTRATE_NETWORK_LIST, ETHEREUM_NETWORK_LIST, UNKNOWN_NETWORK));
export const NETWORK_LIST = Object.freeze(Object.assign({}, SUBSTRATE_NETWORK_LIST, [], UNKNOWN_NETWORK));

export const defaultNetworkKey = SubstrateNetworkKeys.KUSAMA;

Expand Down
6 changes: 4 additions & 2 deletions js_api/src/service/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ export async function getNetworkConst(api: ApiPromise) {
*/
export async function getNetworkProperties(api: ApiPromise) {
const chainProperties = await api.rpc.system.properties();
return api.genesisHash.toHuman() == SubstrateNetworkKeys.POLKADOT
const genesisHash = api.genesisHash.toHuman();
return genesisHash == SubstrateNetworkKeys.POLKADOT
? api.registry.createType("ChainProperties", {
...chainProperties,
tokenDecimals: [10],
tokenSymbol: ["DOT"],
genesisHash,
})
: chainProperties;
: { ...chainProperties.toJSON(), genesisHash };
}
55 changes: 7 additions & 48 deletions lib/api/subscan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class SubScanRequestParams {
String module;
String call;
}
const post_headers = {
"Content-type": "application/json",
"Accept": "*/*"
};

/// Querying txs from [subscan.io](https://subscan.io).
class SubScanApi {
Expand Down Expand Up @@ -141,16 +145,12 @@ class SubScanApi {

static Future<Map> fetchTransfers(SubScanRequestParams params) async {
String url = '${getSnEndpoint(params.network)}/transfers';
Map<String, String> headers = {
"Content-type": "application/json",
"Accept": "*/*"
};
String body = jsonEncode({
"page": params.page,
"row": params.row,
"address": params.address,
});
Response res = await post(url, headers: headers, body: body);
Response res = await post(url, headers: post_headers, body: body);
if (res.body != null) {
final obj = await compute(jsonDecode, res.body);
if (params.sendPort != null) {
Expand All @@ -166,7 +166,6 @@ class SubScanApi {

static Future<Map> fetchTxs(SubScanRequestParams para) async {
String url = '${getSnEndpoint(para.network)}/extrinsics';
Map<String, String> headers = {"Content-type": "application/json"};
Map params = {
"page": para.page,
"row": para.row,
Expand All @@ -179,7 +178,7 @@ class SubScanApi {
params['call'] = para.call;
}
String body = jsonEncode(params);
Response res = await post(url, headers: headers, body: body);
Response res = await post(url, headers: post_headers, body: body);
if (res.body != null) {
final obj = await compute(jsonDecode, res.body);
if (para.sendPort != null) {
Expand All @@ -195,14 +194,13 @@ class SubScanApi {

static Future<Map> fetchRewardTxs(SubScanRequestParams para) async {
String url = '${getSnEndpoint(para.network)}/account/reward_slash';
Map<String, String> headers = {"Content-type": "application/json"};
Map params = {
"address": para.address,
"page": para.page,
"row": para.row,
};
String body = jsonEncode(params);
Response res = await post(url, headers: headers, body: body);
Response res = await post(url, headers: post_headers, body: body);
if (res.body != null) {
final obj = await compute(jsonDecode, res.body);
if (para.sendPort != null) {
Expand All @@ -215,43 +213,4 @@ class SubScanApi {
}
return {};
}

Future<Map> fetchTokenPriceAsync(String network) async {
Completer completer = new Completer<Map>();
ReceivePort receivePort = ReceivePort();
Isolate isolateIns = await Isolate.spawn(
SubScanApi.fetchTokenPrice,
SubScanRequestParams(
sendPort: receivePort.sendPort,
network: network,
));
receivePort.listen((msg) {
receivePort.close();
isolateIns.kill(priority: Isolate.immediate);
completer.complete(msg);
});
return completer.future;
}

static Future<Map> fetchTokenPrice(SubScanRequestParams para) async {
String url = '${getSnEndpoint(para.network)}/token';
Map<String, String> headers = {"Content-type": "application/json"};

Response res = await post(url, headers: headers);
if (res.body != null) {
try {
final obj = await compute(jsonDecode, res.body);
if (para.sendPort != null) {
para.sendPort.send(obj['data']);
}
return obj['data'];
} catch (err) {
// ignore error
}
}
if (para.sendPort != null) {
para.sendPort.send({});
}
return {};
}
}
Loading

0 comments on commit 897812b

Please sign in to comment.