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 // BlockbookInfo contains information about the running blockbook instance
type BlockbookInfo struct { type BlockbookInfo struct {
Coin string `json:"coin"` Coin string `json:"coin"`
Network string `json:"network"`
Host string `json:"host"` Host string `json:"host"`
Version string `json:"version"` Version string `json:"version"`
GitCommit string `json:"gitCommit"` GitCommit string `json:"gitCommit"`

View File

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

View File

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

View File

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

View File

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

View File

@ -12,6 +12,7 @@ type Config 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"` CoinLabel string `json:"coin_label"`
Network string `json:"network"`
FourByteSignatures string `json:"fourByteSignatures"` FourByteSignatures string `json:"fourByteSignatures"`
FiatRates string `json:"fiat_rates"` FiatRates string `json:"fiat_rates"`
FiatRatesParams string `json:"fiat_rates_params"` FiatRatesParams string `json:"fiat_rates_params"`

View File

@ -57,6 +57,7 @@ type InternalState struct {
CoinShortcut string `json:"coinShortcut"` CoinShortcut string `json:"coinShortcut"`
CoinLabel string `json:"coinLabel"` CoinLabel string `json:"coinLabel"`
Host string `json:"host"` Host string `json:"host"`
Network string `json:"network,omitempty"`
DbState uint32 `json:"dbState"` DbState uint32 `json:"dbState"`
ExtendedIndex bool `json:"extendedIndex"` ExtendedIndex bool `json:"extendedIndex"`
@ -305,6 +306,15 @@ func (is *InternalState) computeAvgBlockPeriod() {
is.AvgBlockPeriod = (is.BlockTimes[last] - is.BlockTimes[first]) / avgBlockPeriodSample 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 // SetBackendInfo sets new BackendInfo
func (is *InternalState) SetBackendInfo(bi *BackendInfo) { func (is *InternalState) SetBackendInfo(bi *BackendInfo) {
is.mux.Lock() is.mux.Lock()

View File

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

View File

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

View File

@ -1,66 +1,67 @@
{ {
"coin": { "coin": {
"name": "Optimism", "name": "Optimism",
"shortcut": "ETH", "shortcut": "ETH",
"label": "Optimism", "network": "OP",
"alias": "optimism" "label": "Optimism",
}, "alias": "optimism"
"ports": { },
"backend_rpc": 8200, "ports": {
"backend_p2p": 38400, "backend_rpc": 8200,
"backend_http": 8300, "backend_p2p": 38400,
"backend_authrpc": 8400, "backend_http": 8300,
"blockbook_internal": 9200, "backend_authrpc": 8400,
"blockbook_public": 9300 "blockbook_internal": 9200,
}, "blockbook_public": 9300
"ipc": { },
"rpc_url_template": "ws://127.0.0.1:{{.Ports.BackendRPC}}", "ipc": {
"rpc_timeout": 25 "rpc_url_template": "ws://127.0.0.1:{{.Ports.BackendRPC}}",
}, "rpc_timeout": 25
"backend": { },
"package_name": "backend-optimism", "backend": {
"package_revision": "satoshilabs-1", "package_name": "backend-optimism",
"system_user": "optimism", "package_revision": "satoshilabs-1",
"version": "1.101315.1", "system_user": "optimism",
"binary_url": "https://github.com/ethereum-optimism/op-geth/archive/refs/tags/v1.101315.1.tar.gz", "version": "1.101315.1",
"verification_type": "sha256", "binary_url": "https://github.com/ethereum-optimism/op-geth/archive/refs/tags/v1.101315.1.tar.gz",
"verification_source": "f0f31ef2982f87f9e3eb90f2b603f5fcd9d680e487d35f5bdcf5aeba290b153f", "verification_type": "sha256",
"extract_command": "mkdir backend/source && tar -C backend/source --strip 1 -xf v1.101315.1.tar.gz && cd backend/source && make geth && mv build/bin/geth ../ && rm -rf ../source && echo", "verification_source": "f0f31ef2982f87f9e3eb90f2b603f5fcd9d680e487d35f5bdcf5aeba290b153f",
"exclude_files": [], "extract_command": "mkdir backend/source && tar -C backend/source --strip 1 -xf v1.101315.1.tar.gz && cd backend/source && make geth && mv build/bin/geth ../ && rm -rf ../source && echo",
"exec_command_template": "/bin/sh -c '{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/optimism_exec.sh 2>> {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log'", "exclude_files": [],
"exec_script": "optimism.sh", "exec_command_template": "/bin/sh -c '{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/optimism_exec.sh 2>> {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log'",
"logrotate_files_template": "{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log", "exec_script": "optimism.sh",
"postinst_script_template": "openssl rand -hex 32 > {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/jwtsecret", "logrotate_files_template": "{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log",
"service_type": "simple", "postinst_script_template": "openssl rand -hex 32 > {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/jwtsecret",
"service_additional_params_template": "", "service_type": "simple",
"protect_memory": true, "service_additional_params_template": "",
"mainnet": true, "protect_memory": true,
"server_config_file": "", "mainnet": true,
"client_config_file": "" "server_config_file": "",
}, "client_config_file": ""
"blockbook": { },
"package_name": "blockbook-optimism", "blockbook": {
"system_user": "blockbook-optimism", "package_name": "blockbook-optimism",
"internal_binding_template": ":{{.Ports.BlockbookInternal}}", "system_user": "blockbook-optimism",
"public_binding_template": ":{{.Ports.BlockbookPublic}}", "internal_binding_template": ":{{.Ports.BlockbookInternal}}",
"explorer_url": "", "public_binding_template": ":{{.Ports.BlockbookPublic}}",
"additional_params": "", "explorer_url": "",
"block_chain": { "additional_params": "",
"parse": true, "block_chain": {
"mempool_workers": 8, "parse": true,
"mempool_sub_workers": 2, "mempool_workers": 8,
"block_addresses_to_keep": 300, "mempool_sub_workers": 2,
"additional_params": { "block_addresses_to_keep": 300,
"mempoolTxTimeoutHours": 48, "additional_params": {
"queryBackendOnMempoolResync": false, "mempoolTxTimeoutHours": 48,
"fiat_rates": "coingecko", "queryBackendOnMempoolResync": false,
"fiat_rates_vs_currencies": "AED,ARS,AUD,BDT,BHD,BMD,BRL,CAD,CHF,CLP,CNY,CZK,DKK,EUR,GBP,HKD,HUF,IDR,ILS,INR,JPY,KRW,KWD,LKR,MMK,MXN,MYR,NGN,NOK,NZD,PHP,PKR,PLN,RUB,SAR,SEK,SGD,THB,TRY,TWD,UAH,USD,VEF,VND,ZAR,BTC,ETH", "fiat_rates": "coingecko",
"fiat_rates_params": "{\"url\": \"https://api.coingecko.com/api/v3\", \"coin\": \"ethereum\",\"platformIdentifier\": \"ethereum\",\"platformVsCurrency\": \"eth\",\"periodSeconds\": 900}" "fiat_rates_vs_currencies": "AED,ARS,AUD,BDT,BHD,BMD,BRL,CAD,CHF,CLP,CNY,CZK,DKK,EUR,GBP,HKD,HUF,IDR,ILS,INR,JPY,KRW,KWD,LKR,MMK,MXN,MYR,NGN,NOK,NZD,PHP,PKR,PLN,RUB,SAR,SEK,SGD,THB,TRY,TWD,UAH,USD,VEF,VND,ZAR,BTC,ETH",
} "fiat_rates_params": "{\"url\": \"https://api.coingecko.com/api/v3\", \"coin\": \"ethereum\",\"platformIdentifier\": \"ethereum\",\"platformVsCurrency\": \"eth\",\"periodSeconds\": 900}"
}
}
},
"meta": {
"package_maintainer": "IT",
"package_maintainer_email": "it@satoshilabs.com"
} }
}, }
"meta": {
"package_maintainer": "IT",
"package_maintainer_email": "it@satoshilabs.com"
}
}

View File

@ -1,69 +1,70 @@
{ {
"coin": { "coin": {
"name": "Optimism Archive", "name": "Optimism Archive",
"shortcut": "ETH", "shortcut": "ETH",
"label": "Optimism", "network": "OP",
"alias": "optimism_archive" "label": "Optimism",
}, "alias": "optimism_archive"
"ports": { },
"backend_rpc": 8202, "ports": {
"backend_p2p": 38402, "backend_rpc": 8202,
"backend_http": 8302, "backend_p2p": 38402,
"backend_authrpc": 8402, "backend_http": 8302,
"blockbook_internal": 9202, "backend_authrpc": 8402,
"blockbook_public": 9302 "blockbook_internal": 9202,
}, "blockbook_public": 9302
"ipc": { },
"rpc_url_template": "ws://127.0.0.1:{{.Ports.BackendRPC}}", "ipc": {
"rpc_timeout": 25 "rpc_url_template": "ws://127.0.0.1:{{.Ports.BackendRPC}}",
}, "rpc_timeout": 25
"backend": { },
"package_name": "backend-optimism-archive", "backend": {
"package_revision": "satoshilabs-1", "package_name": "backend-optimism-archive",
"system_user": "optimism", "package_revision": "satoshilabs-1",
"version": "1.101315.1", "system_user": "optimism",
"binary_url": "https://github.com/ethereum-optimism/op-geth/archive/refs/tags/v1.101315.1.tar.gz", "version": "1.101315.1",
"verification_type": "sha256", "binary_url": "https://github.com/ethereum-optimism/op-geth/archive/refs/tags/v1.101315.1.tar.gz",
"verification_source": "f0f31ef2982f87f9e3eb90f2b603f5fcd9d680e487d35f5bdcf5aeba290b153f", "verification_type": "sha256",
"extract_command": "mkdir backend/source && tar -C backend/source --strip 1 -xf v1.101315.1.tar.gz && cd backend/source && make geth && mv build/bin/geth ../ && rm -rf ../source && echo", "verification_source": "f0f31ef2982f87f9e3eb90f2b603f5fcd9d680e487d35f5bdcf5aeba290b153f",
"exclude_files": [], "extract_command": "mkdir backend/source && tar -C backend/source --strip 1 -xf v1.101315.1.tar.gz && cd backend/source && make geth && mv build/bin/geth ../ && rm -rf ../source && echo",
"exec_command_template": "/bin/sh -c '{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/optimism_archive_exec.sh 2>> {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log'", "exclude_files": [],
"exec_script": "optimism_archive.sh", "exec_command_template": "/bin/sh -c '{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/optimism_archive_exec.sh 2>> {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log'",
"logrotate_files_template": "{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log", "exec_script": "optimism_archive.sh",
"postinst_script_template": "openssl rand -hex 32 > {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/jwtsecret", "logrotate_files_template": "{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log",
"service_type": "simple", "postinst_script_template": "openssl rand -hex 32 > {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/jwtsecret",
"service_additional_params_template": "", "service_type": "simple",
"protect_memory": true, "service_additional_params_template": "",
"mainnet": true, "protect_memory": true,
"server_config_file": "", "mainnet": true,
"client_config_file": "" "server_config_file": "",
}, "client_config_file": ""
"blockbook": { },
"package_name": "blockbook-optimism-archive", "blockbook": {
"system_user": "blockbook-optimism", "package_name": "blockbook-optimism-archive",
"internal_binding_template": ":{{.Ports.BlockbookInternal}}", "system_user": "blockbook-optimism",
"public_binding_template": ":{{.Ports.BlockbookPublic}}", "internal_binding_template": ":{{.Ports.BlockbookInternal}}",
"explorer_url": "", "public_binding_template": ":{{.Ports.BlockbookPublic}}",
"additional_params": "-workers=16", "explorer_url": "",
"block_chain": { "additional_params": "-workers=16",
"parse": true, "block_chain": {
"mempool_workers": 8, "parse": true,
"mempool_sub_workers": 2, "mempool_workers": 8,
"block_addresses_to_keep": 600, "mempool_sub_workers": 2,
"additional_params": { "block_addresses_to_keep": 600,
"address_aliases": true, "additional_params": {
"mempoolTxTimeoutHours": 48, "address_aliases": true,
"processInternalTransactions": true, "mempoolTxTimeoutHours": 48,
"queryBackendOnMempoolResync": false, "processInternalTransactions": true,
"fiat_rates": "coingecko", "queryBackendOnMempoolResync": false,
"fiat_rates_vs_currencies": "AED,ARS,AUD,BDT,BHD,BMD,BRL,CAD,CHF,CLP,CNY,CZK,DKK,EUR,GBP,HKD,HUF,IDR,ILS,INR,JPY,KRW,KWD,LKR,MMK,MXN,MYR,NGN,NOK,NZD,PHP,PKR,PLN,RUB,SAR,SEK,SGD,THB,TRY,TWD,UAH,USD,VEF,VND,ZAR,BTC,ETH", "fiat_rates": "coingecko",
"fiat_rates_params": "{\"url\": \"https://api.coingecko.com/api/v3\", \"coin\": \"ethereum\",\"platformIdentifier\": \"ethereum\",\"platformVsCurrency\": \"eth\",\"periodSeconds\": 900}", "fiat_rates_vs_currencies": "AED,ARS,AUD,BDT,BHD,BMD,BRL,CAD,CHF,CLP,CNY,CZK,DKK,EUR,GBP,HKD,HUF,IDR,ILS,INR,JPY,KRW,KWD,LKR,MMK,MXN,MYR,NGN,NOK,NZD,PHP,PKR,PLN,RUB,SAR,SEK,SGD,THB,TRY,TWD,UAH,USD,VEF,VND,ZAR,BTC,ETH",
"fourByteSignatures": "https://www.4byte.directory/api/v1/signatures/" "fiat_rates_params": "{\"url\": \"https://api.coingecko.com/api/v3\", \"coin\": \"ethereum\",\"platformIdentifier\": \"ethereum\",\"platformVsCurrency\": \"eth\",\"periodSeconds\": 900}",
} "fourByteSignatures": "https://www.4byte.directory/api/v1/signatures/"
}
}
},
"meta": {
"package_maintainer": "IT",
"package_maintainer_email": "it@satoshilabs.com"
} }
}, }
"meta": {
"package_maintainer": "IT",
"package_maintainer_email": "it@satoshilabs.com"
}
}

View File

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

View File

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

View File

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

View File

@ -1039,7 +1039,7 @@ var websocketTestsBitcoinType = []websocketTest{
req: websocketReq{ req: websocketReq{
Method: "getInfo", 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", name: "websocket getBlockHash",
@ -1681,7 +1681,7 @@ var websocketTestsBitcoinTypeExtendedIndex = []websocketTest{
req: websocketReq{ req: websocketReq{
Method: "getInfo", 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", name: "websocket getBlockHash",

View File

@ -277,8 +277,8 @@ var requestHandlers = map[string]func(*WebsocketServer, *websocketChannel, *WsRe
c.getAddressInfoDescriptorsMux.Unlock() c.getAddressInfoDescriptorsMux.Unlock()
if l > s.is.WsGetAccountInfoLimit { if l > s.is.WsGetAccountInfoLimit {
if s.closeChannel(c) { if s.closeChannel(c) {
glog.Info("Client ", c.id, " exceeded getAddressInfo limit, ", c.ip) glog.Info("Client ", c.id, " exceeded getAddressInfo limit, ", c.ip)
s.is.AddWsLimitExceedingIP(c.ip) s.is.AddWsLimitExceedingIP(c.ip)
} }
return return
} }
@ -580,6 +580,7 @@ func (s *WebsocketServer) getInfo() (*WsInfoRes, error) {
return &WsInfoRes{ return &WsInfoRes{
Name: s.is.Coin, Name: s.is.Coin,
Shortcut: s.is.CoinShortcut, Shortcut: s.is.CoinShortcut,
Network: s.is.GetNetwork(),
Decimals: s.chainParser.AmountDecimals(), Decimals: s.chainParser.AmountDecimals(),
BestHeight: int(height), BestHeight: int(height),
BestHash: hash, BestHash: hash,

View File

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