Skip to content

Commit

Permalink
♻️ refactor project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelStark committed Sep 4, 2024
1 parent 10d70d8 commit 28c54f6
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 61 deletions.
21 changes: 0 additions & 21 deletions src/cli.zig

This file was deleted.

File renamed without changes.
4 changes: 2 additions & 2 deletions src/mempool.zig → src/core/mempool.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const Config = @import("config.zig").Config;
const tx = @import("transaction.zig");
const Config = @import("../config/config.zig").Config;
const tx = @import("../types/transaction.zig");

const Transaction = struct {};

Expand Down
11 changes: 6 additions & 5 deletions src/lib.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pub usingnamespace @import("config.zig");
pub usingnamespace @import("mempool.zig");
pub usingnamespace @import("p2p.zig");
pub usingnamespace @import("rpc.zig");
pub usingnamespace @import("storage.zig");
pub const config = @import("config/config.zig");
pub const mempool = @import("core/mempool.zig");
pub const p2p = @import("network/p2p.zig");
pub const rpc = @import("network/rpc.zig");
pub const storage = @import("storage/storage.zig");
pub const wallet = @import("wallet/wallet.zig");

test {
@import("std").testing.refAllDeclsRecursive(@This());
Expand Down
34 changes: 7 additions & 27 deletions src/main.zig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const std = @import("std");
const Config = @import("config.zig").Config;
const Mempool = @import("mempool.zig").Mempool;
const Storage = @import("storage.zig").Storage;
const P2P = @import("p2p.zig").P2P;
const RPC = @import("rpc.zig").RPC;
const CLI = @import("cli.zig").CLI;
const Config = @import("config/config.zig").Config;
const Mempool = @import("core/mempool.zig").Mempool;
const Storage = @import("storage/storage.zig").Storage;
const P2P = @import("network/p2p.zig").P2P;
const RPC = @import("network/rpc.zig").RPC;
const node = @import("node/node.zig");

pub fn main() !void {
// Initialize the allocator
Expand All @@ -16,9 +16,6 @@ pub fn main() !void {
var config = try Config.load(allocator, "bitcoin.conf.example");
defer config.deinit();

var cli = try CLI.init(allocator);
defer cli.deinit();

// Initialize components
var mempool = try Mempool.init(allocator, &config);
defer mempool.deinit();
Expand All @@ -33,22 +30,5 @@ pub fn main() !void {
defer rpc.deinit();

// Start the node
try startNode(&mempool, &storage, &p2p, &rpc, &cli);
}

fn startNode(_: *Mempool, _: *Storage, p2p: *P2P, rpc: *RPC, _: *CLI) !void {
std.log.info("Starting btczee node...", .{});

// Start P2P network
try p2p.start();

// Start RPC server
try rpc.start();

// Main event loop
while (true) {
// Handle events, process blocks, etc.
std.log.debug("Waiting for blocks...", .{});
std.time.sleep(std.time.ns_per_s);
}
try node.startNode(&mempool, &storage, &p2p, &rpc);
}
2 changes: 1 addition & 1 deletion src/p2p.zig → src/network/p2p.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const net = std.net;
const Config = @import("config.zig").Config;
const Config = @import("../config/config.zig").Config;
const Peer = @import("peer.zig").Peer;

/// P2P network handler.
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions src/rpc.zig → src/network/rpc.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const std = @import("std");
const Config = @import("config.zig").Config;
const Mempool = @import("mempool.zig").Mempool;
const Storage = @import("storage.zig").Storage;
const P2P = @import("p2p.zig").P2P;
const Config = @import("../config/config.zig").Config;
const Mempool = @import("../core/mempool.zig").Mempool;
const Storage = @import("../storage/storage.zig").Storage;
const httpz = @import("httpz");

/// RPC Server handler.
Expand Down
23 changes: 23 additions & 0 deletions src/node/node.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const std = @import("std");
const Config = @import("../config/config.zig").Config;
const Mempool = @import("../core/mempool.zig").Mempool;
const Storage = @import("../storage/storage.zig").Storage;
const P2P = @import("../network/p2p.zig").P2P;
const RPC = @import("../network/rpc.zig").RPC;

pub fn startNode(_: *Mempool, _: *Storage, p2p: *P2P, rpc: *RPC) !void {
std.log.info("Starting btczee node...", .{});

// Start P2P network
try p2p.start();

// Start RPC server
try rpc.start();

// Main event loop
while (true) {
// Handle events, process blocks, etc.
std.log.debug("Waiting for blocks...", .{});
std.time.sleep(std.time.ns_per_s);
}
}
Empty file added src/primitives/lib.zig
Empty file.
2 changes: 1 addition & 1 deletion src/storage.zig → src/storage/storage.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const Config = @import("config.zig").Config;
const Config = @import("../config/config.zig").Config;

/// Storage handler.
///
Expand Down
File renamed without changes.
Empty file added src/wallet/wallet.zig
Empty file.

0 comments on commit 28c54f6

Please sign in to comment.