Skip to content

Commit

Permalink
Correlate x-request-id to correlate route requests from Squid transac…
Browse files Browse the repository at this point in the history
…tions (#23)
  • Loading branch information
ruixhuang authored Mar 14, 2024
1 parent a6adc3b commit 948d1dd
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion v4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ ext {
compileSdkVersion = 34

// App dependencies
abacusVersion = '1.4.14'
abacusVersion = '1.6.1'
carteraVersion = '0.1.12'
kollectionsVersion = '2.0.16'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class DydxTransferStatusViewModel @Inject constructor(
fromChainId = transfer.fromChainId,
toChainId = transfer.toChainId,
isCctp = transfer.isCctp ?: false,
requestId = transfer.requestId,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DydxTransferInstanceStore(
usdcSize = parser.asDouble(transferInput.size?.usdcSize),
size = parser.asDouble(transferInput.size?.size),
isCctp = transferInput.isCctp,
requestId = transferInput.requestPayload?.requestId,
)
abacusStateManager.addTransferInstance(transfer)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ interface AbacusStateManagerProtocol {

fun addTransferInstance(transfer: DydxTransferInstance)
fun removeTransferInstance(transfer: DydxTransferInstance)
fun transferStatus(hash: String, fromChainId: String?, toChainId: String?, isCctp: Boolean)
fun transferStatus(hash: String, fromChainId: String?, toChainId: String?, isCctp: Boolean, requestId: String?)

fun screen(address: String, callback: ((Restriction) -> Unit))
fun commitCCTPWithdraw(callback: (Boolean, ParsingError?, Any?) -> Unit)
Expand Down Expand Up @@ -347,8 +347,8 @@ class AbacusStateManager @Inject constructor(
transferStateManager.remove(transfer)
}

override fun transferStatus(hash: String, fromChainId: String?, toChainId: String?, isCctp: Boolean) {
asyncStateManager.transferStatus(hash, fromChainId, toChainId, isCctp)
override fun transferStatus(hash: String, fromChainId: String?, toChainId: String?, isCctp: Boolean, requestId: String?) {
asyncStateManager.transferStatus(hash, fromChainId, toChainId, isCctp, requestId)
}

override fun screen(address: String, callback: ((Restriction) -> Unit)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ data class DydxTransferInstance(
val usdcSize: Double? = null,
val size: Double? = null,
val isCctp: Boolean? = null,
val requestId: String? = null,
) {
enum class TransferType {
DEPOSIT, WITHDRAWAL, TRANSFER_OUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package exchange.dydx.dydxstatemanager.protocolImplementations

import android.os.AsyncTask
import android.util.Log
import exchange.dydx.abacus.protocols.RestCallback
import exchange.dydx.abacus.protocols.RestProtocol
import exchange.dydx.abacus.utils.IMap
import exchange.dydx.abacus.utils.toJson
import okhttp3.CacheControl
import okhttp3.Callback
import okhttp3.MediaType.Companion.toMediaTypeOrNull
Expand Down Expand Up @@ -31,15 +33,15 @@ class AbacusRestImp @Inject constructor() : RestProtocol {
override fun delete(
url: String,
headers: IMap<String, String>?,
callback: (response: String?, httpCode: Int) -> Unit,
callback: RestCallback,
) {
processRest(url, headers, null, "DELETE", callback)
}

override fun get(
url: String,
headers: IMap<String, String>?,
callback: (response: String?, httpCode: Int) -> Unit,
callback: RestCallback,
) {
processRest(url, headers, null, "GET", callback)
}
Expand All @@ -48,7 +50,7 @@ class AbacusRestImp @Inject constructor() : RestProtocol {
url: String,
headers: IMap<String, String>?,
body: String?,
callback: (response: String?, httpCode: Int) -> Unit,
callback: RestCallback,
) {
processRest(url, headers, body, "POST", callback)
}
Expand All @@ -57,7 +59,7 @@ class AbacusRestImp @Inject constructor() : RestProtocol {
url: String,
headers: IMap<String, String>?,
body: String?,
callback: (response: String?, httpCode: Int) -> Unit,
callback: RestCallback,
) {
processRest(url, headers, body, "PUT", callback)
}
Expand All @@ -67,7 +69,7 @@ class AbacusRestImp @Inject constructor() : RestProtocol {
headers: IMap<String, String>?,
body: String?,
verb: String,
callback: (String?, Int) -> Unit,
callback: RestCallback,
) {
var requestBuilder = Request.Builder()

Expand Down Expand Up @@ -97,21 +99,22 @@ class AbacusRestImp @Inject constructor() : RestProtocol {
run(request, callback)
}

private fun run(request: Request, callback: (String?, Int) -> Unit) {
private fun run(request: Request, callback: RestCallback) {
beginBackgroundTask()
// Log.d(TAG, "AbacusRestImp Requesting ${request.url}")
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: okhttp3.Call, e: IOException) {
Log.e(TAG, "AbacusRestImp Request Failed ${request.url}, ${e.message}")
endBackgroundTask()
callback(null, 0)
callback(null, 0, null)
}

override fun onResponse(call: okhttp3.Call, response: Response) {
endBackgroundTask()
val code = response.code
val body = response.body?.string()
callback(body, code)
val headersJsonString = response.headers.toMap().toJson()
callback(body, code, headersJsonString)
}
})
}
Expand Down

0 comments on commit 948d1dd

Please sign in to comment.