-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathjustfile
More file actions
151 lines (137 loc) · 6.12 KB
/
justfile
File metadata and controls
151 lines (137 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# list available just commands
default:
@just --list
@echo "Run 'just <recipe>' to execute a command."
# format nix files
formatnix:
alejandra .
# enter devenv shell
shell:
devenv shell
# start development processes; pass 'backtrace' to enable RUST_BACKTRACE=1
up mode="":
@if [ "{{mode}}" = "backtrace" ]; then \
RUST_BACKTRACE=1 devenv up; \
else \
devenv up; \
fi
# point cdk cargo dependencies to local repo
local-cdk:
./scripts/patch-cdk-path.sh
# restore cargo dependencies from .bak files
restore-deps:
find . -name "Cargo.toml.bak" | while IFS= read -r bakfile; do \
origfile="${bakfile%.bak}"; \
echo "✅ Restoring $origfile from $bakfile"; \
mv "$bakfile" "$origfile"; \
done
# update cdk commit hash in all Cargo.toml files and build configs
update-cdk OLD_REV NEW_REV:
@echo "Updating CDK revision from {{OLD_REV}} to {{NEW_REV}}..."
@# Update Cargo.toml files
@find . -name "Cargo.toml" | xargs grep -l "cdk.*git.*vnprc.*rev.*{{OLD_REV}}" | while IFS= read -r file; do \
echo "✅ Updating $file"; \
sed -i 's|rev = "{{OLD_REV}}"|rev = "{{NEW_REV}}"|g' "$file"; \
done
@# Update justfile CDK_COMMIT variable
@echo "✅ Updating justfile CDK_COMMIT"
@sed -i 's|CDK_COMMIT := "{{OLD_REV}}"|CDK_COMMIT := "{{NEW_REV}}"|g' justfile
@# Update devenv.nix
@echo "✅ Updating devenv.nix"
@sed -i 's|git checkout {{OLD_REV}}|git checkout {{NEW_REV}}|g' devenv.nix
@echo "Done! CDK updated from {{OLD_REV}} to {{NEW_REV}}"
@echo "Run 'just build-cdk-cli' to rebuild with new version"
# update bitcoind.nix with latest rev & hash
update-bitcoind:
@echo "Fetching latest commit hash for sv2 branch..."
@LATEST_COMMIT=$(curl -s "https://api.github.com/repos/Sjors/bitcoin/commits/sv2" | jq -r ".sha") && \
echo "Latest commit: $LATEST_COMMIT" && \
echo "Fetching new hash for Nix..." && \
HASH_RAW=$(nix-prefetch-url --unpack "https://github.com/Sjors/bitcoin/archive/$LATEST_COMMIT.tar.gz") && \
HASH=$(nix hash to-sri --type sha256 "$HASH_RAW") && \
echo "Computed Nix SRI hash: $HASH" && \
echo "Updating bitcoind.nix..." && \
sed -i "s|rev = \".*\";|rev = \"$LATEST_COMMIT\";|" bitcoind.nix && \
sed -i "s|hash = \".*\";|hash = \"$HASH\";|" bitcoind.nix && \
echo "Done! bitcoind updated to commit $LATEST_COMMIT\nYou are now ready to test and commit"
# generate blocks in regtest
generate-blocks COUNT="1":
@echo "Generating {{COUNT}} blocks in regtest..."
@bitcoin-cli -datadir=.devenv/state/bitcoind -conf=$(pwd)/config/bitcoin.conf -rpcuser=username -rpcpassword=password -regtest -rpcwallet=regtest -generate {{COUNT}}
# Open sqlite terminal client for various databases
# Usage: just db [wallet|mint|all]
db TYPE="":
@if [ "{{TYPE}}" = "wallet" ]; then \
sqlite3 -cmd ".mode line" .devenv/state/translator/wallet.sqlite; \
elif [ "{{TYPE}}" = "mint" ]; then \
sqlite3 -cmd ".mode line" .devenv/state/mint/mint.sqlite; \
elif [ "{{TYPE}}" = "all" ]; then \
echo "Available databases:"; \
echo " - Wallet: .devenv/state/translator/wallet.sqlite"; \
echo " - Mint: .devenv/state/mint/mint.sqlite"; \
echo ""; \
echo "Usage: just db [wallet|mint|all]"; \
else \
echo "Error: TYPE must be 'wallet', 'mint', or 'all'"; \
echo "Usage: just db [wallet|mint|all]"; \
exit 1; \
fi
# CDK configuration - update these when CDK version changes
CDK_REPO := "https://github.com/vnprc/cdk.git"
CDK_COMMIT := "77df2ae4"
# build cdk-cli from remote repo
build-cdk-cli:
./scripts/build-cdk-cli.sh
# check ecash balance using built cdk-cli
balance:
@if [ ! -f "{{justfile_directory()}}/bin/cdk-cli" ]; then \
echo "Error: CDK CLI not built. Run 'just build-cdk-cli' first"; \
exit 1; \
fi
@# Create symlink so CDK CLI can read translator's wallet
@if [ ! -L "{{justfile_directory()}}/.devenv/state/translator/cdk-cli.sqlite" ]; then \
ln -s wallet.sqlite {{justfile_directory()}}/.devenv/state/translator/cdk-cli.sqlite; \
fi
@sqlite3 {{justfile_directory()}}/.devenv/state/translator/wallet.sqlite \
"SELECT 'Total: ' || SUM(amount) || ' ' || unit || ' (' || COUNT(*) || ' proofs)' \
FROM proof WHERE state = 'UNSPENT' GROUP BY unit;" \
2>/dev/null || echo "Error: Could not read wallet database"
# set minimum difficulty in dev shared configs (1-256)
set-min-diff DIFFICULTY:
@if [ "{{DIFFICULTY}}" -lt 1 ] || [ "{{DIFFICULTY}}" -gt 256 ]; then \
echo "Error: DIFFICULTY must be between 1 and 256"; \
exit 1; \
fi
@echo "Setting minimum_difficulty = {{DIFFICULTY}} in dev configs..."
@sed -i 's/^minimum_difficulty = [0-9]\+$/minimum_difficulty = {{DIFFICULTY}}/' \
config/shared/miner.toml config/shared/pool.toml
@echo "✅ Updated config/shared/miner.toml"
@echo "✅ Updated config/shared/pool.toml"
@echo "Note: Production configs unchanged. Restart services for changes to take effect."
# delete persistent storage; options: cashu, regtest, testnet4, logs
clean TYPE="":
@if [ "{{TYPE}}" = "cashu" ]; then \
echo "deleting all sqlite data..."; \
rm -f .devenv/state/translator/wallet.sqlite \
.devenv/state/translator/wallet.sqlite-shm \
.devenv/state/translator/wallet.sqlite-wal \
.devenv/state/mint/mint.sqlite \
.devenv/state/mint/mint.sqlite-shm \
.devenv/state/mint/mint.sqlite-wal; \
echo "all sqlite data deleted"; \
elif [ "{{TYPE}}" = "regtest" ]; then \
echo "deleting regtest data..."; \
rm -rf .devenv/state/bitcoind/regtest; \
echo "regtest data deleted"; \
elif [ "{{TYPE}}" = "testnet4" ]; then \
echo "deleting testnet4 data..."; \
rm -rf .devenv/state/bitcoind/testnet4; \
echo "testnet4 data deleted"; \
elif [ "{{TYPE}}" = "logs" ]; then \
echo "deleting logs..."; \
rm -rf logs/*; \
echo "logs deleted"; \
else \
echo "Error: TYPE must be 'cashu', 'regtest', 'testnet4', or 'logs'"; \
exit 1; \
fi