Skip to content

Commit

Permalink
broadcast tx cli
Browse files Browse the repository at this point in the history
  • Loading branch information
iskyd committed Nov 24, 2024
1 parent 93ffde4 commit 06e37f6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/walle.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Output = @import("tx.zig").Output;
const tx = @import("tx.zig");
const sqlite = @import("sqlite");
const crypto = @import("crypto");
const rpc = @import("rpc/rpc.zig");

fn showHelp() void {
std.debug.print("Valid commands: createwallet, newaddr, listoutputs, send\nFor more information use walle <cmd> help", .{});
Expand Down Expand Up @@ -75,6 +76,7 @@ pub fn main() !void {
newaddr,
listoutputs,
send,
broadcasttx,
};

const args = std.process.argsAlloc(allocator) catch {
Expand Down Expand Up @@ -276,5 +278,25 @@ pub fn main() !void {

std.debug.print("\n{s}\n", .{raw_tx_hex});
},
.broadcasttx => {
if (args.len < 6 or std.mem.eql(u8, args[2], "help")) {
std.debug.print("Broadcast tx <rpc location> <rpc user> <rpc password> <raw tx>\n", .{});
return;
}
const rpc_location = args[2];
const rpc_user = args[3];
const rpc_password = args[4];
const raw_tx = args[5];

std.debug.print("rpc location {s}\n", .{rpc_location});

const auth = try rpc.generateAuth(allocator, rpc_user, rpc_password);
defer allocator.free(auth);
var client = std.http.Client{ .allocator = allocator };
defer client.deinit();
try rpc.sendRawTx(allocator, &client, rpc_location, auth, raw_tx);

std.debug.print("Transaction broadcasted\n", .{});
},
}
}

0 comments on commit 06e37f6

Please sign in to comment.