Skip to content
Draft
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# exclude all db
*.sqlite

# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
Expand Down
48 changes: 48 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,42 @@ const external_dependencies = [_]build_helpers.Dependency{
.name = "clap",
.module_name = "clap",
},
.{
.name = "zqlite",
.module_name = "zqlite",
},
};

fn installSqliteDependency(sqlitec: *std.Build.Dependency, compile: *std.Build.Step.Compile) void {
compile.addCSourceFile(.{
.file = sqlitec.path("sqlite3.c"),
.flags = &[_][]const u8{
"-DSQLITE_DQS=0",
"-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1",
"-DSQLITE_USE_ALLOCA=1",
"-DSQLITE_THREADSAFE=1",
"-DSQLITE_TEMP_STORE=3",
"-DSQLITE_ENABLE_API_ARMOR=1",
"-DSQLITE_ENABLE_UNLOCK_NOTIFY",
"-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1",
"-DSQLITE_DEFAULT_FILE_PERMISSIONS=0600",
"-DSQLITE_OMIT_DECLTYPE=1",
"-DSQLITE_OMIT_DEPRECATED=1",
"-DSQLITE_OMIT_LOAD_EXTENSION=1",
"-DSQLITE_OMIT_PROGRESS_CALLBACK=1",
"-DSQLITE_OMIT_SHARED_CACHE",
"-DSQLITE_OMIT_UTF16=1",
"-DHAVE_USLEEP=0",
"-DSQLITE_DEBUG=1",
"-DSQLITE_ENABLE_EXPLAIN_COMMENTS=1",
"-DSQLITE_ENABLE_TREETRACE=1",
"-DSQLITE_ENABLE_WHERETRACE=1",
"-DSQLITE_TRACE_STMT=1",
},
});
compile.linkLibC();
}

pub fn build(b: *std.Build) !void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
Expand All @@ -43,6 +77,12 @@ pub fn build(b: *std.Build) !void {
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});

// Sqlite3 c library source code
const sqlitec = b.dependency("sqlitec", .{
.target = target,
.optimize = optimize,
});

// **************************************************************
// * HANDLE DEPENDENCY MODULES *
// **************************************************************
Expand Down Expand Up @@ -101,6 +141,7 @@ pub fn build(b: *std.Build) !void {
.target = target,
.optimize = optimize,
});
installSqliteDependency(sqlitec, exe);

// Add dependency modules to the library.
for (deps) |mod| exe.root_module.addImport(
Expand All @@ -124,6 +165,7 @@ pub fn build(b: *std.Build) !void {
mod.name,
mod.module,
);
installSqliteDependency(sqlitec, exe);

check.dependOn(&exe.step);
}
Expand All @@ -136,6 +178,7 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
.single_threaded = false,
});
installSqliteDependency(sqlitec, lib_unit_tests);

// Add dependency modules to the library.
for (deps) |mod| lib_unit_tests.root_module.addImport(
Expand All @@ -160,6 +203,8 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
});

installSqliteDependency(sqlitec, exe);

// Add dependency modules to the library.
for (deps) |mod| exe.root_module.addImport(
mod.name,
Expand Down Expand Up @@ -190,6 +235,8 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
});

installSqliteDependency(sqlitec, exe);

// Add dependency modules to the library.
for (deps) |mod| exe.root_module.addImport(
mod.name,
Expand All @@ -215,6 +262,7 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
.single_threaded = false,
});
installSqliteDependency(sqlitec, lib_unit_tests);

