check all json.Unmarshal() error returns
This commit is contained in:
parent
c7c5da1fda
commit
22dda4a28d
|
@ -88,8 +88,11 @@ func (s *lwdStreamer) GetTaddressTxids(addressBlockFilter *walletrpc.Transparent
|
||||||
Start: addressBlockFilter.Range.Start.Height,
|
Start: addressBlockFilter.Range.Start.Height,
|
||||||
End: addressBlockFilter.Range.End.Height,
|
End: addressBlockFilter.Range.End.Height,
|
||||||
}
|
}
|
||||||
params[0], _ = json.Marshal(request)
|
param, err := json.Marshal(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
params[0] = param
|
||||||
result, rpcErr := common.RawRequest("getaddresstxids", params)
|
result, rpcErr := common.RawRequest("getaddresstxids", params)
|
||||||
|
|
||||||
// For some reason, the error responses are not JSON
|
// For some reason, the error responses are not JSON
|
||||||
|
@ -98,7 +101,7 @@ func (s *lwdStreamer) GetTaddressTxids(addressBlockFilter *walletrpc.Transparent
|
||||||
}
|
}
|
||||||
|
|
||||||
var txids []string
|
var txids []string
|
||||||
err := json.Unmarshal(result, &txids)
|
err = json.Unmarshal(result, &txids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -284,11 +287,13 @@ func (s *lwdStreamer) SendTransaction(ctx context.Context, rawtx *walletrpc.RawT
|
||||||
|
|
||||||
// Construct raw JSON-RPC params
|
// Construct raw JSON-RPC params
|
||||||
params := make([]json.RawMessage, 1)
|
params := make([]json.RawMessage, 1)
|
||||||
txJSON, _ := json.Marshal(hex.EncodeToString(rawtx.Data))
|
txJSON, err := json.Marshal(hex.EncodeToString(rawtx.Data))
|
||||||
|
if err != nil {
|
||||||
|
return &walletrpc.SendResponse{}, err
|
||||||
|
}
|
||||||
params[0] = txJSON
|
params[0] = txJSON
|
||||||
result, rpcErr := common.RawRequest("sendrawtransaction", params)
|
result, rpcErr := common.RawRequest("sendrawtransaction", params)
|
||||||
|
|
||||||
var err error
|
|
||||||
var errCode int64
|
var errCode int64
|
||||||
var errMsg string
|
var errMsg string
|
||||||
|
|
||||||
|
@ -319,14 +324,18 @@ func getTaddressBalanceZcashdRpc(addressList []string) (*walletrpc.Balance, erro
|
||||||
addrList := &common.ZcashdRpcRequestGetaddressbalance{
|
addrList := &common.ZcashdRpcRequestGetaddressbalance{
|
||||||
Addresses: addressList,
|
Addresses: addressList,
|
||||||
}
|
}
|
||||||
params[0], _ = json.Marshal(addrList)
|
param, err := json.Marshal(addrList)
|
||||||
|
if err != nil {
|
||||||
|
return &walletrpc.Balance{}, err
|
||||||
|
}
|
||||||
|
params[0] = param
|
||||||
|
|
||||||
result, rpcErr := common.RawRequest("getaddressbalance", params)
|
result, rpcErr := common.RawRequest("getaddressbalance", params)
|
||||||
if rpcErr != nil {
|
if rpcErr != nil {
|
||||||
return &walletrpc.Balance{}, rpcErr
|
return &walletrpc.Balance{}, rpcErr
|
||||||
}
|
}
|
||||||
var balanceReply common.ZcashdRpcReplyGetaddressbalance
|
var balanceReply common.ZcashdRpcReplyGetaddressbalance
|
||||||
err := json.Unmarshal(result, &balanceReply)
|
err = json.Unmarshal(result, &balanceReply)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &walletrpc.Balance{}, err
|
return &walletrpc.Balance{}, err
|
||||||
}
|
}
|
||||||
|
@ -389,7 +398,10 @@ func (s *lwdStreamer) GetMempoolTx(exclude *walletrpc.Exclude, resp walletrpc.Co
|
||||||
newmempoolMap[txidstr] = ctx
|
newmempoolMap[txidstr] = ctx
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
txidJSON, _ := json.Marshal(txidstr)
|
txidJSON, err := json.Marshal(txidstr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
// The "0" is because we only need the raw hex, which is returned as
|
// 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).
|
// just a hex string, and not even a json string (with quotes).
|
||||||
params := []json.RawMessage{txidJSON, json.RawMessage("0")}
|
params := []json.RawMessage{txidJSON, json.RawMessage("0")}
|
||||||
|
@ -400,7 +412,7 @@ func (s *lwdStreamer) GetMempoolTx(exclude *walletrpc.Exclude, resp walletrpc.Co
|
||||||
}
|
}
|
||||||
// strip the quotes
|
// strip the quotes
|
||||||
var txStr string
|
var txStr string
|
||||||
err := json.Unmarshal(result, &txStr)
|
err = json.Unmarshal(result, &txStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -489,13 +501,17 @@ func getAddressUtxos(arg *walletrpc.GetAddressUtxosArg, f func(*walletrpc.GetAdd
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
params := make([]json.RawMessage, 1)
|
params := make([]json.RawMessage, 1)
|
||||||
params[0], _ = json.Marshal(arg.Address)
|
param, err := json.Marshal(arg.Address)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
params[0] = param
|
||||||
result, rpcErr := common.RawRequest("getaddressutxos", params)
|
result, rpcErr := common.RawRequest("getaddressutxos", params)
|
||||||
if rpcErr != nil {
|
if rpcErr != nil {
|
||||||
return rpcErr
|
return rpcErr
|
||||||
}
|
}
|
||||||
var utxosReply common.ZcashdRpcReplyGetaddressutxos
|
var utxosReply common.ZcashdRpcReplyGetaddressutxos
|
||||||
err := json.Unmarshal(result, &utxosReply)
|
err = json.Unmarshal(result, &utxosReply)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue