From 88e1be44b9c98f17e84c9337d21eb91939bb1e9e Mon Sep 17 00:00:00 2001 From: webwarrior Date: Mon, 19 Aug 2024 11:14:58 +0200 Subject: [PATCH] Backend: handle other Eth server null responses Raise WeirdNullResponseException on all possible null responses or responses that contain null value from Ethereum servers. --- src/GWallet.Backend/Ether/EtherServer.fs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/GWallet.Backend/Ether/EtherServer.fs b/src/GWallet.Backend/Ether/EtherServer.fs index acf2b915c..428217d9d 100644 --- a/src/GWallet.Backend/Ether/EtherServer.fs +++ b/src/GWallet.Backend/Ether/EtherServer.fs @@ -482,7 +482,10 @@ module Server = let! cancelToken = Async.CancellationToken let task = web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(address, null, cancelToken) - return! Async.AwaitTask task + let! txCount = Async.AwaitTask task + if isNull txCount then + raise <| AbnormalNullValueInJsonResponseException "Weird null response from tx count job" + return txCount } GetRandomizedFuncs currency web3Func return! faultTolerantEtherClient.Query @@ -655,7 +658,10 @@ module Server = let! cancelToken = Async.CancellationToken let task = contractHandler.EstimateGasAsync(transferFunctionMsg, cancelToken) - return! Async.AwaitTask task + let! fee = Async.AwaitTask task + if isNull fee then + raise <| AbnormalNullValueInJsonResponseException "Weird null response from transfer fee job" + return fee } GetRandomizedFuncs account.Currency web3Func return! faultTolerantEtherClient.Query @@ -678,6 +684,8 @@ module Server = let! cancelToken = Async.CancellationToken let task = web3.Eth.GasPrice.SendRequestAsync(null, cancelToken) let! hexBigInteger = Async.AwaitTask task + if isNull hexBigInteger then + raise <| AbnormalNullValueInJsonResponseException "Weird null response from gas price job" if hexBigInteger.Value = BigInteger 0 then return failwith "Some server returned zero for gas price, which is invalid" return hexBigInteger @@ -708,7 +716,12 @@ module Server = let! cancelToken = Async.CancellationToken let task = web3.Eth.Transactions.SendRawTransaction.SendRequestAsync(transaction, null, cancelToken) - return! Async.AwaitTask task + let! response = Async.AwaitTask task + if isNull response then + raise <| + AbnormalNullValueInJsonResponseException + "Weird null response from broadcast transaction job" + return response } GetRandomizedFuncs currency web3Func try @@ -739,6 +752,10 @@ module Server = let task = web3.TransactionManager.TransactionReceiptService.PollForReceiptAsync(txHash, cancelToken) let! transactionReceipt = Async.AwaitTask task + if isNull transactionReceipt || isNull transactionReceipt.GasUsed || isNull transactionReceipt.Status then + raise <| + AbnormalNullValueInJsonResponseException + (SPrintF1 "Weird null response when getting details from tx receipt (%A)" transactionReceipt) return { GasUsed = transactionReceipt.GasUsed.Value Status = transactionReceipt.Status.Value