Add coin shortcut description
This commit is contained in:
parent
f6cbe5ffeb
commit
22b7289fa6
@ -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"`
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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"`
|
||||
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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -28,6 +28,7 @@ type InternalState struct {
|
||||
mux sync.Mutex
|
||||
|
||||
Coin string `json:"coin"`
|
||||
CoinShortcut string `json:"coinShortcut"`
|
||||
Host string `json:"host"`
|
||||
|
||||
DbState uint32 `json:"dbState"`
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Bcash",
|
||||
"coin_shortcut": "BCH",
|
||||
"rpcURL": "http://127.0.0.1:8031",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Bcash Testnet",
|
||||
"coin_shortcut": "TBCH",
|
||||
"rpcURL": "http://localhost:18031",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Bgold",
|
||||
"coin_shortcut": "BTG",
|
||||
"rpcURL": "http://127.0.0.1:8035",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Bitcoin",
|
||||
"coin_shortcut": "BTC",
|
||||
"rpcURL": "http://127.0.0.1:8030",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Testnet",
|
||||
"coin_shortcut": "TEST",
|
||||
"rpcURL": "http://localhost:18030",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Dash",
|
||||
"coin_shortcut": "DASH",
|
||||
"rpcURL": "http://127.0.0.1:8033",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Dash Testnet",
|
||||
"coin_shortcut": "tDASH",
|
||||
"rpcURL": "http://localhost:18033",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Dogecoin",
|
||||
"coin_shortcut": "DOGE",
|
||||
"rpcURL": "http://127.0.0.1:8038",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpcp",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Ethereum",
|
||||
"coin_shortcut": "ETH",
|
||||
"rpcURL": "ws://localhost:8036",
|
||||
"rpcTimeout": 25
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Ethereum Testnet Ropsten",
|
||||
"coin_shortcut": "tETH",
|
||||
"rpcURL": "ws://localhost:18036",
|
||||
"rpcTimeout": 25
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Litecoin",
|
||||
"coin_shortcut": "LTC",
|
||||
"rpcURL": "http://localhost:8034",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Litecoin Testnet",
|
||||
"coin_shortcut": "TLTC",
|
||||
"rpcURL": "http://localhost:18034",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Namecoin",
|
||||
"coin_shortcut": "NMC",
|
||||
"rpcURL": "http://127.0.0.1:8039",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Vertcoin",
|
||||
"coin_shortcut": "VTC",
|
||||
"rpcURL": "http://localhost:8040",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Vertcoin Testnet",
|
||||
"coin_shortcut": "tVTC",
|
||||
"rpcURL": "http://localhost:18040",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Zcash",
|
||||
"coin_shortcut": "ZEC",
|
||||
"rpcURL": "http://127.0.0.1:8032",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"coin_name": "Zcash Testnet",
|
||||
"coin_shortcut": "TAZ",
|
||||
"rpcURL": "http://127.0.0.1:18032",
|
||||
"rpcUser": "rpc",
|
||||
"rpcPass": "rpc",
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user