Blocktank is an LSP that allows businesses, apps, or online platforms to integrate, automate, and monetize services from your Lightning node. This includes channel configuration, channel purchases, channel info and more.
Blocktank is a fully open source and everyone is welcome to contribute. The Blocktank project gives you everything you need to become your own LSP.
Run this program at your own risk.
- Mongodb
- LND
- Node.js >v12
- PM2
- Grenache Grape
Start 2 Grapes in the background for microservice communication:
grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002' &
grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001' &
Copy and update the example settings files located in ./config
cp ./config/server.json.example ./config/server.json
cp ./config/auth.json.example ./config/auth.json
Create Inventory item (this creates a product in the mongodb database)
cd ./cli
node update-inventory
Add the new inventory id to ./config/server.json
under product_id
. Blocktank creates a new DB in MongoDB called Lighthouse. Looking in the Inventory
collection to find your new product id...
mongosh
use Lighthouse
db.Inventory.find({})
Run all microservice workers (including the dependent workers)
pm2 start ecosystem.config.js
Blocktank BTC Worker - a set of service workers that provide access to Bitcoin RPC endpoints, watch the mempool and alerts on new blocks
Blocktank LN Worker - service workers that provide access to Lightning Node features
- LN-Channel-Opener:
- Fetches orders that have been paid and claimed, then opens the channel.
- LN-Channel-Watch
- Watch channels that are opened and update an order's channel.
- LN-Invoice-Watch
- Listens for payments on from Lightning.
- Order-Expiry-Watch
- Update orders that have been expired
- AddressWatch
- Watch for on chain payments for orders
- ZeroConf
- Watch for on chain zero conf payments for orders
- Start-Express
- Express Server for routing requests to workers.
- GetOrder
- Handle the get order api endpoint.
- NodeInfo
- Handle the get node info api endpoint
- BuyChannel
- Creates an order.
- FinaliseChannel
- Claim a paid channels
- LnUrlChannel
- Handlers for LNURL Channel. Prowxies to FinaliseChannel endpoint
- Auth.js
- Authenticate Admin endpoints
- ChannelAdmin
- Handle admin endpoints
- Exchange Rate
- Handle currency conversions api endpoint.
- Blocktank-worker-ln
- Worker for interacting with Lightning Network Node
- Blocktank-worker-btc
- Worker for interacting with Bitcoin node
- Blocktank-worker-router
- Handle fee managment and various other routing node features.
- When starting application. API endpoints are set by looking at
Endpoints.js
Http.js
runs express and listens to HTTP calls- When an API is called, it uses config in
Endpoints.js
to find the microservice worker name and calls it. - If the API call is GET, query parameters are passed to the worker, if POST, body is passed. This is done in
HTTP.js
- Looking at Controller class in
util/Worker.js
you can see some pre written helper functions for calling popular workers like The bitcoin worker or the LN worker. Most microservice workers extend from the Controller class. - Every worker is running a Grenache server and a client
- Grenache server is listening to calls from other workers.
- Grenache client is used to call other workers.
These are some admin endpoints that should only be accessed by authorised BT admins.
you need to call createUser
locate in ./src/Auth/Auth.js
with a username and password. and save the output to ./config/auth.json
Credit a channel manually, if it hasn't been picked up automatically.
Parameters:
{
"tx_id":"10a646815e29b0780c6525d39dfcf32b1fc44453a0e38ce4e05d21539831d3a3", // Bitcoin Txid
"order_id":"6147e8ca19d94f8a1226a212" // Order id
}
Get a list of orders
Parameters:
{
"state" : 100, // Get orders in a state
"expired_channels": true, // Get all channels that can be closed
"order_id": "6147e8ca19d94f8a1226a212", // Get a single order
"page": 1, // Pagination
}
Begin channel closing process.
NOTE: When calling this api, you have 30 seconds to stop the process by calling the api again.
Parameters:
{
"order_id":"ALL || order id" // pass ALL to close all expired channels, pass order id to close a channel
}
Save refund info and change order state to REFUNDED.
Parameters:
{
"order_id": "xxx", // Order id
"refund_tx": "xxx", // Transaction id or invoice
}
- In order to start testing you need to install the
devDependencies
and Mocha - Update
test.config.js.example
with your local Regtest Bitcoin and Lightning node.- You must make sure you have enough Bitcoin liquidity before running test.
- Run
mocha ./test/BuyChannel.e2e.test.js