# ローカル開発
# 前提条件
開発環境 では次のツールをインストールする必要があります。
- .NET 8.0 SDK (opens new window)
- Docker: Windows (opens new window) | Mac OS (opens new window) | Linux (opens new window)
# 依存関係
テスト実行やデバッグ実行のために、いくつかの 依存サービス を起動する必要があります。
依存関係はすべて docker-compose ファイルにまとめてあり、これを使って開発環境を立ち上げられます。 BTCPayServer.Tests/docker-compose.yml (opens new window) を使うと一式を起動できます。
git clone https://github.com/btcpayserver/btcpayserver.git
cd btcpayserver/BTCPayServer.Tests
docker-compose up dev
# どの IDE を使うべきか?
Visual Studio 2022(Windows のみ)または Rider(クロスプラットフォーム)を推奨します。Visual Studio Code(クロスプラットフォーム)でも可能ですが、快適な開発環境の構築はやや複雑です。 もちろん VIM も使えます。.NET Core はコマンドラインでも扱いやすいです。
Visual Studio Code、Visual Studio、Rider は launch profile Bitcoin を実行します。
これにより Docker サービス内の依存関係へ接続する BTCPay Server インスタンス が起動し、デバッグやステップ実行が簡単になります。
# ビルド構成
build configuration は BTCPay Server のビルド方法 を定義します。たとえば、特定のソースを含めるかどうか、デバッグ最適化か性能最適化かなどです。
利用可能な build configuration は次のとおりです。
DebugReleaseAltcoins-DebugAltcoins-Release
ローカル開発中に別構成を使う方法は IDE によって異なります。
デフォルトは Debug で、これは altcoin 依存関係を含まない Bitcoin 専用ビルドです。別構成の使い方は IDE に依存します。
dotnet コマンドラインでは -c スイッチでビルド構成を選択できます。コマンドラインで Release ビルドを実行する場合は次のとおりです。
dotnet run -c Release
# Launch profiles
ローカル開発のために BTCPay Server をローカル起動 する際は、docker-compose の開発用依存関係へ接続するための適切なパラメータが必要です。
これらのパラメータは dotnet の launch profile という仕組みにまとめられています。
launch profile は launchSettings.json (opens new window) で定義されています。
現在は次の3つがあります。
BitcoinBitcoin-HTTPSAltcoins-HTTPS
デフォルトは Bitcoin です。別の profile を使う方法は IDE によって異なります。
コマンドラインを使う場合、dotnet run で任意の launch profile を選択できます。
dotnet run --launch-profile Bitcoin
# テスト実行
テスト実行は、開発時の BTCPay Server 実行とほぼ同じ仕組みで動作します。
cd BTCPayServer.Tests
dotnet test
テストでは launch profile の概念は適用されませんが、build configuration は適用されます。たとえば Release ビルドでテストしたい場合は次のとおりです。
dotnet test -c Release
テストは、先ほど示した docker-compose の開発用依存関係を使うよう、すでに設定済みです。
特定のテストだけを実行するには --f(filter)スイッチを使えます。
IDE を使う場合は、テスト実行や構成切り替えについて IDE のドキュメントを参照してください。
# Altcoin サポート開発
デフォルトでは、IDE または単純な dotnet run は Debug ビルド上の Bitcoin launch profile を使用します。
- これは、BTCPay Server がローカル HTTP ポートで起動し、altcoin サポートなしでビルドされることを意味します。
- また、BTCPayServer.Tests/docker-compose.yml (opens new window) に定義された Bitcoin 専用依存関係へ接続します。
altcoins サポート付きで開発 したい場合は、Altcoins-Debug ビルドで Altcoins-HTTPS launch profile を使い、BTCPayServer.Tests/docker-compose.altcoins.yml (opens new window) を実行してください。
コマンドラインを使う場合:
cd BTCPayServer.Tests
docker-compose -f docker-compose.altcoins.yml up dev
cd ../BTCPayServer
dotnet run -c Altcoins-Debug --launch-profile Altcoins-HTTPS
テストの場合:
cd BTCPayServer.Tests
dotnet test -c Altcoins-Debug
# ローカル開発での HTTPS サポート
一部ブラウザのセキュリティ機能を正しく検証するには HTTPS が必要な場合があります。
その場合は Bitcoin-HTTPS(または Altcoin-HTTPS)launch profile を使用します。開発用の自己署名証明書が作成されます。
ただし、ブラウザはこの証明書を信頼しないため、デバッグしづらくなることがあります。
次を実行すると、OS にこの開発用証明書を信頼させることができます。
dotnet dev-certs https --trust
# 動画
詳細は次の動画を参照してください。
- BTCPay Server 開発への貢献方法(Windows) (opens new window) by Nicolas Dorier
- Linux(Ubuntu)で BTCPayServer 開発環境を構築する (opens new window) by RockStarDev
- BTCPay Server 開発 - Pull Request と支払いのテスト(MacOS) (opens new window) by Pavlenex
あわせて次のノートも参照してください。
- 開発の始め方 (opens new window) by Nicolas Dorier(関連する Docker コマンドと regtest 請求書の支払い手順を解説)
# How to manually test payments
# Using the test bitcoin-cli
You can call bitcoin-cli inside the container with docker exec.
For example, if you want to send 0.23111090 to mohu16LH66ptoWGEL1GtP6KHTBJYXMWhEf:
./docker-bitcoin-cli.sh sendtoaddress "mohu16LH66ptoWGEL1GtP6KHTBJYXMWhEf" 0.23111090
If you are using Powershell:
.\docker-bitcoin-cli.ps1 sendtoaddress "mohu16LH66ptoWGEL1GtP6KHTBJYXMWhEf" 0.23111090
You can also generate blocks:
.\docker-bitcoin-generate.ps1 3
# Using Polar to test Lightning payments
- Install and run Polar (opens new window). Setup a small network of nodes.
- Go to your store's General Settings and enable Lightning.
- Build your connection string using the Connect information in the Polar app.
LND Connection string example: type=lnd-rest;server=https://127.0.0.1:8084/;macaroonfilepath="local path to admin.macaroon on your computer, without these quotes";allowinsecure=true
Now you can create a Lightning invoice on BTCPay Server regtest and make a payment through Polar.
PLEASE NOTE: You may get an exception break in Visual Studio. You must quickly click "Continue" in VS so the invoice is generated. Or, uncheck the box that says, "Break when this exception type is thrown".
# Using the test litecoin-cli
Same as bitcoin-cli, but with .\docker-litecoin-cli.ps1 and .\docker-litecoin-cli.sh instead.
# Using the test lightning-cli
If you are using Linux:
./docker-customer-lightning-cli.sh pay lnbcrt100u1pd2e6uspp5ajnadvhazjrz55twd5k6yeg9u87wpw0q2fdr7g960yl5asv5fmnqdq9d3hkccqpxmedyrk0ehw5ueqx5e0r4qrrv74cewddfcvsxaawqz7634cmjj39sqwy5tvhz0hasktkk6t9pqfdh3edmf3z09zst5y7khv3rvxh8ctqqw6mwhh
If you are using Powershell:
.\docker-customer-lightning-cli.ps1 pay lnbcrt100u1pd2e6uspp5ajnadvhazjrz55twd5k6yeg9u87wpw0q2fdr7g960yl5asv5fmnqdq9d3hkccqpxmedyrk0ehw5ueqx5e0r4qrrv74cewddfcvsxaawqz7634cmjj39sqwy5tvhz0hasktkk6t9pqfdh3edmf3z09zst5y7khv3rvxh8ctqqw6mwhh
If you get this message:
{ "code" : 205, "message" : "Could not find a route", "data" : { "getroute_tries" : 1, "sendpay_tries" : 0 } }
Please, run the test CanSetLightningServer, this will establish a channel between the customer and the merchant, then, retry.
Alternatively you can run the ./docker-lightning-channel-setup.sh script to establish the channel connection.
The ./docker-lightning-channel-teardown.sh script closes any existing lightning channels.
# Alternative Lightning testing: Using Polar to test Lightning payments
- Install and run Polar (opens new window). Setup a small network of nodes.
- Go to your store's General Settings and enable Lightning.
- Build your connection string using the Connect information in the Polar app.
LND Connection string example: type=lnd-rest;server=https://127.0.0.1:8084/;macaroonfilepath="local path to admin.macaroon on your computer, without these quotes";allowinsecure=true
Now you can create a lightning invoice on BTCPay Server regtest and make a payment through Polar.
PLEASE NOTE: You may get an exception break in Visual Studio. You must quickly click "Continue" in VS so the invoice is generated. Or, uncheck the box that says, "Break when this exception type is thrown".
# FAQ
# docker-compose up dev failed or tests are not passing, what should I do?
- Run
docker-compose down --volumes(this will reset your test environment) - Run
docker-compose pull(this will ensure you have the latest images) - Run again with
docker-compose up dev
# How to run the Altcoin environment?
docker-compose -f docker-compose.altcoins.yml up dev
If you still have issues, try to restart docker.