Skip to content

Commit

Permalink
parse out of gas error
Browse files Browse the repository at this point in the history
  • Loading branch information
aforaleka committed Oct 18, 2024
1 parent cde9fd2 commit 314df05
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.13.2"
version = "1.13.3"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import exchange.dydx.abacus.responses.ParsingErrorType
class V4TransactionErrors {
companion object {
private const val QUERY_RESULT_ERROR_PREFIX = "Query failed"
private const val OUT_OF_GAS_ERROR_RAW_LOG_PREFIX = "out of gas"
private val FAILED_SUBACCOUNT_UPDATE_RESULT_PATTERN = Regex("""Subaccount with id \{[^}]+\} failed with UpdateResult:\s*([A-Za-z]+):""")

fun error(code: Int?, message: String?, codespace: String? = null): ParsingError? {
Expand Down Expand Up @@ -43,6 +44,17 @@ class V4TransactionErrors {
)
}
}

fun parseErrorFromRawLog(rawLog: String): ParsingError? {
return if (rawLog.startsWith(OUT_OF_GAS_ERROR_RAW_LOG_PREFIX)) {
return ParsingError(
ParsingErrorType.BackendError,
"Out of gas: inaccurate gas estimation for transaction",
)
} else {
null
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,15 @@ class NetworkHelper(
val result = parser.decodeJsonObject(response)
if (result != null) {
val error = parser.asMap(result["error"])
val rawLog = parser.asString(result["rawLog"])
if (error != null) {
val message = parser.asString(error["message"])
val code = parser.asInt(error["code"])
val codespace = parser.asString(error["codespace"])
return V4TransactionErrors.error(code, message, codespace)
} else if (rawLog != null) {
// certain tx results (e.g. out of gas) are not error but should still be treated as one
return V4TransactionErrors.parseErrorFromRawLog(rawLog)
} else {
null
}
Expand Down
2 changes: 1 addition & 1 deletion v4_abacus.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'v4_abacus'
spec.version = '1.13.2'
spec.version = '1.13.3'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit 314df05

Please sign in to comment.