Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ğecko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kapis
Ğecko
Commits
f70b9b30
Commit
f70b9b30
authored
4 years ago
by
poka
Browse files
Options
Downloads
Patches
Plain Diff
Improve compareTo declaration (feat @elois)
parent
fa428e55
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/globals.dart
+1
-1
1 addition, 1 deletion
lib/globals.dart
lib/models/home.dart
+68
-21
68 additions, 21 deletions
lib/models/home.dart
lib/models/myWallets.dart
+1
-3
1 addition, 3 deletions
lib/models/myWallets.dart
with
70 additions
and
25 deletions
lib/globals.dart
+
1
−
1
View file @
f70b9b30
...
...
@@ -12,7 +12,7 @@ File currentChestFile;
WalletData
defaultWallet
;
String
appVersion
;
SharedPreferences
prefs
;
List
<
String
>
endPointGVA
;
List
<
String
>
endPointGVA
=
[]
;
int
ramSys
;
// String cesiumPod = "https://g1.data.le-sou.org";
...
...
This diff is collapsed.
Click to expand it.
lib/models/home.dart
+
68
−
21
View file @
f70b9b30
...
...
@@ -62,7 +62,7 @@ class HomeProvider with ChangeNotifier {
// - else break;
// - return map.get(key: consensus).toList
var
blockstampMap
=
SplayTreeMap
<
Blockstamp
,
String
>();
var
blockstampMap
=
SplayTreeMap
<
Blockstamp
,
List
<
String
>
>
();
List
_endpointsToScan
=
[];
_endpointsToScan
=
await
rootBundle
...
...
@@ -71,8 +71,22 @@ class HomeProvider with ChangeNotifier {
// Loop on endpoints
Future
loopEndpoints
(
List
_endpoints
)
async
{
log
.
i
(
"List of endpoint to scan:
\n
$_endpoints
"
);
for
(
String
_endpoint
in
_endpoints
)
{
print
(
"Endpoint:
$_endpoint
"
);
bool
_validURL
=
Uri
.
parse
(
_endpoint
)
.
isAbsolute
;
// final RegExp regExpUrl = RegExp(
// r'^((?:.|\n)*?)((http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)([-A-Z0-9.]+)(/[-A-Z0-9+&@#/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#/%=~_|!:,.;]*)?)',
// multiLine: false,
// );
//
if
(
!
_validURL
)
{
log
.
w
(
'
$_endpoint
is not a valid URL'
);
continue
;
}
log
.
i
(
"Process endpoint:
$_endpoint
"
);
final
HttpLink
httpLink
=
HttpLink
(
_endpoint
,
);
...
...
@@ -101,10 +115,22 @@ class HomeProvider with ChangeNotifier {
variables:
<
String
,
dynamic
>{},
);
final
QueryResult
result
=
await
client
.
query
(
options
);
QueryResult
result
;
// TODO: Open a stackOverflow to Dart team about non catching ServerException execptions
try
{
result
=
await
client
.
query
(
options
);
}
on
OperationException
{
log
.
w
(
"###
$_endpoint
:
${result.exception.toString()}
###"
);
continue
;
}
catch
(
e
)
{
log
.
w
(
"###
$_endpoint
:
${result.exception.toString()}
###"
);
continue
;
}
if
(
result
.
hasException
)
{
print
(
result
.
exception
.
toString
());
log
.
w
(
"###
$_endpoint
:
${result.exception.toString()}
###"
);
continue
;
}
// Get current blockstamp
...
...
@@ -112,26 +138,35 @@ class HomeProvider with ChangeNotifier {
String
_hash
=
result
.
data
[
'currentBlock'
][
'hash'
];
Blockstamp
_blockstamp
=
Blockstamp
(
_blockNumber
,
_hash
);
// int keyBlock = _blockstamp.compareTo(_blockNumber);
// Store Map blockstamp and endpoints
print
(
"
$_blockstamp
$_endpoint
"
);
blockstampMap
.
putIfAbsent
(
_blockstamp
,
()
=
>
_endpoint
);
var
blockStampEndpoints
=
blockstampMap
[
_blockstamp
];
if
(
blockStampEndpoints
==
null
)
{
blockStampEndpoints
=
[];
}
blockStampEndpoints
.
add
(
_endpoint
);
blockstampMap
[
_blockstamp
]
=
blockStampEndpoints
;
// Get known endpoints
_endpointsToScan
.
clear
();
for
(
String
_brutEndPoint
in
result
.
data
[
'network'
][
'endpoints'
])
{
String
_httpEndPoint
;
int
_port
=
int
.
parse
(
_brutEndPoint
.
split
(
' '
)[
3
]);
String
_path
=
_brutEndPoint
.
split
(
' '
)[
4
];
List
<
String
>
_brutEndPointSplited
=
_brutEndPoint
.
split
(
' '
);
int
_port
=
int
.
parse
(
_brutEndPointSplited
[
3
]);
String
_path
=
_brutEndPointSplited
[
4
];
String
_host
=
_brutEndPointSplited
[
2
];
if
(
_port
==
443
)
{
_httpEndPoint
=
"https://
$
{_brutEndPoint.split(' ')[2]}
/
$_path
"
;
_httpEndPoint
=
"https://
$
_host
/
$_path
"
;
}
else
{
_httpEndPoint
=
"http://
${_brutEndPoint.split(' ')[2]}
:
$_port
/
$_path
"
;
_httpEndPoint
=
"http://
$_host
:
$_port
/
$_path
"
;
}
_endpointsToScan
.
add
((
_httpEndPoint
));
}
// end of known endpoints by node loop
_endpointsToScan
=
_endpointsToScan
.
sublist
(
0
,
3
);
}
// end of endpoints loop
}
...
...
@@ -139,10 +174,13 @@ class HomeProvider with ChangeNotifier {
await
loopEndpoints
(
_endpointsToScan
);
}
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
endPointGVA
.
add
(
blockstampMap
.
values
.
toList
()[
i
]);
var
blockStamp
=
blockstampMap
.
firstKey
();
endPointGVA
.
add
(
blockstampMap
[
blockStamp
][
0
]);
endPointGVA
=
endPointGVA
.
toSet
()
.
toList
();
endPointGVA
.
shuffle
();
}
log
.
i
(
"Valid endpoints list:
\n
$endPointGVA
"
);
return
endPointGVA
;
}
...
...
@@ -255,19 +293,28 @@ class HomeProvider with ChangeNotifier {
}
}
class
Blockstamp
{
class
Blockstamp
implements
Comparable
{
int
blockNumber
;
String
hash
;
String
blockstamp
;
Blockstamp
(
int
_blockNumber
,
String
_hash
)
{
this
.
blockNumber
=
_blockNumber
;
this
.
hash
=
_hash
;
this
.
blockstamp
=
_blockNumber
.
toString
()
+
_hash
;
Blockstamp
(
int
blockNumber
,
String
hash
)
{
this
.
blockNumber
=
blockNumber
;
this
.
hash
=
hash
;
}
@override
int
compareTo
(
other
)
{
int
blockNumberCompare
=
blockNumber
.
compareTo
(
other
.
blockNumber
);
if
(
blockNumberCompare
==
0
)
{
return
hash
.
compareTo
(
other
.
hash
);
}
else
{
return
blockNumberCompare
;
}
}
// representation of blockstamp when debugging
@override
String
toString
()
{
return
this
.
blockstamp
;
return
blockNumber
.
toString
()
+
hash
;
}
}
This diff is collapsed.
Click to expand it.
lib/models/myWallets.dart
+
1
−
3
View file @
f70b9b30
...
...
@@ -59,6 +59,7 @@ class MyWalletsProvider with ChangeNotifier {
log
.
i
(
'No wallets detected'
);
return
false
;
}
else
{
log
.
i
(
listWallets
.
toString
());
return
true
;
}
}
...
...
@@ -73,12 +74,10 @@ class MyWalletsProvider with ChangeNotifier {
listWallets
.
add
(
WalletData
(
element
));
});
log
.
i
(
listWallets
.
toString
());
return
listWallets
;
}
WalletData
getWalletData
(
String
_id
)
{
// log.d(_id);
if
(
_id
==
''
)
return
WalletData
(
''
);
int
chest
=
int
.
parse
(
_id
.
split
(
':'
)[
0
]);
final
_walletConfig
=
File
(
'
${walletsDirectory.path}
/
$chest
/list.conf'
);
...
...
@@ -95,7 +94,6 @@ class MyWalletsProvider with ChangeNotifier {
final
_walletConfig
=
File
(
'
${walletsDirectory.path}
/
$chest
/list.conf'
);
List
configLines
=
await
_walletConfig
.
readAsLines
();
//log.d(configLines);
if
(
configLines
.
isEmpty
)
{
return
WalletData
(
''
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment