-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
49 lines (39 loc) · 1.18 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"os"
"github.com/gonative-cc/bitcoin-lightclient/btclightclient"
"github.com/gonative-cc/bitcoin-lightclient/rpcserver"
"github.com/gonative-cc/bitcoin-lightclient/data"
"github.com/btcsuite/btcd/wire"
"github.com/rs/zerolog/log"
)
func main() {
// read the json file
// example: ./data/sample.json
if len(os.Args) < 2 {
log.Error().Msg("Missing filename.\nUsage: bitcoin-lightclient <sample_file.json>")
return
}
sampleFilename := os.Args[1]
if _, err := os.Stat(sampleFilename); os.IsNotExist(err) {
log.Error().Msgf("Sample file does not exist: %s", sampleFilename)
return
}
networkParams, startHeight, blockHeaders, err := data.ReadJSON(sampleFilename)
if err != nil {
log.Error().Msgf("Error reading data file: %s", err)
return
}
headers := make([]wire.BlockHeader, len(blockHeaders))
for id, headerStr := range blockHeaders {
h, _ := btclightclient.BlockHeaderFromHex(headerStr)
headers[id] = h
}
btcLC := btclightclient.NewBTCLightClientWithData(networkParams, headers, int(startHeight))
btcLC.Status()
err = rpcserver.StartRPCServer(btcLC)
if err != nil {
log.Error().Msgf("Error creating RPC server: %s", err)
return
}
}