Skip to content

Commit

Permalink
feat(config): be able to specify Hedera node rpc urls for the target …
Browse files Browse the repository at this point in the history
…network (#347)

Signed-off-by: failfmi <[email protected]>
  • Loading branch information
failfmi authored Dec 16, 2021
1 parent fdfe23f commit e732ed5
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 77 deletions.
40 changes: 9 additions & 31 deletions app/clients/hedera/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,6 @@ import (
log "github.com/sirupsen/logrus"
)

var mainnetNodes = map[string]hedera.AccountID{
"15.165.118.251:50211": {Account: 3},
"137.116.36.18:50211": {Account: 4},
"107.155.64.98:50211": {Account: 5},
"13.71.90.154:50211": {Account: 6},
"23.102.74.34:50211": {Account: 7},
"23.96.185.18:50211": {Account: 8},
//"31.214.8.131:50211": {Account: 9},
"179.190.33.184:50211": {Account: 10},
"69.87.221.231:50211": {Account: 11},
"51.140.102.228:50211": {Account: 12},
"13.77.158.252:50211": {Account: 13},
"40.114.107.85:50211": {Account: 14},
"40.89.139.247:50211": {Account: 15},
"50.7.124.46:50211": {Account: 16},
"40.114.92.39:50211": {Account: 17},
"139.162.156.222:50211": {Account: 18},
//"51.140.43.81:50211": {Account: 19},
"13.77.151.212:50211": {Account: 20},
"13.36.123.209:50211": {Account: 21},
"52.78.202.34:50211": {Account: 22},
"3.18.91.176:50211": {Account: 23},
//"18.135.7.211:50211": {Account: 24},
"13.232.240.207:50211": {Account: 25},
"13.228.103.14:50211": {Account: 26},
}

// Node struct holding the hedera.Client. Used to interact with Hedera consensus nodes
type Node struct {
client *hedera.Client
Expand All @@ -63,17 +36,22 @@ func NewNodeClient(config config.Hedera) *Node {
switch config.Network {
case "mainnet":
client = hedera.ClientForMainnet()
err := client.SetNetwork(mainnetNodes)
if err != nil {
log.Fatalf("Could not set mainnet nodes. Error [%s]", err)
}
case "testnet":
client = hedera.ClientForTestnet()
case "previewnet":
client = hedera.ClientForPreviewnet()
default:
log.Fatalf("Invalid Client Network provided: [%s]", config.Network)
}
if len(config.Rpc) > 0 {
log.Infof("Setting provided RPC nodes for [%s].", config.Network)
err := client.SetNetwork(config.Rpc)
if err != nil {
log.Fatalf("Could not set rpc nodes [%s]. Error: [%s]", config.Rpc, err)
}
} else {
log.Infof("Setting default node rpc urls for [%s].", config.Network)
}

accID, err := hedera.AccountIDFromString(config.Operator.AccountId)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions config/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package config

import (
"github.com/hashgraph/hedera-sdk-go/v2"
"github.com/limechain/hedera-eth-bridge-validator/config/parser"
log "github.com/sirupsen/logrus"
"time"
)

Expand Down Expand Up @@ -55,6 +57,7 @@ type Evm struct {
type Hedera struct {
Operator Operator
Network string
Rpc map[string]hedera.AccountID
StartTimestamp int64
}

Expand All @@ -75,13 +78,23 @@ type Recovery struct {
}

func New(node parser.Node) Node {
rpc := make(map[string]hedera.AccountID)
for key, value := range node.Clients.Hedera.Rpc {
nodeAccoundID, err := hedera.AccountIDFromString(value)
if err != nil {
log.Fatalf("Hedera RPC [%s] failed to parse Node Account ID [%s]. Error: [%s]", key, value, err)
}
rpc[key] = nodeAccoundID
}

config := Node{
Database: Database(node.Database),
Clients: Clients{
Hedera: Hedera{
Operator: Operator(node.Clients.Hedera.Operator),
Network: node.Clients.Hedera.Network,
StartTimestamp: node.Clients.Hedera.StartTimestamp,
Rpc: rpc,
},
MirrorNode: MirrorNode(node.Clients.MirrorNode),
Evm: make(map[int64]Evm),
Expand Down
5 changes: 2 additions & 3 deletions config/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ node:
account_id:
private_key:
network: testnet
rpc:
# "127.0.0.1": "0.0.1"
mirror_node:
api_address: https://testnet.mirrornode.hedera.com/api/v1/
client_address: hcs.testnet.mirrornode.hedera.com:5600
polling_interval: 5
log_level: info
port: 5200
recovery:
start_timestamp:
start_block:
validator: true
7 changes: 4 additions & 3 deletions config/parser/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ type Evm struct {
}

type Hedera struct {
Operator Operator `yaml:"operator"`
Network string `yaml:"network"`
StartTimestamp int64 `yaml:"start_timestamp"`
Operator Operator `yaml:"operator"`
Network string `yaml:"network"`
Rpc map[string]string `yaml:"rpc"`
StartTimestamp int64 `yaml:"start_timestamp"`
}

type Operator struct {
Expand Down
Loading

0 comments on commit e732ed5

Please sign in to comment.