Use coin label in the explorer header

pull/74/head
Martin Boehm 2018-10-10 00:23:31 +02:00
parent 4f3cb9c4ad
commit a16ef2904e
7 changed files with 18 additions and 9 deletions

View File

@ -55,20 +55,21 @@ func init() {
}
// GetCoinNameFromConfig gets coin name and coin shortcut from config file
func GetCoinNameFromConfig(configfile string) (string, string, error) {
func GetCoinNameFromConfig(configfile string) (string, string, string, error) {
data, err := ioutil.ReadFile(configfile)
if err != nil {
return "", "", errors.Annotatef(err, "Error reading file %v", configfile)
return "", "", "", errors.Annotatef(err, "Error reading file %v", configfile)
}
var cn struct {
CoinName string `json:"coin_name"`
CoinShortcut string `json:"coin_shortcut"`
CoinLabel string `json:"coin_label"`
}
err = json.Unmarshal(data, &cn)
if err != nil {
return "", "", errors.Annotatef(err, "Error parsing file %v", configfile)
return "", "", "", errors.Annotatef(err, "Error parsing file %v", configfile)
}
return cn.CoinName, cn.CoinShortcut, nil
return cn.CoinName, cn.CoinShortcut, cn.CoinLabel, nil
}
// NewBlockChain creates bchain.BlockChain of type defined by parameter coin

View File

@ -152,7 +152,7 @@ func main() {
glog.Fatal("Missing blockchaincfg configuration parameter")
}
coin, coinShortcut, err := coins.GetCoinNameFromConfig(*blockchain)
coin, coinShortcut, coinLabel, err := coins.GetCoinNameFromConfig(*blockchain)
if err != nil {
glog.Fatal("config: ", err)
}
@ -174,7 +174,7 @@ func main() {
}
defer index.Close()
internalState, err = newInternalState(coin, coinShortcut, index)
internalState, err = newInternalState(coin, coinShortcut, coinLabel, index)
if err != nil {
glog.Error("internalState: ", err)
return
@ -369,12 +369,16 @@ func blockbookAppInfoMetric(db *db.RocksDB, chain bchain.BlockChain, txCache *db
return nil
}
func newInternalState(coin string, coinShortcut string, d *db.RocksDB) (*common.InternalState, error) {
func newInternalState(coin, coinShortcut, coinLabel string, d *db.RocksDB) (*common.InternalState, error) {
is, err := d.LoadInternalState(coin)
if err != nil {
return nil, err
}
is.CoinShortcut = coinShortcut
if coinLabel == "" {
coinLabel = coin
}
is.CoinLabel = coinLabel
name, err := os.Hostname()
if err != nil {
glog.Error("get hostname ", err)

View File

@ -8,6 +8,7 @@
"coin_name": "{{.Coin.Name}}",
"coin_shortcut": "{{.Coin.Shortcut}}",
"coin_label": "{{.Coin.Label}}",
"rpc_url": "{{template "IPC.RPCURLTemplate" .}}",
"rpc_user": "{{.IPC.RPCUser}}",
"rpc_pass": "{{.IPC.RPCPass}}",

View File

@ -31,6 +31,7 @@ type InternalState struct {
Coin string `json:"coin"`
CoinShortcut string `json:"coinShortcut"`
CoinLabel string `json:"coinLabel"`
Host string `json:"host"`
DbState uint32 `json:"dbState"`

View File

@ -2,7 +2,7 @@
"coin": {
"name": "Testnet",
"shortcut": "TEST",
"label": "Testnet",
"label": "Bitcoin Testnet",
"alias": "bitcoin_testnet"
},
"ports": {

View File

@ -228,6 +228,7 @@ func (s *PublicServer) newTemplateData() *TemplateData {
return &TemplateData{
CoinName: s.is.Coin,
CoinShortcut: s.is.CoinShortcut,
CoinLabel: s.is.CoinLabel,
InternalExplorer: s.internalExplorer && !s.is.InitialSync,
}
}
@ -311,6 +312,7 @@ const (
type TemplateData struct {
CoinName string
CoinShortcut string
CoinLabel string
InternalExplorer bool
Address *api.Address
AddrStr string

View File

@ -29,7 +29,7 @@
</div>
</a>
<span class="navbar-text ml-md-auto">
<a href="/" class="nav-link">{{.CoinName}} Explorer</a>
<a href="/" class="nav-link">{{.CoinLabel}} Explorer</a>
</span>
{{- if .InternalExplorer -}}
<ul class="navbar-nav flex-row ml-md-auto d-none d-lg-flex">