main.go raw

   1  package main
   2  
   3  import (
   4  	"context"
   5  	"fmt"
   6  	"os"
   7  	"time"
   8  
   9  	"next.orly.dev/pkg/protocol/nwc"
  10  )
  11  
  12  func main() {
  13  	uri := os.Getenv("ORLY_NWC_URI")
  14  	if uri == "" && len(os.Args) > 1 {
  15  		uri = os.Args[1]
  16  	}
  17  	if uri == "" {
  18  		fmt.Fprintf(os.Stderr, "usage: test-nwc <nwc-uri> or set ORLY_NWC_URI\n")
  19  		os.Exit(1)
  20  	}
  21  
  22  	client, err := nwc.NewClient(uri)
  23  	if err != nil {
  24  		fmt.Fprintf(os.Stderr, "parse NWC URI: %v\n", err)
  25  		os.Exit(1)
  26  	}
  27  
  28  	ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
  29  	defer cancel()
  30  
  31  	fmt.Println("testing get_info...")
  32  	var info map[string]any
  33  	if err := client.Request(ctx, "get_info", nil, &info); err != nil {
  34  		fmt.Fprintf(os.Stderr, "get_info failed: %v\n", err)
  35  	} else {
  36  		fmt.Printf("get_info result: %v\n", info)
  37  	}
  38  
  39  	fmt.Println("\ntesting make_invoice (100 sats)...")
  40  	params := map[string]any{
  41  		"amount":      int64(100000), // 100 sats in msats
  42  		"description": "test invoice from test-nwc",
  43  	}
  44  	var invoice map[string]any
  45  	if err := client.Request(ctx, "make_invoice", params, &invoice); err != nil {
  46  		fmt.Fprintf(os.Stderr, "make_invoice failed: %v\n", err)
  47  	} else {
  48  		fmt.Printf("make_invoice result: %v\n", invoice)
  49  	}
  50  }
  51