2018-03-08 10:36:01 -07:00
|
|
|
package coins
|
|
|
|
|
|
|
|
import (
|
2018-05-30 06:37:30 -06:00
|
|
|
"context"
|
2018-03-15 05:34:29 -06:00
|
|
|
"encoding/json"
|
2018-03-08 10:36:01 -07:00
|
|
|
"fmt"
|
2018-03-15 05:34:29 -06:00
|
|
|
"io/ioutil"
|
2018-07-24 07:58:37 -06:00
|
|
|
"math/big"
|
2018-03-08 10:36:01 -07:00
|
|
|
"reflect"
|
2018-03-20 18:23:17 -06:00
|
|
|
"time"
|
2018-03-08 10:36:01 -07:00
|
|
|
|
|
|
|
"github.com/juju/errors"
|
2020-02-26 09:17:43 -07:00
|
|
|
"github.com/trezor/blockbook/bchain"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/bch"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/bellcoin"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/bitcore"
|
2020-03-20 18:17:42 -06:00
|
|
|
"github.com/trezor/blockbook/bchain/coins/bitzeny"
|
2020-02-26 09:17:43 -07:00
|
|
|
"github.com/trezor/blockbook/bchain/coins/btc"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/btg"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/cpuchain"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/dash"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/dcr"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/deeponion"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/digibyte"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/divi"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/dogecoin"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/eth"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/flo"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/fujicoin"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/gamecredits"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/grs"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/koto"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/liquid"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/litecoin"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/monacoin"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/monetaryunit"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/myriad"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/namecoin"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/nuls"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/omotenashicoin"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/pivx"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/polis"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/qtum"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/ravencoin"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/ritocoin"
|
2020-05-08 17:50:51 -06:00
|
|
|
"github.com/trezor/blockbook/bchain/coins/snowgem"
|
2020-12-28 17:39:37 -07:00
|
|
|
"github.com/trezor/blockbook/bchain/coins/trezarcoin"
|
2020-02-26 09:17:43 -07:00
|
|
|
"github.com/trezor/blockbook/bchain/coins/unobtanium"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/vertcoin"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/viacoin"
|
|
|
|
"github.com/trezor/blockbook/bchain/coins/vipstarcoin"
|
2020-12-28 15:38:56 -07:00
|
|
|
"github.com/trezor/blockbook/bchain/coins/firo"
|
2020-02-26 09:17:43 -07:00
|
|
|
"github.com/trezor/blockbook/bchain/coins/zec"
|
|
|
|
"github.com/trezor/blockbook/common"
|
2018-03-08 10:36:01 -07:00
|
|
|
)
|
|
|
|
|
2018-03-27 15:39:06 -06:00
|
|
|
type blockChainFactory func(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error)
|
2018-03-08 10:36:01 -07:00
|
|
|
|
2019-01-24 07:24:56 -07:00
|
|
|
// BlockChainFactories is a map of constructors of coin RPC interfaces
|
2018-09-11 08:36:32 -06:00
|
|
|
var BlockChainFactories = make(map[string]blockChainFactory)
|
2018-03-08 10:36:01 -07:00
|
|
|
|
|
|
|
func init() {
|
2018-09-11 08:36:32 -06:00
|
|
|
BlockChainFactories["Bitcoin"] = btc.NewBitcoinRPC
|
|
|
|
BlockChainFactories["Testnet"] = btc.NewBitcoinRPC
|
2020-12-28 16:47:50 -07:00
|
|
|
BlockChainFactories["Signet"] = btc.NewBitcoinRPC
|
2018-09-11 08:36:32 -06:00
|
|
|
BlockChainFactories["Zcash"] = zec.NewZCashRPC
|
|
|
|
BlockChainFactories["Zcash Testnet"] = zec.NewZCashRPC
|
|
|
|
BlockChainFactories["Ethereum"] = eth.NewEthereumRPC
|
2018-10-01 04:47:42 -06:00
|
|
|
BlockChainFactories["Ethereum Classic"] = eth.NewEthereumRPC
|
2018-09-11 08:36:32 -06:00
|
|
|
BlockChainFactories["Ethereum Testnet Ropsten"] = eth.NewEthereumRPC
|
|
|
|
BlockChainFactories["Bcash"] = bch.NewBCashRPC
|
|
|
|
BlockChainFactories["Bcash Testnet"] = bch.NewBCashRPC
|
|
|
|
BlockChainFactories["Bgold"] = btg.NewBGoldRPC
|
2020-12-29 15:19:53 -07:00
|
|
|
BlockChainFactories["Bgold Testnet"] = btg.NewBGoldRPC
|
2018-09-11 08:36:32 -06:00
|
|
|
BlockChainFactories["Dash"] = dash.NewDashRPC
|
|
|
|
BlockChainFactories["Dash Testnet"] = dash.NewDashRPC
|
2019-07-07 14:41:01 -06:00
|
|
|
BlockChainFactories["Decred"] = dcr.NewDecredRPC
|
|
|
|
BlockChainFactories["Decred Testnet"] = dcr.NewDecredRPC
|
2018-10-24 03:33:26 -06:00
|
|
|
BlockChainFactories["GameCredits"] = gamecredits.NewGameCreditsRPC
|
2019-01-23 14:08:28 -07:00
|
|
|
BlockChainFactories["Koto"] = koto.NewKotoRPC
|
|
|
|
BlockChainFactories["Koto Testnet"] = koto.NewKotoRPC
|
2018-09-11 08:36:32 -06:00
|
|
|
BlockChainFactories["Litecoin"] = litecoin.NewLitecoinRPC
|
|
|
|
BlockChainFactories["Litecoin Testnet"] = litecoin.NewLitecoinRPC
|
|
|
|
BlockChainFactories["Dogecoin"] = dogecoin.NewDogecoinRPC
|
|
|
|
BlockChainFactories["Vertcoin"] = vertcoin.NewVertcoinRPC
|
|
|
|
BlockChainFactories["Vertcoin Testnet"] = vertcoin.NewVertcoinRPC
|
|
|
|
BlockChainFactories["Namecoin"] = namecoin.NewNamecoinRPC
|
|
|
|
BlockChainFactories["Monacoin"] = monacoin.NewMonacoinRPC
|
|
|
|
BlockChainFactories["Monacoin Testnet"] = monacoin.NewMonacoinRPC
|
2019-04-30 08:03:36 -06:00
|
|
|
BlockChainFactories["MonetaryUnit"] = monetaryunit.NewMonetaryUnitRPC
|
2018-10-07 16:36:27 -06:00
|
|
|
BlockChainFactories["DigiByte"] = digibyte.NewDigiByteRPC
|
2020-05-19 15:58:46 -06:00
|
|
|
BlockChainFactories["DigiByte Testnet"] = digibyte.NewDigiByteRPC
|
2018-10-02 09:09:56 -06:00
|
|
|
BlockChainFactories["Myriad"] = myriad.NewMyriadRPC
|
2018-12-05 12:52:34 -07:00
|
|
|
BlockChainFactories["Liquid"] = liquid.NewLiquidRPC
|
2018-10-18 10:08:19 -06:00
|
|
|
BlockChainFactories["Groestlcoin"] = grs.NewGroestlcoinRPC
|
|
|
|
BlockChainFactories["Groestlcoin Testnet"] = grs.NewGroestlcoinRPC
|
2019-01-04 14:09:55 -07:00
|
|
|
BlockChainFactories["PIVX"] = pivx.NewPivXRPC
|
2019-01-29 02:15:03 -07:00
|
|
|
BlockChainFactories["PIVX Testnet"] = pivx.NewPivXRPC
|
2019-04-05 16:18:24 -06:00
|
|
|
BlockChainFactories["Polis"] = polis.NewPolisRPC
|
2020-12-28 15:38:56 -07:00
|
|
|
BlockChainFactories["Firo"] = firo.NewFiroRPC
|
2019-01-16 15:06:36 -07:00
|
|
|
BlockChainFactories["Fujicoin"] = fujicoin.NewFujicoinRPC
|
2019-02-04 16:15:33 -07:00
|
|
|
BlockChainFactories["Flo"] = flo.NewFloRPC
|
2019-03-06 09:32:17 -07:00
|
|
|
BlockChainFactories["Bellcoin"] = bellcoin.NewBellcoinRPC
|
2019-03-05 20:31:11 -07:00
|
|
|
BlockChainFactories["Qtum"] = qtum.NewQtumRPC
|
2019-04-14 11:19:36 -06:00
|
|
|
BlockChainFactories["Viacoin"] = viacoin.NewViacoinRPC
|
2019-03-05 20:31:11 -07:00
|
|
|
BlockChainFactories["Qtum Testnet"] = qtum.NewQtumRPC
|
2019-03-28 07:31:29 -06:00
|
|
|
BlockChainFactories["NULS"] = nuls.NewNulsRPC
|
2019-04-22 08:37:57 -06:00
|
|
|
BlockChainFactories["VIPSTARCOIN"] = vipstarcoin.NewVIPSTARCOINRPC
|
2019-05-06 01:52:18 -06:00
|
|
|
BlockChainFactories["ZelCash"] = zec.NewZCashRPC
|
2019-05-19 15:33:12 -06:00
|
|
|
BlockChainFactories["Ravencoin"] = ravencoin.NewRavencoinRPC
|
2019-05-23 19:30:32 -06:00
|
|
|
BlockChainFactories["Ritocoin"] = ritocoin.NewRitocoinRPC
|
2019-08-21 11:07:35 -06:00
|
|
|
BlockChainFactories["Divi"] = divi.NewDiviRPC
|
2019-09-16 14:32:08 -06:00
|
|
|
BlockChainFactories["CPUchain"] = cpuchain.NewCPUchainRPC
|
2019-09-15 14:53:51 -06:00
|
|
|
BlockChainFactories["Unobtanium"] = unobtanium.NewUnobtaniumRPC
|
2019-11-19 03:15:00 -07:00
|
|
|
BlockChainFactories["DeepOnion"] = deeponion.NewDeepOnionRPC
|
2020-04-11 08:34:37 -06:00
|
|
|
BlockChainFactories["SnowGem"] = snowgem.NewSnowGemRPC
|
2020-01-10 07:13:06 -07:00
|
|
|
BlockChainFactories["Bitcore"] = bitcore.NewBitcoreRPC
|
2020-01-29 10:50:53 -07:00
|
|
|
BlockChainFactories["Omotenashicoin"] = omotenashicoin.NewOmotenashiCoinRPC
|
|
|
|
BlockChainFactories["Omotenashicoin Testnet"] = omotenashicoin.NewOmotenashiCoinRPC
|
2020-03-20 17:39:24 -06:00
|
|
|
BlockChainFactories["BitZeny"] = bitzeny.NewBitZenyRPC
|
2020-12-28 17:39:37 -07:00
|
|
|
BlockChainFactories["Trezarcoin"] = trezarcoin.NewTrezarcoinRPC
|
2018-03-08 10:36:01 -07:00
|
|
|
}
|
|
|
|
|
2018-06-27 16:36:56 -06:00
|
|
|
// GetCoinNameFromConfig gets coin name and coin shortcut from config file
|
2018-10-09 16:23:31 -06:00
|
|
|
func GetCoinNameFromConfig(configfile string) (string, string, string, error) {
|
2018-06-05 08:14:46 -06:00
|
|
|
data, err := ioutil.ReadFile(configfile)
|
|
|
|
if err != nil {
|
2018-10-09 16:23:31 -06:00
|
|
|
return "", "", "", errors.Annotatef(err, "Error reading file %v", configfile)
|
2018-06-05 08:14:46 -06:00
|
|
|
}
|
|
|
|
var cn struct {
|
2018-06-27 16:36:56 -06:00
|
|
|
CoinName string `json:"coin_name"`
|
|
|
|
CoinShortcut string `json:"coin_shortcut"`
|
2018-10-09 16:23:31 -06:00
|
|
|
CoinLabel string `json:"coin_label"`
|
2018-06-05 08:14:46 -06:00
|
|
|
}
|
|
|
|
err = json.Unmarshal(data, &cn)
|
|
|
|
if err != nil {
|
2018-10-09 16:23:31 -06:00
|
|
|
return "", "", "", errors.Annotatef(err, "Error parsing file %v", configfile)
|
2018-06-05 08:14:46 -06:00
|
|
|
}
|
2018-10-09 16:23:31 -06:00
|
|
|
return cn.CoinName, cn.CoinShortcut, cn.CoinLabel, nil
|
2018-03-08 10:36:01 -07:00
|
|
|
}
|
|
|
|
|
2019-03-25 09:43:57 -06:00
|
|
|
// NewBlockChain creates bchain.BlockChain and bchain.Mempool for the coin passed by the parameter coin
|
|
|
|
func NewBlockChain(coin string, configfile string, pushHandler func(bchain.NotificationType), metrics *common.Metrics) (bchain.BlockChain, bchain.Mempool, error) {
|
2018-03-15 05:34:29 -06:00
|
|
|
data, err := ioutil.ReadFile(configfile)
|
|
|
|
if err != nil {
|
2019-03-25 09:43:57 -06:00
|
|
|
return nil, nil, errors.Annotatef(err, "Error reading file %v", configfile)
|
2018-03-15 05:34:29 -06:00
|
|
|
}
|
|
|
|
var config json.RawMessage
|
|
|
|
err = json.Unmarshal(data, &config)
|
|
|
|
if err != nil {
|
2019-03-25 09:43:57 -06:00
|
|
|
return nil, nil, errors.Annotatef(err, "Error parsing file %v", configfile)
|
2018-03-15 05:34:29 -06:00
|
|
|
}
|
2018-09-11 08:36:32 -06:00
|
|
|
bcf, ok := BlockChainFactories[coin]
|
2018-06-05 08:14:46 -06:00
|
|
|
if !ok {
|
2019-03-25 09:43:57 -06:00
|
|
|
return nil, nil, errors.New(fmt.Sprint("Unsupported coin '", coin, "'. Must be one of ", reflect.ValueOf(BlockChainFactories).MapKeys()))
|
2018-06-05 08:14:46 -06:00
|
|
|
}
|
2018-03-21 08:33:48 -06:00
|
|
|
bc, err := bcf(config, pushHandler)
|
2018-03-20 18:23:17 -06:00
|
|
|
if err != nil {
|
2019-03-25 09:43:57 -06:00
|
|
|
return nil, nil, err
|
2018-03-20 18:23:17 -06:00
|
|
|
}
|
2018-03-27 15:18:25 -06:00
|
|
|
err = bc.Initialize()
|
|
|
|
if err != nil {
|
2019-03-25 09:43:57 -06:00
|
|
|
return nil, nil, err
|
2018-03-27 15:18:25 -06:00
|
|
|
}
|
2019-04-03 14:08:32 -06:00
|
|
|
mempool, err := bc.CreateMempool(bc)
|
2019-03-25 09:43:57 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
return &blockChainWithMetrics{b: bc, m: metrics}, &mempoolWithMetrics{mempool: mempool, m: metrics}, nil
|
2018-03-20 18:23:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type blockChainWithMetrics struct {
|
|
|
|
b bchain.BlockChain
|
|
|
|
m *common.Metrics
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockChainWithMetrics) observeRPCLatency(method string, start time.Time, err error) {
|
2018-03-21 08:33:48 -06:00
|
|
|
var e string
|
|
|
|
if err != nil {
|
2019-06-04 05:09:15 -06:00
|
|
|
e = "failure"
|
2018-03-21 08:33:48 -06:00
|
|
|
}
|
|
|
|
c.m.RPCLatency.With(common.Labels{"method": method, "error": e}).Observe(float64(time.Since(start)) / 1e6) // in milliseconds
|
2018-03-20 18:23:17 -06:00
|
|
|
}
|
|
|
|
|
2018-03-21 08:33:48 -06:00
|
|
|
func (c *blockChainWithMetrics) Initialize() error {
|
|
|
|
return c.b.Initialize()
|
2018-03-21 07:50:38 -06:00
|
|
|
}
|
|
|
|
|
2019-04-03 14:08:32 -06:00
|
|
|
func (c *blockChainWithMetrics) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, error) {
|
|
|
|
return c.b.CreateMempool(chain)
|
2019-03-25 09:43:57 -06:00
|
|
|
}
|
|
|
|
|
2020-05-24 09:58:29 -06:00
|
|
|
func (c *blockChainWithMetrics) InitializeMempool(addrDescForOutpoint bchain.AddrDescForOutpointFunc, onNewTxAddr bchain.OnNewTxAddrFunc, onNewTx bchain.OnNewTxFunc) error {
|
|
|
|
return c.b.InitializeMempool(addrDescForOutpoint, onNewTxAddr, onNewTx)
|
2019-03-25 09:43:57 -06:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:37:30 -06:00
|
|
|
func (c *blockChainWithMetrics) Shutdown(ctx context.Context) error {
|
|
|
|
return c.b.Shutdown(ctx)
|
2018-03-20 18:23:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockChainWithMetrics) IsTestnet() bool {
|
|
|
|
return c.b.IsTestnet()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockChainWithMetrics) GetNetworkName() string {
|
|
|
|
return c.b.GetNetworkName()
|
|
|
|
}
|
|
|
|
|
2018-06-05 08:14:46 -06:00
|
|
|
func (c *blockChainWithMetrics) GetCoinName() string {
|
|
|
|
return c.b.GetCoinName()
|
|
|
|
}
|
|
|
|
|
2018-04-27 02:53:33 -06:00
|
|
|
func (c *blockChainWithMetrics) GetSubversion() string {
|
|
|
|
return c.b.GetSubversion()
|
|
|
|
}
|
|
|
|
|
2018-09-14 06:48:43 -06:00
|
|
|
func (c *blockChainWithMetrics) GetChainInfo() (v *bchain.ChainInfo, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetChainInfo", s, err) }(time.Now())
|
|
|
|
return c.b.GetChainInfo()
|
2018-05-17 04:30:45 -06:00
|
|
|
}
|
|
|
|
|
2018-03-20 18:23:17 -06:00
|
|
|
func (c *blockChainWithMetrics) GetBestBlockHash() (v string, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetBestBlockHash", s, err) }(time.Now())
|
|
|
|
return c.b.GetBestBlockHash()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockChainWithMetrics) GetBestBlockHeight() (v uint32, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetBestBlockHeight", s, err) }(time.Now())
|
|
|
|
return c.b.GetBestBlockHeight()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockChainWithMetrics) GetBlockHash(height uint32) (v string, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetBlockHash", s, err) }(time.Now())
|
|
|
|
return c.b.GetBlockHash(height)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockChainWithMetrics) GetBlockHeader(hash string) (v *bchain.BlockHeader, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetBlockHeader", s, err) }(time.Now())
|
|
|
|
return c.b.GetBlockHeader(hash)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockChainWithMetrics) GetBlock(hash string, height uint32) (v *bchain.Block, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetBlock", s, err) }(time.Now())
|
|
|
|
return c.b.GetBlock(hash, height)
|
|
|
|
}
|
|
|
|
|
2018-09-17 10:28:08 -06:00
|
|
|
func (c *blockChainWithMetrics) GetBlockInfo(hash string) (v *bchain.BlockInfo, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetBlockInfo", s, err) }(time.Now())
|
|
|
|
return c.b.GetBlockInfo(hash)
|
|
|
|
}
|
|
|
|
|
2019-03-25 09:43:57 -06:00
|
|
|
func (c *blockChainWithMetrics) GetMempoolTransactions() (v []string, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetMempoolTransactions", s, err) }(time.Now())
|
|
|
|
return c.b.GetMempoolTransactions()
|
2018-03-20 18:23:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockChainWithMetrics) GetTransaction(txid string) (v *bchain.Tx, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetTransaction", s, err) }(time.Now())
|
|
|
|
return c.b.GetTransaction(txid)
|
|
|
|
}
|
|
|
|
|
2018-11-13 02:31:27 -07:00
|
|
|
func (c *blockChainWithMetrics) GetTransactionSpecific(tx *bchain.Tx) (v json.RawMessage, err error) {
|
2018-10-16 04:25:31 -06:00
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetTransactionSpecific", s, err) }(time.Now())
|
2018-11-13 02:31:27 -07:00
|
|
|
return c.b.GetTransactionSpecific(tx)
|
2018-10-16 04:25:31 -06:00
|
|
|
}
|
|
|
|
|
2018-05-14 10:12:01 -06:00
|
|
|
func (c *blockChainWithMetrics) GetTransactionForMempool(txid string) (v *bchain.Tx, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetTransactionForMempool", s, err) }(time.Now())
|
|
|
|
return c.b.GetTransactionForMempool(txid)
|
|
|
|
}
|
|
|
|
|
2018-07-24 07:58:37 -06:00
|
|
|
func (c *blockChainWithMetrics) EstimateSmartFee(blocks int, conservative bool) (v big.Int, err error) {
|
2018-03-20 18:23:17 -06:00
|
|
|
defer func(s time.Time) { c.observeRPCLatency("EstimateSmartFee", s, err) }(time.Now())
|
|
|
|
return c.b.EstimateSmartFee(blocks, conservative)
|
|
|
|
}
|
|
|
|
|
2018-07-24 07:58:37 -06:00
|
|
|
func (c *blockChainWithMetrics) EstimateFee(blocks int) (v big.Int, err error) {
|
2018-03-27 02:30:30 -06:00
|
|
|
defer func(s time.Time) { c.observeRPCLatency("EstimateFee", s, err) }(time.Now())
|
|
|
|
return c.b.EstimateFee(blocks)
|
|
|
|
}
|
|
|
|
|
2018-03-20 18:23:17 -06:00
|
|
|
func (c *blockChainWithMetrics) SendRawTransaction(tx string) (v string, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("SendRawTransaction", s, err) }(time.Now())
|
|
|
|
return c.b.SendRawTransaction(tx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockChainWithMetrics) GetMempoolEntry(txid string) (v *bchain.MempoolEntry, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetMempoolEntry", s, err) }(time.Now())
|
|
|
|
return c.b.GetMempoolEntry(txid)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockChainWithMetrics) GetChainParser() bchain.BlockChainParser {
|
|
|
|
return c.b.GetChainParser()
|
2018-03-08 10:36:01 -07:00
|
|
|
}
|
2018-11-28 06:27:02 -07:00
|
|
|
|
|
|
|
func (c *blockChainWithMetrics) EthereumTypeGetBalance(addrDesc bchain.AddressDescriptor) (v *big.Int, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("EthereumTypeGetBalance", s, err) }(time.Now())
|
|
|
|
return c.b.EthereumTypeGetBalance(addrDesc)
|
|
|
|
}
|
|
|
|
|
2018-12-06 05:14:46 -07:00
|
|
|
func (c *blockChainWithMetrics) EthereumTypeGetNonce(addrDesc bchain.AddressDescriptor) (v uint64, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("EthereumTypeGetNonce", s, err) }(time.Now())
|
|
|
|
return c.b.EthereumTypeGetNonce(addrDesc)
|
|
|
|
}
|
|
|
|
|
2018-12-18 01:52:46 -07:00
|
|
|
func (c *blockChainWithMetrics) EthereumTypeEstimateGas(params map[string]interface{}) (v uint64, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("EthereumTypeEstimateGas", s, err) }(time.Now())
|
|
|
|
return c.b.EthereumTypeEstimateGas(params)
|
|
|
|
}
|
|
|
|
|
2018-11-28 06:27:02 -07:00
|
|
|
func (c *blockChainWithMetrics) EthereumTypeGetErc20ContractInfo(contractDesc bchain.AddressDescriptor) (v *bchain.Erc20Contract, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("EthereumTypeGetErc20ContractInfo", s, err) }(time.Now())
|
|
|
|
return c.b.EthereumTypeGetErc20ContractInfo(contractDesc)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockChainWithMetrics) EthereumTypeGetErc20ContractBalance(addrDesc, contractDesc bchain.AddressDescriptor) (v *big.Int, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("EthereumTypeGetErc20ContractInfo", s, err) }(time.Now())
|
|
|
|
return c.b.EthereumTypeGetErc20ContractBalance(addrDesc, contractDesc)
|
|
|
|
}
|
2019-03-25 09:43:57 -06:00
|
|
|
|
|
|
|
type mempoolWithMetrics struct {
|
|
|
|
mempool bchain.Mempool
|
|
|
|
m *common.Metrics
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *mempoolWithMetrics) observeRPCLatency(method string, start time.Time, err error) {
|
|
|
|
var e string
|
|
|
|
if err != nil {
|
2019-06-04 05:09:15 -06:00
|
|
|
e = "failure"
|
2019-03-25 09:43:57 -06:00
|
|
|
}
|
|
|
|
c.m.RPCLatency.With(common.Labels{"method": method, "error": e}).Observe(float64(time.Since(start)) / 1e6) // in milliseconds
|
|
|
|
}
|
|
|
|
|
2019-04-01 09:00:34 -06:00
|
|
|
func (c *mempoolWithMetrics) Resync() (count int, err error) {
|
2019-03-25 09:43:57 -06:00
|
|
|
defer func(s time.Time) { c.observeRPCLatency("ResyncMempool", s, err) }(time.Now())
|
2019-04-01 09:00:34 -06:00
|
|
|
count, err = c.mempool.Resync()
|
2019-03-25 09:43:57 -06:00
|
|
|
if err == nil {
|
|
|
|
c.m.MempoolSize.Set(float64(count))
|
|
|
|
}
|
|
|
|
return count, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *mempoolWithMetrics) GetTransactions(address string) (v []bchain.Outpoint, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetMempoolTransactions", s, err) }(time.Now())
|
|
|
|
return c.mempool.GetTransactions(address)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *mempoolWithMetrics) GetAddrDescTransactions(addrDesc bchain.AddressDescriptor) (v []bchain.Outpoint, err error) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetMempoolTransactionsForAddrDesc", s, err) }(time.Now())
|
|
|
|
return c.mempool.GetAddrDescTransactions(addrDesc)
|
|
|
|
}
|
2019-04-02 03:39:38 -06:00
|
|
|
|
|
|
|
func (c *mempoolWithMetrics) GetAllEntries() (v bchain.MempoolTxidEntries) {
|
|
|
|
defer func(s time.Time) { c.observeRPCLatency("GetAllEntries", s, nil) }(time.Now())
|
|
|
|
return c.mempool.GetAllEntries()
|
|
|
|
}
|
2019-04-03 06:08:36 -06:00
|
|
|
|
|
|
|
func (c *mempoolWithMetrics) GetTransactionTime(txid string) uint32 {
|
|
|
|
return c.mempool.GetTransactionTime(txid)
|
|
|
|
}
|