main.go raw
1 // Command nostrino-profile prints a chain profile as the JSON file a client, a bridge or a
2 // browser wallet loads.
3 //
4 // It exists because a forked chain's profile is data, not a name: the fork height, its target
5 // shift and the checkpoint below it have no built-in spelling, so the operator needs one file to
6 // hand around.
7 package main
8
9 import (
10 "flag"
11 "fmt"
12 "os"
13
14 "git.smesh.lol/nostrino/pkg/chain"
15 )
16
17 func main() {
18 chainName := flag.String("chain", "xbt", "profile name: btc, xbt, regtest, signet or testnet3")
19 cpHeight := flag.Uint("checkpoint-height", 0, "checkpoint height to add (0 = none)")
20 cpHash := flag.String("checkpoint-hash", "", "checkpoint block hash (display order)")
21 cpFilter := flag.String("checkpoint-filter-header", "", "checkpoint filter header (display order)")
22 out := flag.String("out", "", "write here (default standard output)")
23 flag.Parse()
24
25 profile, err := chain.ByName(*chainName)
26
27 if err != nil {
28 fail(err)
29 }
30
31 if *cpHeight != 0 || *cpHash != "" || *cpFilter != "" {
32 cp, err := chain.ParseCheckpoint(uint32(*cpHeight), *cpHash, *cpFilter)
33
34 if err != nil {
35 fail(err)
36 }
37
38 profile.Checkpoint = cp
39 }
40
41 if err := profile.Validate(); err != nil {
42 fail(err)
43 }
44
45 body, err := chain.MarshalProfile(profile)
46
47 if err != nil {
48 fail(err)
49 }
50
51 if *out == "" {
52 fmt.Println(string(body))
53
54 return
55 }
56
57 if err := os.WriteFile(*out, append(body, '\n'), 0o644); err != nil {
58 fail(err)
59 }
60 }
61
62 func fail(err error) {
63 fmt.Fprintln(os.Stderr, "nostrino-profile:", err)
64 os.Exit(1)
65 }
66