-
Notifications
You must be signed in to change notification settings - Fork 12
/
config.go
152 lines (126 loc) · 4.57 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Copyright 2021 LimeChain Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package config
import (
"io/ioutil"
"os"
"path/filepath"
"time"
"github.com/caarlos0/env/v6"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
const (
defaultConfigFile = "config/application.yml"
mainConfigFile = "application.yml"
)
func LoadConfig() *Config {
var configuration Config
GetConfig(&configuration, defaultConfigFile)
GetConfig(&configuration, mainConfigFile)
if err := env.Parse(&configuration); err != nil {
panic(err)
}
return &configuration
}
func GetConfig(config *Config, path string) error {
if _, err := os.Stat(path); os.IsNotExist(err) {
return err
}
filename, _ := filepath.Abs(path)
yamlFile, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
}
err = yaml.Unmarshal(yamlFile, config)
if err != nil {
log.Fatal(err)
}
return err
}
type Config struct {
Hedera Hedera `yaml:"hedera"`
}
type Hedera struct {
Validator Validator `yaml:"validator"`
Eth Ethereum `yaml:"eth"`
MirrorNode MirrorNode `yaml:"mirror_node"`
Client Client `yaml:"client"`
Watcher Watcher `yaml:"watcher"`
Handler Handler `yaml:"handler"`
}
type Handler struct {
CryptoTransfer CryptoTransferHandler `yaml:"crypto-transfer"`
ConsensusMessage ConsensusMessageHandler `yaml:"consensus-message"`
}
type ConsensusMessageHandler struct {
TopicId string `yaml:"topic_id"`
Addresses []string `yaml:"addresses"`
SendDeadline int64 `yaml:"send_deadline"`
}
type CryptoTransferHandler struct {
TopicId string `yaml:"topic_id"`
PollingInterval time.Duration `yaml:"polling_interval"`
}
type Watcher struct {
CryptoTransfer CryptoTransfer `yaml:"crypto-transfer"`
ConsensusMessage ConsensusMessage `yaml:"consensus-message"`
}
type Ethereum struct {
NodeUrl string `yaml:"node_url" env:"HEDERA_ETH_BRIDGE_ETH_NODE_URL"`
BridgeContractAddress string `yaml:"bridge_contract_address" env:"HEDERA_ETH_BRIDGE_ETH_BRIDGE_CONTRACT_ADDRESS"`
WhbarContractAddress string `yaml:"whbar_contract_address" env:"HEDERA_ETH_BRIDGE_ETH_WHBAR_CONTRACT_ADDRESS"`
CustodialAccount string `yaml:"custodial_account" env:"HEDERA_ETH_BRIDGE_ETH_CUSTODIAL_ACCOUNT"`
}
type CryptoTransfer struct {
Accounts []ID `yaml:"accounts" env:"HEDERA_ETH_BRIDGE_WATCHER_CRYPTO_TRANSFER"`
}
type ConsensusMessage struct {
Topics []ID `yaml:"topics" env:"HEDERA_ETH_BRIDGE_WATCHER_CONSENSUS_MESSAGE"`
}
type ID struct {
Id string `yaml:"id"`
MaxRetries int `yaml:"max_retries"`
StartTimestamp int64 `yaml:"start_timestamp"`
}
type Client struct {
NetworkType string `yaml:"network_type" env:"HEDERA_ETH_BRIDGE_CLIENT_NETWORK_TYPE"`
Operator Operator `yaml:"operator"`
ServiceFeePercent uint64 `yaml:"service_fee_percent"`
BaseGasUsage uint64 `yaml:"base_gas_usage"`
GasPerValidator uint64 `yaml:"gas_per_validator"`
}
type Operator struct {
AccountId string `yaml:"account_id" env:"HEDERA_ETH_BRIDGE_CLIENT_OPERATOR_ACCOUNT_ID"`
EthPrivateKey string `yaml:"eth_private_key" env:"HEDERA_ETH_BRIDGE_CLIENT_OPERATOR_ETH_PRIVATE_KEY"`
PrivateKey string `yaml:"private_key" env:"HEDERA_ETH_BRIDGE_CLIENT_OPERATOR_PRIVATE_KEY"`
}
type MirrorNode struct {
ClientAddress string `yaml:"client_address" env:"HEDERA_ETH_BRIDGE_MIRROR_NODE_CLIENT_ADDRESS"`
ApiAddress string `yaml:"api_address" env:"HEDERA_ETH_BRIDGE_MIRROR_NODE_API_ADDRESS"`
PollingInterval time.Duration `yaml:"polling_interval" env:"HEDERA_ETH_BRIDGE_MIRROR_NODE_POLLING_INTERVAL"`
}
type Validator struct {
Db Db `yaml:"db"`
Port string `yaml:"port" env:"HEDERA_ETH_BRIDGE_VALIDATOR_PORT"`
}
type Db struct {
Host string `yaml:"host" env:"HEDERA_ETH_BRIDGE_VALIDATOR_DB_HOST"`
Name string `yaml:"name" env:"HEDERA_ETH_BRIDGE_VALIDATOR_DB_NAME"`
Password string `yaml:"password" env:"HEDERA_ETH_BRIDGE_VALIDATOR_DB_PASSWORD"`
Port string `yaml:"port" env:"HEDERA_ETH_BRIDGE_VALIDATOR_DB_PORT"`
Username string `yaml:"username" env:"HEDERA_ETH_BRIDGE_VALIDATOR_DB_USERNAME"`
}