Skip to content

Commit

Permalink
sail/zcash/cast: set execute time of new bills in the future
Browse files Browse the repository at this point in the history
prior to this change, we executed and recreated bills in a loop
  • Loading branch information
octobocto committed Sep 9, 2024
1 parent 34a7698 commit 08808a5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
14 changes: 8 additions & 6 deletions packages/sidesail/lib/providers/cast_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PendingCastBill {
required this.executeAction,
}) {
DateTime now = DateTime.now().toUtc();
executeTime = DateTime.utc(now.year, now.month, now.day);
executeTime = DateTime.utc(now.year, now.month, now.day + 1);

int weekday;

Expand Down Expand Up @@ -113,7 +113,7 @@ class CastProvider extends ChangeNotifier {
for (int i = 1; i <= maxCastFactor; i++) {
final newBundle = PendingCastBill(
powerOf: i,
executeAction: () => _executeCast(i),
executeAction: () => _executeCast(i, 0),
);

log.d(
Expand Down Expand Up @@ -152,7 +152,9 @@ class CastProvider extends ChangeNotifier {
}
}

void _executeCast(int powerOf) async {
void _executeCast(int powerOf, int iteration) async {
print('execute cast $iteration');

try {
final bundle = futureCasts.elementAt(powerOf);
log.t('executing powerOf=${bundle.powerOf} with amount=${bundle.castAmount}');
Expand All @@ -164,13 +166,13 @@ class CastProvider extends ChangeNotifier {

final newBill = PendingCastBill(
powerOf: bundle.powerOf,
executeAction: () => _executeCast(powerOf),
executeAction: () => _executeCast(powerOf, iteration + 1),
);
futureCasts[bundle.powerOf] = newBill;
log.t('recreated next bundle to be executed at ${newBill.executeTime} arraySize=${futureCasts.length}');
print('recreated next bundle to be executed at ${newBill.executeTime} arraySize=${futureCasts.length}');
await Future.delayed(const Duration(seconds: 1), () {});

await _zcashProvider.fetch();
notifyListeners();
} catch (error) {
log.e('could not cast ${error.toString()}');
}
Expand Down
4 changes: 2 additions & 2 deletions packages/sidesail/lib/rpc/rpc_zcash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class ZcashRPCLive extends ZCashRPC {
}

Future<double> _balanceForAccount(int account, int confirmations) async {
final saplingBalance = await _client.call().call('z_getbalanceforaccount', [account, confirmations]).then(
final saplingBalance = await _client().call('z_getbalanceforaccount', [account, confirmations]).then(
(res) {
final pools = res['pools'];
num zBalanceSat = 0;
Expand Down Expand Up @@ -200,7 +200,7 @@ class ZcashRPCLive extends ZCashRPC {
// z_listaddresses.
final addresses = await _client().call('z_listaddresses') as List<dynamic>;
for (final address in addresses) {
final addressBalance = await _client.call().call('z_getbalance', [address, confirmations]);
final addressBalance = await _client().call('z_getbalance', [address, confirmations]);
balance += addressBalance;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sidesail/macos/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Cocoa
import FlutterMacOS

@NSApplicationMain
@main
class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
Expand Down
2 changes: 1 addition & 1 deletion packages/sidesail/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1079,5 +1079,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.4.0 <4.0.0"
dart: ">=3.5.0-259.0.dev <4.0.0"
flutter: ">=3.22.0"

0 comments on commit 08808a5

Please sign in to comment.