Skip to content

Instantly share code, notes, and snippets.

@killerstorm
Last active June 18, 2022 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killerstorm/a8532d27cca23cf8c5e3ef8ccb60d402 to your computer and use it in GitHub Desktop.
Save killerstorm/a8532d27cca23cf8c5e3ef8ccb60d402 to your computer and use it in GitHub Desktop.
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