-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
92 lines (82 loc) · 3.27 KB
/
config.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package config
import (
"fmt"
"github.com/allinbits/cosmos-cash-agent/pkg/helpers"
"github.com/google/uuid"
log "github.com/sirupsen/logrus"
"os"
"path"
)
// NewEdgeConfigSchema sensible defaults for configuration
func NewEdgeConfigSchema(controllerName string) EdgeConfigSchema {
if helpers.Env("CASH_ENV", "live") == "dev" {
return EdgeConfigSchema{
ControllerName: controllerName,
NodeURI: helpers.Env("NODE_URI", "http://127.0.0.1:26657"),
FaucetURL: helpers.Env("FAUCET_URL", "https://faucet.cosmos-cash.app.beta.starport.cloud"),
ChainID: helpers.Env("CHAIN_ID", "cash"),
CloudAgentWsURL: helpers.Env("AGENT_WS_URL", "wss://ws.agent.cosmos-cash.app.beta.starport.cloud"),
CloudAgentPublicURL: helpers.Env("AGENT_PUBLIC_URL", "http://localhost:8090"),
CosmosDIDResolverURL: helpers.Env("RESOLVER_URL", "http://localhost:2109/identifier/aries/"),
ControllerDidID: uuid.New().String(),
// runtime
RuntimeMsgs: NewMsgHub(),
}
}
return EdgeConfigSchema{
ControllerName: controllerName,
NodeURI: helpers.Env("NODE_URI", "https://rpc.cosmos-cash.app.beta.starport.cloud:443"),
FaucetURL: helpers.Env("FAUCET_URL", "https://faucet.cosmos-cash.app.beta.starport.cloud"),
ChainID: helpers.Env("CHAIN_ID", "cosmoscash-testnet"),
CloudAgentWsURL: helpers.Env("AGENT_WS_URL", "wss://ws.agent.cosmos-cash.app.beta.starport.cloud"),
CloudAgentPublicURL: helpers.Env("AGENT_PUBLIC_URL", "https://agent.cosmos-cash.app.beta.starport.cloud"),
CosmosDIDResolverURL: helpers.Env("RESOLVER_URL", "https://resolver-driver.cosmos-cash.app.beta.starport.cloud/identifier/aries"),
ControllerDidID: uuid.New().String(),
// runtime
RuntimeMsgs: NewMsgHub(),
}
}
type EdgeConfigSchema struct {
ControllerName string `json:"controller_name"`
ControllerDidID string `json:"controller_did"`
NodeURI string `json:"node_uri"`
FaucetURL string `json:"faucet_url"`
ChainID string `json:"chain_id"`
CloudAgentWsURL string `json:"cloud_agent_ws_url"`
CloudAgentPublicURL string `json:"cloud_agent_public_url"`
CosmosDIDResolverURL string `json:"cosmos_did_resolver_url"`
// Runtime
RuntimeMsgs *MsgHub `json:"-"`
}
// ControllerDID returns the current user did
func (ecs EdgeConfigSchema) ControllerDID() string {
return fmt.Sprintf("did:cosmos:net:%s:%s", ecs.ChainID, ecs.ControllerDidID)
}
// MediatorDID returns the cloud agent mediator did
func (ecs EdgeConfigSchema) MediatorDID() string {
return "did:cosmos:net:cosmoscash-testnet:mediatortestnetws10"
}
// CloudAgentAPIURL returns the cloud agent mediator did
func (ecs EdgeConfigSchema) CloudAgentAPIURL() string {
return "https://agent.cosmos-cash.app.beta.starport.cloud"
}
func GetAppData(subPath ...string) (string, bool) {
v := []string{"data"}
v = append(v, subPath...)
return GetAppConfig(v...)
}
func GetAppConfig(subPath ...string) (cfgPath string, exists bool) {
cfgPath, err := os.UserConfigDir()
if err != nil {
log.Fatalln(err)
}
cfgPath = path.Join(cfgPath, "cosmos-cash-agent")
for _, sp := range subPath {
cfgPath = path.Join(cfgPath, sp)
}
exists = true
if _, err := os.Stat(cfgPath); os.IsNotExist(err) {
exists = false
}
return
}