add util for get port from base and diff

pull/952/head
Minh Doan 6 years ago committed by Minh Doan
parent c627012a8f
commit e38a01b615
  1. 2
      internal/configs/node/config.go
  2. 11
      internal/utils/utils.go

@ -69,6 +69,8 @@ type ConfigType struct {
isBeacon bool // whether this node is beacon node doing consensus or not
ShardID uint32 // ShardID of this node
role Role // Role of the node
Port string
IP string
StringRole string
Host p2p.Host

@ -15,8 +15,8 @@ import (
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/internal/utils"
p2p_crypto "github.com/libp2p/go-libp2p-crypto"
)
@ -233,3 +233,12 @@ func GetBlsAddress(key *bls.PublicKey) common.Address {
addr.SetBytes(addrBytes[:])
return addr
}
// GetPortFromDiff returns the port from base and the diff.
func GetPortFromDiff(port string, diff int) string {
if portNum, err := strconv.Atoi(port); err == nil {
return fmt.Sprintf("%d", portNum-diff)
}
utils.GetLogInstance().Error("error on parsing port.")
return ""
}

Loading…
Cancel
Save