// Add dependency modules to the library.
for (deps) |mod| lib_unit_tests.root_module.addImport(
Expand Down
16 changes: 14 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
// internet connectivity.
.dependencies = .{
.zul = .{
.url = "https://github.com/karlseguin/zul/archive/08c989bf6871e87807a4668232913ee245425863.zip",
.hash = "12206f5d1e5bd4793fe952bbae891b7424a19026e0d296a1381074c7d21d5d76c1a1",
.url = "https://github.com/StringNick/zul/archive/9f9acdff296918e0f81e8af39b269dad988c48f9.zip",
.hash = "122016552e83ec129489fd32d89b4122f737fcdacb22dbee34dca2fbc62981bb487d",
},
.@"zig-cli" = .{
.url = "https://github.com/StringNick/zig-cli/archive/c9b9d17b14c524785a32a5b7c930b9584a331372.zip",
Expand All @@ -51,6 +51,18 @@
.url = "git+https://github.com/Hejsil/zig-clap#2d9db156ae928860a9acf2f1260750d3b44a4c98",
.hash = "122005e589ab3b6bff8e589b45f5b12cd27ce79f266bdac17e9f33ebfe2fbaff7fe3",
},
.rocksdb = .{
.url = "git+https://github.com/zig-bitcoin/rocksdb-zig#27f69e3756999ac711f4f9278a698fd5eecce169",
.hash = "122086b7931284e391223ce165a9bee94b624a7fb34531ecc95cafb22f049887d175",
},
.zqlite = .{
.url = "git+https://github.com/karlseguin/zqlite.zig#5b9e8715fb174c1c1f0bf15e4fbf5e77df5c6b34",
.hash = "12209446c0581a04f460f978c489c6e5eec62ca1c4f95a7c5cf8f1d2abc597074db7",
},
.sqlitec = .{
.url = "https://www.sqlite.org/2024/sqlite-amalgamation-3460100.zip",
.hash = "12206bc219bf56b927469c7d43f53c23fe2801c8158800f8613a783956998b7fc37f",
},
},
.paths = .{
"build.zig",
Expand Down
18 changes: 9 additions & 9 deletions src/core/database/database.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ const MintQuote = @import("../mint/mint.zig").MintQuote;
const MeltQuote = @import("../mint/mint.zig").MeltQuote;

pub const MintMemoryDatabase = @import("mint_memory.zig").MintMemoryDatabase;
pub const MintSqliteDatabase = @import("mint_sqlite.zig").Database;

pub const MintDatabase = struct {
const Self = @This();

allocator: std.mem.Allocator,
ptr: *anyopaque,
size: usize,
align_of: usize,

deinitFn: *const fn (ptr: *anyopaque, allocator: std.mem.Allocator) void,

setActiveKeysetFn: *const fn (ptr: *anyopaque, unit: nuts.CurrencyUnit, id: nuts.Id) anyerror!void,
Expand Down Expand Up @@ -70,6 +68,7 @@ pub const MintDatabase = struct {
ptr: *anyopaque,
blinded_messages: []const secp256k1.PublicKey,
blind_signatures: []const nuts.BlindSignature,
quote_id: ?[]const u8,
) anyerror!void,
getBlindSignaturesFn: *const fn (
ptr: *anyopaque,
Expand Down Expand Up @@ -218,9 +217,10 @@ pub const MintDatabase = struct {
pointer: *anyopaque,
blinded_messages: []const secp256k1.PublicKey,
blind_signatures: []const nuts.BlindSignature,
quote_id: ?[]const u8,
) anyerror!void {
const self: *T = @ptrCast(@alignCast(pointer));
return self.addBlindSignatures(blinded_messages, blind_signatures);
return self.addBlindSignatures(blinded_messages, blind_signatures, quote_id);
}

pub fn getBlindSignatures(
Expand All @@ -240,14 +240,15 @@ pub const MintDatabase = struct {
const self: *T = @ptrCast(@alignCast(pointer));
return self.getBlindSignaturesForKeyset(gpa, keyset_id);
}
pub fn deinit(pointer: *anyopaque, allocator: std.mem.Allocator) void {

pub fn deinit(pointer: *anyopaque, __allocator: std.mem.Allocator) void {
const self: *T = @ptrCast(@alignCast(pointer));

if (std.meta.hasFn(T, "deinit")) {
self.deinit();
}

allocator.destroy(self);
__allocator.destroy(self);
}
};

Expand All @@ -257,8 +258,6 @@ pub const MintDatabase = struct {
return .{
.ptr = ptr,
.allocator = _allocator,
.size = @sizeOf(T),
.align_of = @alignOf(T),

.getBlindSignaturesForKeysetFn = gen.getBlindSignaturesForKeyset,

Expand Down Expand Up @@ -406,8 +405,9 @@ pub const MintDatabase = struct {
self: Self,
blinded_messages: []const secp256k1.PublicKey,
blind_signatures: []const nuts.BlindSignature,
quote_id: ?[]const u8,
) anyerror!void {
return self.addBlindSignaturesFn(self.ptr, blinded_messages, blind_signatures);
return self.addBlindSignaturesFn(self.ptr, blinded_messages, blind_signatures, quote_id);
}

pub fn getBlindSignatures(
Expand Down
4 changes: 4 additions & 0 deletions src/core/database/mint_memory.zig
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,17 @@ pub const MintMemoryDatabase = struct {
self: *Self,
blinded_messages: []const secp256k1.PublicKey,
blind_signatures: []const nuts.BlindSignature,
quote_id: ?[]const u8,
) !void {
_ = quote_id; // autofix
self.lock.lock();
defer self.lock.unlock();

for (blinded_messages, blind_signatures) |blinded_message, blind_signature| {
try self.blinded_signatures.put(blinded_message.serialize(), blind_signature);
}

// TODO quote signatures
}

pub fn getBlindSignatures(
Expand Down
Loading
Loading