Add network parameter to getInfo ws request

This commit is contained in:
Martin Boehm 2024-08-06 10:50:01 +02:00
parent c1f2e62c45
commit a0960c8e17
17 changed files with 165 additions and 135 deletions

View File

@ -503,6 +503,7 @@ type BlockRaw struct {
// BlockbookInfo contains information about the running blockbook instance
type BlockbookInfo struct {
Coin string `json:"coin"`
Network string `json:"network"`
Host string `json:"host"`
Version string `json:"version"`
GitCommit string `json:"gitCommit"`

View File

@ -2413,6 +2413,7 @@ func (w *Worker) GetSystemInfo(internal bool) (*SystemInfo, error) {
}
blockbookInfo := &BlockbookInfo{
Coin: w.is.Coin,
Network: w.is.GetNetwork(),
Host: w.is.Host,
Version: vi.Version,
GitCommit: vi.GitCommit,

View File

@ -33,6 +33,10 @@ export interface EthereumSpecific {
gasLimit: number;
gasUsed?: number;
gasPrice?: string;
l1Fee?: number;
l1FeeScalar?: string;
l1GasPrice?: string;
l1GasUsed?: number;
data?: string;
parsedData?: EthereumParsedInputData;
internalTransfers?: EthereumInternalTransfer[];
@ -351,6 +355,7 @@ export interface WsBackendInfo {
export interface WsInfoRes {
name: string;
shortcut: string;
network: string;
decimals: number;
version: string;
bestHeight: number;

View File

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

View File

@ -44,6 +44,7 @@ type Config struct {
Coin struct {
Name string `json:"name"`
Shortcut string `json:"shortcut"`
Network string `json:"network,omitempty"`
Label string `json:"label"`
Alias string `json:"alias"`
} `json:"coin"`

View File

@ -12,6 +12,7 @@ type Config struct {
CoinName string `json:"coin_name"`
CoinShortcut string `json:"coin_shortcut"`
CoinLabel string `json:"coin_label"`
Network string `json:"network"`
FourByteSignatures string `json:"fourByteSignatures"`
FiatRates string `json:"fiat_rates"`
FiatRatesParams string `json:"fiat_rates_params"`

View File

@ -57,6 +57,7 @@ type InternalState struct {
CoinShortcut string `json:"coinShortcut"`
CoinLabel string `json:"coinLabel"`
Host string `json:"host"`
Network string `json:"network,omitempty"`
DbState uint32 `json:"dbState"`
ExtendedIndex bool `json:"extendedIndex"`
@ -305,6 +306,15 @@ func (is *InternalState) computeAvgBlockPeriod() {
is.AvgBlockPeriod = (is.BlockTimes[last] - is.BlockTimes[first]) / avgBlockPeriodSample
}
// GetNetwork returns network. If not set returns the same value as CoinShortcut
func (is *InternalState) GetNetwork() string {
network := is.Network
if network == "" {
return is.CoinShortcut
}
return network
}
// SetBackendInfo sets new BackendInfo
func (is *InternalState) SetBackendInfo(bi *BackendInfo) {
is.mux.Lock()

View File

@ -2,6 +2,7 @@
"coin": {
"name": "BNB Smart Chain",
"shortcut": "BNB",
"network": "BNB",
"label": "BNB Smart Chain",
"alias": "bsc"
},

View File

@ -2,6 +2,7 @@
"coin": {
"name": "BNB Smart Chain Archive",
"shortcut": "BNB",
"network": "BNB",
"label": "BNB Smart Chain",
"alias": "bsc_archive"
},

View File

@ -2,6 +2,7 @@
"coin": {
"name": "Optimism",
"shortcut": "ETH",
"network": "OP",
"label": "Optimism",
"alias": "optimism"
},

View File

@ -2,6 +2,7 @@
"coin": {
"name": "Optimism Archive",
"shortcut": "ETH",
"network": "OP",
"label": "Optimism",
"alias": "optimism_archive"
},

View File

@ -2,6 +2,7 @@
"coin": {
"name": "Polygon",
"shortcut": "MATIC",
"network": "MATIC",
"label": "Polygon",
"alias": "polygon_bor"
},

View File

@ -2,6 +2,7 @@
"coin": {
"name": "Polygon Archive",
"shortcut": "MATIC",
"network": "MATIC",
"label": "Polygon",
"alias": "polygon_archive_bor"
},

View File

@ -1962,6 +1962,7 @@ func (d *RocksDB) LoadInternalState(config *common.Config) (*common.InternalStat
} else {
is.CoinLabel = config.CoinLabel
}
is.Network = config.Network
return is, nil
}

View File

@ -1039,7 +1039,7 @@ var websocketTestsBitcoinType = []websocketTest{
req: websocketReq{
Method: "getInfo",
},
want: `{"id":"0","data":{"name":"Fakecoin","shortcut":"FAKE","decimals":8,"version":"unknown","bestHeight":225494,"bestHash":"00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6","block0Hash":"","testnet":true,"backend":{"version":"001001","subversion":"/Fakecoin:0.0.1/"}}}`,
want: `{"id":"0","data":{"name":"Fakecoin","shortcut":"FAKE","network":"FAKE","decimals":8,"version":"unknown","bestHeight":225494,"bestHash":"00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6","block0Hash":"","testnet":true,"backend":{"version":"001001","subversion":"/Fakecoin:0.0.1/"}}}`,
},
{
name: "websocket getBlockHash",
@ -1681,7 +1681,7 @@ var websocketTestsBitcoinTypeExtendedIndex = []websocketTest{
req: websocketReq{
Method: "getInfo",
},
want: `{"id":"0","data":{"name":"Fakecoin","shortcut":"FAKE","decimals":8,"version":"unknown","bestHeight":225494,"bestHash":"00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6","block0Hash":"","testnet":true,"backend":{"version":"001001","subversion":"/Fakecoin:0.0.1/"}}}`,
want: `{"id":"0","data":{"name":"Fakecoin","shortcut":"FAKE","network":"FAKE","decimals":8,"version":"unknown","bestHeight":225494,"bestHash":"00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6","block0Hash":"","testnet":true,"backend":{"version":"001001","subversion":"/Fakecoin:0.0.1/"}}}`,
},
{
name: "websocket getBlockHash",

View File

@ -580,6 +580,7 @@ func (s *WebsocketServer) getInfo() (*WsInfoRes, error) {
return &WsInfoRes{
Name: s.is.Coin,
Shortcut: s.is.CoinShortcut,
Network: s.is.GetNetwork(),
Decimals: s.chainParser.AmountDecimals(),
BestHeight: int(height),
BestHash: hash,

View File

@ -36,6 +36,7 @@ type WsBackendInfo struct {
type WsInfoRes struct {
Name string `json:"name"`
Shortcut string `json:"shortcut"`
Network string `json:"network"`
Decimals int `json:"decimals"`
Version string `json:"version"`
BestHeight int `json:"bestHeight"`