How lightninglabs/taproot-assets works
Project Type and Purpose
• This is a full-stack, single-binary daemon (tapd) plus companion CLI (tapcli) implementing the Taproot Assets Protocol on Bitcoin.
• Purpose: mint, transfer, burn, and verify “Taproot Assets” using LND’s signing/Taproot wallet, off-chain witness data, and local state storage. It exposes both gRPC and REST interfaces, and integrates with Bitcoin and LND.
File Structure
• Top-level binaries:
• cmd/tapd (daemon)
• cmd/tapcli (CLI)
• cmd/merge-sql-schemas
• Core domain packages (asset, commitment, proof, rfq, universe, tapscript, tapchannel, etc.).
• Storage: tapdb with SQLC-generated code, supports Postgres/SQLite.
• RPC layer: taprpc contains .proto definitions and generated gRPC+REST gateway.
• LND integration: lndservices package for calling LND’s gRPC (chainrpc, walletrpc, signrpc).
• Monitoring: monitoring collects Prometheus metrics.
• Integration tests: itest directory with harnesses.
• Dev/CI: Dockerfiles, GitHub Actions, Makefile, scripts.
README Insights
• Architecture summary: Bitcoin ←→ LND ←→ Taproot Assets (tapd).
• Components: tapd (daemon), tapcli (CLI), gRPC & REST endpoints, LND backend, Bitcoin network.
• External federation: “universes” are peer tapd instances syncing asset universes.
a. Main Components
• Bitcoin Network (full node)
• LND Node (gRPC interface: chainrpc, signrpc, walletrpc)
• Taproot-Assets Daemon (tapd)
– Service Layer: modules for asset mgmt, commitments, proofs, RFQ, universe sync
– Storage Layer: tapdb (Postgres/SQLite)
– API Layer:
· gRPC Server (port 10029)
· REST Gateway (port 8089)
– Monitoring (Prometheus exporter)
• CLI Client (tapcli)
• Universe Federation Peers (other tapd instances)
b. Relationships & Data Flows
1. tapcli → (gRPC/REST) → tapd
2. tapd → (gRPC) → LND for on-chain wallet operations & signatures
3. tapd ↔ Bitcoin Network via LND’s chainrpc
4. tapd ↔ tapdb for persisting assets, commitments, proofs, macaroon/session data
5. tapd ↔ Universe Peers using custom peer-to-peer sync protocols (federation)
6. tapd → Prometheus for metrics
c. Architectural Patterns & Principles
• Layered/Hexagonal: clearly separated API, domain logic, infrastructure
• Domain-driven: each domain (asset, proof, universe, rfq) encapsulated in its package
• SQLC code generation for type-safe queries
• gRPC + REST Gateway for polyglot integration
• Test harnesses (unit, integration) for domain services
d. Key Technologies & Frameworks
• Go modules (go.mod), Docker
• gRPC (google.golang.org/grpc) + grpc-gateway (REST)
• SQLC for DB access (Postgres & SQLite)
• Prometheus for monitoring
• macaroons for authentication
• LND’s RPCs
Detail
• Drill down if necessary: e.g., inside domain, show “asset.Mint”, “commitment.Taproot”, “proof.Courier” modules
• SQL migrations and codegen as part of the storage infrastructure