-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71c03a0
commit 3a5fdbd
Showing
13 changed files
with
227 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Bitcoin configuration file | ||
|
||
# Network-related settings | ||
testnet=0 | ||
port=8333 | ||
rpcport=8332 | ||
|
||
# Data directory | ||
datadir=.bitcoin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const std = @import("std"); | ||
const Config = @import("config.zig").Config; | ||
const RPC = @import("rpc.zig").RPC; | ||
|
||
pub const CLI = struct { | ||
allocator: std.mem.Allocator, | ||
config: *const Config, | ||
rpc: *RPC, | ||
|
||
pub fn init(allocator: std.mem.Allocator, config: *const Config, rpc: *RPC) !CLI { | ||
return CLI{ | ||
.allocator = allocator, | ||
.config = config, | ||
.rpc = rpc, | ||
}; | ||
} | ||
|
||
pub fn deinit(self: *CLI) void { | ||
// Clean up resources if needed | ||
_ = self; | ||
} | ||
|
||
pub fn start(_: *CLI) !void {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const std = @import("std"); | ||
|
||
pub const Config = struct { | ||
allocator: std.mem.Allocator, | ||
rpc_port: u16, | ||
p2p_port: u16, | ||
testnet: bool, | ||
datadir: []const u8, | ||
|
||
pub fn load(allocator: std.mem.Allocator, filename: []const u8) !Config { | ||
const file = try std.fs.cwd().openFile(filename, .{}); | ||
defer file.close(); | ||
|
||
var buf_reader = std.io.bufferedReader(file.reader()); | ||
var in_stream = buf_reader.reader(); | ||
|
||
var config = Config{ | ||
.allocator = allocator, | ||
.rpc_port = 8332, | ||
.p2p_port = 8333, | ||
.testnet = false, | ||
.datadir = try allocator.dupe(u8, ".bitcoin"), | ||
}; | ||
|
||
var buf: [1024]u8 = undefined; | ||
while (try in_stream.readUntilDelimiterOrEof(&buf, '\n')) |line| { | ||
var it = std.mem.splitSequence(u8, line, "="); | ||
const key = it.next() orelse continue; | ||
const value = it.next() orelse continue; | ||
|
||
if (std.mem.eql(u8, key, "rpcport")) { | ||
config.rpc_port = try std.fmt.parseInt(u16, value, 10); | ||
} else if (std.mem.eql(u8, key, "port")) { | ||
config.p2p_port = try std.fmt.parseInt(u16, value, 10); | ||
} else if (std.mem.eql(u8, key, "testnet")) { | ||
config.testnet = std.mem.eql(u8, value, "1"); | ||
} else if (std.mem.eql(u8, key, "datadir")) { | ||
allocator.free(config.datadir); | ||
config.datadir = try allocator.dupe(u8, value); | ||
} | ||
} | ||
|
||
return config; | ||
} | ||
|
||
pub fn deinit(self: *Config) void { | ||
self.allocator.free(self.datadir); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
pub usingnamespace @import("core/lib.zig"); | ||
pub usingnamespace @import("primitives/lib.zig"); | ||
|
||
test { | ||
@import("std").testing.refAllDeclsRecursive(@This()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,57 @@ | ||
const std = @import("std"); | ||
const cli = @import("zig-cli"); | ||
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; | ||
|
||
// Configuration settings for the CLI | ||
const Args = struct { | ||
mint: bool = false, | ||
mnemonic: bool = false, | ||
}; | ||
pub fn main() !void { | ||
// Initialize the allocator | ||
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | ||
defer _ = gpa.deinit(); | ||
const allocator = gpa.allocator(); | ||
|
||
var cfg: Args = .{}; | ||
// Load configuration | ||
var config = try Config.load(allocator, "bitcoin.conf.example"); | ||
defer config.deinit(); | ||
|
||
pub fn main() !void { | ||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); | ||
defer arena.deinit(); | ||
|
||
const allocator = arena.allocator(); | ||
|
||
var r = try cli.AppRunner.init(allocator); | ||
defer r.deinit(); | ||
|
||
// Define the CLI app | ||
const app = cli.App{ | ||
.version = "0.0.1", | ||
.author = "@AbdelStark", | ||
.command = .{ | ||
.name = "btczee", | ||
.target = .{ | ||
.subcommands = &.{ | ||
.{ | ||
.name = "info", | ||
.description = .{ | ||
.one_line = "Display information about btczee", | ||
}, | ||
.options = &.{}, | ||
.target = .{ .action = .{ .exec = displayInfo } }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
return r.run(&app); | ||
// Initialize components | ||
var mempool = try Mempool.init(allocator, &config); | ||
defer mempool.deinit(); | ||
|
||
var storage = try Storage.init(allocator, &config); | ||
defer storage.deinit(); | ||
|
||
var p2p = try P2P.init(allocator, &config); | ||
defer p2p.deinit(); | ||
|
||
var rpc = try RPC.init(allocator, &config, &mempool, &storage, &p2p); | ||
defer rpc.deinit(); | ||
|
||
var cli = try CLI.init(allocator, &config, &rpc); | ||
defer cli.deinit(); | ||
|
||
// Start the node | ||
try startNode(&mempool, &storage, &p2p, &rpc, &cli); | ||
} | ||
|
||
fn displayInfo() !void { | ||
const stdout = std.io.getStdOut().writer(); | ||
fn startNode(_: *Mempool, _: *Storage, p2p: *P2P, rpc: *RPC, cli: *CLI) !void { | ||
std.log.info("Starting btczee node...", .{}); | ||
|
||
// Start P2P network | ||
try p2p.start(); | ||
|
||
// Start RPC server | ||
try rpc.start(); | ||
|
||
// Start CLI | ||
try cli.start(); | ||
|
||
try stdout.print("Version: 0.1.0\n", .{}); | ||
// Main event loop | ||
while (true) { | ||
// Handle events, process blocks, etc. | ||
std.log.debug("Waiting for blocks...", .{}); | ||
std.time.sleep(std.time.ns_per_s); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const std = @import("std"); | ||
const Config = @import("config.zig").Config; | ||
|
||
pub const Mempool = struct { | ||
allocator: std.mem.Allocator, | ||
config: *const Config, | ||
|
||
pub fn init(allocator: std.mem.Allocator, config: *const Config) !Mempool { | ||
return Mempool{ | ||
.allocator = allocator, | ||
.config = config, | ||
}; | ||
} | ||
|
||
pub fn deinit(self: *Mempool) void { | ||
// Clean up resources if needed | ||
_ = self; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const std = @import("std"); | ||
const Config = @import("config.zig").Config; | ||
|
||
pub const P2P = struct { | ||
allocator: std.mem.Allocator, | ||
config: *const Config, | ||
|
||
pub fn init(allocator: std.mem.Allocator, config: *const Config) !P2P { | ||
return P2P{ | ||
.allocator = allocator, | ||
.config = config, | ||
}; | ||
} | ||
|
||
pub fn deinit(self: *P2P) void { | ||
// Clean up resources if needed | ||
_ = self; | ||
} | ||
|
||
pub fn start(self: *P2P) !void { | ||
std.log.info("Starting P2P network on port {}", .{self.config.p2p_port}); | ||
// Implement P2P network initialization | ||
} | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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; | ||
|
||
pub const RPC = struct { | ||
allocator: std.mem.Allocator, | ||
config: *const Config, | ||
mempool: *Mempool, | ||
storage: *Storage, | ||
p2p: *P2P, | ||
|
||
pub fn init(allocator: std.mem.Allocator, config: *const Config, mempool: *Mempool, storage: *Storage, p2p: *P2P) !RPC { | ||
return RPC{ | ||
.allocator = allocator, | ||
.config = config, | ||
.mempool = mempool, | ||
.storage = storage, | ||
.p2p = p2p, | ||
}; | ||
} | ||
|
||
pub fn deinit(self: *RPC) void { | ||
// Clean up resources if needed | ||
_ = self; | ||
} | ||
|
||
pub fn start(self: *RPC) !void { | ||
std.log.info("Starting RPC server on port {}", .{self.config.rpc_port}); | ||
// Implement RPC server initialization | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const std = @import("std"); | ||
const Config = @import("config.zig").Config; | ||
|
||
pub const Storage = struct { | ||
allocator: std.mem.Allocator, | ||
config: *const Config, | ||
|
||
pub fn init(allocator: std.mem.Allocator, config: *const Config) !Storage { | ||
return Storage{ | ||
.allocator = allocator, | ||
.config = config, | ||
}; | ||
} | ||
|
||
pub fn deinit(self: *Storage) void { | ||
// Clean up resources if needed | ||
_ = self; | ||
} | ||
}; |