mirror of https://github.com/waku-org/nwaku.git
refactor: avoid result and unnecesary branching
This commit is contained in:
parent
5167eb61a6
commit
829c1f6d9b
|
@ -10,28 +10,26 @@ proc checkTxIdIsEligible(txHash: TxHash, ethClient: string): Future[bool] {.asyn
|
||||||
let txReceipt = await web3.getMinedTransactionReceipt(txHash)
|
let txReceipt = await web3.getMinedTransactionReceipt(txHash)
|
||||||
# check that it is not a contract creation tx
|
# check that it is not a contract creation tx
|
||||||
let toAddressOption = txReceipt.to
|
let toAddressOption = txReceipt.to
|
||||||
let isContractCreationTx = toAddressOption.isNone
|
if toAddressOption.isNone:
|
||||||
if isContractCreationTx:
|
# this is a contract creation tx
|
||||||
result = false
|
return false
|
||||||
else:
|
# check that it is a simple transfer (not a contract call)
|
||||||
# check that it is a simple transfer (not a contract call)
|
# a simple transfer uses 21000 gas
|
||||||
# a simple transfer uses 21000 gas
|
let gasUsed = txReceipt.gasUsed
|
||||||
let gasUsed = txReceipt.gasUsed
|
let isSimpleTransferTx = (gasUsed == Quantity(21000))
|
||||||
let isSimpleTransferTx = (gasUsed == Quantity(21000))
|
if not isSimpleTransferTx:
|
||||||
if not isSimpleTransferTx:
|
return false
|
||||||
result = false
|
# check that the amount is "as expected" (hard-coded for now)
|
||||||
else:
|
let txValue = tx.value
|
||||||
# check that the amount is "as expected" (hard-coded for now)
|
let hasExpectedValue = (txValue == 200500000000005063.u256)
|
||||||
let txValue = tx.value
|
# check that the to address is "as expected" (hard-coded for now)
|
||||||
let hasExpectedValue = (txValue == 200500000000005063.u256)
|
let toAddress = toAddressOption.get()
|
||||||
# check that the to address is "as expected" (hard-coded for now)
|
let hasExpectedToAddress = (toAddress == Address.fromHex("0x5e809a85aa182a9921edd10a4163745bb3e36284"))
|
||||||
let toAddress = toAddressOption.get()
|
defer:
|
||||||
let hasExpectedToAddress = (toAddress == Address.fromHex("0x5e809a85aa182a9921edd10a4163745bb3e36284"))
|
await web3.close()
|
||||||
result = true
|
return (hasExpectedValue and hasExpectedToAddress)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
result = false
|
return false
|
||||||
await web3.close()
|
|
||||||
result
|
|
||||||
|
|
||||||
proc txidEligiblityCriteriaMet*(
|
proc txidEligiblityCriteriaMet*(
|
||||||
eligibilityProof: EligibilityProof, ethClient: string
|
eligibilityProof: EligibilityProof, ethClient: string
|
||||||
|
|
Loading…
Reference in New Issue