99 lines
2.8 KiB
Go
99 lines
2.8 KiB
Go
// Package helpers provides useful helper structures for KermaGo
|
|
package helpers
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
ipAddress = "3.126.74.45"
|
|
port = 18018
|
|
connTimeout = 10
|
|
storeBaseDir = "/var/local/badkerma"
|
|
peerListStore = "peers.json"
|
|
blockStore = "blocks.json"
|
|
transactionStore = "transactions.json"
|
|
privateKeyFile = "private.pem"
|
|
listenAddr = "0.0.0.0"
|
|
initialPeerList = ""
|
|
)
|
|
|
|
/*
|
|
A Config is a helper used for storing and obtaining the application configuration.
|
|
Supported configuration includes:
|
|
- IPAddress
|
|
- Port
|
|
- ListenAddr - address to listen on
|
|
- ConnTimeout - timeout for the client connections
|
|
- PeerListStore - filename for the peer list store
|
|
- BlockStore - filename for the blockchain store
|
|
- TransactionStore - filename for the transaction store
|
|
- PrivateKeyFile - filename for the private key
|
|
- InitialPeerList - initial peer list for building up
|
|
*/
|
|
type Config struct {
|
|
IPAddress string
|
|
Port int
|
|
PeerListStore string
|
|
ConnTimeout int
|
|
PrivateKeyFile string
|
|
BlockStore string
|
|
TransactionStore string
|
|
ListenAddr string
|
|
InitialPeerList string
|
|
}
|
|
|
|
/*
|
|
Construct fetches the configuration from the KERMA_* environment variables or sets sensible defaults
|
|
*/
|
|
func (c *Config) Construct() {
|
|
c.IPAddress = ipAddress
|
|
c.Port = port
|
|
c.PeerListStore = peerListStore
|
|
c.ConnTimeout = connTimeout
|
|
c.PrivateKeyFile = privateKeyFile
|
|
c.BlockStore = blockStore
|
|
c.TransactionStore = transactionStore
|
|
c.InitialPeerList = initialPeerList
|
|
|
|
baseDir := storeBaseDir
|
|
|
|
if os.Getenv("KERMA_IP_ADDR") != "" {
|
|
c.IPAddress = os.Getenv("KERMA_IP_ADDR")
|
|
}
|
|
if os.Getenv("KERMA_PORT") != "" {
|
|
c.Port, _ = strconv.Atoi(os.Getenv("KERMA_PORT"))
|
|
}
|
|
if os.Getenv("KERMA_CONN_TIMEOUT") != "" {
|
|
c.ConnTimeout, _ = strconv.Atoi(os.Getenv("KERMA_CONN_TIMEOUT"))
|
|
}
|
|
if os.Getenv("KERMA_INITIAL_PEER_LIST") != "" {
|
|
c.InitialPeerList = os.Getenv("KERMA_INITIAL_PEER_LIST")
|
|
}
|
|
if os.Getenv("KERMA_STORE_BASE_DIR") != "" {
|
|
baseDir = os.Getenv("KERMA_STORE_BASE_DIR")
|
|
baseDir = strings.TrimSuffix(baseDir, "/")
|
|
}
|
|
if os.Getenv("KERMA_PEER_LIST_STORE") != "" {
|
|
c.PeerListStore = os.Getenv("KERMA_PEER_LIST_STORE")
|
|
}
|
|
if os.Getenv("KERMA_BLOCK_STORE") != "" {
|
|
c.BlockStore = os.Getenv("KERMA_BLOCK_STORE")
|
|
}
|
|
if os.Getenv("KERMA_TRANSACTION_STORE") != "" {
|
|
c.TransactionStore = os.Getenv("KERMA_TRANSACTION_STORE")
|
|
}
|
|
if os.Getenv("KERMA_PRIVATE_KEY_FILE") != "" {
|
|
c.PrivateKeyFile = os.Getenv("KERMA_PRIVATE_KEY_FILE")
|
|
}
|
|
|
|
c.PeerListStore = baseDir + "/" + c.PeerListStore
|
|
c.BlockStore = baseDir + "/" + c.BlockStore
|
|
c.TransactionStore = baseDir + "/" + c.TransactionStore
|
|
c.PrivateKeyFile = baseDir + "/" + c.PrivateKeyFile
|
|
c.ListenAddr = listenAddr + ":" + fmt.Sprint(c.Port)
|
|
}
|