Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start refactoring into storeutils #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ test: all
UEX_TEST_BIN_DIR=$(shell pwd)/build go test -v ./...

test-unit:
go test -v ./... -integration=false
go test -v ./...

format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./x/embedded/ui/a_ui-packr.go" | xargs gofmt -w -s
Expand Down
4 changes: 1 addition & 3 deletions embedded/balance/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (

"github.com/gorilla/mux"

"github.com/tendermint/dex-demo/types/store"

"github.com/cosmos/cosmos-sdk/client/keys"

"github.com/tendermint/dex-demo/embedded"
Expand Down Expand Up @@ -106,7 +104,7 @@ func faucetHandler(ctx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
}
}

func doTransfer(kb *auth.Keybase, ctx context.CLIContext, w http.ResponseWriter, cdc *codec.Codec, to sdk.AccAddress, amount sdk.Uint, assetID store.EntityID, passphrase string) {
func doTransfer(kb *auth.Keybase, ctx context.CLIContext, w http.ResponseWriter, cdc *codec.Codec, to sdk.AccAddress, amount sdk.Uint, assetID sdk.Uint, passphrase string) {
owner := kb.GetAddr()
ctx = ctx.WithFromAddress(owner)
msg := types.NewMsgTransfer(assetID, owner, to, amount)
Expand Down
16 changes: 7 additions & 9 deletions embedded/balance/types.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package balance

import (
"github.com/tendermint/dex-demo/embedded"
"github.com/tendermint/dex-demo/types/store"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/dex-demo/embedded"
)

type GetQueryRequest struct {
Address sdk.AccAddress
}

type GetQueryResponseBalance struct {
AssetID store.EntityID `json:"asset_id"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Liquid sdk.Uint `json:"liquid"`
AtRisk sdk.Uint `json:"at_risk"`
AssetID sdk.Uint `json:"asset_id"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Liquid sdk.Uint `json:"liquid"`
AtRisk sdk.Uint `json:"at_risk"`
}

type GetQueryResponse struct {
Expand All @@ -25,7 +23,7 @@ type GetQueryResponse struct {

type TransferBalanceRequest struct {
To sdk.AccAddress `json:"to"`
AssetID store.EntityID `json:"asset_id"`
AssetID sdk.Uint `json:"asset_id"`
Amount sdk.Uint `json:"amount"`
}

Expand Down
13 changes: 7 additions & 6 deletions embedded/batch/keeper.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package batch

import (
"github.com/tendermint/dex-demo/storeutil"
dbm "github.com/tendermint/tm-db"

"github.com/tendermint/dex-demo/embedded/store"
"github.com/tendermint/dex-demo/types"
"github.com/tendermint/dex-demo/types/errs"
"github.com/tendermint/dex-demo/types/store"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -29,7 +30,7 @@ func NewKeeper(db dbm.DB, cdc *codec.Codec) Keeper {
}
}

func (k Keeper) LatestByMarket(marketID store.EntityID) (Batch, sdk.Error) {
func (k Keeper) LatestByMarket(marketID sdk.Uint) (Batch, sdk.Error) {
var res Batch
var found bool
k.as.ReversePrefixIterator(batchIterKey(marketID), func(_ []byte, v []byte) bool {
Expand Down Expand Up @@ -66,10 +67,10 @@ func (k Keeper) OnEvent(event interface{}) error {
return nil
}

func batchKey(marketID store.EntityID, blkNum int64) []byte {
return store.PrefixKeyBytes(batchIterKey(marketID), store.Int64Subkey(blkNum))
func batchKey(marketID sdk.Uint, blkNum int64) []byte {
return storeutil.PrefixKeyBytes(batchIterKey(marketID), storeutil.Int64Subkey(blkNum))
}

func batchIterKey(marketID store.EntityID) []byte {
return store.PrefixKeyString(batchKeyPrefix, marketID.Bytes())
func batchIterKey(marketID sdk.Uint) []byte {
return storeutil.PrefixKeyString(batchKeyPrefix, storeutil.SDKUintSubkey(marketID))
}
6 changes: 2 additions & 4 deletions embedded/batch/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package batch
import (
abci "github.com/tendermint/tendermint/abci/types"

"github.com/tendermint/dex-demo/types/errs"
"github.com/tendermint/dex-demo/types/store"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/dex-demo/types/errs"
)

const (
Expand All @@ -30,7 +28,7 @@ func queryLatest(path []string, keeper Keeper) ([]byte, sdk.Error) {
return nil, errs.ErrInvalidArgument("must specify a market ID")
}

marketID := store.NewEntityIDFromString(path[0])
marketID := sdk.NewUintFromString(path[0])
res, sdkErr := keeper.LatestByMarket(marketID)
if sdkErr != nil {
if sdkErr.Code() == errs.CodeNotFound {
Expand Down
6 changes: 2 additions & 4 deletions embedded/batch/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ package batch
import (
"time"

"github.com/tendermint/dex-demo/pkg/matcheng"
"github.com/tendermint/dex-demo/types/store"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/dex-demo/pkg/matcheng"
)

type Batch struct {
BlockNumber int64 `json:"block_number"`
BlockTime time.Time `json:"block_time"`
MarketID store.EntityID `json:"market_id"`
MarketID sdk.Uint `json:"market_id"`
ClearingPrice sdk.Uint `json:"clearing_price"`
Bids []matcheng.AggregatePrice `json:"bids"`
Asks []matcheng.AggregatePrice `json:"asks"`
Expand Down
8 changes: 3 additions & 5 deletions embedded/book/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package book
import (
abci "github.com/tendermint/tendermint/abci/types"

"github.com/tendermint/dex-demo/embedded/order"
"github.com/tendermint/dex-demo/types/errs"
"github.com/tendermint/dex-demo/types/store"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/dex-demo/embedded/order"
"github.com/tendermint/dex-demo/types/errs"
)

const (
Expand All @@ -31,7 +29,7 @@ func queryGet(path []string, keeper order.Keeper) ([]byte, sdk.Error) {
return nil, errs.ErrInvalidArgument("must specify a market ID")
}

mktId := store.NewEntityIDFromString(path[0])
mktId := sdk.NewUintFromString(path[0])
res := keeper.OpenOrdersByMarket(mktId)
b, err := codec.MarshalJSONIndent(codec.New(), res)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions embedded/book/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/rest"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/dex-demo/embedded/auth"
"github.com/tendermint/dex-demo/embedded/node"
"github.com/tendermint/dex-demo/embedded/order"
"github.com/tendermint/dex-demo/pkg/matcheng"
"github.com/tendermint/dex-demo/types/store"
)

func RegisterRoutes(ctx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
Expand Down Expand Up @@ -50,7 +50,7 @@ func bookHandler(ctx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
cdc.MustUnmarshalJSON(resJSON, &orders)

qRes := QueryResult{
MarketID: store.NewEntityIDFromString(mktId),
MarketID: sdk.NewUintFromString(mktId),
BlockNumber: block.Block.Height,
Bids: make([]QueryResultEntry, 0),
Asks: make([]QueryResultEntry, 0),
Expand Down
6 changes: 2 additions & 4 deletions embedded/book/types.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package book

import (
"github.com/tendermint/dex-demo/pkg/matcheng"
"github.com/tendermint/dex-demo/types/store"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/dex-demo/pkg/matcheng"
)

type Book struct {
Expand All @@ -18,7 +16,7 @@ type QueryResultEntry struct {
}

type QueryResult struct {
MarketID store.EntityID `json:"market_id"`
MarketID sdk.Uint `json:"market_id"`
BlockNumber int64 `json:"block_number"`
Bids []QueryResultEntry `json:"bids"`
Asks []QueryResultEntry `json:"asks"`
Expand Down
3 changes: 1 addition & 2 deletions embedded/exchange/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/tendermint/dex-demo/embedded"
"github.com/tendermint/dex-demo/embedded/auth"
"github.com/tendermint/dex-demo/types/store"
"github.com/tendermint/dex-demo/x/order/types"

"github.com/cosmos/cosmos-sdk/client/context"
Expand Down Expand Up @@ -73,7 +72,7 @@ func postOrderHandler(ctx context.CLIContext, cdc *codec.Codec) http.HandlerFunc
break
}
}
orderID := store.NewEntityIDFromString(orderIDStr)
orderID := sdk.NewUintFromString(orderIDStr)
res := OrderCreationResponse{
BlockInclusion: embedded.BlockInclusion{
BlockNumber: broadcastRes.Height,
Expand Down
10 changes: 4 additions & 6 deletions embedded/exchange/types.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package exchange

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/dex-demo/embedded"
"github.com/tendermint/dex-demo/pkg/matcheng"
"github.com/tendermint/dex-demo/types/store"

sdk "github.com/cosmos/cosmos-sdk/types"
)

type OrderCreationRequest struct {
MarketID store.EntityID `json:"market_id"`
MarketID sdk.Uint `json:"market_id"`
Direction matcheng.Direction `json:"direction"`
Price sdk.Uint `json:"price"`
Quantity sdk.Uint `json:"quantity"`
Expand All @@ -19,8 +17,8 @@ type OrderCreationRequest struct {

type OrderCreationResponse struct {
BlockInclusion embedded.BlockInclusion `json:"block_inclusion"`
ID store.EntityID `json:"id"`
MarketID store.EntityID `json:"market_id"`
ID sdk.Uint `json:"id"`
MarketID sdk.Uint `json:"market_id"`
Direction matcheng.Direction `json:"direction"`
Price sdk.Uint `json:"price"`
Quantity sdk.Uint `json:"quantity"`
Expand Down
10 changes: 6 additions & 4 deletions embedded/fill/keeper.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package fill

import (
"github.com/tendermint/dex-demo/storeutil"
dbm "github.com/tendermint/tm-db"

"github.com/tendermint/dex-demo/embedded/store"
"github.com/tendermint/dex-demo/types"
"github.com/tendermint/dex-demo/types/store"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

const (
Expand Down Expand Up @@ -60,9 +62,9 @@ func (k Keeper) OnEvent(event interface{}) error {
}

func fillIterKey(blockNum int64) []byte {
return store.PrefixKeyBytes(store.Int64Subkey(blockNum))
return storeutil.PrefixKeyBytes(storeutil.Int64Subkey(blockNum))
}

func fillKey(blockNum int64, orderId store.EntityID) []byte {
return store.PrefixKeyBytes(fillIterKey(blockNum), orderId.Bytes())
func fillKey(blockNum int64, orderId sdk.Uint) []byte {
return storeutil.PrefixKeyBytes(fillIterKey(blockNum), storeutil.SDKUintSubkey(orderId))
}
8 changes: 3 additions & 5 deletions embedded/fill/types.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package fill

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/dex-demo/embedded"
"github.com/tendermint/dex-demo/pkg/matcheng"
"github.com/tendermint/dex-demo/types/store"

sdk "github.com/cosmos/cosmos-sdk/types"
)

type Fill struct {
OrderID store.EntityID `json:"order_id"`
OrderID sdk.Uint `json:"order_id"`
Owner sdk.AccAddress `json:"owner"`
Pair string `json:"pair"`
Direction matcheng.Direction `json:"direction"`
Expand Down Expand Up @@ -38,7 +36,7 @@ type RESTFill struct {
QuantityFilled sdk.Uint `json:"quantity_filled"`
QuantityUnfilled sdk.Uint `json:"quantity_unfilled"`
Direction matcheng.Direction `json:"direction"`
OrderID store.EntityID `json:"order_id"`
OrderID sdk.Uint `json:"order_id"`
Pair string `json:"pair"`
Price sdk.Uint `json:"price"`
Owner sdk.AccAddress `json:"owner"`
Expand Down
Loading