diff --git a/src/comm.zig b/src/comm.zig index 5503c16..618b31a 100644 --- a/src/comm.zig +++ b/src/comm.zig @@ -66,7 +66,7 @@ pub const MessageTag = enum(u16) { // nd -> ngui: reports poweroff progress poweroff_progress = 0x09, // nd -> ngui: bitcoin core daemon status report - bitcoind_report = 0x0a, + onchain_report = 0x0a, // nd -> ngui: lnd status and stats report lightning_report = 0x0b, // ngui -> nd: switch sysupdates channel @@ -87,7 +87,7 @@ pub const Message = union(MessageTag) { network_report: NetworkReport, get_network_report: GetNetworkReport, poweroff_progress: PoweroffProgress, - bitcoind_report: BitcoinReport, + onchain_report: OnchainReport, lightning_report: LightningReport, switch_sysupdates: SysupdatesChan, settings: Settings, @@ -117,7 +117,7 @@ pub const Message = union(MessageTag) { }; }; - pub const BitcoinReport = struct { + pub const OnchainReport = struct { blocks: u64, headers: u64, timestamp: u64, // unix epoch @@ -269,7 +269,7 @@ pub fn write(allocator: mem.Allocator, writer: anytype, msg: Message) !void { .network_report => try json.stringify(msg.network_report, .{}, data.writer()), .get_network_report => try json.stringify(msg.get_network_report, .{}, data.writer()), .poweroff_progress => try json.stringify(msg.poweroff_progress, .{}, data.writer()), - .bitcoind_report => try json.stringify(msg.bitcoind_report, .{}, data.writer()), + .onchain_report => try json.stringify(msg.onchain_report, .{}, data.writer()), .lightning_report => try json.stringify(msg.lightning_report, .{}, data.writer()), .switch_sysupdates => try json.stringify(msg.switch_sysupdates, .{}, data.writer()), .settings => try json.stringify(msg.settings, .{}, data.writer()), diff --git a/src/nd/Daemon.zig b/src/nd/Daemon.zig index 68a302d..6e65322 100644 --- a/src/nd/Daemon.zig +++ b/src/nd/Daemon.zig @@ -57,9 +57,9 @@ network_report_ready: bool, // indicates whether the network status is ready to wifi_scan_in_progress: bool = false, wpa_save_config_on_connected: bool = false, // bitcoin fields -want_bitcoind_report: bool, +want_onchain_report: bool, bitcoin_timer: time.Timer, -bitcoin_report_interval: u64 = 1 * time.ns_per_min, +onchain_report_interval: u64 = 1 * time.ns_per_min, // lightning fields want_lnd_report: bool, lnd_timer: time.Timer, @@ -111,7 +111,7 @@ pub fn init(opt: InitOpt) !Daemon { .want_wifi_scan = false, .network_report_ready = true, // report bitcoind status immediately on start - .want_bitcoind_report = true, + .want_onchain_report = true, .bitcoin_timer = try time.Timer.start(), // report lightning status immediately on start .want_lnd_report = true, @@ -327,12 +327,12 @@ fn mainThreadLoopCycle(self: *Daemon) !void { } } - if (self.want_bitcoind_report or self.bitcoin_timer.read() > self.bitcoin_report_interval) { - if (self.sendBitcoindReport()) { + if (self.want_onchain_report or self.bitcoin_timer.read() > self.onchain_report_interval) { + if (self.sendOnchainReport()) { self.bitcoin_timer.reset(); - self.want_bitcoind_report = false; + self.want_onchain_report = false; } else |err| { - logger.err("sendBitcoinReport: {any}", .{err}); + logger.err("sendOnchainReport: {any}", .{err}); } } if (self.want_lnd_report or self.lnd_timer.read() > self.lnd_report_interval) { @@ -566,7 +566,7 @@ fn readWPACtrlMsg(self: *Daemon) !void { } } -fn sendBitcoindReport(self: *Daemon) !void { +fn sendOnchainReport(self: *Daemon) !void { var client = bitcoindrpc.Client{ .allocator = self.allocator, .cookiepath = "/ssd/bitcoind/mainnet/.cookie", @@ -590,7 +590,7 @@ fn sendBitcoindReport(self: *Daemon) !void { }; defer if (balance) |bal| bal.deinit(); - const btcrep: comm.Message.BitcoinReport = .{ + const btcrep: comm.Message.OnchainReport = .{ .blocks = bcinfo.value.blocks, .headers = bcinfo.value.headers, .timestamp = bcinfo.value.time, @@ -624,7 +624,7 @@ fn sendBitcoindReport(self: *Daemon) !void { } else null, }; - try comm.write(self.allocator, self.uiwriter, .{ .bitcoind_report = btcrep }); + try comm.write(self.allocator, self.uiwriter, .{ .onchain_report = btcrep }); } fn sendLightningReport(self: *Daemon) !void { @@ -802,7 +802,7 @@ test "start-stop" { }); daemon.want_settings = false; daemon.want_network_report = false; - daemon.want_bitcoind_report = false; + daemon.want_onchain_report = false; daemon.want_lnd_report = false; try t.expect(daemon.state == .stopped); @@ -854,7 +854,7 @@ test "start-poweroff" { }); daemon.want_settings = false; daemon.want_network_report = false; - daemon.want_bitcoind_report = false; + daemon.want_onchain_report = false; daemon.want_lnd_report = false; defer { daemon.deinit(); diff --git a/src/ngui.zig b/src/ngui.zig index 6a193a8..d7d7e58 100644 --- a/src/ngui.zig +++ b/src/ngui.zig @@ -39,7 +39,7 @@ var state: enum { var last_report: struct { mu: std.Thread.Mutex = .{}, network: ?comm.ParsedMessage = null, // NetworkReport - bitcoind: ?comm.ParsedMessage = null, // BitcoinReport + onchain: ?comm.ParsedMessage = null, // OnchainReport lightning: ?comm.ParsedMessage = null, // LightningReport fn deinit(self: *@This()) void { @@ -49,9 +49,9 @@ var last_report: struct { v.deinit(); self.network = null; } - if (self.bitcoind) |v| { + if (self.onchain) |v| { v.deinit(); - self.bitcoind = null; + self.onchain = null; } if (self.lightning) |v| { v.deinit(); @@ -70,11 +70,11 @@ var last_report: struct { } self.network = new; }, - .bitcoind_report => { - if (self.bitcoind) |old| { + .onchain_report => { + if (self.onchain) |old| { old.deinit(); } - self.bitcoind = new; + self.onchain = new; }, .lightning_report => { if (self.lightning) |old| { @@ -231,7 +231,7 @@ fn commThreadLoopCycle() !void { try comm.pipeWrite(comm.Message.pong); }, .network_report, - .bitcoind_report, + .onchain_report, .lightning_report, => last_report.replace(msg), else => { @@ -252,7 +252,7 @@ fn commThreadLoopCycle() !void { updateNetworkStatus(rep) catch |err| logger.err("updateNetworkStatus: {any}", .{err}); last_report.replace(msg); }, - .bitcoind_report => |rep| { + .onchain_report => |rep| { ui.bitcoin.updateTabPanel(rep) catch |err| logger.err("bitcoin.updateTabPanel: {any}", .{err}); last_report.replace(msg); }, @@ -306,8 +306,8 @@ fn uiThreadLoop() void { logger.err("updateNetworkStatus: {any}", .{err}); }; } - if (last_report.bitcoind) |msg| { - ui.bitcoin.updateTabPanel(msg.value.bitcoind_report) catch |err| { + if (last_report.onchain) |msg| { + ui.bitcoin.updateTabPanel(msg.value.onchain_report) catch |err| { logger.err("bitcoin.updateTabPanel: {any}", .{err}); }; } diff --git a/src/test/guiplay.zig b/src/test/guiplay.zig index 2a05d3b..fd433cd 100644 --- a/src/test/guiplay.zig +++ b/src/test/guiplay.zig @@ -152,7 +152,7 @@ fn commWriteThread(gpa: std.mem.Allocator, w: anytype) !void { block_count += 1; const now = time.timestamp(); - const btcrep: comm.Message.BitcoinReport = .{ + const btcrep: comm.Message.OnchainReport = .{ .blocks = block_count, .headers = block_count, .timestamp = @intCast(now), @@ -183,7 +183,7 @@ fn commWriteThread(gpa: std.mem.Allocator, w: anytype) !void { .reserved = 100000, }, }; - comm.write(gpa, w, .{ .bitcoind_report = btcrep }) catch |err| logger.err("comm.write: {any}", .{err}); + comm.write(gpa, w, .{ .onchain_report = btcrep }) catch |err| logger.err("comm.write: {any}", .{err}); if (block_count % 2 == 0) { const lndrep: comm.Message.LightningReport = .{ diff --git a/src/ui/bitcoin.zig b/src/ui/bitcoin.zig index c9423d5..ac910c1 100644 --- a/src/ui/bitcoin.zig +++ b/src/ui/bitcoin.zig @@ -113,7 +113,7 @@ pub fn initTabPanel(cont: lvgl.Container) !void { /// updates the tab with new data from the report. /// the tab must be inited first with initTabPanel. -pub fn updateTabPanel(rep: comm.Message.BitcoinReport) !void { +pub fn updateTabPanel(rep: comm.Message.OnchainReport) !void { var buf: [512]u8 = undefined; // blockchain section