solution: access logging for SubscribeTxStatus method
This commit is contained in:
@@ -39,6 +39,7 @@ class AccessHandler(
|
||||
return when (val method = call.methodDescriptor.bareMethodName) {
|
||||
"SubscribeHead" -> processSubscribeHead(call, headers, next)
|
||||
"SubscribeBalance" -> processSubscribeBalance(call, headers, next, true)
|
||||
"SubscribeTxStatus" -> processSubscribeTxStatus(call, headers, next)
|
||||
"GetBalance" -> processSubscribeBalance(call, headers, next, false)
|
||||
"NativeCall" -> processNativeCall(call, headers, next)
|
||||
else -> {
|
||||
@@ -81,6 +82,22 @@ class AccessHandler(
|
||||
) as ServerCall.Listener<ReqT>
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun <ReqT : Any, RespT : Any> processSubscribeTxStatus(
|
||||
call: ServerCall<ReqT, RespT>,
|
||||
headers: Metadata,
|
||||
next: ServerCallHandler<ReqT, RespT>
|
||||
): ServerCall.Listener<ReqT> {
|
||||
val builder = EventsBuilder.TxStatus()
|
||||
.start(headers, call.attributes)
|
||||
val callWrapper: ServerCall<ReqT, RespT> = OnTxStatusResponse(
|
||||
call as ServerCall<BlockchainOuterClass.TxStatusRequest, BlockchainOuterClass.TxStatus>, builder, accessLogWriter) as ServerCall<ReqT, RespT>
|
||||
return OnSubscribeTxStatus(
|
||||
next.startCall(callWrapper, headers) as ServerCall.Listener<BlockchainOuterClass.TxStatusRequest>,
|
||||
builder
|
||||
) as ServerCall.Listener<ReqT>
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun <ReqT : Any, RespT : Any> processNativeCall(
|
||||
call: ServerCall<ReqT, RespT>,
|
||||
@@ -131,6 +148,21 @@ class AccessHandler(
|
||||
}
|
||||
}
|
||||
|
||||
class OnSubscribeTxStatus(
|
||||
val next: ServerCall.Listener<BlockchainOuterClass.TxStatusRequest>,
|
||||
val builder: EventsBuilder.TxStatus
|
||||
) : ForwardingServerCallListener<BlockchainOuterClass.TxStatusRequest>() {
|
||||
|
||||
override fun onMessage(message: BlockchainOuterClass.TxStatusRequest) {
|
||||
builder.withRequest(message)
|
||||
super.onMessage(message)
|
||||
}
|
||||
|
||||
override fun delegate(): ServerCall.Listener<BlockchainOuterClass.TxStatusRequest> {
|
||||
return next
|
||||
}
|
||||
}
|
||||
|
||||
class OnNativeCall(
|
||||
val next: ServerCall.Listener<BlockchainOuterClass.NativeCallRequest>,
|
||||
val builder: EventsBuilder.NativeCall,
|
||||
@@ -213,4 +245,17 @@ class AccessHandler(
|
||||
super.sendMessage(message)
|
||||
}
|
||||
}
|
||||
|
||||
class OnTxStatusResponse(
|
||||
next: ServerCall<BlockchainOuterClass.TxStatusRequest, BlockchainOuterClass.TxStatus>,
|
||||
val builder: EventsBuilder.TxStatus,
|
||||
val accessLogWriter: AccessLogWriter
|
||||
) : BaseCallResponse<BlockchainOuterClass.TxStatusRequest, BlockchainOuterClass.TxStatus>(next) {
|
||||
|
||||
override fun sendMessage(message: BlockchainOuterClass.TxStatus) {
|
||||
val event = builder.onReply(message)
|
||||
accessLogWriter.submit(event)
|
||||
super.sendMessage(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,24 @@ class Events {
|
||||
val index: Int
|
||||
) : ChainBase(blockchain, if (subscribe) "SubscribeBalance" else "GetBalance", id)
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
class TxStatus(
|
||||
blockchain: Chain, id: UUID,
|
||||
val request: StreamRequestDetails,
|
||||
val txStatusRequest: TxStatusRequest,
|
||||
val txStatus: TxStatusResponse,
|
||||
// index of the current response
|
||||
val index: Int
|
||||
) : ChainBase(blockchain, "SubscribeTxStatus", id)
|
||||
|
||||
data class TxStatusRequest(
|
||||
val txId: String
|
||||
)
|
||||
|
||||
data class TxStatusResponse(
|
||||
val confirmations: Int
|
||||
)
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
class NativeCall(
|
||||
blockchain: Chain, id: UUID,
|
||||
|
||||
@@ -160,6 +160,29 @@ class EventsBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
class TxStatus() : Base<TxStatus>() {
|
||||
private var index = 0
|
||||
private var txStatusRequest: Events.TxStatusRequest? = null
|
||||
|
||||
fun withRequest(req: BlockchainOuterClass.TxStatusRequest): TxStatus {
|
||||
this.txStatusRequest = Events.TxStatusRequest(req.txId)
|
||||
return withChain(req.chainValue)
|
||||
}
|
||||
|
||||
fun onReply(resp: BlockchainOuterClass.TxStatus): Events.TxStatus {
|
||||
return Events.TxStatus(
|
||||
chain, UUID.randomUUID(), requestDetails, txStatusRequest!!,
|
||||
Events.TxStatusResponse(resp.confirmations),
|
||||
index++
|
||||
)
|
||||
}
|
||||
|
||||
override fun getT(): TxStatus {
|
||||
return this
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class NativeCall : Base<NativeCall>() {
|
||||
val items = ArrayList<Events.NativeCallItemDetails>()
|
||||
val replies = HashMap<Int, Events.NativeCallReplyDetails>()
|
||||
|
||||
Reference in New Issue
Block a user