Skip to content

Commit

Permalink
Sweeping util/*
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon committed Nov 26, 2017
1 parent fdc7834 commit 6a9b8c3
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 947 deletions.
21 changes: 0 additions & 21 deletions types/account.go

This file was deleted.

197 changes: 0 additions & 197 deletions types/coins.go

This file was deleted.

85 changes: 0 additions & 85 deletions types/coins_test.go

This file was deleted.

73 changes: 73 additions & 0 deletions types/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package types

import (
"context"
tm "github.com/tendermint/tendermint/types"
)

/*
NOTE: Golang's Context is embedded and relied on
for compatibility w/ tools like monkit.
(https://github.com/spacemonkeygo/monkit)
Usage:
defer mon.Task()(&ctx.Context)(&err)
*/
type SDKContext struct {
context.Context
// NOTE: adding fields here will break monkit compatibility
// use context.Context instead if possible.
}

func NewSDKContext(header tm.Header) SDKContext {
c := SDKContext{
Context: context.Background(),
}
c = c.setBlockHeader(header)
c = c.setBlockHeight(int64(header.Height))
c = c.setChainID(header.ChainID)
return c
}

func (c SDKContext) WithValueSDK(key interface{}, value interface{}) SDKContext {
return SDKContext{
Context: context.WithValue(c.Context, key, value),
}
}

func (c SDKContext) WithValue(key interface{}, value interface{}) Context {
return c
}

//----------------------------------------
// Our extensions

type contextKey int // local to the context module

const (
contextKeyBlockHeader contextKey = iota
contextKeyBlockHeight
contextKeyChainID
)

func (c SDKContext) BlockHeader() tm.Header {
return c.Value(contextKeyBlockHeader).(tm.Header)
}

// Unexposed to prevent overriding.
func (c SDKContext) setBlockHeader(header tm.Header) SDKContext {
return c.WithValueSDK(contextKeyBlockHeader, header)
}

// Unexposed to prevent overriding.
func (c SDKContext) setBlockHeight(height int64) SDKContext {
return c.WithValueSDK(contextKeyBlockHeight, header)
}

// Unexposed to prevent overriding.
func (c SDKContext) setChainID(chainID string) SDKContext {
return c.WithValueSDK(contextKeyChainID, header)
}
2 changes: 1 addition & 1 deletion types/msg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package types

import "github.com/tendermint/tmlibs/crypto"
import crypto "github.com/tendermint/go-crypto"

// The parsed tx bytes is called a Msg.
type Msg interface {
Expand Down
Loading

0 comments on commit 6a9b8c3

Please sign in to comment.