Browse Source

Support arbitrary params in CallRpcWithRetries

pull/56/head
Duke 12 months ago
parent
commit
957af58d8b
  1. 27
      common/common.go
  2. 16
      frontend/service.go

27
common/common.go

@ -159,7 +159,7 @@ type (
//TODO: this function is not currently used, but some of it's code
// needs to be implemented elsewhere
func GetSaplingInfo() (int, int, string, string, int, int, int, error) {
result, rpcErr := RawRequest("getblockchaininfo", []json.RawMessage{})
result, rpcErr := CallRpcWithRetries("getblockchaininfo", []json.RawMessage{})
var err error
var errCode int64
@ -199,8 +199,8 @@ func GetSaplingInfo() (int, int, string, string, int, int, int, error) {
}
func GetLightdInfo() (*walletrpc.LightdInfo, error) {
// result, rpcErr := RawRequest("getinfo", []json.RawMessage{})
result, rpcErr := CallRpcWithRetries("getinfo")
params := []json.RawMessage{}
result, rpcErr := CallRpcWithRetries("getinfo", params)
if rpcErr != nil {
return nil, rpcErr
}
@ -210,8 +210,8 @@ func GetLightdInfo() (*walletrpc.LightdInfo, error) {
return nil, rpcErr
}
// result, rpcErr = RawRequest("getblockchaininfo", []json.RawMessage{})
result, rpcErr = CallRpcWithRetries("getblockchaininfo")
params = []json.RawMessage{}
result, rpcErr = CallRpcWithRetries("getblockchaininfo", params)
if rpcErr != nil {
return nil, rpcErr
}
@ -275,11 +275,12 @@ func FirstRPC() {
}
}
func CallRpcWithRetries(method string) (json.RawMessage, error) {
func CallRpcWithRetries(method string, params []json.RawMessage) (json.RawMessage, error) {
retryCount := 0
maxRetries := 50
for {
result, err := RawRequest(method, []json.RawMessage{})
// params := []json.RawMessage{}
result, err := RawRequest(method, params)
if err == nil {
if retryCount > 0 {
Log.Warn(fmt.Sprintf("%s RPC successful"), method)
@ -317,8 +318,8 @@ func GetBlockChainInfo() (*HushdRpcReplyGetblockchaininfo, error) {
}
func GetCoinsupply() (string, string, int, int, int, int, error) {
//result1, rpcErr := RawRequest("coinsupply", []json.RawMessage{})
result1, rpcErr := CallRpcWithRetries("coinsupply")
params := []json.RawMessage{}
result1, rpcErr := CallRpcWithRetries("coinsupply", params)
var err error
var errCode int64
@ -372,7 +373,7 @@ func getBlockFromRPC(height int) (*walletrpc.CompactBlock, error) {
// by height in case a reorg occurs between the two getblock calls;
// using block hash ensures that we're fetching the same block.
params[1] = json.RawMessage("1")
result, rpcErr := RawRequest("getblock", params)
result, rpcErr := CallRpcWithRetries("getblock", params)
if rpcErr != nil {
// Check to see if we are requesting a height the hushd doesn't have yet
if (strings.Split(rpcErr.Error(), ":"))[0] == "-8" {
@ -391,7 +392,7 @@ func getBlockFromRPC(height int) (*walletrpc.CompactBlock, error) {
}
params[0] = blockHash
params[1] = json.RawMessage("0") // non-verbose (raw hex)
result, rpcErr = RawRequest("getblock", params)
result, rpcErr = CallRpcWithRetries("getblock", params)
// For some reason, the error responses are not JSON
if rpcErr != nil {
@ -464,8 +465,8 @@ func BlockIngestor(c *BlockCache, rep int) {
default:
}
// result, err := RawRequest("getbestblockhash", []json.RawMessage{})
result, err := CallRpcWithRetries("getbestblockhash")
params := []json.RawMessage{}
result, err := CallRpcWithRetries("getbestblockhash", params)
if err != nil {
Log.WithFields(logrus.Fields{
"error": err,

16
frontend/service.go

@ -95,7 +95,7 @@ func (s *lwdStreamer) GetTaddressTxids(addressBlockFilter *walletrpc.Transparent
return err
}
params[0] = param
result, rpcErr := common.RawRequest("getaddresstxids", params)
result, rpcErr := common.CallRpcWithRetries("getaddresstxids", params)
// For some reason, the error responses are not JSON
if rpcErr != nil {
@ -200,7 +200,7 @@ func (s *lwdStreamer) GetTransaction(ctx context.Context, txf *walletrpc.TxFilte
leHashStringJSON,
json.RawMessage("1"),
}
result, rpcErr := common.RawRequest("getrawtransaction", params)
result, rpcErr := common.CallRpcWithRetries("getrawtransaction", params)
// For some reason, the error responses are not JSON
if rpcErr != nil {
@ -279,7 +279,7 @@ func (s *lwdStreamer) SendTransaction(ctx context.Context, rawtx *walletrpc.RawT
return &walletrpc.SendResponse{}, err
}
params[0] = txJSON
result, rpcErr := common.RawRequest("sendrawtransaction", params)
result, rpcErr := common.CallRpcWithRetries("sendrawtransaction", params)
var errCode int64
var errMsg string
@ -325,7 +325,7 @@ func getTaddressBalanceHushdRpc(addressList []string) (*walletrpc.Balance, error
}
params[0] = param
result, rpcErr := common.RawRequest("getaddressbalance", params)
result, rpcErr := common.CallRpcWithRetries("getaddressbalance", params)
if rpcErr != nil {
return &walletrpc.Balance{}, rpcErr
}
@ -353,7 +353,7 @@ func getAddressUtxos(arg *walletrpc.GetAddressUtxosArg, f func(*walletrpc.GetAdd
return err
}
params[0] = param
result, rpcErr := common.RawRequest("getaddressutxos", params)
result, rpcErr := common.CallRpcWithRetries("getaddressutxos", params)
if rpcErr != nil {
return rpcErr
}
@ -431,7 +431,7 @@ func (s *lwdStreamer) GetMempoolStream(_empty *walletrpc.Empty, resp walletrpc.C
var mempoolMap *map[string]*walletrpc.CompactTx
var mempoolList []string
// Last time we pulled a copy of the mempool from zcashd.
// Last time we pulled a copy of the mempool from hushd
var lastMempool time.Time
func (s *lwdStreamer) GetMempoolTx(exclude *walletrpc.Exclude, resp walletrpc.CompactTxStreamer_GetMempoolTxServer) error {
@ -442,7 +442,7 @@ func (s *lwdStreamer) GetMempoolTx(exclude *walletrpc.Exclude, resp walletrpc.Co
lastMempool = time.Now()
// Refresh our copy of the mempool.
params := make([]json.RawMessage, 0)
result, rpcErr := common.RawRequest("getrawmempool", params)
result, rpcErr := common.CallRpcWithRetries("getrawmempool", params)
if rpcErr != nil {
return rpcErr
}
@ -467,7 +467,7 @@ func (s *lwdStreamer) GetMempoolTx(exclude *walletrpc.Exclude, resp walletrpc.Co
// The "0" is because we only need the raw hex, which is returned as
// just a hex string, and not even a json string (with quotes).
params := []json.RawMessage{txidJSON, json.RawMessage("0")}
result, rpcErr := common.RawRequest("getrawtransaction", params)
result, rpcErr := common.CallRpcWithRetries("getrawtransaction", params)
if rpcErr != nil {
// Not an error; mempool transactions can disappear
continue

Loading…
Cancel
Save