wrap try/finally around populateTransaction logic to ensure the lock is always released in the case of an error
This commit is contained in:
parent
2428b756d6
commit
16b28f4535
|
@ -103,33 +103,35 @@ method populateTransaction*(signer: Signer,
|
||||||
|
|
||||||
var populated = transaction
|
var populated = transaction
|
||||||
|
|
||||||
if transaction.sender.isNone:
|
try:
|
||||||
populated.sender = some(await signer.getAddress())
|
if transaction.sender.isNone:
|
||||||
if transaction.chainId.isNone:
|
populated.sender = some(await signer.getAddress())
|
||||||
populated.chainId = some(await signer.getChainId())
|
if transaction.chainId.isNone:
|
||||||
if transaction.gasPrice.isNone and (transaction.maxFee.isNone or transaction.maxPriorityFee.isNone):
|
populated.chainId = some(await signer.getChainId())
|
||||||
populated.gasPrice = some(await signer.getGasPrice())
|
if transaction.gasPrice.isNone and (transaction.maxFee.isNone or transaction.maxPriorityFee.isNone):
|
||||||
|
populated.gasPrice = some(await signer.getGasPrice())
|
||||||
|
|
||||||
if transaction.nonce.isNone and transaction.gasLimit.isNone:
|
if transaction.nonce.isNone and transaction.gasLimit.isNone:
|
||||||
# when both nonce and gasLimit are not populated, we must ensure getNonce is
|
# when both nonce and gasLimit are not populated, we must ensure getNonce is
|
||||||
# followed by an estimateGas so we can determine if there was an error. If
|
# followed by an estimateGas so we can determine if there was an error. If
|
||||||
# there is an error, the nonce must be deprecated to prevent nonce gaps and
|
# there is an error, the nonce must be deprecated to prevent nonce gaps and
|
||||||
# stuck transactions
|
# stuck transactions
|
||||||
try:
|
try:
|
||||||
populated.nonce = some(await signer.getNonce())
|
populated.nonce = some(await signer.getNonce())
|
||||||
populated.gasLimit = some(await signer.estimateGas(populated))
|
populated.gasLimit = some(await signer.estimateGas(populated))
|
||||||
except ProviderError, EstimateGasError:
|
except ProviderError, EstimateGasError:
|
||||||
let e = getCurrentException()
|
let e = getCurrentException()
|
||||||
signer.decreaseNonce()
|
signer.decreaseNonce()
|
||||||
raise e
|
raise e
|
||||||
finally:
|
|
||||||
signer.populateLock.release()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if transaction.nonce.isNone:
|
if transaction.nonce.isNone:
|
||||||
populated.nonce = some(await signer.getNonce())
|
populated.nonce = some(await signer.getNonce())
|
||||||
if transaction.gasLimit.isNone:
|
if transaction.gasLimit.isNone:
|
||||||
populated.gasLimit = some(await signer.estimateGas(populated))
|
populated.gasLimit = some(await signer.estimateGas(populated))
|
||||||
|
|
||||||
|
finally:
|
||||||
|
signer.populateLock.release()
|
||||||
|
|
||||||
return populated
|
return populated
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue