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 13762be commit 06c557d
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 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 "Abnormal null response from tx count job"
return txCount
}
GetRandomizedFuncs currency web3Func
return! faultTolerantEtherClient.Query
Expand All @@ -498,7 +501,7 @@ module Server =
web3.Eth.Blocks.GetBlockNumber.SendRequestAsync (null, cancelToken)
|> Async.AwaitTask
if isNull latestBlock then
failwith "latestBlock somehow is null"
raise <| AbnormalNullValueInJsonResponseException "latestBlock somehow is null"

let blockToCheck = BigInteger.Subtract(latestBlock.Value,
NUMBER_OF_CONFIRMATIONS_TO_CONSIDER_BALANCE_CONFIRMED)
Expand Down Expand Up @@ -593,7 +596,7 @@ module Server =

let contractHandler = web3.Eth.GetContractHandler contractAddress
if isNull contractHandler then
failwith "contractHandler somehow is null"
raise <| AbnormalNullValueInJsonResponseException "contractHandler somehow is null"

let! cancelToken = Async.CancellationToken
cancelToken.ThrowIfCancellationRequested()
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 "Abnormal 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 "Abnormal 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
"Abnormal 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 "Abnormal null response when getting details from tx receipt (%A)" transactionReceipt)
return {
GasUsed = transactionReceipt.GasUsed.Value
Status = transactionReceipt.Status.Value
Expand Down

0 comments on commit 06c557d

Please sign in to comment.