mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-02 12:14:09 +01:00
Merge pull request #142 from cake-tech/CAKE-168-blockheight-calculation-by-date
Cake 168 blockheight calculation by date
This commit is contained in:
@@ -82,37 +82,32 @@ final dates = {
|
|||||||
"2020-8": 2153983,
|
"2020-8": 2153983,
|
||||||
"2020-9": 2176466,
|
"2020-9": 2176466,
|
||||||
"2020-10": 2198453,
|
"2020-10": 2198453,
|
||||||
"2020-11": 2221803
|
"2020-11": 2220000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
final heightCoefficient = 0.7;
|
||||||
|
|
||||||
int getHeigthByDate({DateTime date}) {
|
int getHeigthByDate({DateTime date}) {
|
||||||
final raw = '${date.year}' + '-' + '${date.month}';
|
final raw = '${date.year}' + '-' + '${date.month}';
|
||||||
var endHeight = dates[raw] ?? 0;
|
final lastHeight = dates.values.last;
|
||||||
int preLastYear = date.year;
|
int startHeight;
|
||||||
int preLastMonth = date.month - 1;
|
int endHeight;
|
||||||
|
int height;
|
||||||
|
|
||||||
if (endHeight <= 0) {
|
if ((dates[raw] == null)||(dates[raw] == lastHeight)) {
|
||||||
|
startHeight = dates.values.toList()[dates.length - 2];
|
||||||
endHeight = dates.values.toList()[dates.length - 1];
|
endHeight = dates.values.toList()[dates.length - 1];
|
||||||
final preLastDate =
|
final heightPerDay = (endHeight - startHeight) / 31;
|
||||||
dateFormat.parse(dates.keys.elementAt(dates.keys.length - 2));
|
final daysHeight = (heightCoefficient * (date.day - 1) * heightPerDay).round();
|
||||||
preLastYear = preLastDate.year;
|
height = endHeight + daysHeight;
|
||||||
preLastMonth = preLastDate.month;
|
|
||||||
} else {
|
} else {
|
||||||
preLastYear = date.year;
|
startHeight = dates[raw];
|
||||||
preLastMonth = date.month - 1;
|
final index = dates.values.toList().indexOf(startHeight);
|
||||||
|
endHeight = dates.values.toList()[index + 1];
|
||||||
|
final heightPerDay = ((endHeight - startHeight) / 31).round();
|
||||||
|
final daysHeight = (date.day - 1) * heightPerDay;
|
||||||
|
height = startHeight + daysHeight - heightPerDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preLastMonth <= 0) {
|
|
||||||
preLastMonth = 12;
|
|
||||||
preLastYear -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
final startRaw = '$preLastYear' + '-' + '$preLastMonth';
|
|
||||||
final startHeight = dates[startRaw];
|
|
||||||
final diff = endHeight - startHeight;
|
|
||||||
final heightPerDay = diff / 30;
|
|
||||||
final daysHeight = date.day * heightPerDay.round();
|
|
||||||
final height = endHeight + daysHeight;
|
|
||||||
|
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
|
|||||||
final date = await getDate(
|
final date = await getDate(
|
||||||
context: context,
|
context: context,
|
||||||
initialDate: now.subtract(Duration(days: 1)),
|
initialDate: now.subtract(Duration(days: 1)),
|
||||||
firstDate: DateTime(2014, DateTime.april),
|
firstDate: DateTime(2014, DateTime.may),
|
||||||
lastDate: now);
|
lastDate: now);
|
||||||
|
|
||||||
if (date != null) {
|
if (date != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user