Skip to content

Commit

Permalink
Backend: handle other Eth server null responses
Browse files Browse the repository at this point in the history
Raise WeirdNullResponseException on all possible null responses
or responses that contain null value from Ethereum servers.
  • Loading branch information
webwarrior-ws committed Aug 19, 2024
1 parent 27bf893 commit 88e1be4
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/GWallet.Backend/Ether/EtherServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -655,7 +658,10 @@ module Server =
let! cancelToken = Async.CancellationToken
let task =
contractHandler.EstimateGasAsync<TransferFunction>(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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

1 comment on commit 88e1be4

@knocte
Copy link
Member

@knocte knocte commented on 88e1be4 Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webwarrior-ws the name is not WeirdNullResponseException anymore

Please sign in to comment.