Skip to content

Commit 3293c06

Browse files
committed
Start refactoring into storeutils
Note that the files in `storeutils` now return generic `error` objects rather than `sdk.Error`s. This is done in an effort to decouple them from the DEX codebase. To transform the error objects back into `sdk.Error`s that are meaningful to the DEX, I've created some wrapper functions in `types/errs/errs.go` that convert the `error` objects into the DEC-appropriate `sdk.Error`.
1 parent 209f9f9 commit 3293c06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+674
-911
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ test: all
105105
UEX_TEST_BIN_DIR=$(shell pwd)/build go test -v ./...
106106

107107
test-unit:
108-
go test -v ./... -integration=false
108+
go test -v ./...
109109

110110
format:
111111
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./x/embedded/ui/a_ui-packr.go" | xargs gofmt -w -s

embedded/balance/routes.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66

77
"github.com/gorilla/mux"
88

9-
"github.com/tendermint/dex-demo/types/store"
10-
119
"github.com/cosmos/cosmos-sdk/client/keys"
1210

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

109-
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) {
107+
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) {
110108
owner := kb.GetAddr()
111109
ctx = ctx.WithFromAddress(owner)
112110
msg := types.NewMsgTransfer(assetID, owner, to, amount)

embedded/balance/types.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
package balance
22

33
import (
4-
"github.com/tendermint/dex-demo/embedded"
5-
"github.com/tendermint/dex-demo/types/store"
6-
74
sdk "github.com/cosmos/cosmos-sdk/types"
5+
"github.com/tendermint/dex-demo/embedded"
86
)
97

108
type GetQueryRequest struct {
119
Address sdk.AccAddress
1210
}
1311

1412
type GetQueryResponseBalance struct {
15-
AssetID store.EntityID `json:"asset_id"`
16-
Name string `json:"name"`
17-
Symbol string `json:"symbol"`
18-
Liquid sdk.Uint `json:"liquid"`
19-
AtRisk sdk.Uint `json:"at_risk"`
13+
AssetID sdk.Uint `json:"asset_id"`
14+
Name string `json:"name"`
15+
Symbol string `json:"symbol"`
16+
Liquid sdk.Uint `json:"liquid"`
17+
AtRisk sdk.Uint `json:"at_risk"`
2018
}
2119

2220
type GetQueryResponse struct {
@@ -25,7 +23,7 @@ type GetQueryResponse struct {
2523

2624
type TransferBalanceRequest struct {
2725
To sdk.AccAddress `json:"to"`
28-
AssetID store.EntityID `json:"asset_id"`
26+
AssetID sdk.Uint `json:"asset_id"`
2927
Amount sdk.Uint `json:"amount"`
3028
}
3129

embedded/batch/keeper.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package batch
22

33
import (
4+
"github.com/tendermint/dex-demo/storeutil"
45
dbm "github.com/tendermint/tm-db"
56

7+
"github.com/tendermint/dex-demo/embedded/store"
68
"github.com/tendermint/dex-demo/types"
79
"github.com/tendermint/dex-demo/types/errs"
8-
"github.com/tendermint/dex-demo/types/store"
910

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

32-
func (k Keeper) LatestByMarket(marketID store.EntityID) (Batch, sdk.Error) {
33+
func (k Keeper) LatestByMarket(marketID sdk.Uint) (Batch, sdk.Error) {
3334
var res Batch
3435
var found bool
3536
k.as.ReversePrefixIterator(batchIterKey(marketID), func(_ []byte, v []byte) bool {
@@ -66,10 +67,10 @@ func (k Keeper) OnEvent(event interface{}) error {
6667
return nil
6768
}
6869

69-
func batchKey(marketID store.EntityID, blkNum int64) []byte {
70-
return store.PrefixKeyBytes(batchIterKey(marketID), store.Int64Subkey(blkNum))
70+
func batchKey(marketID sdk.Uint, blkNum int64) []byte {
71+
return storeutil.PrefixKeyBytes(batchIterKey(marketID), storeutil.Int64Subkey(blkNum))
7172
}
7273

73-
func batchIterKey(marketID store.EntityID) []byte {
74-
return store.PrefixKeyString(batchKeyPrefix, marketID.Bytes())
74+
func batchIterKey(marketID sdk.Uint) []byte {
75+
return storeutil.PrefixKeyString(batchKeyPrefix, storeutil.SDKUintSubkey(marketID))
7576
}

embedded/batch/querier.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ package batch
33
import (
44
abci "github.com/tendermint/tendermint/abci/types"
55

6-
"github.com/tendermint/dex-demo/types/errs"
7-
"github.com/tendermint/dex-demo/types/store"
8-
96
"github.com/cosmos/cosmos-sdk/codec"
107
sdk "github.com/cosmos/cosmos-sdk/types"
8+
"github.com/tendermint/dex-demo/types/errs"
119
)
1210

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

33-
marketID := store.NewEntityIDFromString(path[0])
31+
marketID := sdk.NewUintFromString(path[0])
3432
res, sdkErr := keeper.LatestByMarket(marketID)
3533
if sdkErr != nil {
3634
if sdkErr.Code() == errs.CodeNotFound {

embedded/batch/types.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ package batch
33
import (
44
"time"
55

6-
"github.com/tendermint/dex-demo/pkg/matcheng"
7-
"github.com/tendermint/dex-demo/types/store"
8-
96
sdk "github.com/cosmos/cosmos-sdk/types"
7+
"github.com/tendermint/dex-demo/pkg/matcheng"
108
)
119

1210
type Batch struct {
1311
BlockNumber int64 `json:"block_number"`
1412
BlockTime time.Time `json:"block_time"`
15-
MarketID store.EntityID `json:"market_id"`
13+
MarketID sdk.Uint `json:"market_id"`
1614
ClearingPrice sdk.Uint `json:"clearing_price"`
1715
Bids []matcheng.AggregatePrice `json:"bids"`
1816
Asks []matcheng.AggregatePrice `json:"asks"`

embedded/book/querier.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ package book
33
import (
44
abci "github.com/tendermint/tendermint/abci/types"
55

6-
"github.com/tendermint/dex-demo/embedded/order"
7-
"github.com/tendermint/dex-demo/types/errs"
8-
"github.com/tendermint/dex-demo/types/store"
9-
106
"github.com/cosmos/cosmos-sdk/codec"
117
sdk "github.com/cosmos/cosmos-sdk/types"
8+
"github.com/tendermint/dex-demo/embedded/order"
9+
"github.com/tendermint/dex-demo/types/errs"
1210
)
1311

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

34-
mktId := store.NewEntityIDFromString(path[0])
32+
mktId := sdk.NewUintFromString(path[0])
3533
res := keeper.OpenOrdersByMarket(mktId)
3634
b, err := codec.MarshalJSONIndent(codec.New(), res)
3735
if err != nil {

embedded/book/routes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
"github.com/cosmos/cosmos-sdk/codec"
1414
"github.com/cosmos/cosmos-sdk/types/rest"
1515

16+
sdk "github.com/cosmos/cosmos-sdk/types"
1617
"github.com/tendermint/dex-demo/embedded/auth"
1718
"github.com/tendermint/dex-demo/embedded/node"
1819
"github.com/tendermint/dex-demo/embedded/order"
1920
"github.com/tendermint/dex-demo/pkg/matcheng"
20-
"github.com/tendermint/dex-demo/types/store"
2121
)
2222

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

5252
qRes := QueryResult{
53-
MarketID: store.NewEntityIDFromString(mktId),
53+
MarketID: sdk.NewUintFromString(mktId),
5454
BlockNumber: block.Block.Height,
5555
Bids: make([]QueryResultEntry, 0),
5656
Asks: make([]QueryResultEntry, 0),

embedded/book/types.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package book
22

33
import (
4-
"github.com/tendermint/dex-demo/pkg/matcheng"
5-
"github.com/tendermint/dex-demo/types/store"
6-
74
sdk "github.com/cosmos/cosmos-sdk/types"
5+
"github.com/tendermint/dex-demo/pkg/matcheng"
86
)
97

108
type Book struct {
@@ -18,7 +16,7 @@ type QueryResultEntry struct {
1816
}
1917

2018
type QueryResult struct {
21-
MarketID store.EntityID `json:"market_id"`
19+
MarketID sdk.Uint `json:"market_id"`
2220
BlockNumber int64 `json:"block_number"`
2321
Bids []QueryResultEntry `json:"bids"`
2422
Asks []QueryResultEntry `json:"asks"`

embedded/exchange/routes.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/tendermint/dex-demo/embedded"
1010
"github.com/tendermint/dex-demo/embedded/auth"
11-
"github.com/tendermint/dex-demo/types/store"
1211
"github.com/tendermint/dex-demo/x/order/types"
1312

1413
"github.com/cosmos/cosmos-sdk/client/context"
@@ -73,7 +72,7 @@ func postOrderHandler(ctx context.CLIContext, cdc *codec.Codec) http.HandlerFunc
7372
break
7473
}
7574
}
76-
orderID := store.NewEntityIDFromString(orderIDStr)
75+
orderID := sdk.NewUintFromString(orderIDStr)
7776
res := OrderCreationResponse{
7877
BlockInclusion: embedded.BlockInclusion{
7978
BlockNumber: broadcastRes.Height,

0 commit comments

Comments
 (0)