abci.host.middleware
Utility functions for transforming ABCI handler functions. All middleware assumes asynchronous handler functions, excepting wrap-synchronous.
default-response
(default-response v & [{envelop? :envelop?, :or {envelop? true}}])
Convenience. Return the default response for the given request keyword, the :stickler/msg
value of the given map, or the :stickler/msg
key of its :stickler.one-of/value
, when enveloped.
Result will be stripped of its :abci/Response
envelope when not :envelop?
.
(default-response :abci/RequestDeliverTx)
(default-response {:stickler/msg :abci/RequestDeliverTx ...})
(default-response {:stickler/msg :abci/Request
:stickler.one-of/value :deliver-tx
:deliver-tx {:stickler/msg :abci/RequestDeliverTx ...}})
wrap-code-keywords
(wrap-code-keywords f)
Wrap f
such that the structure its deferred resolves to is walked, substituting keywords in the abci.code
namespace (:abci.code/ok
, :abci.code/error
) with the corresponding numbers (0, 1).
wrap-default
(wrap-default f & [opts])
If the deferred returned by f
resolves to ::default
, substitute it for a request-appropriate success response.
If opts
contains a :predicate
key, its value will be used over (partial
identical? ::default)
when determining whether to substitute a return value.
wrap-envelope
(wrap-envelope f)
Use both wrap-request-envelope and wrap-response-envelope with their default configuration.
wrap-prewalk-replace
(wrap-prewalk-replace f substitutions)
Wrap f
such that the structure its deferred resolves to is passed to walk/prewalk-replace
, with the given substitutions
map.
wrap-request-envelope
(wrap-request-envelope f & [{lift-key? :lift-key?, :or {lift-key? #{:abci.host/conn}}}])
Wrap f
such that it receives the :stickler.one-of/value
map for each incoming :abci/Request
, rather than the request map itself.
Pass-through values which don’t appear to be enveloped.
wrap-response-envelope
(wrap-response-envelope f & [{lift-key? :lift-key?, :or {lift-key? nil}}])
Wrap f
such that its eventual result is wrapped in an :abci/Response
.
Pass-through values which appear enveloped.
wrap-synchronous
(wrap-synchronous f & [opts])
Wrap f
such that calls to it are initiated from a worker thread, using future-with. The wrapped function will always return a deferred.
The default executor may be overridden by providing :executor
in opts
.