-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
63 lines (49 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"encoding/json"
"strings"
"github.com/extism/go-pdk"
)
//export run
func run() int32 {
keywords := map[string]func() (interface{}, error){
"market": GetMarketData,
"latestBlock": GetLatestBlockInfo,
"mining": GetMiningData,
"fees": GetFeeRecommendation,
"mempool": GetMempoolStats,
"lightning": GetLightningStats,
"nodes": GetBitcoinNodeStats,
}
outputData := make(map[string]interface{})
input := strings.ToLower(pdk.InputString())
includeData := ""
for kw := range keywords {
if strings.Contains(input, "-"+kw) {
continue
}
if strings.Contains(input, kw) {
includeData = input
break
}
includeData = includeData + " " + kw
}
for kw, function := range keywords {
if strings.Contains(includeData, kw) && !strings.Contains(includeData, "-"+kw) {
data, err := function()
if err != nil {
pdk.SetErrorString("Failed to get " + kw + " data: " + err.Error())
return 1
}
outputData[kw] = data
}
}
output, err := json.Marshal(outputData)
if err != nil {
pdk.SetErrorString("Failed to marshal the result.")
return 1
}
pdk.OutputString(string(output))
return 0
}
func main() {}