This commit is contained in:
Jae Kwon
2017-11-26 20:29:17 -08:00
parent 458fba22d3
commit 6e8e4331ea
4 changed files with 121 additions and 4 deletions
+8
View File
@@ -57,6 +57,14 @@ func (c SDKContext) BlockHeader() tm.Header {
return c.Value(contextKeyBlockHeader).(tm.Header)
}
func (c SDKContext) BlockHeight() int64 {
return c.Value(contextKeyBlockHeight).(int64)
}
func (c SDKContext) ChainID() string {
return c.Value(contextKeyChainID).(string)
}
// Unexposed to prevent overriding.
func (c SDKContext) setBlockHeader(header tm.Header) SDKContext {
return c.WithValueSDK(contextKeyBlockHeader, header)
+4 -4
View File
@@ -25,18 +25,18 @@ func Decorate(dec Decorator, next Handler) Handler {
/*
Helper to construct a decorated Handler from a stack of Decorators
(first-decorator-first-call as in Python @decorators) , w/ Handler provided
last for syntactic sugar of Stack().WithHandler()
last for syntactic sugar of ChainDecorators().WithHandler()
Usage:
handler := sdk.Stack(
handler := sdk.ChainDecorators(
decorator1,
decorator2,
...,
).WithHandler(myHandler)
*/
func Stack(decorators ...Decorator) stack {
func ChainDecorators(decorators ...Decorator) stack {
return stack{
decs: decorators,
}
@@ -49,7 +49,7 @@ type stack struct {
// WithHandler sets the final handler for the stack and
// returns the decoratored Handler.
func (s *Stack) WithHandler(handler Handler) Handler {
func (s stack) WithHandler(handler Handler) Handler {
if handler == nil {
panic("WithHandler() requires a non-nil Handler")
}