generated from mrz1836/go-template
/
nodes.go
69 lines (60 loc) · 1.59 KB
/
nodes.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
64
65
66
67
68
69
package config
import (
"errors"
broadcastclient "github.com/bitcoin-sv/go-broadcast-client/broadcast/broadcast-client"
"github.com/tonicpow/go-minercraft/v2"
)
// NodesProtocol is the protocol/api_type used to communicate with the miners
type NodesProtocol string
const (
// NodesProtocolMapi represents the mapi protocol provided by minercraft
NodesProtocolMapi NodesProtocol = "mapi"
// NodesProtocolArc represents the arc protocol provided by go-broadcast-client
NodesProtocolArc NodesProtocol = "arc"
)
// Validate whether the protocol is known
func (n NodesProtocol) Validate() error {
switch n {
case NodesProtocolMapi, NodesProtocolArc:
return nil
default:
return errors.New("invalid nodes protocol")
}
}
func (nodes *NodesConfig) toMinercraftMapi() []*minercraft.MinerAPIs {
minerApis := []*minercraft.MinerAPIs{}
if nodes.Apis != nil {
for _, api := range nodes.Apis {
if api.MapiURL == "" {
continue
}
minerApis = append(minerApis, &minercraft.MinerAPIs{
MinerID: api.MinerID,
APIs: []minercraft.API{
{
Token: api.Token,
URL: api.MapiURL,
Type: minercraft.MAPI,
},
},
})
}
}
return minerApis
}
func (nodes *NodesConfig) toBroadcastClientArc() []*broadcastclient.ArcClientConfig {
minerApis := []*broadcastclient.ArcClientConfig{}
if nodes.Apis != nil {
for _, cfg := range nodes.Apis {
if cfg.ArcURL == "" {
continue
}
minerApis = append(minerApis, &broadcastclient.ArcClientConfig{
Token: cfg.Token,
APIUrl: cfg.ArcURL,
DeploymentID: nodes.DeploymentID,
})
}
}
return minerApis
}