Last active
June 18, 2022 13:26
-
-
Save killerstorm/a8532d27cca23cf8c5e3ef8ccb60d402 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun createSpecialOperations(position: SpecialTransactionPosition, bctx: BlockEContext): List<OpData> { | |
if (position == SpecialTransactionPosition.Begin) { | |
val retval = mutableListOf<OpData>() | |
val rqs = this.module.query(bctx, "get_auth_requests", | |
GtvDictionary.build(mapOf())) | |
for (r in rqs.asArray()) { | |
val rString = r.asString() | |
val res = pendingRequests[rString] | |
if (res != null) { | |
if (res.resolved) { | |
retval.add(OpData("__auth", | |
arrayOf( | |
r, | |
gtv(if (res.authorized) 1 else 0) | |
))) | |
} else { | |
// otherwise we are waiting till it resolves | |
} | |
} else { | |
val res = Response(false, false, null) | |
pendingRequests[rString] = res | |
res.task = task { | |
val externalResponse = callExternalService(rString) | |
res.resolved = true | |
res.authorized = externalResponse | |
} | |
} | |
} | |
return retval | |
} else return listOf() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment