justfile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. alias b := build
  2. alias c := check
  3. alias t := test
  4. default:
  5. @just --list
  6. # Create a new SQL migration file
  7. new-migration target name:
  8. #!/usr/bin/env bash
  9. set -euo pipefail
  10. if [ "{{target}}" != "mint" ] && [ "{{target}}" != "wallet" ]; then
  11. echo "Error: target must be either 'mint' or 'wallet'"
  12. exit 1
  13. fi
  14. timestamp=$(date +%Y%m%d%H%M%S)
  15. migration_path="./crates/cdk-sql-common/src/{{target}}/migrations/${timestamp}_{{name}}.sql"
  16. # Create the file
  17. mkdir -p "$(dirname "$migration_path")"
  18. touch "$migration_path"
  19. echo "Created new migration: $migration_path"
  20. final-check: typos format clippy test
  21. # run `cargo build` on everything
  22. build *ARGS="--workspace --all-targets":
  23. #!/usr/bin/env bash
  24. set -euo pipefail
  25. if [ ! -f Cargo.toml ]; then
  26. cd {{invocation_directory()}}
  27. fi
  28. cargo build {{ARGS}}
  29. # run `cargo check` on everything
  30. check *ARGS="--workspace --all-targets":
  31. #!/usr/bin/env bash
  32. set -euo pipefail
  33. if [ ! -f Cargo.toml ]; then
  34. cd {{invocation_directory()}}
  35. fi
  36. cargo check {{ARGS}}
  37. # run code formatters
  38. format:
  39. #!/usr/bin/env bash
  40. set -euo pipefail
  41. if [ ! -f Cargo.toml ]; then
  42. cd {{invocation_directory()}}
  43. fi
  44. cargo fmt --all
  45. nixpkgs-fmt $(echo **.nix)
  46. # run doc tests
  47. test:
  48. #!/usr/bin/env bash
  49. set -euo pipefail
  50. if [ ! -f Cargo.toml ]; then
  51. cd {{invocation_directory()}}
  52. fi
  53. cargo test --lib
  54. # Run pure integration tests
  55. cargo test -p cdk-integration-tests --test mint
  56. # run doc tests
  57. test-pure db="memory": build
  58. #!/usr/bin/env bash
  59. set -euo pipefail
  60. if [ ! -f Cargo.toml ]; then
  61. cd {{invocation_directory()}}
  62. fi
  63. # Run pure integration tests
  64. CDK_TEST_DB_TYPE={{db}} cargo test -p cdk-integration-tests --test integration_tests_pure -- --test-threads 1
  65. test-all db="memory":
  66. #!/usr/bin/env bash
  67. set -euo pipefail
  68. just test {{db}}
  69. ./misc/itests.sh "{{db}}"
  70. ./misc/fake_itests.sh "{{db}}" external_signatory
  71. ./misc/fake_itests.sh "{{db}}"
  72. test-nutshell:
  73. #!/usr/bin/env bash
  74. set -euo pipefail
  75. # Function to cleanup docker containers
  76. cleanup() {
  77. echo "Cleaning up docker containers..."
  78. docker stop nutshell 2>/dev/null || true
  79. docker rm nutshell 2>/dev/null || true
  80. unset CDK_ITESTS_DIR
  81. }
  82. # Trap to ensure cleanup happens on exit (success or failure)
  83. trap cleanup EXIT
  84. docker run -d -p 3338:3338 --name nutshell -e MINT_LIGHTNING_BACKEND=FakeWallet -e MINT_LISTEN_HOST=0.0.0.0 -e MINT_LISTEN_PORT=3338 -e MINT_PRIVATE_KEY=TEST_PRIVATE_KEY -e MINT_INPUT_FEE_PPK=100 cashubtc/nutshell:latest poetry run mint
  85. export CDK_ITESTS_DIR=$(mktemp -d)
  86. # Wait for the Nutshell service to be ready
  87. echo "Waiting for Nutshell to start..."
  88. max_attempts=30
  89. attempt=0
  90. while ! curl -s http://127.0.0.1:3338/v1/info > /dev/null; do
  91. attempt=$((attempt+1))
  92. if [ $attempt -ge $max_attempts ]; then
  93. echo "Nutshell failed to start after $max_attempts attempts"
  94. exit 1
  95. fi
  96. echo "Waiting for Nutshell to start (attempt $attempt/$max_attempts)..."
  97. sleep 1
  98. done
  99. echo "Nutshell is ready!"
  100. # Set environment variables and run tests
  101. export CDK_TEST_MINT_URL=http://127.0.0.1:3338
  102. export LN_BACKEND=FAKEWALLET
  103. # Track test results
  104. test_exit_code=0
  105. # Run first test and capture exit code
  106. echo "Running happy_path_mint_wallet test..."
  107. if ! cargo test -p cdk-integration-tests --test happy_path_mint_wallet; then
  108. echo "ERROR: happy_path_mint_wallet test failed"
  109. test_exit_code=1
  110. fi
  111. # Run second test and capture exit code
  112. echo "Running test_fees test..."
  113. if ! cargo test -p cdk-integration-tests --test test_fees; then
  114. echo "ERROR: test_fees test failed"
  115. test_exit_code=1
  116. fi
  117. unset CDK_TEST_MINT_URL
  118. unset LN_BACKEND
  119. # Exit with error code if any test failed
  120. if [ $test_exit_code -ne 0 ]; then
  121. echo "One or more tests failed"
  122. exit $test_exit_code
  123. fi
  124. echo "All tests passed successfully"
  125. # run `cargo clippy` on everything
  126. clippy *ARGS="--locked --offline --workspace --all-targets":
  127. cargo clippy {{ARGS}}
  128. # run `cargo clippy --fix` on everything
  129. clippy-fix *ARGS="--locked --offline --workspace --all-targets":
  130. cargo clippy {{ARGS}} --fix
  131. typos:
  132. typos
  133. # fix all typos
  134. [no-exit-message]
  135. typos-fix:
  136. just typos -w
  137. # Goose AI Recipe Commands
  138. # Update changelog from staged changes using Goose AI
  139. goose-git-msg:
  140. #!/usr/bin/env bash
  141. set -euo pipefail
  142. goose run --recipe ./misc/recipes/git-commit-message.yaml --interactive
  143. # Create git message from staged changes using Goose AI
  144. goose-changelog-staged:
  145. #!/usr/bin/env bash
  146. set -euo pipefail
  147. goose run --recipe ./misc/recipes/changelog-update.yaml --interactive
  148. # Update changelog from recent commits using Goose AI
  149. # Usage: just goose-changelog-commits [number_of_commits]
  150. goose-changelog-commits *COMMITS="5":
  151. #!/usr/bin/env bash
  152. set -euo pipefail
  153. COMMITS={{COMMITS}} goose run --recipe ./misc/recipes/changelog-from-commits.yaml --interactive
  154. itest db:
  155. #!/usr/bin/env bash
  156. set -euo pipefail
  157. ./misc/itests.sh "{{db}}"
  158. fake-mint-itest db:
  159. #!/usr/bin/env bash
  160. set -euo pipefail
  161. ./misc/fake_itests.sh "{{db}}" external_signatory
  162. ./misc/fake_itests.sh "{{db}}"
  163. itest-payment-processor ln:
  164. #!/usr/bin/env bash
  165. set -euo pipefail
  166. ./misc/mintd_payment_processor.sh "{{ln}}"
  167. fake-auth-mint-itest db openid_discovery:
  168. #!/usr/bin/env bash
  169. set -euo pipefail
  170. ./misc/fake_auth_itests.sh "{{db}}" "{{openid_discovery}}"
  171. nutshell-wallet-itest:
  172. #!/usr/bin/env bash
  173. set -euo pipefail
  174. ./misc/nutshell_wallet_itest.sh
  175. # Start interactive regtest environment (Bitcoin + 4 LN nodes + 2 CDK mints)
  176. regtest db="sqlite":
  177. #!/usr/bin/env bash
  178. set -euo pipefail
  179. ./misc/interactive_regtest_mprocs.sh {{db}}
  180. # Lightning Network Commands (require regtest environment to be running)
  181. # Get CLN node 1 info
  182. ln-cln1 *ARGS:
  183. #!/usr/bin/env bash
  184. set -euo pipefail
  185. ./misc/regtest_helper.sh ln-cln1 {{ARGS}}
  186. # Get CLN node 2 info
  187. ln-cln2 *ARGS:
  188. #!/usr/bin/env bash
  189. set -euo pipefail
  190. ./misc/regtest_helper.sh ln-cln2 {{ARGS}}
  191. # Get LND node 1 info
  192. ln-lnd1 *ARGS:
  193. #!/usr/bin/env bash
  194. set -euo pipefail
  195. ./misc/regtest_helper.sh ln-lnd1 {{ARGS}}
  196. # Get LND node 2 info
  197. ln-lnd2 *ARGS:
  198. #!/usr/bin/env bash
  199. set -euo pipefail
  200. ./misc/regtest_helper.sh ln-lnd2 {{ARGS}}
  201. # Bitcoin regtest commands
  202. btc *ARGS:
  203. #!/usr/bin/env bash
  204. set -euo pipefail
  205. ./misc/regtest_helper.sh btc {{ARGS}}
  206. # Mine blocks in regtest
  207. btc-mine blocks="10":
  208. #!/usr/bin/env bash
  209. set -euo pipefail
  210. ./misc/regtest_helper.sh btc-mine {{blocks}}
  211. # Show mint information
  212. mint-info:
  213. #!/usr/bin/env bash
  214. set -euo pipefail
  215. ./misc/regtest_helper.sh mint-info
  216. # Run integration tests against regtest environment
  217. mint-test:
  218. #!/usr/bin/env bash
  219. set -euo pipefail
  220. ./misc/regtest_helper.sh mint-test
  221. # Restart mints after recompiling (useful for development)
  222. restart-mints:
  223. #!/usr/bin/env bash
  224. set -euo pipefail
  225. ./misc/regtest_helper.sh restart-mints
  226. # Show regtest environment status
  227. regtest-status:
  228. #!/usr/bin/env bash
  229. set -euo pipefail
  230. ./misc/regtest_helper.sh show-status
  231. # Show regtest environment logs
  232. regtest-logs:
  233. #!/usr/bin/env bash
  234. set -euo pipefail
  235. ./misc/regtest_helper.sh show-logs
  236. run-examples:
  237. cargo r --example p2pk
  238. cargo r --example mint-token
  239. cargo r --example melt-token
  240. cargo r --example proof_selection
  241. cargo r --example wallet
  242. check-wasm *ARGS="--target wasm32-unknown-unknown":
  243. #!/usr/bin/env bash
  244. set -euo pipefail
  245. if [ ! -f Cargo.toml ]; then
  246. cd {{invocation_directory()}}
  247. fi
  248. buildargs=(
  249. "-p cdk"
  250. "-p cdk --no-default-features"
  251. "-p cdk --no-default-features --features wallet"
  252. "-p cdk --no-default-features --features mint"
  253. )
  254. for arg in "${buildargs[@]}"; do
  255. echo "Checking '$arg'"
  256. cargo check $arg {{ARGS}}
  257. echo
  258. done
  259. release m="":
  260. #!/usr/bin/env bash
  261. set -euo pipefail
  262. args=(
  263. "-p cashu"
  264. "-p cdk-common"
  265. "-p cdk-sql-common"
  266. "-p cdk-sqlite"
  267. "-p cdk-postgres"
  268. "-p cdk-redb"
  269. "-p cdk-signatory"
  270. "-p cdk"
  271. "-p cdk-axum"
  272. "-p cdk-mint-rpc"
  273. "-p cdk-cln"
  274. "-p cdk-lnd"
  275. "-p cdk-lnbits"
  276. "-p cdk-ldk-node"
  277. "-p cdk-fake-wallet"
  278. "-p cdk-payment-processor"
  279. "-p cdk-cli"
  280. "-p cdk-mintd"
  281. )
  282. for arg in "${args[@]}";
  283. do
  284. echo "Publishing '$arg'"
  285. cargo publish $arg {{m}}
  286. echo
  287. done
  288. # Extract version from the cdk-ffi crate
  289. VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "cdk-ffi") | .version')
  290. # Trigger Swift package release after Rust crates are published
  291. echo "📦 Triggering Swift package release for version $VERSION..."
  292. just ffi-release-swift $VERSION
  293. check-docs:
  294. #!/usr/bin/env bash
  295. set -euo pipefail
  296. args=(
  297. "-p cashu"
  298. "-p cdk-common"
  299. "-p cdk-sql-common"
  300. "-p cdk"
  301. "-p cdk-redb"
  302. "-p cdk-sqlite"
  303. "-p cdk-axum"
  304. "-p cdk-cln"
  305. "-p cdk-lnd"
  306. "-p cdk-lnbits"
  307. "-p cdk-fake-wallet"
  308. "-p cdk-mint-rpc"
  309. "-p cdk-payment-processor"
  310. "-p cdk-signatory"
  311. "-p cdk-cli"
  312. "-p cdk-mintd"
  313. )
  314. for arg in "${args[@]}"; do
  315. echo "Checking '$arg' docs"
  316. cargo doc $arg --all-features
  317. echo
  318. done
  319. # Build docs for all crates and error on warnings
  320. docs-strict:
  321. #!/usr/bin/env bash
  322. set -euo pipefail
  323. args=(
  324. "-p cashu"
  325. "-p cdk-common"
  326. "-p cdk-sql-common"
  327. "-p cdk"
  328. "-p cdk-redb"
  329. "-p cdk-sqlite"
  330. "-p cdk-axum"
  331. "-p cdk-cln"
  332. "-p cdk-lnd"
  333. "-p cdk-lnbits"
  334. "-p cdk-fake-wallet"
  335. "-p cdk-mint-rpc"
  336. "-p cdk-payment-processor"
  337. "-p cdk-signatory"
  338. "-p cdk-cli"
  339. "-p cdk-mintd"
  340. )
  341. for arg in "${args[@]}"; do
  342. echo "Building docs for $arg with strict warnings"
  343. RUSTDOCFLAGS="-D warnings" cargo doc $arg --all-features --no-deps
  344. echo
  345. done
  346. # =============================================================================
  347. # FFI Commands - CDK Foreign Function Interface bindings
  348. # =============================================================================
  349. # Helper function to get library extension based on platform
  350. _ffi-lib-ext:
  351. #!/usr/bin/env bash
  352. if [[ "$OSTYPE" == "darwin"* ]]; then
  353. echo "dylib"
  354. else
  355. echo "so"
  356. fi
  357. # Build the FFI library
  358. ffi-build *ARGS="--release":
  359. cargo build {{ARGS}} --package cdk-ffi
  360. # Generate bindings for a specific language
  361. ffi-generate LANGUAGE *ARGS="--release": ffi-build
  362. #!/usr/bin/env bash
  363. set -euo pipefail
  364. LANG="{{LANGUAGE}}"
  365. # Validate language
  366. case "$LANG" in
  367. python|swift|kotlin)
  368. ;;
  369. *)
  370. echo "❌ Unsupported language: $LANG"
  371. echo "Supported languages: python, swift, kotlin"
  372. exit 1
  373. ;;
  374. esac
  375. # Set emoji and build type
  376. case "$LANG" in
  377. python) EMOJI="🐍" ;;
  378. swift) EMOJI="🍎" ;;
  379. kotlin) EMOJI="🎯" ;;
  380. esac
  381. # Determine build type and library path
  382. if [[ "{{ARGS}}" == *"--release"* ]] || [[ "{{ARGS}}" == "" ]]; then
  383. BUILD_TYPE="release"
  384. else
  385. BUILD_TYPE="debug"
  386. cargo build --package cdk-ffi
  387. fi
  388. LIB_EXT=$(just _ffi-lib-ext)
  389. echo "$EMOJI Generating $LANG bindings..."
  390. mkdir -p target/bindings/$LANG
  391. cargo run --bin uniffi-bindgen generate \
  392. --library target/$BUILD_TYPE/libcdk_ffi.$LIB_EXT \
  393. --language $LANG \
  394. --out-dir target/bindings/$LANG
  395. echo "✅ $LANG bindings generated in target/bindings/$LANG/"
  396. # Generate Python bindings (shorthand)
  397. ffi-generate-python *ARGS="--release":
  398. just ffi-generate python {{ARGS}}
  399. # Generate Swift bindings (shorthand)
  400. ffi-generate-swift *ARGS="--release":
  401. just ffi-generate swift {{ARGS}}
  402. # Generate Kotlin bindings (shorthand)
  403. ffi-generate-kotlin *ARGS="--release":
  404. just ffi-generate kotlin {{ARGS}}
  405. # Generate bindings for all supported languages
  406. ffi-generate-all *ARGS="--release": ffi-build
  407. @echo "🔧 Generating UniFFI bindings for all languages..."
  408. just ffi-generate python {{ARGS}}
  409. just ffi-generate swift {{ARGS}}
  410. just ffi-generate kotlin {{ARGS}}
  411. @echo "✅ All bindings generated successfully!"
  412. # Build debug version and generate Python bindings quickly (for development)
  413. ffi-dev-python:
  414. #!/usr/bin/env bash
  415. set -euo pipefail
  416. # Generate Python bindings first
  417. just ffi-generate python --debug
  418. # Copy library to Python bindings directory
  419. LIB_EXT=$(just _ffi-lib-ext)
  420. echo "📦 Copying library to Python bindings directory..."
  421. cp target/debug/libcdk_ffi.$LIB_EXT target/bindings/python/
  422. # Launch Python REPL with CDK FFI loaded
  423. cd target/bindings/python
  424. echo "🐍 Launching Python REPL with CDK FFI library loaded..."
  425. echo "💡 The 'cdk_ffi' module is pre-imported and ready to use!"
  426. python3 -i -c "from cdk_ffi import *; print('✅ CDK FFI library loaded successfully!');"
  427. # Test language bindings with a simple import
  428. ffi-test-bindings LANGUAGE: (ffi-generate LANGUAGE "--debug")
  429. #!/usr/bin/env bash
  430. set -euo pipefail
  431. LANG="{{LANGUAGE}}"
  432. LIB_EXT=$(just _ffi-lib-ext)
  433. echo "📦 Copying library to $LANG bindings directory..."
  434. cp target/debug/libcdk_ffi.$LIB_EXT target/bindings/$LANG/
  435. cd target/bindings/$LANG
  436. echo "🧪 Testing $LANG bindings..."
  437. case "$LANG" in
  438. python)
  439. python3 -c "import cdk_ffi; print('✅ Python bindings work!')"
  440. ;;
  441. *)
  442. echo "✅ $LANG bindings generated (manual testing required)"
  443. ;;
  444. esac
  445. # Test Python bindings (shorthand)
  446. ffi-test-python:
  447. just ffi-test-bindings python
  448. # Trigger Swift Package release workflow
  449. ffi-release-swift VERSION:
  450. #!/usr/bin/env bash
  451. set -euo pipefail
  452. echo "🚀 Triggering Publish Swift Package workflow..."
  453. echo " Version: {{VERSION}}"
  454. echo " CDK Ref: v{{VERSION}}"
  455. # Trigger the workflow using GitHub CLI
  456. gh workflow run "Publish Swift Package" \
  457. --repo cashubtc/cdk-swift \
  458. --field version="{{VERSION}}" \
  459. --field cdk_repo="cashubtc/cdk" \
  460. --field cdk_ref="v{{VERSION}}"
  461. echo "✅ Workflow triggered successfully!"