Skip to content

Commit

Permalink
move dependencies to zon
Browse files Browse the repository at this point in the history
  • Loading branch information
iskyd committed Sep 30, 2024
1 parent 4733421 commit 5d31569
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 39 deletions.
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,11 @@ zig build test
zig build test --summary all -- src/bip39/bip39.zig src/bip38/bip38.zig
```

### Lib
External libraries such as base58 and clap are installed as git submodule and added to build.zig

### Dev Environment
See devbox.json
``` bash
devbox shell
```
Ensure that you installed the submodule by:
```bash
git submodule update --init
```

### Bitcoin Node
Use Dockerfile to run bitcoin node using bitcoin-core. node/bitcoin.conf can be used as bitcoin config to run regtest with rpcuser walle and pwd password.
Expand Down Expand Up @@ -70,12 +63,12 @@ Join [WALL•E's Discord channel](https://discord.gg/9e9qnzQAH6) to chat with th
- [x] Serialized Extendend Private/Public Key (https://learnmeabitcoin.com/technical/keys/hd-wallets/extended-keys/)
- [x] BIP38 (Encrypting Bitcoin Private Key)
- [x] BIP44
- [ ] Wallet files
- [x] ECDSA Signatures
- [ ] Segwit
- [x] Segwit
- [x] Bech32
- [x] BTC Node integration
- [x] Wallet Sync
- [ ] Legacy Wallet
- [ ] Script Hash (P2SH, P2WSH)
- [ ] Transactions
- [ ] CLI
Expand Down
36 changes: 11 additions & 25 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,21 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});

const base58 = b.addModule("base58", .{
.root_source_file = b.path("lib/base58/src/lib.zig"),
});
const clap = b.addModule("clap", .{
.root_source_file = b.path("lib/clap/clap.zig"),
});
const crypto = b.addModule("crypto", .{
.root_source_file = b.path("src/crypto/crypto.zig"),
});
const base58_module = b.dependency("base58-zig", .{ .target = target, .optimize = optimize }).module("base58-zig");
const clap_module = b.dependency("clap", .{ .target = target, .optimize = optimize }).module("clap");
const sqlite = b.dependency("sqlite", .{ .target = target, .optimize = optimize });
const sqlite_module = sqlite.module("sqlite");

const sqlite = b.addModule("sqlite", .{
.root_source_file = b.path("lib/zig-sqlite/sqlite.zig"),
});
sqlite.addCSourceFiles(.{
.files = &[_][]const u8{
"lib/zig-sqlite/c/workaround.c",
},
.flags = &[_][]const u8{"-std=c99"},
});
sqlite.addIncludePath(b.path("lib/zig-sqlite/c"));

indexer.root_module.addImport("base58", base58);
indexer.root_module.addImport("clap", clap);
indexer.root_module.addImport("base58", base58_module);
indexer.root_module.addImport("clap", clap_module);
indexer.root_module.addImport("crypto", crypto);
indexer.linkLibC();
indexer.linkSystemLibrary("sqlite3");
indexer.root_module.addImport("sqlite", sqlite);
indexer.linkLibrary(sqlite.artifact("sqlite"));
indexer.root_module.addImport("sqlite", sqlite_module);

wbx.root_module.addImport("base58", base58);
wbx.root_module.addImport("base58", base58_module);
wbx.root_module.addImport("crypto", crypto);

// This declares intent for the executable to be installed into the
Expand Down Expand Up @@ -117,9 +103,9 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
// .main_mod_path = .{ .path = "." }, // .main_mod_path in zig 0.12.0
});
unit_tests.root_module.addImport("base58", base58);
unit_tests.root_module.addImport("base58", base58_module);
unit_tests.root_module.addImport("crypto", crypto);
unit_tests.root_module.addImport("sqlite", sqlite);
unit_tests.root_module.addImport("sqlite", sqlite_module);
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
57 changes: 57 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.{
// This is the default name used by packages depending on this one. For
// example, when a user runs `zig fetch --save <url>`, this field is used
// as the key in the `dependencies` table. Although the user can choose a
// different name, most users will stick with this provided value.
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "walle",

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
// with this value.
.minimum_zig_version = "0.13.0",

// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
.@"base58-zig" = .{
.url = "https://github.com/iskyd/base58-zig/archive/0.1.2.tar.gz",
.hash = "12206e5050a03cd9dcb896781de0cf541081488006532675371653f61d00c1f27433",
},
.clap = .{
.url = "https://github.com/Hejsil/zig-clap/archive/0.9.1.tar.gz",
.hash = "122062d301a203d003547b414237229b09a7980095061697349f8bef41be9c30266b",
},
.sqlite = .{
.url = "https://github.com/vrischmann/zig-sqlite/archive/91e5fedd15c5ea3cb42ccceefb3d0f4bb9bad68f.tar.gz",
.hash = "1220ba277845cb3cece7a7a1f929b920c97e9085bb644471c5dc8c72571f1485c75f",
},
},

// Specifies the set of files and directories that are included in this package.
// Only files and directories listed here are included in the `hash` that
// is computed for this package. Only files listed here will remain on disk
// when using the zig package manager. As a rule of thumb, one should list
// files required for compilation plus any license(s).
// Paths are relative to the build root. Use the empty string (`""`) to refer to
// the build root itself.
// A directory listed here means that all files within, recursively, are included.
.paths = .{
"build.zig",
"build.zig.zon",
"src",
// For example...
//"LICENSE",
"README.md",
},
}
1 change: 0 additions & 1 deletion lib/base58
Submodule base58 deleted from e1001f
1 change: 0 additions & 1 deletion lib/clap
Submodule clap deleted from 1d413d
1 change: 0 additions & 1 deletion lib/zig-sqlite
Submodule zig-sqlite deleted from 91e5fe
2 changes: 1 addition & 1 deletion run_indexer.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#! /bin/bash

./zig-out/bin/walle --location http://0.0.0.0:18444 --user walle --password password
./zig-out/bin/indexer --location http://0.0.0.0:18444 --user walle --password password
2 changes: 1 addition & 1 deletion src/db/db.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn initDB(db: *sqlite.Db) !void {
var stmt_transactions = try db.prepare(sql_transactions);
defer stmt_transactions.deinit();

const sql_outputs = "CREATE TABLE IF NOT EXISTS outputs(txid VARCHAR(64), vout INTEGER, amount INTEGER NOT NULL, unspent INTEGER, path TEXT NOT NULL, PRIMARY KEY(txid, n));";
const sql_outputs = "CREATE TABLE IF NOT EXISTS outputs(txid VARCHAR(64), vout INTEGER NOT NULL, amount INTEGER NOT NULL, unspent INTEGER, path TEXT NOT NULL, PRIMARY KEY(txid, vout));";
var stmt_outputs = try db.prepare(sql_outputs);
defer stmt_outputs.deinit();

Expand Down

0 comments on commit 5d31569

Please sign in to comment.