Skip to content

Commit

Permalink
segwit pre image hash
Browse files Browse the repository at this point in the history
  • Loading branch information
iskyd committed Sep 18, 2024
1 parent 77a25a6 commit 65a1ad6
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 95 deletions.
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub fn build(b: *std.Build) void {
});
unit_tests.root_module.addImport("base58", base58);
unit_tests.root_module.addImport("crypto", crypto);
unit_tests.root_module.addImport("sqlite", sqlite);
const run_unit_tests = b.addRunArtifact(unit_tests);
run_unit_tests.has_side_effects = true; // Always execute test, do not cache
test_step.dependOn(&run_unit_tests.step);
Expand Down
18 changes: 9 additions & 9 deletions src/db/db.zig
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ pub fn getOutputDescriptorPath(allocator: std.mem.Allocator, db: *sqlite.Db, txi
const sqlOutput = "SELECT path AS c FROM outputs WHERE txid = ? AND n = ?";
var stmt = try db.prepare(sqlOutput);
defer stmt.deinit();
const row = try stmt.one(struct { path: []u8 }, .{}, .{ .txid = txid, .n = n }, allocator);
const row = try stmt.oneAlloc(struct { path: []u8 }, allocator, .{}, .{ .txid = txid, .n = n });
if (row != null) {
defer allocator.free(row.path);
return KeyPath(5).fromStr(row.path);
defer allocator.free(row.?.path);
return KeyPath(5).fromStr(row.?.path);
}

return null;
return error.DescriptorNotFound;
}

pub fn saveTransaction(db: *sqlite.Db, block_heigth: usize, transactions: std.AutoHashMap([64]u8, bool), rawtransactionsmap: std.AutoHashMap([64]u8, []u8)) !void {
Expand Down Expand Up @@ -220,14 +220,14 @@ pub fn getDescriptors(allocator: std.mem.Allocator, db: *sqlite.Db) ![]Descripto
return descriptors;
}

pub fn getDescriptor(allocator: std.mem.Allocator, db: *sqlite.Db, path: []u8) !?Descriptor {
const sql = "SELECT extended_key, path, private FROM descriptor WHERE path=? LIMIT 1;";
pub fn getDescriptor(allocator: std.mem.Allocator, db: *sqlite.Db, path: []u8, private: bool) !?Descriptor {
const sql = "SELECT extended_key, path, private FROM descriptor WHERE path=? AND private=? LIMIT 1;";
var stmt = try db.prepare(sql);
defer stmt.deinit();
const row = try stmt.one(struct { extended_key: [111]u8, path: []const u8, private: bool }, allocator, .{}, .{ .path = path });
const row = try stmt.oneAlloc(struct { extended_key: [111]u8, path: []const u8, private: bool }, allocator, .{}, .{ .path = path, .private = private });
if (row != null) {
defer allocator.free(row.path);
return Descriptor{ .extended_key = row.extended_key, .keypath = try KeyPath(3).fromStr(row.path), .private = row.private };
defer allocator.free(row.?.path);
return Descriptor{ .extended_key = row.?.extended_key, .keypath = try KeyPath(3).fromStr(row.?.path), .private = row.?.private };
}

return null;
Expand Down
Loading

0 comments on commit 65a1ad6

Please sign in to comment.