Use coin label in the explorer header
parent
4f3cb9c4ad
commit
a16ef2904e
|
@ -55,20 +55,21 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCoinNameFromConfig gets coin name and coin shortcut from config file
|
// 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)
|
data, err := ioutil.ReadFile(configfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", errors.Annotatef(err, "Error reading file %v", configfile)
|
return "", "", "", errors.Annotatef(err, "Error reading file %v", configfile)
|
||||||
}
|
}
|
||||||
var cn struct {
|
var cn struct {
|
||||||
CoinName string `json:"coin_name"`
|
CoinName string `json:"coin_name"`
|
||||||
CoinShortcut string `json:"coin_shortcut"`
|
CoinShortcut string `json:"coin_shortcut"`
|
||||||
|
CoinLabel string `json:"coin_label"`
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(data, &cn)
|
err = json.Unmarshal(data, &cn)
|
||||||
if err != nil {
|
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
|
// NewBlockChain creates bchain.BlockChain of type defined by parameter coin
|
||||||
|
|
10
blockbook.go
10
blockbook.go
|
@ -152,7 +152,7 @@ func main() {
|
||||||
glog.Fatal("Missing blockchaincfg configuration parameter")
|
glog.Fatal("Missing blockchaincfg configuration parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
coin, coinShortcut, err := coins.GetCoinNameFromConfig(*blockchain)
|
coin, coinShortcut, coinLabel, err := coins.GetCoinNameFromConfig(*blockchain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal("config: ", err)
|
glog.Fatal("config: ", err)
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ func main() {
|
||||||
}
|
}
|
||||||
defer index.Close()
|
defer index.Close()
|
||||||
|
|
||||||
internalState, err = newInternalState(coin, coinShortcut, index)
|
internalState, err = newInternalState(coin, coinShortcut, coinLabel, index)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Error("internalState: ", err)
|
glog.Error("internalState: ", err)
|
||||||
return
|
return
|
||||||
|
@ -369,12 +369,16 @@ func blockbookAppInfoMetric(db *db.RocksDB, chain bchain.BlockChain, txCache *db
|
||||||
return nil
|
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)
|
is, err := d.LoadInternalState(coin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
is.CoinShortcut = coinShortcut
|
is.CoinShortcut = coinShortcut
|
||||||
|
if coinLabel == "" {
|
||||||
|
coinLabel = coin
|
||||||
|
}
|
||||||
|
is.CoinLabel = coinLabel
|
||||||
name, err := os.Hostname()
|
name, err := os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Error("get hostname ", err)
|
glog.Error("get hostname ", err)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
"coin_name": "{{.Coin.Name}}",
|
"coin_name": "{{.Coin.Name}}",
|
||||||
"coin_shortcut": "{{.Coin.Shortcut}}",
|
"coin_shortcut": "{{.Coin.Shortcut}}",
|
||||||
|
"coin_label": "{{.Coin.Label}}",
|
||||||
"rpc_url": "{{template "IPC.RPCURLTemplate" .}}",
|
"rpc_url": "{{template "IPC.RPCURLTemplate" .}}",
|
||||||
"rpc_user": "{{.IPC.RPCUser}}",
|
"rpc_user": "{{.IPC.RPCUser}}",
|
||||||
"rpc_pass": "{{.IPC.RPCPass}}",
|
"rpc_pass": "{{.IPC.RPCPass}}",
|
||||||
|
|
|
@ -31,6 +31,7 @@ type InternalState struct {
|
||||||
|
|
||||||
Coin string `json:"coin"`
|
Coin string `json:"coin"`
|
||||||
CoinShortcut string `json:"coinShortcut"`
|
CoinShortcut string `json:"coinShortcut"`
|
||||||
|
CoinLabel string `json:"coinLabel"`
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
|
|
||||||
DbState uint32 `json:"dbState"`
|
DbState uint32 `json:"dbState"`
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"coin": {
|
"coin": {
|
||||||
"name": "Testnet",
|
"name": "Testnet",
|
||||||
"shortcut": "TEST",
|
"shortcut": "TEST",
|
||||||
"label": "Testnet",
|
"label": "Bitcoin Testnet",
|
||||||
"alias": "bitcoin_testnet"
|
"alias": "bitcoin_testnet"
|
||||||
},
|
},
|
||||||
"ports": {
|
"ports": {
|
||||||
|
|
|
@ -228,6 +228,7 @@ func (s *PublicServer) newTemplateData() *TemplateData {
|
||||||
return &TemplateData{
|
return &TemplateData{
|
||||||
CoinName: s.is.Coin,
|
CoinName: s.is.Coin,
|
||||||
CoinShortcut: s.is.CoinShortcut,
|
CoinShortcut: s.is.CoinShortcut,
|
||||||
|
CoinLabel: s.is.CoinLabel,
|
||||||
InternalExplorer: s.internalExplorer && !s.is.InitialSync,
|
InternalExplorer: s.internalExplorer && !s.is.InitialSync,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,6 +312,7 @@ const (
|
||||||
type TemplateData struct {
|
type TemplateData struct {
|
||||||
CoinName string
|
CoinName string
|
||||||
CoinShortcut string
|
CoinShortcut string
|
||||||
|
CoinLabel string
|
||||||
InternalExplorer bool
|
InternalExplorer bool
|
||||||
Address *api.Address
|
Address *api.Address
|
||||||
AddrStr string
|
AddrStr string
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
<span class="navbar-text ml-md-auto">
|
<span class="navbar-text ml-md-auto">
|
||||||
<a href="/" class="nav-link">{{.CoinName}} Explorer</a>
|
<a href="/" class="nav-link">{{.CoinLabel}} Explorer</a>
|
||||||
</span>
|
</span>
|
||||||
{{- if .InternalExplorer -}}
|
{{- if .InternalExplorer -}}
|
||||||
<ul class="navbar-nav flex-row ml-md-auto d-none d-lg-flex">
|
<ul class="navbar-nav flex-row ml-md-auto d-none d-lg-flex">
|
||||||
|
|
Loading…
Reference in New Issue