diff --git a/api/types.go b/api/types.go index b00915ad..8e8a1aca 100644 --- a/api/types.go +++ b/api/types.go @@ -46,4 +46,6 @@ type Tx struct { Size int `json:"size,omitempty"` ValueIn float64 `json:"valueIn"` Fees float64 `json:"fees"` + CoinShortcut string `json:"coinShortcut"` + WithSpends bool `json:"withSpends,omitempty"` } diff --git a/api/worker.go b/api/worker.go index 9a8c91a5..0f22255b 100644 --- a/api/worker.go +++ b/api/worker.go @@ -2,6 +2,7 @@ package api import ( "blockbook/bchain" + "blockbook/common" "blockbook/db" ) @@ -11,19 +12,22 @@ type Worker struct { txCache *db.TxCache chain bchain.BlockChain chainParser bchain.BlockChainParser + is *common.InternalState } // NewWorker creates new api worker -func NewWorker(db *db.RocksDB, chain bchain.BlockChain, txCache *db.TxCache) (*Worker, error) { +func NewWorker(db *db.RocksDB, chain bchain.BlockChain, txCache *db.TxCache, is *common.InternalState) (*Worker, error) { w := &Worker{ db: db, txCache: txCache, chain: chain, chainParser: chain.GetChainParser(), + is: is, } return w, nil } +// GetTransaction reads transaction data from txid func (w *Worker) GetTransaction(txid string, bestheight uint32, spendingTx bool) (*Tx, error) { bchainTx, height, err := w.txCache.GetTransaction(txid, bestheight) if err != nil { @@ -80,9 +84,11 @@ func (w *Worker) GetTransaction(txid string, bestheight uint32, spendingTx bool) Blockhash: blockhash, Blockheight: int(height), Blocktime: bchainTx.Blocktime, + CoinShortcut: w.is.CoinShortcut, Confirmations: bchainTx.Confirmations, Fees: fees, Locktime: bchainTx.LockTime, + WithSpends: spendingTx, Time: bchainTx.Time, Txid: txid, ValueIn: valIn, diff --git a/bchain/coins/blockchain.go b/bchain/coins/blockchain.go index 84e08655..b1611161 100644 --- a/bchain/coins/blockchain.go +++ b/bchain/coins/blockchain.go @@ -9,8 +9,8 @@ import ( "blockbook/bchain/coins/dogecoin" "blockbook/bchain/coins/eth" "blockbook/bchain/coins/litecoin" - "blockbook/bchain/coins/vertcoin" "blockbook/bchain/coins/namecoin" + "blockbook/bchain/coins/vertcoin" "blockbook/bchain/coins/zec" "blockbook/common" "context" @@ -47,20 +47,21 @@ func init() { blockChainFactories["Namecoin"] = namecoin.NewNamecoinRPC } -// GetCoinNameFromConfig gets coin name from config file -func GetCoinNameFromConfig(configfile string) (string, error) { +// GetCoinNameFromConfig gets coin name and coin shortcut from config file +func GetCoinNameFromConfig(configfile 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"` + CoinName string `json:"coin_name"` + CoinShortcut string `json:"coin_shortcut"` } 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, nil + return cn.CoinName, cn.CoinShortcut, nil } // NewBlockChain creates bchain.BlockChain of type defined by parameter coin diff --git a/blockbook.go b/blockbook.go index f10c1b2f..cea2c5b6 100644 --- a/blockbook.go +++ b/blockbook.go @@ -148,7 +148,7 @@ func main() { glog.Fatal("Missing blockchaincfg configuration parameter") } - coin, err := coins.GetCoinNameFromConfig(*blockchain) + coin, coinShortcut, err := coins.GetCoinNameFromConfig(*blockchain) if err != nil { glog.Fatal("config: ", err) } @@ -168,7 +168,7 @@ func main() { } defer index.Close() - internalState, err = newInternalState(coin, index) + internalState, err = newInternalState(coin, coinShortcut, index) if err != nil { glog.Error("internalState: ", err) return @@ -327,11 +327,12 @@ func main() { } } -func newInternalState(coin string, d *db.RocksDB) (*common.InternalState, error) { +func newInternalState(coin string, coinShortcut string, d *db.RocksDB) (*common.InternalState, error) { is, err := d.LoadInternalState(coin) if err != nil { return nil, err } + is.CoinShortcut = coinShortcut name, err := os.Hostname() if err != nil { glog.Error("get hostname ", err) diff --git a/common/internalstate.go b/common/internalstate.go index 15b8f26a..8e7b2b61 100644 --- a/common/internalstate.go +++ b/common/internalstate.go @@ -27,8 +27,9 @@ type InternalStateColumn struct { type InternalState struct { mux sync.Mutex - Coin string `json:"coin"` - Host string `json:"host"` + Coin string `json:"coin"` + CoinShortcut string `json:"coinShortcut"` + Host string `json:"host"` DbState uint32 `json:"dbState"` diff --git a/configs/bcash.json b/configs/bcash.json index 7782bb76..a18b5f94 100644 --- a/configs/bcash.json +++ b/configs/bcash.json @@ -1,5 +1,6 @@ { "coin_name": "Bcash", + "coin_shortcut": "BCH", "rpcURL": "http://127.0.0.1:8031", "rpcUser": "rpc", "rpcPass": "rpc", diff --git a/configs/bcash_testnet.json b/configs/bcash_testnet.json index ebe41a9d..e5cdbe47 100644 --- a/configs/bcash_testnet.json +++ b/configs/bcash_testnet.json @@ -1,5 +1,6 @@ { "coin_name": "Bcash Testnet", + "coin_shortcut": "TBCH", "rpcURL": "http://localhost:18031", "rpcUser": "rpc", "rpcPass": "rpc", diff --git a/configs/bgold.json b/configs/bgold.json index 8627e5ae..b72edb5d 100644 --- a/configs/bgold.json +++ b/configs/bgold.json @@ -1,5 +1,6 @@ { "coin_name": "Bgold", + "coin_shortcut": "BTG", "rpcURL": "http://127.0.0.1:8035", "rpcUser": "rpc", "rpcPass": "rpc", @@ -10,4 +11,4 @@ "mempoolWorkers": 8, "mempoolSubWorkers": 2, "blockAddressesToKeep": 300 -} +} \ No newline at end of file diff --git a/configs/bitcoin.json b/configs/bitcoin.json index 97534f9c..ffa15701 100644 --- a/configs/bitcoin.json +++ b/configs/bitcoin.json @@ -1,5 +1,6 @@ { "coin_name": "Bitcoin", + "coin_shortcut": "BTC", "rpcURL": "http://127.0.0.1:8030", "rpcUser": "rpc", "rpcPass": "rpc", diff --git a/configs/bitcoin_testnet.json b/configs/bitcoin_testnet.json index 0bb00bb4..3ca273a3 100644 --- a/configs/bitcoin_testnet.json +++ b/configs/bitcoin_testnet.json @@ -1,5 +1,6 @@ { "coin_name": "Testnet", + "coin_shortcut": "TEST", "rpcURL": "http://localhost:18030", "rpcUser": "rpc", "rpcPass": "rpc", diff --git a/configs/dash.json b/configs/dash.json index 8ecf4818..fd97c74b 100644 --- a/configs/dash.json +++ b/configs/dash.json @@ -1,5 +1,6 @@ { "coin_name": "Dash", + "coin_shortcut": "DASH", "rpcURL": "http://127.0.0.1:8033", "rpcUser": "rpc", "rpcPass": "rpc", diff --git a/configs/dash_testnet.json b/configs/dash_testnet.json index 7a613a4d..35555196 100644 --- a/configs/dash_testnet.json +++ b/configs/dash_testnet.json @@ -1,5 +1,6 @@ { "coin_name": "Dash Testnet", + "coin_shortcut": "tDASH", "rpcURL": "http://localhost:18033", "rpcUser": "rpc", "rpcPass": "rpc", @@ -10,4 +11,4 @@ "mempoolWorkers": 8, "mempoolSubWorkers": 2, "blockAddressesToKeep": 300 -} +} \ No newline at end of file diff --git a/configs/dogecoin.json b/configs/dogecoin.json index c16fdc3a..10c1b551 100644 --- a/configs/dogecoin.json +++ b/configs/dogecoin.json @@ -1,5 +1,6 @@ { "coin_name": "Dogecoin", + "coin_shortcut": "DOGE", "rpcURL": "http://127.0.0.1:8038", "rpcUser": "rpc", "rpcPass": "rpcp", @@ -9,4 +10,4 @@ "mempoolWorkers": 8, "mempoolSubWorkers": 2, "blockAddressesToKeep": 300 -} +} \ No newline at end of file diff --git a/configs/ethereum.json b/configs/ethereum.json index 1a3ec103..d9b692b7 100644 --- a/configs/ethereum.json +++ b/configs/ethereum.json @@ -1,5 +1,6 @@ { "coin_name": "Ethereum", + "coin_shortcut": "ETH", "rpcURL": "ws://localhost:8036", "rpcTimeout": 25 } diff --git a/configs/ethereum_testnet_ropsten.json b/configs/ethereum_testnet_ropsten.json index d89fc039..b7c9b41a 100644 --- a/configs/ethereum_testnet_ropsten.json +++ b/configs/ethereum_testnet_ropsten.json @@ -1,5 +1,6 @@ { "coin_name": "Ethereum Testnet Ropsten", + "coin_shortcut": "tETH", "rpcURL": "ws://localhost:18036", "rpcTimeout": 25 -} +} \ No newline at end of file diff --git a/configs/litecoin.json b/configs/litecoin.json index 2a351101..6899770b 100644 --- a/configs/litecoin.json +++ b/configs/litecoin.json @@ -1,5 +1,6 @@ { "coin_name": "Litecoin", + "coin_shortcut": "LTC", "rpcURL": "http://localhost:8034", "rpcUser": "rpc", "rpcPass": "rpc", @@ -9,4 +10,4 @@ "mempoolWorkers": 8, "mempoolSubWorkers": 2, "blockAddressesToKeep": 300 -} +} \ No newline at end of file diff --git a/configs/litecoin_testnet.json b/configs/litecoin_testnet.json index 67232ebb..99df3d18 100644 --- a/configs/litecoin_testnet.json +++ b/configs/litecoin_testnet.json @@ -1,5 +1,6 @@ { "coin_name": "Litecoin Testnet", + "coin_shortcut": "TLTC", "rpcURL": "http://localhost:18034", "rpcUser": "rpc", "rpcPass": "rpc", @@ -9,4 +10,4 @@ "mempoolWorkers": 8, "mempoolSubWorkers": 2, "blockAddressesToKeep": 300 -} +} \ No newline at end of file diff --git a/configs/namecoin.json b/configs/namecoin.json index 8fadb00d..b62a4489 100644 --- a/configs/namecoin.json +++ b/configs/namecoin.json @@ -1,5 +1,6 @@ { "coin_name": "Namecoin", + "coin_shortcut": "NMC", "rpcURL": "http://127.0.0.1:8039", "rpcUser": "rpc", "rpcPass": "rpc", @@ -9,4 +10,4 @@ "mempoolWorkers": 8, "mempoolSubWorkers": 2, "blockAddressesToKeep": 300 -} +} \ No newline at end of file diff --git a/configs/vertcoin.json b/configs/vertcoin.json index b1dec1d5..6ee09e63 100644 --- a/configs/vertcoin.json +++ b/configs/vertcoin.json @@ -1,5 +1,6 @@ { "coin_name": "Vertcoin", + "coin_shortcut": "VTC", "rpcURL": "http://localhost:8040", "rpcUser": "rpc", "rpcPass": "rpc", @@ -9,4 +10,4 @@ "mempoolWorkers": 8, "mempoolSubWorkers": 2, "blockAddressesToKeep": 300 -} +} \ No newline at end of file diff --git a/configs/vertcoin_testnet.json b/configs/vertcoin_testnet.json index 45bead82..7d88ace9 100644 --- a/configs/vertcoin_testnet.json +++ b/configs/vertcoin_testnet.json @@ -1,5 +1,6 @@ { "coin_name": "Vertcoin Testnet", + "coin_shortcut": "tVTC", "rpcURL": "http://localhost:18040", "rpcUser": "rpc", "rpcPass": "rpc", @@ -9,4 +10,4 @@ "mempoolWorkers": 8, "mempoolSubWorkers": 2, "blockAddressesToKeep": 300 -} +} \ No newline at end of file diff --git a/configs/zcash.json b/configs/zcash.json index e9f0126f..96850e65 100644 --- a/configs/zcash.json +++ b/configs/zcash.json @@ -1,5 +1,6 @@ { "coin_name": "Zcash", + "coin_shortcut": "ZEC", "rpcURL": "http://127.0.0.1:8032", "rpcUser": "rpc", "rpcPass": "rpc", diff --git a/configs/zcash_testnet.json b/configs/zcash_testnet.json index 6196bb76..436221fd 100644 --- a/configs/zcash_testnet.json +++ b/configs/zcash_testnet.json @@ -1,5 +1,6 @@ { "coin_name": "Zcash Testnet", + "coin_shortcut": "TAZ", "rpcURL": "http://127.0.0.1:18032", "rpcUser": "rpc", "rpcPass": "rpc", diff --git a/server/public.go b/server/public.go index 543e07ec..5de9c817 100644 --- a/server/public.go +++ b/server/public.go @@ -39,7 +39,7 @@ type PublicServer struct { // NewPublicServerS creates new public server http interface to blockbook and returns its handle func NewPublicServer(binding string, certFiles string, db *db.RocksDB, chain bchain.BlockChain, txCache *db.TxCache, explorerURL string, metrics *common.Metrics, is *common.InternalState) (*PublicServer, error) { - api, err := api.NewWorker(db, chain, txCache) + api, err := api.NewWorker(db, chain, txCache, is) if err != nil { return nil, err }