Skip to content

Commit 39e426f

Browse files
committed
V2.4.0
- Update dependencies. - Support for Cosmos Wasm module.
1 parent 21a02bb commit 39e426f

File tree

25 files changed

+343
-32
lines changed

25 files changed

+343
-32
lines changed

.DS_Store

2 KB
Binary file not shown.

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.4.0
2+
3+
- Update dependencies.
4+
- Support for Cosmos Wasm module.
5+
16
## 2.3.0
27

38
- Update dependencies.

assets/chains.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

cosmos_chain_builder.dart

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import 'dart:io';
2+
3+
import 'package:blockchain_utils/bip/bip/conf/core/coin_conf.dart';
4+
import 'package:blockchain_utils/helper/extensions/extensions.dart';
5+
import 'package:blockchain_utils/service/service.dart';
6+
import 'package:blockchain_utils/utils/string/string.dart';
7+
import 'package:cosmos_sdk/cosmos_sdk.dart';
8+
import 'package:http/http.dart' as http;
9+
10+
class ChainRegistryHTTPProvider implements ChainRegistryServiceProvider {
11+
ChainRegistryHTTPProvider(
12+
{this.url = CCRConst.chainRegisteryUri,
13+
http.Client? client,
14+
this.defaultRequestTimeout = const Duration(seconds: 30)})
15+
: client = client ?? http.Client();
16+
17+
final String url;
18+
final http.Client client;
19+
final Duration defaultRequestTimeout;
20+
21+
@override
22+
Future<BaseServiceResponse<T>> doRequest<T>(
23+
ChainRegistryRequestRequestDetails params,
24+
{Duration? timeout}) async {
25+
final uri = params.toUri(url);
26+
final response = await client.get(uri,
27+
headers: {...params.headers}).timeout(timeout ?? defaultRequestTimeout);
28+
return params.parseResponse(response.bodyBytes, response.statusCode);
29+
}
30+
}
31+
32+
void main() async {
33+
const List<ChainType> chains = [ChainType.mainnet, ChainType.testnet];
34+
35+
Map<String, dynamic> chainInfos = {
36+
ChainType.mainnet.name: [],
37+
ChainType.testnet.name: []
38+
};
39+
40+
String getUrl(ChainType type) {
41+
switch (type) {
42+
case ChainType.testnet:
43+
return CCRConst.cosmosTestnetDirectoryUri;
44+
case ChainType.mainnet:
45+
return CCRConst.cosmosDirectoryUri;
46+
}
47+
}
48+
49+
for (final chain in chains) {
50+
final provider =
51+
ChainRegistryProvider(ChainRegistryHTTPProvider(url: getUrl(chain)));
52+
final chains =
53+
await provider.request(ChainRegistryRequestCosmosDirectoryChains());
54+
print("chains done!");
55+
final List<Map<String, dynamic>> infos = [];
56+
for (final i in chains) {
57+
final data = await provider
58+
.request(ChainRegistryRequestCosmosDirectoryChain(chainName: i.name));
59+
final natvieAsset = data.assets?.firstWhere((e) => e.denom == i.denom);
60+
if (natvieAsset == null) {
61+
print("native not found ${i.chainId}");
62+
continue;
63+
}
64+
List<String> accountPageUrls = [];
65+
List<String> txPageUrls = [];
66+
for (final e in i.explorers) {
67+
if (e.accountPage != null) {
68+
accountPageUrls.add(e.accountPage!
69+
.replaceFirst("\${accountAddress}", "#address")
70+
.replaceFirst(r"{$accountAddress}", "#address"));
71+
}
72+
if (e.txPage != null) {
73+
txPageUrls.add(e.txPage!
74+
.replaceFirst("\${txHash}", "#txid")
75+
.replaceFirst("#txId", "#txid"));
76+
}
77+
}
78+
final Map<String, dynamic> chainData = {
79+
"name": i.name,
80+
"chain_name": i.prettyName ?? i.chainName,
81+
"chain_id": i.chainId,
82+
"bech32_prefix": i.bech32Prefix,
83+
"type": chain.name,
84+
"native": {
85+
"name": natvieAsset.name,
86+
"denom": natvieAsset.denom,
87+
"decimals": natvieAsset.decimals,
88+
"symbol": natvieAsset.symbol,
89+
if (natvieAsset.logoURIs?.png != null)
90+
"png_logo": natvieAsset.logoURIs?.png,
91+
if (natvieAsset.logoURIs?.svg != null)
92+
"svg_logo": natvieAsset.logoURIs?.svg,
93+
if (natvieAsset.coingeckoId != null)
94+
"coingecko_id": natvieAsset.coingeckoId
95+
},
96+
"best_apis": i.bestApis.toJson(),
97+
"explorers": {
98+
"account_page":
99+
accountPageUrls.firstWhereNullable((e) => !e.contains(r"${")),
100+
"tx_page": txPageUrls.firstWhereNullable((e) => !e.contains(r"${"))
101+
},
102+
"slip44": i.slip44,
103+
"path": i.path
104+
};
105+
106+
if (data.keyAlgos.isNotEmpty) {
107+
chainData["algs"] = data.keyAlgos;
108+
}
109+
List<Map<String, dynamic>> fees = [];
110+
for (final i in data.fees.feeTokens) {
111+
final asset = data.assets?.firstWhere((e) => e.denom == i.denom);
112+
assert(asset != null);
113+
if (asset == null) continue;
114+
final f = {
115+
"name": asset.name,
116+
"denom": asset.denom,
117+
"decimals": asset.decimals,
118+
"symbol": asset.symbol,
119+
if (asset.logoURIs?.png != null) "png_logo": asset.logoURIs?.png,
120+
if (asset.logoURIs?.svg != null) "svg_logo": asset.logoURIs?.svg,
121+
if (asset.coingeckoId != null) "coingecko_id": asset.coingeckoId
122+
}..removeWhere((k, v) => v == null);
123+
final fee = {...f, ...i.toJson()};
124+
fees.add(fee);
125+
}
126+
if (fees.isEmpty) {
127+
print("noo fee ${data.chainId}");
128+
continue;
129+
}
130+
chainData["fees"] = fees;
131+
infos.add(chainData);
132+
print("done ${data.chainId}");
133+
}
134+
chainInfos[chain.name] = infos;
135+
}
136+
final file = File('./assets/chains.json');
137+
await file.writeAsString(StringUtils.fromJson(chainInfos));
138+
}

example/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*.swp
66
.DS_Store
77
.atom/
8+
.build/
89
.buildlog/
910
.history
1011
.svn/
12+
.swiftpm/
1113
migrate_working_dir/
1214

1315
# IntelliJ related

example/f.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/f2.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/lib/message.dart

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
ignoresPersistentStateOnLaunch = "NO"
6060
debugDocumentVersioning = "YES"
6161
debugServiceExtension = "internal"
62+
enableGPUValidationMode = "1"
6263
allowLocationSimulation = "YES">
6364
<BuildableProductRunnable
6465
runnableDebuggingMode = "0">
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import Cocoa
22
import FlutterMacOS
33

4-
@NSApplicationMain
4+
@main
55
class AppDelegate: FlutterAppDelegate {
66
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
77
return true
88
}
9+
10+
override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
11+
return true
12+
}
913
}

0 commit comments

Comments
 (0)