Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(p2p): add wire package for messages io #51

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
.hash = "1220f9e1eb744c8dc2750c1e6e1ceb1c2d521bedb161ddead1a6bb772032e576d74a",
},
.@"bitcoin-primitives" = .{
.url = "git+https://github.com/zig-bitcoin/bitcoin-primitives#4d179bb3027dbc35a99a56938c05008b62e4bf7e",
.hash = "1220a65f6105a79c9347449d2553e7abf965b3f61fa883478954d861e824631d5396",
.url = "git+https://github.com/zig-bitcoin/bitcoin-primitives#3743701d398b35af80826b729b6eb12d3e8e8df9",
.hash = "12204e7aa2c42049440faf891e80cd7bc85f64b4aacdcda75e891ca52787f267342c",
},
},
.paths = .{
Expand Down
1 change: 1 addition & 0 deletions src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub const wallet = @import("wallet/wallet.zig");
pub const miner = @import("miner/miner.zig");
pub const node = @import("node/node.zig");
pub const script = @import("script/lib.zig");
pub const wire = @import("network/wire/lib.zig");

test {
@import("std").testing.refAllDeclsRecursive(@This());
Expand Down
23 changes: 5 additions & 18 deletions src/network/protocol/lib.zig
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
pub const message = @import("./message.zig");
pub const messages = @import("./messages/lib.zig");

/// Protocol version
pub const PROTOCOL_VERSION: i32 = 70015;

/// Known network ids
pub const NetworkMagicBytes = struct {
pub const MAINNET: [4]u8 = 0xd9b4bef9;
pub const BitcoinNetworkId = struct {
pub const MAINNET: [4]u8 = .{ 0xd9, 0xb4, 0xbe, 0xf9 };
pub const REGTEST: [4]u8 = 0xdab5bffa;
pub const TESTNET3: [4]u8 = 0x0709110b;
pub const SIGNET: [4]u8 = 0x40cf030a;
};

/// Protocol version
pub const PROTOCOL_VERSION: i32 = 70015;

/// Network services
pub const ServiceFlags = struct {
pub const NODE_NETWORK: u64 = 0x1;
Expand All @@ -22,18 +21,6 @@ pub const ServiceFlags = struct {
pub const NODE_NETWORK_LIMITED: u64 = 0x0400;
};

/// An IpV6 address
pub const IpV6Address = struct {
ip: [8]u16, // represented in big endian
port: u16, // represented in system native endian
};

/// NetworkAddress represents a network address
pub const NetworkAddress = struct {
services: u64,
address: IpV6Address,
};

pub const CommandNames = struct {
pub const VERSION = "version";
pub const VERACK = "verack";
Expand Down
42 changes: 0 additions & 42 deletions src/network/protocol/message.zig

This file was deleted.

13 changes: 13 additions & 0 deletions src/network/protocol/messages/lib.zig
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
const std = @import("std");
pub const VersionMessage = @import("version.zig").VersionMessage;

pub const MessageTypes = enum { Version };

pub const Message = union(MessageTypes) {
Version: VersionMessage,

pub fn deinit(self: Message, allocator: std.mem.Allocator) void {
switch (self) {
.Version => |m| m.deinit(allocator),
}
}
};
Loading
Loading