diff --git a/Makefile b/Makefile index ec5131e..a568f19 100755 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/embedded/balance/routes.go b/embedded/balance/routes.go index bd69136..50caf17 100755 --- a/embedded/balance/routes.go +++ b/embedded/balance/routes.go @@ -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" @@ -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) diff --git a/embedded/balance/types.go b/embedded/balance/types.go index 3bb9434..bcf647e 100755 --- a/embedded/balance/types.go +++ b/embedded/balance/types.go @@ -1,10 +1,8 @@ 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 { @@ -12,11 +10,11 @@ type GetQueryRequest struct { } 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 { @@ -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"` } diff --git a/embedded/batch/keeper.go b/embedded/batch/keeper.go index 8a7399f..80dd96e 100755 --- a/embedded/batch/keeper.go +++ b/embedded/batch/keeper.go @@ -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" @@ -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 { @@ -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)) } diff --git a/embedded/batch/querier.go b/embedded/batch/querier.go index eaa3e96..d8a8b69 100755 --- a/embedded/batch/querier.go +++ b/embedded/batch/querier.go @@ -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 ( @@ -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 { diff --git a/embedded/batch/types.go b/embedded/batch/types.go index ea185e2..aa72f2a 100755 --- a/embedded/batch/types.go +++ b/embedded/batch/types.go @@ -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"` diff --git a/embedded/book/querier.go b/embedded/book/querier.go index 91d5f4c..699d671 100755 --- a/embedded/book/querier.go +++ b/embedded/book/querier.go @@ -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 ( @@ -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 { diff --git a/embedded/book/routes.go b/embedded/book/routes.go index ae0a2cf..1be17bb 100755 --- a/embedded/book/routes.go +++ b/embedded/book/routes.go @@ -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) { @@ -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), diff --git a/embedded/book/types.go b/embedded/book/types.go index cefb51b..6246d61 100755 --- a/embedded/book/types.go +++ b/embedded/book/types.go @@ -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 { @@ -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"` diff --git a/embedded/exchange/routes.go b/embedded/exchange/routes.go index 16cc7e0..44e3c57 100755 --- a/embedded/exchange/routes.go +++ b/embedded/exchange/routes.go @@ -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" @@ -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, diff --git a/embedded/exchange/types.go b/embedded/exchange/types.go index cd4b5da..f5145a4 100755 --- a/embedded/exchange/types.go +++ b/embedded/exchange/types.go @@ -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"` @@ -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"` diff --git a/embedded/fill/keeper.go b/embedded/fill/keeper.go index 64a8dc3..3e1b4d1 100755 --- a/embedded/fill/keeper.go +++ b/embedded/fill/keeper.go @@ -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 ( @@ -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)) } diff --git a/embedded/fill/types.go b/embedded/fill/types.go index 9128d24..b5c7da7 100755 --- a/embedded/fill/types.go +++ b/embedded/fill/types.go @@ -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"` @@ -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"` diff --git a/embedded/order/keeper.go b/embedded/order/keeper.go index 91e2d64..5dce679 100755 --- a/embedded/order/keeper.go +++ b/embedded/order/keeper.go @@ -1,11 +1,13 @@ package order import ( + "github.com/tendermint/dex-demo/storeutil" dbm "github.com/tendermint/tm-db" + "math/big" + "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" @@ -33,10 +35,10 @@ func NewKeeper(db dbm.DB, cdc *codec.Codec) Keeper { } } -func (k Keeper) OpenOrdersByMarket(mktID store.EntityID) []Order { +func (k Keeper) OpenOrdersByMarket(mktID sdk.Uint) []Order { var out []Order k.ReverseIteratorOpenOrders(func(order Order) bool { - if !mktID.Equals(order.MarketID) { + if !mktID.Equal(order.MarketID) { return true } @@ -47,10 +49,10 @@ func (k Keeper) OpenOrdersByMarket(mktID store.EntityID) []Order { } func (k Keeper) OrdersByOwner(owner sdk.AccAddress, cb IteratorCB) { - var ownedOrders []store.EntityID + var ownedOrders []sdk.Uint k.as.ReversePrefixIterator(ownerOrderIterKey(owner), func(_ []byte, v []byte) bool { - id := store.NewEntityIDFromBytes(v) + id := sdk.NewUintFromBigInt(new(big.Int).SetBytes(v)) ownedOrders = append(ownedOrders, id) return true }) @@ -78,11 +80,11 @@ func (k Keeper) OnOrderCreatedEvent(event types.OrderCreated) { Status: "OPEN", Type: "LIMIT", TimeInForce: event.TimeInForceBlocks, - QuantityFilled: sdk.NewUint(0), + QuantityFilled: sdk.ZeroUint(), CreatedBlock: event.CreatedBlock, } k.Set(order) - k.as.Set(ownerOrderKey(order.Owner, order.ID), order.ID.Bytes()) + k.as.Set(ownerOrderKey(order.Owner, order.ID), storeutil.SDKUintSubkey(order.ID)) } func (k Keeper) OnFillEvent(event types.Fill) sdk.Error { @@ -111,7 +113,7 @@ func (k Keeper) OnOrderCancelledEvent(event types.OrderCancelled) sdk.Error { return nil } -func (k Keeper) Get(id store.EntityID) (Order, sdk.Error) { +func (k Keeper) Get(id sdk.Uint) (Order, sdk.Error) { var order Order ordB := k.as.Get(orderKey(id)) if ordB == nil { @@ -126,7 +128,7 @@ func (k Keeper) Set(order Order) { k.as.Set(orderKey(order.ID), ordB) if order.Status == "OPEN" { - k.as.Set(openOrderKey(order.MarketID, order.ID), order.ID.Bytes()) + k.as.Set(openOrderKey(order.MarketID, order.ID), storeutil.SDKUintSubkey(order.ID)) } else { k.as.Delete(openOrderKey(order.MarketID, order.ID)) } @@ -141,10 +143,10 @@ func (k Keeper) ReverseIterator(cb IteratorCB) { } func (k Keeper) ReverseIteratorOpenOrders(cb IteratorCB) { - var openOrderIDs []store.EntityID + var openOrderIDs []sdk.Uint k.as.ReversePrefixIterator([]byte(openOrderPrefix), func(_ []byte, v []byte) bool { - id := store.NewEntityIDFromBytes(v) + id := sdk.NewUintFromBigInt(new(big.Int).SetBytes(v)) openOrderIDs = append(openOrderIDs, id) return true }) @@ -161,9 +163,9 @@ func (k Keeper) ReverseIteratorOpenOrders(cb IteratorCB) { } } -func (k Keeper) ReverseIteratorFrom(startID store.EntityID, cb IteratorCB) { +func (k Keeper) ReverseIteratorFrom(startID sdk.Uint, cb IteratorCB) { // Inc() below because end is exclusive - k.as.ReverseIterator(orderKey(store.NewEntityID(0)), orderKey(startID.Inc()), func(_ []byte, v []byte) bool { + k.as.ReverseIterator(orderKey(sdk.ZeroUint()), orderKey(startID.Add(sdk.OneUint())), func(_ []byte, v []byte) bool { var order Order k.cdc.MustUnmarshalBinaryBare(v, &order) return cb(order) @@ -183,18 +185,18 @@ func (k Keeper) OnEvent(event interface{}) error { return nil } -func orderKey(id store.EntityID) []byte { - return store.PrefixKeyString(orderPrefix, id.Bytes()) +func orderKey(id sdk.Uint) []byte { + return storeutil.PrefixKeyString(orderPrefix, storeutil.SDKUintSubkey(id)) } -func openOrderKey(marketID store.EntityID, orderID store.EntityID) []byte { - return store.PrefixKeyString(openOrderPrefix, marketID.Bytes(), orderID.Bytes()) +func openOrderKey(marketID sdk.Uint, orderID sdk.Uint) []byte { + return storeutil.PrefixKeyString(openOrderPrefix, storeutil.SDKUintSubkey(marketID), storeutil.SDKUintSubkey(orderID)) } -func ownerOrderKey(owner sdk.AccAddress, orderID store.EntityID) []byte { - return store.PrefixKeyBytes(ownerOrderIterKey(owner), orderID.Bytes()) +func ownerOrderKey(owner sdk.AccAddress, orderID sdk.Uint) []byte { + return storeutil.PrefixKeyBytes(ownerOrderIterKey(owner), storeutil.SDKUintSubkey(orderID)) } func ownerOrderIterKey(owner sdk.AccAddress) []byte { - return store.PrefixKeyString(ownedOrderPrefix, owner.Bytes()) + return storeutil.PrefixKeyString(ownedOrderPrefix, owner.Bytes()) } diff --git a/embedded/order/keeper_test.go b/embedded/order/keeper_test.go index 7790a45..37a139a 100755 --- a/embedded/order/keeper_test.go +++ b/embedded/order/keeper_test.go @@ -7,13 +7,11 @@ import ( "github.com/stretchr/testify/require" dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/dex-demo/pkg/matcheng" "github.com/tendermint/dex-demo/testutil/testflags" "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" ) func TestKeeper(t *testing.T) { @@ -23,9 +21,9 @@ func TestKeeper(t *testing.T) { k := NewKeeper(db, cdc) creationEvs := []types.OrderCreated{ { - ID: store.NewEntityID(1), + ID: sdk.OneUint(), Owner: sdk.AccAddress{}, - MarketID: store.NewEntityID(1), + MarketID: sdk.OneUint(), Direction: matcheng.Bid, Price: sdk.NewUint(100), Quantity: sdk.NewUint(100), @@ -33,9 +31,9 @@ func TestKeeper(t *testing.T) { CreatedBlock: 10, }, { - ID: store.NewEntityID(2), + ID: sdk.NewUint(2), Owner: sdk.AccAddress{}, - MarketID: store.NewEntityID(1), + MarketID: sdk.OneUint(), Direction: matcheng.Ask, Price: sdk.NewUint(110), Quantity: sdk.NewUint(110), @@ -43,9 +41,9 @@ func TestKeeper(t *testing.T) { CreatedBlock: 11, }, { - ID: store.NewEntityID(3), + ID: sdk.NewUint(3), Owner: sdk.AccAddress{}, - MarketID: store.NewEntityID(2), + MarketID: sdk.NewUint(2), Direction: matcheng.Bid, Price: sdk.NewUint(99), Quantity: sdk.NewUint(99), @@ -53,9 +51,9 @@ func TestKeeper(t *testing.T) { CreatedBlock: 12, }, { - ID: store.NewEntityID(4), + ID: sdk.NewUint(4), Owner: sdk.AccAddress{}, - MarketID: store.NewEntityID(1), + MarketID: sdk.OneUint(), Direction: matcheng.Bid, Price: sdk.NewUint(100), Quantity: sdk.NewUint(100), @@ -63,9 +61,9 @@ func TestKeeper(t *testing.T) { CreatedBlock: 10, }, { - ID: store.NewEntityID(5), + ID: sdk.NewUint(5), Owner: sdk.AccAddress{}, - MarketID: store.NewEntityID(1), + MarketID: sdk.OneUint(), Direction: matcheng.Bid, Price: sdk.NewUint(100), Quantity: sdk.NewUint(100), @@ -73,9 +71,9 @@ func TestKeeper(t *testing.T) { CreatedBlock: 10, }, { - ID: store.NewEntityID(6), + ID: sdk.NewUint(6), Owner: sdk.AccAddress{}, - MarketID: store.NewEntityID(2), + MarketID: sdk.NewUint(2), Direction: matcheng.Bid, Price: sdk.NewUint(100), Quantity: sdk.NewUint(100), @@ -85,16 +83,16 @@ func TestKeeper(t *testing.T) { } cancellationEvs := []types.OrderCancelled{ { - OrderID: store.NewEntityID(4), + OrderID: sdk.NewUint(4), }, } fillEvs := []types.Fill{ { - OrderID: store.NewEntityID(5), + OrderID: sdk.NewUint(5), QtyFilled: sdk.NewUint(99), }, { - OrderID: store.NewEntityID(6), + OrderID: sdk.NewUint(6), QtyFilled: sdk.NewUint(100), }, } @@ -109,7 +107,7 @@ func TestKeeper(t *testing.T) { } t.Run("open orders by market returns only open orders from the market", func(t *testing.T) { - res := k.OpenOrdersByMarket(store.NewEntityID(1)) + res := k.OpenOrdersByMarket(sdk.OneUint()) assert.Equal(t, 3, len(res)) ev0 := creationEvs[0] ev1 := creationEvs[1] @@ -137,7 +135,7 @@ func TestKeeper(t *testing.T) { Status: "OPEN", Type: "LIMIT", TimeInForce: ev1.TimeInForceBlocks, - QuantityFilled: sdk.NewUint(0), + QuantityFilled: sdk.ZeroUint(), CreatedBlock: ev1.CreatedBlock, }, res[1]) assertEqualOrders(t, cdc, Order{ @@ -150,7 +148,7 @@ func TestKeeper(t *testing.T) { Status: "OPEN", Type: "LIMIT", TimeInForce: ev0.TimeInForceBlocks, - QuantityFilled: sdk.NewUint(0), + QuantityFilled: sdk.ZeroUint(), CreatedBlock: ev0.CreatedBlock, }, res[2]) }) @@ -168,7 +166,7 @@ func TestKeeper(t *testing.T) { Status: "CANCELLED", Type: "LIMIT", TimeInForce: ev3.TimeInForceBlocks, - QuantityFilled: sdk.NewUint(0), + QuantityFilled: sdk.ZeroUint(), CreatedBlock: ev3.CreatedBlock, }, res) }) diff --git a/embedded/order/querier.go b/embedded/order/querier.go index 36e9b1e..c392759 100755 --- a/embedded/order/querier.go +++ b/embedded/order/querier.go @@ -3,11 +3,9 @@ package order 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 ( @@ -33,7 +31,7 @@ func queryList(keeper Keeper, reqB []byte) ([]byte, sdk.Error) { } orders := make([]Order, 0) - var lastID store.EntityID + var lastID sdk.Uint iterCB := func(order Order) bool { orders = append(orders, order) lastID = order.ID @@ -41,10 +39,10 @@ func queryList(keeper Keeper, reqB []byte) ([]byte, sdk.Error) { } if req.Owner.Empty() { - if req.Start.IsDefined() { - keeper.ReverseIteratorFrom(req.Start, iterCB) - } else { + if req.Start.IsZero() { keeper.ReverseIterator(iterCB) + } else { + keeper.ReverseIteratorFrom(req.Start, iterCB) } } else { // TEMPORARY: can add support for richer querying with sqlite @@ -52,10 +50,16 @@ func queryList(keeper Keeper, reqB []byte) ([]byte, sdk.Error) { } if len(orders) < 50 { - lastID = store.NewEntityID(0) + lastID = sdk.ZeroUint() + } + var nextID sdk.Uint + if lastID.IsZero() { + nextID = sdk.ZeroUint() + } else { + nextID = lastID.Sub(sdk.OneUint()) } res := ListQueryResult{ - NextID: lastID.Dec(), + NextID: nextID, Orders: orders, } b, err := codec.MarshalJSONIndent(keeper.cdc, res) diff --git a/embedded/order/querier_test.go b/embedded/order/querier_test.go index 246191d..1eee437 100755 --- a/embedded/order/querier_test.go +++ b/embedded/order/querier_test.go @@ -8,13 +8,11 @@ import ( abci "github.com/tendermint/tendermint/abci/types" dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/dex-demo/testutil" "github.com/tendermint/dex-demo/testutil/testflags" "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" ) func TestQuerier(t *testing.T) { @@ -36,12 +34,12 @@ func TestQuerier(t *testing.T) { } t.Run("should return no more than 50 orders in descending order", func(t *testing.T) { - id := store.NewEntityID(0) + id := sdk.ZeroUint() for i := 0; i < 55; i++ { - id = id.Inc() + id = id.Add(sdk.OneUint()) require.NoError(t, k.OnEvent(types.OrderCreated{ - MarketID: store.NewEntityID(2), + MarketID: sdk.NewUint(2), ID: id, })) } @@ -50,57 +48,57 @@ func TestQuerier(t *testing.T) { require.NoError(t, err) assert.Equal(t, 50, len(res.Orders)) - testutil.AssertEqualEntityIDs(t, store.NewEntityID(55), res.Orders[0].ID) - testutil.AssertEqualEntityIDs(t, store.NewEntityID(6), res.Orders[49].ID) - testutil.AssertEqualEntityIDs(t, store.NewEntityID(5), res.NextID) + testutil.AssertEqualUints(t, sdk.NewUint(55), res.Orders[0].ID) + testutil.AssertEqualUints(t, sdk.NewUint(6), res.Orders[49].ID) + testutil.AssertEqualUints(t, sdk.NewUint(5), res.NextID) }) t.Run("should work with an offset", func(t *testing.T) { - id := store.NewEntityID(0) + id := sdk.ZeroUint() for i := 0; i < 55; i++ { - id = id.Inc() + id = id.Add(sdk.OneUint()) require.NoError(t, k.OnEvent(types.OrderCreated{ - MarketID: store.NewEntityID(2), + MarketID: sdk.NewUint(2), ID: id, })) } res, err := doListQuery(ListQueryRequest{ - Start: store.NewEntityID(7), + Start: sdk.NewUint(7), }) require.NoError(t, err) assert.Equal(t, 7, len(res.Orders)) - testutil.AssertEqualEntityIDs(t, store.NewEntityID(7), res.Orders[0].ID) - testutil.AssertEqualEntityIDs(t, store.NewEntityID(1), res.Orders[6].ID) - testutil.AssertEqualEntityIDs(t, store.NewEntityID(0), res.NextID) + testutil.AssertEqualUints(t, sdk.NewUint(7), res.Orders[0].ID) + testutil.AssertEqualUints(t, sdk.OneUint(), res.Orders[6].ID) + testutil.AssertEqualUints(t, sdk.ZeroUint(), res.NextID) }) t.Run("should support filter by address alongside offset", func(t *testing.T) { - id := store.NewEntityID(0) + id := sdk.ZeroUint() genOwner := testutil.RandAddr() for i := 0; i < 110; i++ { - id = id.Inc() + id = id.Add(sdk.OneUint()) var owner sdk.AccAddress if i%2 == 0 { owner = genOwner } require.NoError(t, k.OnEvent(types.OrderCreated{ - MarketID: store.NewEntityID(2), + MarketID: sdk.NewUint(2), ID: id, Owner: owner, })) } res, err := doListQuery(ListQueryRequest{ - Start: store.NewEntityID(104), + Start: sdk.NewUint(104), Owner: genOwner, }) require.NoError(t, err) assert.Equal(t, 50, len(res.Orders)) - testutil.AssertEqualEntityIDs(t, store.NewEntityID(109), res.Orders[0].ID) - testutil.AssertEqualEntityIDs(t, store.NewEntityID(11), res.Orders[49].ID) + testutil.AssertEqualUints(t, sdk.NewUint(109), res.Orders[0].ID) + testutil.AssertEqualUints(t, sdk.NewUint(11), res.Orders[49].ID) }) t.Run("should return an error if the request does not deserialize", func(t *testing.T) { _, err := q(ctx, []string{"list"}, abci.RequestQuery{Data: []byte("foo")}) diff --git a/embedded/order/routes.go b/embedded/order/routes.go index 52cc8e6..6255b07 100755 --- a/embedded/order/routes.go +++ b/embedded/order/routes.go @@ -11,8 +11,8 @@ 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/types/store" ) func RegisterRoutes(ctx context.CLIContext, r *mux.Router, cdc *codec.Codec) { @@ -28,7 +28,7 @@ func getOrdersHandler(ctx context.CLIContext, cdc *codec.Codec) http.HandlerFunc Owner: owner.GetAddr(), } if start, ok := q["start"]; ok { - req.Start = store.NewEntityIDFromString(start[0]) + req.Start = sdk.NewUintFromString(start[0]) } resB, _, err := ctx.QueryWithData("custom/embeddedorder/list", cdc.MustMarshalBinaryBare(req)) diff --git a/embedded/order/types.go b/embedded/order/types.go index ce5797c..f32e094 100755 --- a/embedded/order/types.go +++ b/embedded/order/types.go @@ -1,16 +1,14 @@ package order 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 Order struct { - ID store.EntityID `json:"id"` + ID sdk.Uint `json:"id"` Owner sdk.AccAddress `json:"owner"` - 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"` @@ -22,11 +20,11 @@ type Order struct { } type ListQueryRequest struct { - Start store.EntityID + Start sdk.Uint Owner sdk.AccAddress } type ListQueryResult struct { - NextID store.EntityID `json:"next_id"` - Orders []Order `json:"orders"` + NextID sdk.Uint `json:"next_id"` + Orders []Order `json:"orders"` } diff --git a/embedded/price/keeper.go b/embedded/price/keeper.go index fcd841b..d9e7835 100755 --- a/embedded/price/keeper.go +++ b/embedded/price/keeper.go @@ -1,15 +1,16 @@ package price import ( + "github.com/tendermint/dex-demo/storeutil" "time" 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/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) type IteratorCB func(tick Tick) bool @@ -26,7 +27,7 @@ func NewKeeper(db dbm.DB, cdc *codec.Codec) Keeper { } } -func (k Keeper) ReverseIteratorByMarket(mktID store.EntityID, cb IteratorCB) { +func (k Keeper) ReverseIteratorByMarket(mktID sdk.Uint, cb IteratorCB) { k.as.PrefixIterator(tickIterKey(mktID), func(_ []byte, v []byte) bool { var tick Tick k.cdc.MustUnmarshalBinaryBare(v, &tick) @@ -34,7 +35,7 @@ func (k Keeper) ReverseIteratorByMarket(mktID store.EntityID, cb IteratorCB) { }) } -func (k Keeper) ReverseIteratorByMarketFrom(mktID store.EntityID, from time.Time, cb IteratorCB) { +func (k Keeper) ReverseIteratorByMarketFrom(mktID sdk.Uint, from time.Time, cb IteratorCB) { k.as.ReverseIterator(tickKey(mktID, 0), sdk.PrefixEndBytes(tickKey(mktID, 0)), func(_ []byte, v []byte) bool { var tick Tick k.cdc.MustUnmarshalBinaryBare(v, &tick) @@ -42,7 +43,7 @@ func (k Keeper) ReverseIteratorByMarketFrom(mktID store.EntityID, from time.Time }) } -func (k Keeper) IteratorByMarketAndInterval(mktID store.EntityID, from time.Time, to time.Time, cb IteratorCB) { +func (k Keeper) IteratorByMarketAndInterval(mktID sdk.Uint, from time.Time, to time.Time, cb IteratorCB) { k.as.Iterator(tickKey(mktID, from.Unix()), sdk.PrefixEndBytes(tickKey(mktID, to.Unix())), func(_ []byte, v []byte) bool { var tick Tick k.cdc.MustUnmarshalBinaryBare(v, &tick) @@ -71,10 +72,10 @@ func (k Keeper) OnEvent(event interface{}) error { return nil } -func tickKey(mktID store.EntityID, blockTime int64) []byte { - return store.PrefixKeyBytes(tickIterKey(mktID), store.Int64Subkey(blockTime)) +func tickKey(mktID sdk.Uint, blockTime int64) []byte { + return storeutil.PrefixKeyBytes(tickIterKey(mktID), storeutil.Int64Subkey(blockTime)) } -func tickIterKey(mktID store.EntityID) []byte { - return store.PrefixKeyString("tick", mktID.Bytes()) +func tickIterKey(mktID sdk.Uint) []byte { + return storeutil.PrefixKeyString("tick", storeutil.SDKUintSubkey(mktID)) } diff --git a/embedded/price/price_test/querier_test.go b/embedded/price/price_test/querier_test.go index 860eb9d..26f99fa 100755 --- a/embedded/price/price_test/querier_test.go +++ b/embedded/price/price_test/querier_test.go @@ -12,14 +12,12 @@ import ( abci "github.com/tendermint/tendermint/abci/types" dbm "github.com/tendermint/tm-db" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/dex-demo/pkg/matcheng" "github.com/tendermint/dex-demo/testutil" "github.com/tendermint/dex-demo/testutil/mockapp" "github.com/tendermint/dex-demo/testutil/testflags" "github.com/tendermint/dex-demo/types" - "github.com/tendermint/dex-demo/types/store" - - sdk "github.com/cosmos/cosmos-sdk/types" ) func TestQuerier_Candles(t *testing.T) { @@ -27,53 +25,53 @@ func TestQuerier_Candles(t *testing.T) { app := mockapp.New(t) db := dbm.NewMemDB() keeper := price.NewKeeper(db, app.Cdc) - mktID := store.NewEntityID(1) + mktID := sdk.OneUint() fills := []types.Fill{ { - store.NewEntityID(1), + sdk.OneUint(), mktID, testutil.RandAddr(), "DEX/ETH", matcheng.Bid, sdk.NewUint(100), - sdk.NewUint(0), + sdk.ZeroUint(), 1, 100, sdk.NewUint(100), }, { - store.NewEntityID(1), + sdk.OneUint(), mktID, testutil.RandAddr(), "DEX/ETH", matcheng.Bid, sdk.NewUint(100), - sdk.NewUint(0), + sdk.ZeroUint(), 2, 130, sdk.NewUint(90), }, { - store.NewEntityID(1), + sdk.OneUint(), mktID, testutil.RandAddr(), "DEX/ETH", matcheng.Bid, sdk.NewUint(100), - sdk.NewUint(0), + sdk.ZeroUint(), 3, 160, sdk.NewUint(120), }, { - store.NewEntityID(1), + sdk.OneUint(), mktID, testutil.RandAddr(), "DEX/ETH", matcheng.Bid, sdk.NewUint(100), - sdk.NewUint(0), + sdk.ZeroUint(), 4, 190, sdk.NewUint(140), diff --git a/embedded/price/querier.go b/embedded/price/querier.go index 5f4e5b9..16072ab 100755 --- a/embedded/price/querier.go +++ b/embedded/price/querier.go @@ -6,12 +6,9 @@ import ( "github.com/tendermint/go-amino" abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/dex-demo/pkg/conv" - "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 ( @@ -37,7 +34,7 @@ func NewQuerier(keeper Keeper) sdk.Querier { } func queryHistory(path []string, keeper Keeper) ([]byte, sdk.Error) { - mktID := store.NewEntityIDFromString(path[0]) + mktID := sdk.NewUintFromString(path[0]) res := TickQueryResult{ MarketID: mktID, @@ -66,7 +63,7 @@ func queryHistory(path []string, keeper Keeper) ([]byte, sdk.Error) { } func queryCandles(path []string, data []byte, keeper Keeper) ([]byte, sdk.Error) { - mktID := store.NewEntityIDFromString(path[0]) + mktID := sdk.NewUintFromString(path[0]) var params CandleQueryParams err := amino.UnmarshalBinaryBare(data, ¶ms) @@ -125,7 +122,7 @@ func queryCandles(path []string, data []byte, keeper Keeper) ([]byte, sdk.Error) } func queryDaily(path []string, keeper Keeper) ([]byte, sdk.Error) { - mktID := store.NewEntityIDFromString(path[0]) + mktID := sdk.NewUintFromString(path[0]) res := DailyQueryResult{ Pair: "", @@ -170,7 +167,7 @@ func queryDaily(path []string, keeper Keeper) ([]byte, sdk.Error) { if prevClose.IsZero() { res.Change = sdk.OneDec() } else { - res.Change = sdk.NewDecFromBigInt(conv.SDKUint2Big(res.Last)).Quo(sdk.NewDecFromBigInt(conv.SDKUint2Big(prevClose))) + res.Change = sdk.NewDecFromBigInt(res.Last.BigInt()).Quo(sdk.NewDecFromBigInt(prevClose.BigInt())) } b, err := codec.MarshalJSONIndent(keeper.cdc, res) diff --git a/embedded/price/types.go b/embedded/price/types.go index ca507d8..dd28297 100755 --- a/embedded/price/types.go +++ b/embedded/price/types.go @@ -10,13 +10,11 @@ import ( "github.com/olekukonko/tablewriter" - "github.com/tendermint/dex-demo/types/store" - sdk "github.com/cosmos/cosmos-sdk/types" ) type Tick struct { - MarketID store.EntityID + MarketID sdk.Uint Pair string BlockNumber int64 BlockTime int64 @@ -30,9 +28,9 @@ type TickEntry struct { } type TickQueryResult struct { - MarketID store.EntityID `json:"market_id"` - Pair string `json:"pair"` - Ticks []TickEntry `json:"ticks"` + MarketID sdk.Uint `json:"market_id"` + Pair string `json:"pair"` + Ticks []TickEntry `json:"ticks"` } func (t TickQueryResult) String() string { @@ -122,9 +120,9 @@ type CandleQueryParams struct { } type CandleQueryResult struct { - MarketID store.EntityID `json:"market_id"` - Pair string `json:"pair"` - Candles []CandleEntry `json:"candles"` + MarketID sdk.Uint `json:"market_id"` + Pair string `json:"pair"` + Candles []CandleEntry `json:"candles"` } type CandleEntry struct { diff --git a/types/store/archive_store.go b/embedded/store/archive_store.go similarity index 100% rename from types/store/archive_store.go rename to embedded/store/archive_store.go diff --git a/types/store/coins.go b/embedded/store/coins.go similarity index 73% rename from types/store/coins.go rename to embedded/store/coins.go index 771fb02..b1fe632 100755 --- a/types/store/coins.go +++ b/embedded/store/coins.go @@ -2,11 +2,10 @@ package store import ( "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" ) -func FormatCoin(id EntityID, amount sdk.Uint) sdk.Coin { +func FormatCoin(id sdk.Uint, amount sdk.Uint) sdk.Coin { out, err := sdk.ParseCoin(fmt.Sprintf("%s%s", amount.String(), FormatDenom(id))) // should never happen if err != nil { @@ -15,6 +14,6 @@ func FormatCoin(id EntityID, amount sdk.Uint) sdk.Coin { return out } -func FormatDenom(id EntityID) string { +func FormatDenom(id sdk.Uint) string { return fmt.Sprintf("asset%s", id.String()) } diff --git a/types/store/coins_test.go b/embedded/store/coins_test.go similarity index 71% rename from types/store/coins_test.go rename to embedded/store/coins_test.go index 482e5c4..14c2f0a 100755 --- a/types/store/coins_test.go +++ b/embedded/store/coins_test.go @@ -9,11 +9,11 @@ import ( ) func TestFormatCoin(t *testing.T) { - out := FormatCoin(NewEntityID(1), sdk.NewUint(100000)) + out := FormatCoin(sdk.OneUint(), sdk.NewUint(100000)) assert.True(t, out.Amount.Equal(sdk.NewInt(100000))) assert.Equal(t, "asset1", out.Denom) } func TestFormatDenom(t *testing.T) { - assert.Equal(t, "asset99", FormatDenom(NewEntityID(99))) + assert.Equal(t, "asset99", FormatDenom(sdk.NewUint(99))) } diff --git a/types/store/kv_store.go b/embedded/store/kv_store.go similarity index 89% rename from types/store/kv_store.go rename to embedded/store/kv_store.go index 971533b..2d2cc19 100755 --- a/types/store/kv_store.go +++ b/embedded/store/kv_store.go @@ -4,7 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -type KVStore interface { +type SimpleKVStore interface { Get(key []byte) []byte Has(key []byte) bool diff --git a/types/store/table.go b/embedded/store/table.go similarity index 69% rename from types/store/table.go rename to embedded/store/table.go index 833b9cd..f21ae40 100755 --- a/types/store/table.go +++ b/embedded/store/table.go @@ -2,6 +2,7 @@ package store import ( "fmt" + "github.com/tendermint/dex-demo/storeutil" "strings" dbm "github.com/tendermint/tm-db" @@ -24,39 +25,39 @@ func NewTable(db dbm.DB, prefix string) *Table { } func (t *Table) Get(key []byte) []byte { - return t.db.Get(PrefixKeyString(t.prefix, key)) + return t.db.Get(storeutil.PrefixKeyString(t.prefix, key)) } func (t *Table) Has(key []byte) bool { - return t.db.Has(PrefixKeyString(t.prefix, key)) + return t.db.Has(storeutil.PrefixKeyString(t.prefix, key)) } func (t *Table) Set(key, value []byte) { - t.db.Set(PrefixKeyString(t.prefix, key), value) + t.db.Set(storeutil.PrefixKeyString(t.prefix, key), value) } func (t *Table) Delete(key []byte) { - t.db.Delete(PrefixKeyString(t.prefix, key)) + t.db.Delete(storeutil.PrefixKeyString(t.prefix, key)) } func (t *Table) Iterator(start []byte, end []byte, cb IteratorCB) { - iter := t.db.Iterator(PrefixKeyString(t.prefix, start), PrefixKeyString(t.prefix, end)) + iter := t.db.Iterator(storeutil.PrefixKeyString(t.prefix, start), storeutil.PrefixKeyString(t.prefix, end)) t.iterate(iter, cb) } func (t *Table) ReverseIterator(start []byte, end []byte, cb IteratorCB) { - iter := t.db.ReverseIterator(PrefixKeyString(t.prefix, start), PrefixKeyString(t.prefix, end)) + iter := t.db.ReverseIterator(storeutil.PrefixKeyString(t.prefix, start), storeutil.PrefixKeyString(t.prefix, end)) t.iterate(iter, cb) } func (t *Table) PrefixIterator(start []byte, cb IteratorCB) { - start = PrefixKeyString(t.prefix, start) + start = storeutil.PrefixKeyString(t.prefix, start) iter := t.db.Iterator(start, sdk.PrefixEndBytes(start)) t.iterate(iter, cb) } func (t *Table) ReversePrefixIterator(start []byte, cb IteratorCB) { - start = PrefixKeyString(t.prefix, start) + start = storeutil.PrefixKeyString(t.prefix, start) iter := t.db.ReverseIterator(start, sdk.PrefixEndBytes(start)) t.iterate(iter, cb) } diff --git a/types/store/table_test.go b/embedded/store/table_test.go similarity index 90% rename from types/store/table_test.go rename to embedded/store/table_test.go index 1f85d57..6043627 100755 --- a/types/store/table_test.go +++ b/embedded/store/table_test.go @@ -1,6 +1,7 @@ package store import ( + "github.com/tendermint/dex-demo/storeutil" "testing" "github.com/stretchr/testify/assert" @@ -92,8 +93,8 @@ func TestTable(t *testing.T) { }) t.Run("can iterate over a prefix", func(t *testing.T) { for i := 0; i < 255; i++ { - tb1.Set(PrefixKeyString("pref1", []byte{byte(i)}), []byte{byte(i)}) - tb1.Set(PrefixKeyString("pref2", []byte{byte(i)}), []byte{byte(i)}) + tb1.Set(storeutil.PrefixKeyString("pref1", []byte{byte(i)}), []byte{byte(i)}) + tb1.Set(storeutil.PrefixKeyString("pref2", []byte{byte(i)}), []byte{byte(i)}) } i := 0 @@ -110,8 +111,8 @@ func TestTable(t *testing.T) { }) t.Run("can reverse iterate over a prefix", func(t *testing.T) { for i := 0; i < 255; i++ { - tb1.Set(PrefixKeyString("pref1", []byte{byte(i)}), []byte{byte(i)}) - tb1.Set(PrefixKeyString("pref2", []byte{byte(i)}), []byte{byte(i)}) + tb1.Set(storeutil.PrefixKeyString("pref1", []byte{byte(i)}), []byte{byte(i)}) + tb1.Set(storeutil.PrefixKeyString("pref2", []byte{byte(i)}), []byte{byte(i)}) } i := 254 diff --git a/execution/execution_test/keeper_test.go b/execution/execution_test/keeper_test.go index 7648133..e5afe25 100755 --- a/execution/execution_test/keeper_test.go +++ b/execution/execution_test/keeper_test.go @@ -6,11 +6,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/dex-demo/pkg/matcheng" "github.com/tendermint/dex-demo/testutil" "github.com/tendermint/dex-demo/testutil/mockapp" "github.com/tendermint/dex-demo/testutil/testflags" - uexstore "github.com/tendermint/dex-demo/types/store" ) func TestKeeper_ExecuteAndCancelExpired(t *testing.T) { @@ -56,13 +56,13 @@ func TestKeeper_ExecuteAndCancelExpired(t *testing.T) { } require.NoError(t, app.ExecutionKeeper.ExecuteAndCancelExpired(ctx)) t.Run("should expire orders out of TIF", func(t *testing.T) { - assert.False(t, app.OrderKeeper.Has(ctx, uexstore.NewEntityID(1))) + assert.False(t, app.OrderKeeper.Has(ctx, sdk.OneUint())) }) t.Run("should update quantities of partially filled orders", func(t *testing.T) { - ord3, err := app.OrderKeeper.Get(ctx, uexstore.NewEntityID(3)) + ord3, err := app.OrderKeeper.Get(ctx, sdk.NewUint(3)) require.NoError(t, err) testutil.AssertEqualUints(t, testutil.ToBaseUnits(5), ord3.Quantity) - ord4, err := app.OrderKeeper.Get(ctx, uexstore.NewEntityID(4)) + ord4, err := app.OrderKeeper.Get(ctx, sdk.NewUint(4)) require.NoError(t, err) testutil.AssertEqualUints(t, testutil.ToBaseUnits(5), ord4.Quantity) }) @@ -73,7 +73,7 @@ func TestKeeper_ExecuteAndCancelExpired(t *testing.T) { require.NoError(t, app.ExecutionKeeper.ExecuteAndCancelExpired(ctx)) t.Run("should delete completely filled orders", func(t *testing.T) { - assert.False(t, app.OrderKeeper.Has(ctx, uexstore.NewEntityID(5))) + assert.False(t, app.OrderKeeper.Has(ctx, sdk.NewUint(5))) }) t.Run("all executed orders should exchange coins", func(t *testing.T) { // seller should have 9990 asset 1, because two orders were diff --git a/execution/keeper.go b/execution/keeper.go index 26aa2fa..857447f 100755 --- a/execution/keeper.go +++ b/execution/keeper.go @@ -6,7 +6,6 @@ import ( "github.com/tendermint/dex-demo/pkg/log" "github.com/tendermint/dex-demo/pkg/matcheng" "github.com/tendermint/dex-demo/types" - "github.com/tendermint/dex-demo/types/store" assettypes "github.com/tendermint/dex-demo/x/asset/types" "github.com/tendermint/dex-demo/x/market" "github.com/tendermint/dex-demo/x/order" @@ -27,7 +26,7 @@ type Keeper struct { type matcherByMarket struct { matcher *matcheng.Matcher - mktID store.EntityID + mktID sdk.Uint } var logger = log.WithModule("execution") @@ -46,7 +45,7 @@ func (k Keeper) ExecuteAndCancelExpired(ctx sdk.Context) sdk.Error { start := time.Now() height := ctx.BlockHeight() - var toCancel []store.EntityID + var toCancel []sdk.Uint k.ordK.Iterator(ctx, func(ord types2.Order) bool { if height-ord.CreatedBlock > int64(ord.TimeInForceBlocks) { toCancel = append(toCancel, ord.ID) diff --git a/go.mod b/go.mod index e6028f0..983811e 100644 --- a/go.mod +++ b/go.mod @@ -3,35 +3,36 @@ module github.com/tendermint/dex-demo go 1.13 require ( + github.com/99designs/keyring v1.1.3 // indirect github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c - github.com/cosmos/cosmos-sdk v0.37.4 + github.com/cosmos/cosmos-sdk v0.37.5 github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d // indirect + github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect github.com/go-kit/kit v0.9.0 github.com/gobuffalo/packr v1.25.0 - github.com/gorilla/mux v1.7.1 + github.com/gorilla/mux v1.7.3 github.com/gorilla/sessions v1.1.3 - github.com/mattn/go-isatty v0.0.8 // indirect + github.com/hashicorp/golang-lru v0.5.3 // indirect + github.com/mattn/go-isatty v0.0.11 // indirect github.com/mattn/go-runewidth v0.0.4 // indirect github.com/olekukonko/tablewriter v0.0.1 github.com/onsi/ginkgo v1.8.0 // indirect github.com/onsi/gomega v1.5.0 // indirect - github.com/pelletier/go-toml v1.4.0 // indirect + github.com/pelletier/go-toml v1.6.0 // indirect github.com/prometheus/client_golang v0.9.4 github.com/rakyll/statik v0.1.6 // indirect github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a // indirect github.com/rs/cors v1.7.0 github.com/spf13/afero v1.2.2 // indirect github.com/spf13/cobra v0.0.5 - github.com/spf13/viper v1.4.0 + github.com/spf13/viper v1.6.1 github.com/stretchr/testify v1.4.0 - github.com/tendermint/go-amino v0.15.0 - github.com/tendermint/tendermint v0.32.7 + github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect + github.com/tendermint/go-amino v0.15.1 + github.com/tendermint/tendermint v0.32.8 github.com/tendermint/tm-db v0.2.0 - golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734 // indirect - golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 // indirect golang.org/x/text v0.3.2 // indirect google.golang.org/appengine v1.4.0 // indirect - google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 // indirect ) replace golang.org/x/crypto => github.com/kivey87/crypto v0.0.0-20190531000330-76a94ff009f0 diff --git a/go.sum b/go.sum index a51c7ec..a75392e 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/99designs/keyring v1.1.3 h1:mEV3iyZWjkxQ7R8ia8GcG97vCX5zQQ7n4o8R2BylwQY= +github.com/99designs/keyring v1.1.3/go.mod h1:657DQuMrBZRtuL/voxVyiyb6zpMehlm5vLB9Qwrv904= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -28,6 +30,7 @@ github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVa github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= @@ -36,22 +39,33 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cosmos/cosmos-sdk v0.28.2-0.20200107151701-2968247d9c67 h1:fZCax1jHbmuDxOZAFmUeSOYSB7n/OfdsGuRYZgICcSg= +github.com/cosmos/cosmos-sdk v0.28.2-0.20200107151701-2968247d9c67/go.mod h1:hasIdlU9b3FEFCWpoStvNQQPg1ZpAKnpmlFklAk1W1o= github.com/cosmos/cosmos-sdk v0.37.4 h1:1ioXxkpiS+wOgaUbROeDIyuF7hciU5nti0TSyBmV2Ok= github.com/cosmos/cosmos-sdk v0.37.4/go.mod h1:Axr+Q+G2Ffduxt4zMA6KwxxvyVSKPB9+nXZVPKgpC2c= +github.com/cosmos/cosmos-sdk v0.37.5 h1:s03HFQ5N2CkiS/nENtACdfCwUUXSn7E5AvkWBk7wNGM= +github.com/cosmos/cosmos-sdk v0.37.5/go.mod h1:d0WLPdlZyfbfHvFPa+GfWXFxHAiVCpOKp3bDm2YxFN8= github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/ledger-cosmos-go v0.10.3 h1:Qhi5yTR5Pg1CaTpd00pxlGwNl4sFRdtK1J96OTjeFFc= github.com/cosmos/ledger-cosmos-go v0.10.3/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= +github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= +github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI= github.com/cosmos/ledger-go v0.9.2/go.mod h1:oZJ2hHAZROdlHiwTg4t7kP+GKIIkBT+o6c9QWFanOyI= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/danieljoos/wincred v1.0.2/go.mod h1:SnuYRW9lp1oJrZX/dXJqr0cPK5gYXqx3EJbmjhLdK9U= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/dvsekhvalnov/jose2go v0.0.0-20180829124132-7f401d37b68a h1:mq+R6XEM6lJX5VlLyZIrUSP8tSuJp82xTK89hvBwJbU= +github.com/dvsekhvalnov/jose2go v0.0.0-20180829124132-7f401d37b68a/go.mod h1:7BvyPhdbLxMXIYTFPLsyJRFMsKmOZnQmzh6Gb+uquuM= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/etcd-io/bbolt v1.3.2/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= @@ -99,11 +113,14 @@ github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGt github.com/gobuffalo/packr/v2 v2.1.0/go.mod h1:n90ZuXIc2KN2vFAOQascnPItp9A2g9QYSvYvS3AjQEM= github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754 h1:tpom+2CJmpzAWj5/VEHync2rJGi+epHNIeRSWjzGA+4= github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= +github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.3.0 h1:G8O7TerXerS4F6sx9OV7/nRfJdnXgHZu/S/7F2SN+UE= github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -123,11 +140,14 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.1 h1:Dw4jY2nghMMRsh1ol8dv1axHkDwMQK2DHerMNJsIpJU= github.com/gorilla/mux v1.7.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw= +github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.1.3 h1:uXoZdcdA5XdXF3QzuSlheVRUvjl+1rKY7zBXL68L9RU= @@ -140,6 +160,9 @@ github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= +github.com/hashicorp/golang-lru v0.5.3 h1:YPkqC67at8FYaadspW/6uE0COsBxS2656RLEr8Bppgk= +github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= @@ -154,8 +177,11 @@ github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqx github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= +github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d h1:Z+RDyXzjKE0i2sTjZ/b1uxiGtPhFy34Ou/Tk0qwN0kM= +github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -181,10 +207,13 @@ github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kN github.com/mattn/go-isatty v0.0.6/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM= +github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= @@ -204,6 +233,8 @@ github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.4.0 h1:u3Z1r+oOXJIkxqw34zVhyPgjBsm6X2wn21NWs/HfSeg= github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo= +github.com/pelletier/go-toml v1.6.0 h1:aetoXYr0Tv7xRU/V4B4IZJ2QcbtMUFoNb3ORp7TzIK4= +github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -216,6 +247,8 @@ github.com/prometheus/client_golang v0.9.4/go.mod h1:oCXIBxdI62A4cR6aTRJCgetEjec github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20181020173914-7e9e6cabbd39/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= @@ -245,6 +278,8 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa/go.mod h1:oJyF+mSPHbB5mVY2iO9KV3pTt/QbIkGaO8gQ2WrDbP4= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -264,13 +299,19 @@ github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmq github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.0.0/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM= github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU= github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= +github.com/spf13/viper v1.5.0/go.mod h1:AkYRkVJF8TkSG/xet6PzXX+l39KhhXa2pdqVSxnTcn4= +github.com/spf13/viper v1.6.1 h1:VPZzIkznI1YhVMRi6vNFLHSwhnhReBfgTxIPccpfdZk= +github.com/spf13/viper v1.6.1/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -278,21 +319,29 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stumble/gorocksdb v0.0.3 h1:9UU+QA1pqFYJuf9+5p7z1IqdE5k0mma4UAeu2wmX8kA= github.com/stumble/gorocksdb v0.0.3/go.mod h1:v6IHdFBXk5DJ1K4FZ0xi+eY737quiiBxYtSWXadLybY= +github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965 h1:1oFLiOyVl+W7bnBzGhf7BbIv9loSFQcieWWYIjLqcAw= github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= github.com/tendermint/btcd v0.1.1 h1:0VcxPfflS2zZ3RiOAHkBiFUcPvbtRj5O7zHmcJWHV7s= github.com/tendermint/btcd v0.1.1/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrnDD5pN+U= github.com/tendermint/crypto v0.0.0-20180820045704-3764759f34a5 h1:u8i49c+BxloX3XQ55cvzFNXplizZP/q00i+IlttUjAU= github.com/tendermint/crypto v0.0.0-20180820045704-3764759f34a5/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk= +github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 h1:hqAk8riJvK4RMWx1aInLzndwxKalgi5rTqgfXxOxbEI= +github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk= github.com/tendermint/go-amino v0.14.1 h1:o2WudxNfdLNBwMyl2dqOJxiro5rfrEaU0Ugs6offJMk= github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso= github.com/tendermint/go-amino v0.15.0 h1:TC4e66P59W7ML9+bxio17CPKnxW3nKIRAYskntMAoRk= github.com/tendermint/go-amino v0.15.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= +github.com/tendermint/go-amino v0.15.1 h1:D2uk35eT4iTsvJd9jWIetzthE5C0/k2QmMFkCN+4JgQ= +github.com/tendermint/go-amino v0.15.1/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= github.com/tendermint/iavl v0.12.4 h1:hd1woxUGISKkfUWBA4mmmTwOua6PQZTJM/F0FDrmMV8= github.com/tendermint/iavl v0.12.4/go.mod h1:8LHakzt8/0G3/I8FUU0ReNx98S/EP6eyPJkAUvEXT/o= github.com/tendermint/tendermint v0.32.1/go.mod h1:jmPDAKuNkev9793/ivn/fTBnfpA9mGBww8MPRNPNxnU= github.com/tendermint/tendermint v0.32.7 h1:Szu5Fm1L3pvn3t4uQxPAcP+7ndZEQKgLie/yokM56rU= github.com/tendermint/tendermint v0.32.7/go.mod h1:D2+A3pNjY+Po72X0mTfaXorFhiVI8dh/Zg640FGyGtE= +github.com/tendermint/tendermint v0.32.8 h1:eOaLJGRi5x/Rb23fiVsxq9c5fZ/6O5QplExlGjNPDVI= +github.com/tendermint/tendermint v0.32.8/go.mod h1:5/B1XZjNYtVBso8o1l/Eg4A0Mhu42lDcmftoQl95j/E= github.com/tendermint/tm-db v0.1.1/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw= github.com/tendermint/tm-db v0.2.0 h1:rJxgdqn6fIiVJZy4zLpY1qVlyD0TU6vhkT4kEf71TQQ= github.com/tendermint/tm-db v0.2.0/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw= @@ -340,6 +389,10 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 h1:vsphBvatvfbhlb4PO1BYSr9dzugGxJ/SQHoNufZJq1w= golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -350,6 +403,7 @@ golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190404132500-923d25813098/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= @@ -361,12 +415,17 @@ google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoA google.golang.org/genproto v0.0.0-20181029155118-b69ba1387ce2/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 h1:nfPFGzJkUDX6uBmpN/pSw7MbOAWegH5QDQuoXFHedLg= google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/grpc v1.13.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.1 h1:q4XQuHFC6I28BKZpo6IYyb3mNO+l7lSOxRuYTCiDfXk= google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1 h1:wdKvqQk7IttEw92GoRyKG2IDrUIpgpj6H6m81yfeMW0= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= @@ -374,6 +433,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= @@ -381,5 +442,8 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= +gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/pkg/conv/num.go b/pkg/conv/num.go deleted file mode 100755 index 56f3d5b..0000000 --- a/pkg/conv/num.go +++ /dev/null @@ -1,29 +0,0 @@ -package conv - -import ( - "encoding/binary" - "io" - "math/big" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func SDKUint2Big(in sdk.Uint) *big.Int { - out, _ := new(big.Int).SetString(in.String(), 10) - return out -} - -func Uint642Bytes(in uint64) []byte { - b := make([]byte, 8, 8) - binary.BigEndian.PutUint64(b, in) - return b -} - -func ReadUint64(r io.Reader) (uint64, error) { - b := make([]byte, 8, 8) - _, err := r.Read(b) - if err != nil { - return 0, err - } - return binary.BigEndian.Uint64(b), nil -} diff --git a/pkg/conv/num_test.go b/pkg/conv/num_test.go deleted file mode 100755 index ef776b4..0000000 --- a/pkg/conv/num_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package conv - -import ( - "math/big" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/tendermint/dex-demo/testutil/testflags" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func TestUint2Big(t *testing.T) { - testflags.UnitTest(t) - a := sdk.NewUint(1) - b := big.NewInt(1) - assert.Equal(t, "1", SDKUint2Big(a).String()) - assert.EqualValues(t, b, SDKUint2Big(a)) -} diff --git a/pkg/matcheng/fill.go b/pkg/matcheng/fill.go index b4daa82..4d4a9ee 100755 --- a/pkg/matcheng/fill.go +++ b/pkg/matcheng/fill.go @@ -1,13 +1,11 @@ package matcheng import ( - "github.com/tendermint/dex-demo/types/store" - sdk "github.com/cosmos/cosmos-sdk/types" ) type Fill struct { - OrderID store.EntityID + OrderID sdk.Uint QtyFilled sdk.Uint QtyUnfilled sdk.Uint } diff --git a/pkg/matcheng/matcher.go b/pkg/matcheng/matcher.go index 0b30367..2e60bd5 100755 --- a/pkg/matcheng/matcher.go +++ b/pkg/matcheng/matcher.go @@ -4,15 +4,12 @@ import ( "sort" "sync" - "github.com/tendermint/dex-demo/pkg/conv" - "github.com/tendermint/dex-demo/pkg/log" - "github.com/tendermint/dex-demo/types/store" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/dex-demo/pkg/log" ) type Order struct { - ID store.EntityID + ID sdk.Uint Price sdk.Uint Quantity sdk.Uint } @@ -53,7 +50,7 @@ func NewMatcher() *Matcher { // degen case: vertical line (then choose midpoint) // other degen case: no overlap. -func (m *Matcher) EnqueueOrder(oType Direction, id store.EntityID, price sdk.Uint, quantity sdk.Uint) { +func (m *Matcher) EnqueueOrder(oType Direction, id sdk.Uint, price sdk.Uint, quantity sdk.Uint) { m.mtx.Lock() defer m.mtx.Unlock() @@ -231,8 +228,8 @@ func (m *Matcher) Match() *MatchResults { } } - aggDemandDec := sdk.NewDecFromBigInt(conv.SDKUint2Big(aggDemand)) - aggSupplyDec := sdk.NewDecFromBigInt(conv.SDKUint2Big(aggSupply)) + aggDemandDec := sdk.NewDecFromBigInt(aggDemand.BigInt()) + aggSupplyDec := sdk.NewDecFromBigInt(aggSupply.BigInt()) proRataDec := aggSupplyDec.Quo(aggDemandDec) proRataRecip := sdk.OneDec().Quo(proRataDec) @@ -252,7 +249,7 @@ func (m *Matcher) Match() *MatchResults { if overOne { qtyInt = bid.Quantity } else { - qtyDec := sdk.NewDecFromBigInt(conv.SDKUint2Big(bid.Quantity)).Mul(proRataDec).Ceil() + qtyDec := sdk.NewDecFromBigInt(bid.Quantity.BigInt()).Mul(proRataDec).Ceil() qtyInt = sdk.NewUintFromString(qtyDec.RoundInt().String()) if matchedBidVolume.Add(qtyDec).GT(maxBidVolume) { @@ -282,7 +279,7 @@ func (m *Matcher) Match() *MatchResults { var qtyInt sdk.Uint if overOne { - qtyDec := proRataRecip.Mul(sdk.NewDecFromBigInt(conv.SDKUint2Big(ask.Quantity))).Ceil() + qtyDec := proRataRecip.Mul(sdk.NewDecFromBigInt(ask.Quantity.BigInt())).Ceil() qtyInt = sdk.NewUintFromString(qtyDec.RoundInt().String()) if matchedAskVolume.Add(qtyDec).GT(maxAskVolume) { @@ -340,7 +337,7 @@ func (m *Matcher) enqueueBid(order *Order) { i := sort.Search(len(m.bids), func(i int) bool { tester := m.bids[i] if tester.Price.Equal(order.Price) { - return tester.ID.Cmp(order.ID) < 0 + return tester.ID.LT(order.ID) } return tester.Price.GT(order.Price) }) @@ -361,7 +358,7 @@ func (m *Matcher) enqueueAsk(order *Order) { i := sort.Search(len(m.asks), func(i int) bool { tester := m.asks[i] if tester.Price.Equal(order.Price) { - return tester.ID.Cmp(order.ID) < 0 + return tester.ID.LT(order.ID) } return tester.Price.GT(order.Price) }) diff --git a/pkg/matcheng/matcher_bench_test.go b/pkg/matcheng/matcher_bench_test.go index de9ff0a..84e6b4b 100755 --- a/pkg/matcheng/matcher_bench_test.go +++ b/pkg/matcheng/matcher_bench_test.go @@ -4,24 +4,22 @@ import ( "math/rand" "testing" - "github.com/tendermint/dex-demo/types/store" - sdk "github.com/cosmos/cosmos-sdk/types" ) func BenchmarkMatching(b *testing.B) { - id := store.NewEntityID(0) + id := sdk.ZeroUint() matcher := GetMatcher() b.ResetTimer() for i := 0; i < b.N; i++ { b.StopTimer() matcher.Reset() for j := 0; j < 10000; j++ { - id = id.Inc() + id = id.Add(sdk.OneUint()) matcher.EnqueueOrder(Bid, id, sdk.NewUint(uint64(j)), sdk.NewUint(uint64(j))) } for j := 100; j < 11000; j++ { - id := id.Inc() + id := id.Add(sdk.OneUint()) matcher.EnqueueOrder(Ask, id, sdk.NewUint(uint64(j)), sdk.NewUint(uint64(j))) } b.StartTimer() @@ -30,7 +28,7 @@ func BenchmarkMatching(b *testing.B) { } func BenchmarkQueueing(b *testing.B) { - id := store.NewEntityID(0) + id := sdk.ZeroUint() matcher := GetMatcher() b.ResetTimer() @@ -39,10 +37,10 @@ func BenchmarkQueueing(b *testing.B) { matcher.Reset() b.StartTimer() for j := 0; j < 100; j++ { - id = id.Inc() + id = id.Add(sdk.OneUint()) price := sdk.NewUint(rand.Uint64()) quantity := sdk.NewUint(rand.Uint64()) - matcher.EnqueueOrder(Bid, id.Inc(), price, quantity) + matcher.EnqueueOrder(Bid, id.Add(sdk.OneUint()), price, quantity) } } } diff --git a/pkg/matcheng/matcher_test.go b/pkg/matcheng/matcher_test.go index 6b6d9cd..0799bfc 100755 --- a/pkg/matcheng/matcher_test.go +++ b/pkg/matcheng/matcher_test.go @@ -11,11 +11,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/dex-demo/testutil" "github.com/tendermint/dex-demo/testutil/testflags" - "github.com/tendermint/dex-demo/types/store" - - sdk "github.com/cosmos/cosmos-sdk/types" ) func TestMatcher_Golden(t *testing.T) { @@ -63,16 +61,16 @@ func doMatch(bids [][2]uint64, asks [][2]uint64) (*MatchResults, map[string]Fill matcher := GetMatcher() defer ReturnMatcher(matcher) - id := store.NewEntityID(0) + id := sdk.ZeroUint() if bids != nil { for _, bid := range bids { - id = id.Inc() + id = id.Add(sdk.OneUint()) matcher.EnqueueOrder(Bid, id, sdk.NewUint(bid[0]), sdk.NewUint(bid[1])) } } if asks != nil { for _, ask := range asks { - id = id.Inc() + id = id.Add(sdk.OneUint()) matcher.EnqueueOrder(Ask, id, sdk.NewUint(ask[0]), sdk.NewUint(ask[1])) } } diff --git a/pkg/matcheng/normalize.go b/pkg/matcheng/normalize.go index 6a671ee..55a9a58 100755 --- a/pkg/matcheng/normalize.go +++ b/pkg/matcheng/normalize.go @@ -5,8 +5,6 @@ import ( "math" sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/tendermint/dex-demo/pkg/conv" ) const ( @@ -16,8 +14,8 @@ const ( var divisor = sdk.NewDec(int64(math.Pow(float64(10), float64(AssetDecimals)))) func NormalizeQuoteQuantity(quotePrice sdk.Uint, baseQuantity sdk.Uint) (sdk.Uint, error) { - quotePDec := sdk.NewDecFromBigInt(conv.SDKUint2Big(quotePrice)) - baseQDec := sdk.NewDecFromBigInt(conv.SDKUint2Big(baseQuantity)) + quotePDec := sdk.NewDecFromBigInt(quotePrice.BigInt()) + baseQDec := sdk.NewDecFromBigInt(baseQuantity.BigInt()) baseMult := baseQDec.Quo(divisor) res := sdk.NewUintFromBigInt(quotePDec.Mul(baseMult).TruncateInt().BigInt()) var err error diff --git a/pkg/matcheng/normalize_test.go b/pkg/matcheng/normalize_test.go index f9792c6..a880de7 100755 --- a/pkg/matcheng/normalize_test.go +++ b/pkg/matcheng/normalize_test.go @@ -17,10 +17,10 @@ func TestNormalizeQuoteQuantity(t *testing.T) { {testutil.ToBaseUnitsDecimals(1, 0), testutil.ToBaseUnitsDecimals(10, 0), testutil.ToBaseUnitsDecimals(10, 0)}, {testutil.ToBaseUnitsDecimals(10, 0), testutil.ToBaseUnitsDecimals(1, 3), testutil.ToBaseUnitsDecimals(10, 3)}, {testutil.ToBaseUnitsDecimals(2, 2), testutil.ToBaseUnitsDecimals(3, 3), testutil.ToBaseUnitsDecimals(6, 5)}, - {sdk.NewUint(1), testutil.ToBaseUnitsDecimals(1, 0), sdk.NewUint(1)}, + {sdk.OneUint(), testutil.ToBaseUnitsDecimals(1, 0), sdk.OneUint()}, } - _, err := NormalizeQuoteQuantity(sdk.NewUint(1), sdk.NewUint(1)) + _, err := NormalizeQuoteQuantity(sdk.OneUint(), sdk.OneUint()) assert.Error(t, err) assert.Contains(t, err.Error(), "quantity too small to represent") diff --git a/pkg/matcheng/plot_test.go b/pkg/matcheng/plot_test.go index 9c822ee..187d052 100755 --- a/pkg/matcheng/plot_test.go +++ b/pkg/matcheng/plot_test.go @@ -32,7 +32,7 @@ func TestPlotCurves(t *testing.T) { res := &MatchResults{ BidAggregates: []AggregatePrice{ - {sdk.NewUint(1), sdk.NewUint(30)}, + {sdk.OneUint(), sdk.NewUint(30)}, {sdk.NewUint(2), sdk.NewUint(20)}, {sdk.NewUint(3), sdk.NewUint(10)}, }, diff --git a/storeutil/doc.go b/storeutil/doc.go new file mode 100644 index 0000000..863ac72 --- /dev/null +++ b/storeutil/doc.go @@ -0,0 +1,20 @@ +package storeutil + +/* +Package storeutil contains various helper methods that make working with +Cosmos SDK KVStores simpler. + +Most of the methods are self-explanatory, however Increment/GetSeq() +deserve special attention. These methods increment and get an sdk.Uint +stored in the KVStore for the purposes of mimicking an auto-increment column +in SQL. + +IncrementSeq takes three arguments: an sdk.Context, an sdk.StoreKey, and +a byte slice that represents the key at which the sdk.Uint is being stored. +Upon execution, it will retrieve that Uint, increment it, and store the +incremented version in the database. GetSeq() is similar, except it just +returns the sdk.Uint. + +This is useful in situations where rows in an sdk.KVStore are assigned +an automatically-incrementing sdk.Uint at creation time. + */ \ No newline at end of file diff --git a/storeutil/keys.go b/storeutil/keys.go new file mode 100755 index 0000000..53fd5b7 --- /dev/null +++ b/storeutil/keys.go @@ -0,0 +1,70 @@ +package storeutil + +import ( + "bytes" + "encoding/binary" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// PrefixKeyString returns a byte slice +// consisting of the prefix string concatenated +// with all subkeys. +func PrefixKeyString(prefix string, subkeys ...[]byte) []byte { + buf := [][]byte{[]byte(prefix)} + return PrefixKeyBytes(append(buf, subkeys...)...) +} + +// PrefixKeyBytes returns a byte slice consisting +// of all subkeys concatenated together. +func PrefixKeyBytes(subkeys ...[]byte) []byte { + if len(subkeys) == 0 { + return []byte{} + } + + var buf bytes.Buffer + buf.Write(subkeys[0]) + + if len(subkeys) > 1 { + for _, sk := range subkeys[1:] { + if len(sk) == 0 { + continue + } + + buf.WriteRune('/') + buf.Write(sk) + } + } + + return buf.Bytes() +} + +// Int64Subkey returns a byte slice +// from the provided subkey suitable +// for use as a key in the store. +// This method will panic on negative +// numbers. +func Int64Subkey(subkey int64) []byte { + if subkey < 0 { + panic("cannot use negative numbers in subkeys") + } + return Uint64Subkey(uint64(subkey)) +} + +// Uint64Subkey returns a byte slice +// from the provided subkey suitable +// for use as a key in the store. +func Uint64Subkey(subkey uint64) []byte { + b := make([]byte, 8, 8) + binary.BigEndian.PutUint64(b, subkey) + return b +} + +// SDKUintSubkey returns a byte slice +// from the provided subkey suitable +// for use an iterable key in the store. +func SDKUintSubkey(subkey sdk.Uint) []byte { + var buf [32]byte + b := subkey.BigInt().Bytes() + copy(buf[32-len(b):], b) + return buf[:] +} diff --git a/storeutil/keys_test.go b/storeutil/keys_test.go new file mode 100755 index 0000000..4a84825 --- /dev/null +++ b/storeutil/keys_test.go @@ -0,0 +1,81 @@ +package storeutil + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/assert" + "github.com/tendermint/dex-demo/testutil/testflags" + "math" + "testing" +) + +func TestPrefixKey(t *testing.T) { + testflags.UnitTest(t) + out1 := PrefixKeyString("fooprefix") + assert.Equal(t, "fooprefix", string(out1)) + out2 := PrefixKeyString("fooprefix", []byte("sub1"), []byte("sub2")) + assert.Equal(t, "fooprefix/sub1/sub2", string(out2)) + out3 := PrefixKeyString("fooprefix", []byte{}, []byte("sub1")) + assert.Equal(t, "fooprefix/sub1", string(out3)) + out4 := PrefixKeyBytes() + assert.Equal(t, 0, len(out4)) +} + +func TestUint64AndInt64Subkey(t *testing.T) { + tests := []struct { + in int64 + out []byte + }{ + { + 0, + []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + }, + { + 1000, + []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe8}, + }, + { + math.MaxInt64, + []byte{0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, + }, + } + + for _, tt := range tests { + assert.Equal(t, tt.out, Int64Subkey(tt.in)) + assert.Equal(t, tt.out, Uint64Subkey(uint64(tt.in))) + } + + assert.Equal(t, []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, Uint64Subkey(math.MaxUint64)) +} + +func TestInt64Subkey_Panics(t *testing.T) { + assert.Panics(t, func() { + Int64Subkey(-1) + }) + assert.Panics(t, func() { + Int64Subkey(-10) + }) +} + +func TestSDKUintSubkey(t *testing.T) { + tests := []struct { + in sdk.Uint + out []byte + }{ + { + sdk.ZeroUint(), + []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, + }, + { + sdk.OneUint(), + []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1}, + }, + { + sdk.NewUint(1234567890), + []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x49, 0x96, 0x2, 0xd2}, + }, + } + + for _, tt := range tests { + assert.Equal(t, tt.out, SDKUintSubkey(tt.in)) + } +} diff --git a/storeutil/operations.go b/storeutil/operations.go new file mode 100755 index 0000000..e90b370 --- /dev/null +++ b/storeutil/operations.go @@ -0,0 +1,92 @@ +package storeutil + +import ( + "errors" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var ( + ErrStoreKeyNotFound = errors.New("key not found") + ErrKeyExists = errors.New("key exists") +) + +// Get unmarshals a binary object in the store +// identified by sk and key into the object +// identified by proto. +func Get(ctx sdk.Context, sk sdk.StoreKey, cdc *codec.Codec, key []byte, proto interface{}) error { + store := ctx.KVStore(sk) + b := store.Get(key) + if b == nil { + return ErrStoreKeyNotFound + } + cdc.MustUnmarshalBinaryBare(b, proto) + return nil +} + +// Create inserts val into the store +// identified by sk and at the key +// identified by key. Create will return +// an error if the key already exists. +func Create(ctx sdk.Context, sk sdk.StoreKey, cdc *codec.Codec, key []byte, val interface{}) error { + if Has(ctx, sk, key) { + return ErrKeyExists + } + store := ctx.KVStore(sk) + store.Set(key, cdc.MustMarshalBinaryBare(val)) + return nil +} + +// Update inserts val into the store +// identified by sk and at the key +// identified by key. Update will return +// an error if the key does not exist. +func Update(ctx sdk.Context, sk sdk.StoreKey, cdc *codec.Codec, key []byte, val interface{}) error { + if !Has(ctx, sk, key) { + return ErrStoreKeyNotFound + } + store := ctx.KVStore(sk) + store.Set(key, cdc.MustMarshalBinaryBare(val)) + return nil +} + +// Del deletes the value in the store +// identified by sk and at the key +// identified by key. Del will return an error +// if the key does not exist. +func Del(ctx sdk.Context, sk sdk.StoreKey, key []byte) error { + if !Has(ctx, sk, key) { + return ErrStoreKeyNotFound + } + store := ctx.KVStore(sk) + store.Delete(key) + return nil +} + +// Has returns true if the specified key +// exists in the store identified by sk. +func Has(ctx sdk.Context, sk sdk.StoreKey, key []byte) bool { + store := ctx.KVStore(sk) + return store.Has(key) +} + +// IncrementSeq increments the Uint in the store +// identified by sk at the key seqKey. +func IncrementSeq(ctx sdk.Context, sk sdk.StoreKey, seqKey []byte) sdk.Uint { + store := ctx.KVStore(sk) + seq := GetSeq(ctx, sk, seqKey).Add(sdk.OneUint()) + store.Set(seqKey, []byte(seq.String())) + return seq +} + +// GetSeq returns the Uint in the store +// identified by sk at the key seqKey. +func GetSeq(ctx sdk.Context, sk sdk.StoreKey, seqKey []byte) sdk.Uint { + store := ctx.KVStore(sk) + if !store.Has(seqKey) { + return sdk.ZeroUint() + } + + b := store.Get(seqKey) + return sdk.NewUintFromString(string(b)) +} \ No newline at end of file diff --git a/storeutil/operations_test.go b/storeutil/operations_test.go new file mode 100644 index 0000000..64a54e0 --- /dev/null +++ b/storeutil/operations_test.go @@ -0,0 +1,89 @@ +package storeutil + +import ( + "github.com/cosmos/cosmos-sdk/store" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/tendermint/go-amino" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + db "github.com/tendermint/tm-db" + "testing" + "time" +) + +var ( + testSKName = "test" + testKey = []byte("testkey") +) + +func upsert(ctx sdk.Context, sk sdk.StoreKey, cdc *amino.Codec, key []byte, val interface{}) { + s := ctx.KVStore(sk) + s.Set(key, cdc.MustMarshalBinaryBare(val)) +} + +func TestSetAndGet(t *testing.T) { + cdc := amino.NewCodec() + ctx, sk := mockApp(t) + upsert(ctx, sk, cdc, testKey, 12345) + var val int + err := Get(ctx, sk, cdc, testKey, &val) + require.NoError(t, err) + assert.EqualValues(t, 12345, val) + assert.Error(t, Get(ctx, sk, cdc, []byte("not here"), &val)) +} + +func TestSetNotExists(t *testing.T) { + cdc := amino.NewCodec() + ctx, sk := mockApp(t) + assert.NoError(t, Create(ctx, sk, cdc, testKey, 12345)) + assert.Error(t, Create(ctx, sk, cdc, testKey, 12345)) +} + +func TestSetExists(t *testing.T) { + cdc := amino.NewCodec() + ctx, sk := mockApp(t) + assert.Error(t, Update(ctx, sk, cdc, testKey, 12345)) + upsert(ctx, sk, cdc, testKey, 12345) + assert.NoError(t, Update(ctx, sk, cdc, testKey, 54321)) +} + +func TestDel(t *testing.T) { + cdc := amino.NewCodec() + ctx, sk := mockApp(t) + assert.Error(t, Del(ctx, sk, testKey)) + upsert(ctx, sk, cdc, testKey, 12345) + assert.NoError(t, Del(ctx, sk, testKey)) + assert.False(t, Has(ctx, sk, testKey)) +} + +func TestHas(t *testing.T) { + cdc := amino.NewCodec() + ctx, sk := mockApp(t) + assert.False(t, Has(ctx, sk, testKey)) + upsert(ctx, sk, cdc, testKey, 12345) + assert.True(t, Has(ctx, sk, testKey)) +} + +func mockApp(t *testing.T) (sdk.Context, sdk.StoreKey) { + keys := sdk.NewKVStoreKeys(testSKName) + ms := store.NewCommitMultiStore(db.NewMemDB()) + ms.MountStoreWithDB(keys[testSKName], sdk.StoreTypeIAVL, db.NewMemDB()) + require.NoError(t, ms.LoadVersion(0)) + hdr := abci.Header{ChainID: "unit-test-chain", Height: 1, Time: time.Unix(1558332092, 0)} + return sdk.NewContext(ms, hdr, false, log.NewNopLogger()), keys[testSKName] +} + +func TestIncrementSeq(t *testing.T) { + ctx, sk := mockApp(t) + assert.True(t, sdk.OneUint().Equal(IncrementSeq(ctx, sk, testKey))) + assert.True(t, sdk.NewUint(2).Equal(IncrementSeq(ctx, sk, testKey))) +} + +func TestGetSeq(t *testing.T) { + ctx, sk := mockApp(t) + assert.True(t, sdk.ZeroUint().Equal(GetSeq(ctx, sk, testKey))) + IncrementSeq(ctx, sk, testKey) + assert.True(t, sdk.OneUint().Equal(GetSeq(ctx, sk, testKey))) +} diff --git a/testutil/assert.go b/testutil/assert.go index 96140ff..47af095 100755 --- a/testutil/assert.go +++ b/testutil/assert.go @@ -6,8 +6,6 @@ import ( "github.com/stretchr/testify/assert" - "github.com/tendermint/dex-demo/types/store" - sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -19,10 +17,6 @@ func AssertEqualInts(t *testing.T, a sdk.Int, b sdk.Int, msgAndArgs ...interface assert.Equal(t, a.String(), b.String(), msgAndArgs...) } -func AssertEqualEntityIDs(t *testing.T, a store.EntityID, b store.EntityID, msgAndArgs ...interface{}) { - assert.Equal(t, a.String(), b.String(), msgAndArgs...) -} - func AssertEqualHex(t *testing.T, exp string, actual []byte) { assert.Equal(t, exp, hex.EncodeToString(actual)) } diff --git a/types/errs/errs.go b/types/errs/errs.go index b6d32ca..7bf3e8f 100755 --- a/types/errs/errs.go +++ b/types/errs/errs.go @@ -2,12 +2,12 @@ package errs import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/dex-demo/storeutil" ) const ( _ sdk.CodeType = iota CodeNotFound - CodeAlreadyExists CodeInvalidArgument CodeMarshalFailure CodeUnmarshalFailure @@ -23,10 +23,6 @@ func ErrNotFound(msg string) sdk.Error { return newErrWithUEXCodespace(CodeNotFound, msg) } -func ErrAlreadyExists(msg string) sdk.Error { - return newErrWithUEXCodespace(CodeAlreadyExists, msg) -} - func ErrInvalidArgument(msg string) sdk.Error { return newErrWithUEXCodespace(CodeInvalidArgument, msg) } @@ -39,6 +35,24 @@ func ErrUnmarshalFailure(msg string) sdk.Error { return newErrWithUEXCodespace(CodeUnmarshalFailure, msg) } +func WrapNotFound(err error) sdk.Error { + if err == nil { + return nil + } + if err == storeutil.ErrStoreKeyNotFound { + return ErrNotFound(err.Error()) + } + return sdk.ErrInternal(err.Error()) +} + +func WrapOrNil(err error) sdk.Error { + if err == nil { + return nil + } + + return sdk.ErrInternal(err.Error()) +} + func ErrOrBlankResult(err sdk.Error) sdk.Result { if err == nil { return sdk.Result{} diff --git a/types/events.go b/types/events.go index 2af4fcb..0f6a9d8 100755 --- a/types/events.go +++ b/types/events.go @@ -3,10 +3,8 @@ package types 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 EventHandler interface { @@ -16,15 +14,15 @@ type EventHandler interface { type Batch struct { BlockNumber int64 BlockTime time.Time - MarketID store.EntityID + MarketID sdk.Uint ClearingPrice sdk.Uint Bids []matcheng.AggregatePrice Asks []matcheng.AggregatePrice } type Fill struct { - OrderID store.EntityID - MarketID store.EntityID + OrderID sdk.Uint + MarketID sdk.Uint Owner sdk.AccAddress Pair string Direction matcheng.Direction @@ -36,9 +34,9 @@ type Fill struct { } type OrderCreated struct { - ID store.EntityID + ID sdk.Uint Owner sdk.AccAddress - MarketID store.EntityID + MarketID sdk.Uint Direction matcheng.Direction Price sdk.Uint Quantity sdk.Uint @@ -47,12 +45,12 @@ type OrderCreated struct { } type OrderCancelled struct { - OrderID store.EntityID + OrderID sdk.Uint } type BurnCreated struct { - ID store.EntityID - AssetID store.EntityID + ID sdk.Uint + AssetID sdk.Uint BlockNumber int64 Burner sdk.AccAddress Beneficiary []byte diff --git a/types/store/entity_id.go b/types/store/entity_id.go deleted file mode 100755 index 46b86e2..0000000 --- a/types/store/entity_id.go +++ /dev/null @@ -1,100 +0,0 @@ -package store - -import ( - "math/big" - - "github.com/tendermint/dex-demo/pkg/conv" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -var ZeroEntityID = NewEntityID(0) - -type EntityID sdk.Uint - -func NewEntityID(id uint64) EntityID { - return EntityID(sdk.NewUint(id)) -} - -func NewEntityIDFromString(str string) EntityID { - return EntityID(sdk.NewUintFromString(str)) -} - -func NewEntityIDFromBytes(b []byte) EntityID { - s := new(big.Int).SetBytes(b) - return EntityID(sdk.NewUintFromBigInt(s)) -} - -func (id EntityID) String() string { - return sdk.Uint(id).String() -} - -func (id EntityID) Bytes() []byte { - var buf [32]byte - bn := conv.SDKUint2Big(sdk.Uint(id)) - b := bn.Bytes() - copy(buf[32-len(b):], b) - return buf[:] -} - -func (id EntityID) Inc() EntityID { - return EntityID(sdk.Uint(id).Add(sdk.OneUint())) -} - -func (id EntityID) Dec() EntityID { - if !id.IsDefined() { - return id - } - - return EntityID(sdk.Uint(id).Sub(sdk.OneUint())) -} - -func (id EntityID) Cmp(b EntityID) int { - uintA := sdk.Uint(id) - uintB := sdk.Uint(b) - - if uintA.GT(uintB) { - return 1 - } - - if uintA.LT(uintB) { - return -1 - } - - return 0 -} - -func (id EntityID) IsDefined() bool { - return !sdk.Uint(id).IsZero() -} - -func (id EntityID) IsZero() bool { - return sdk.Uint(id).IsZero() -} - -func (id EntityID) Equals(other EntityID) bool { - return sdk.Uint(id).Equal(sdk.Uint(other)) -} - -func (id EntityID) MarshalAmino() (string, error) { - return sdk.Uint(id).MarshalAmino() -} - -func (id *EntityID) UnmarshalAmino(text string) error { - var u sdk.Uint - err := u.UnmarshalAmino(text) - if err != nil { - return err - } - - *id = EntityID(u) - return nil -} - -func (id *EntityID) UnmarshalJSON(data []byte) error { - return (*sdk.Uint)(id).UnmarshalJSON(data) -} - -func (id EntityID) MarshalJSON() ([]byte, error) { - return sdk.Uint(id).MarshalJSON() -} diff --git a/types/store/entity_id_test.go b/types/store/entity_id_test.go deleted file mode 100755 index 347f7cd..0000000 --- a/types/store/entity_id_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package store - -import ( - "encoding/hex" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestEntityID(t *testing.T) { - t.Run("should be stringifiable", func(t *testing.T) { - assert.Equal(t, "10", NewEntityID(10).String()) - }) - t.Run("should be instantiable from a string", func(t *testing.T) { - assert.EqualValues(t, NewEntityID(1), NewEntityIDFromString("1")) - }) - t.Run("should be incrementable without mutation", func(t *testing.T) { - a := NewEntityID(10) - assert.EqualValues(t, NewEntityID(11), a.Inc()) - assert.EqualValues(t, NewEntityID(10), a) - }) - t.Run("should return IsDefined()", func(t *testing.T) { - assert.False(t, NewEntityID(0).IsDefined()) - assert.True(t, NewEntityID(1).IsDefined()) - }) - t.Run("should define equality", func(t *testing.T) { - assert.True(t, NewEntityID(1).Equals(NewEntityID(1))) - assert.False(t, NewEntityID(2).Equals(NewEntityID(1))) - }) - t.Run("should return a fixed length bytes representation", func(t *testing.T) { - res := hex.EncodeToString(NewEntityID(1000).Bytes()) - assert.Equal(t, 64, len(res)) - assert.EqualValues(t, "00000000000000000000000000000000000000000000000000000000000003e8", res) - }) -} diff --git a/types/store/get_set.go b/types/store/get_set.go deleted file mode 100755 index 563e30c..0000000 --- a/types/store/get_set.go +++ /dev/null @@ -1,70 +0,0 @@ -package store - -import ( - "github.com/tendermint/dex-demo/types/errs" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func Get(ctx sdk.Context, sk sdk.StoreKey, cdc *codec.Codec, key []byte, proto interface{}) sdk.Error { - store := ctx.KVStore(sk) - b := store.Get(key) - if b == nil { - return errs.ErrNotFound("not found") - } - cdc.MustUnmarshalBinaryBare(b, proto) - return nil -} - -func Set(ctx sdk.Context, sk sdk.StoreKey, cdc *codec.Codec, key []byte, val interface{}) { - store := ctx.KVStore(sk) - store.Set(key, cdc.MustMarshalBinaryBare(val)) -} - -func SetNotExists(ctx sdk.Context, sk sdk.StoreKey, cdc *codec.Codec, key []byte, val interface{}) sdk.Error { - if Has(ctx, sk, key) { - return errs.ErrAlreadyExists("already exists") - } - Set(ctx, sk, cdc, key, val) - return nil -} - -func SetExists(ctx sdk.Context, sk sdk.StoreKey, cdc *codec.Codec, key []byte, val interface{}) sdk.Error { - if !Has(ctx, sk, key) { - return errs.ErrNotFound("not found") - } - Set(ctx, sk, cdc, key, val) - return nil -} - -func Del(ctx sdk.Context, sk sdk.StoreKey, key []byte) sdk.Error { - if !Has(ctx, sk, key) { - return errs.ErrNotFound("not found") - } - store := ctx.KVStore(sk) - store.Delete(key) - return nil -} - -func Has(ctx sdk.Context, sk sdk.StoreKey, key []byte) bool { - store := ctx.KVStore(sk) - return store.Has(key) -} - -func IncrementSeq(ctx sdk.Context, sk sdk.StoreKey, seqKey []byte) EntityID { - store := ctx.KVStore(sk) - seq := GetSeq(ctx, sk, seqKey).Inc() - store.Set(seqKey, []byte(seq.String())) - return seq -} - -func GetSeq(ctx sdk.Context, sk sdk.StoreKey, seqKey []byte) EntityID { - store := ctx.KVStore(sk) - if !store.Has(seqKey) { - return ZeroEntityID - } - - b := store.Get(seqKey) - return NewEntityIDFromString(string(b)) -} diff --git a/types/store/incrementing.go b/types/store/incrementing.go deleted file mode 100755 index 15dd201..0000000 --- a/types/store/incrementing.go +++ /dev/null @@ -1,94 +0,0 @@ -package store - -import ( - "errors" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -const ( - headKey = "head" - valueKey = "value" -) - -var ErrNoEntities = errors.New("no entities defined yet") - -type Identifiable interface { - GetID() EntityID - SetID(id EntityID) -} - -type Incrementing struct { - backend KVStore - cdc *codec.Codec -} - -func NewIncrementing(backend KVStore, cdc *codec.Codec) *Incrementing { - return &Incrementing{ - backend: backend, - cdc: cdc, - } -} - -func (inc *Incrementing) ByID(id EntityID, val interface{}) error { - b := inc.backend.Get(inc.ValueKey(id)) - if b == nil { - return errors.New("not found") - } - return inc.cdc.UnmarshalBinaryBare(b, val) -} - -func (inc *Incrementing) Head(val interface{}) error { - head := inc.HeadID() - if !head.IsDefined() { - return ErrNoEntities - } - - return inc.ByID(head, val) -} - -func (inc *Incrementing) HasID(id EntityID) bool { - return inc.backend.Has(inc.ValueKey(id)) -} - -func (inc *Incrementing) Iterator() sdk.Iterator { - return KVStorePrefixIterator(inc.backend, []byte(valueKey)) -} - -func (inc *Incrementing) ReverseIterator() sdk.Iterator { - return KVStoreReversePrefixIterator(inc.backend, []byte(valueKey)) -} - -func (inc *Incrementing) Insert(val Identifiable) error { - if !val.GetID().IsZero() { - return errors.New("id must be zero") - } - - id := inc.HeadID().Inc() - val.SetID(id) - b, err := inc.cdc.MarshalBinaryBare(val) - if err != nil { - return err - } - inc.backend.Set(inc.ValueKey(id), b) - inc.backend.Set(inc.HeadKey(), id.Bytes()) - return nil -} - -func (inc *Incrementing) HeadID() EntityID { - b := inc.backend.Get(inc.HeadKey()) - if b == nil { - return NewEntityID(0) - } - - return NewEntityIDFromBytes(b) -} - -func (inc *Incrementing) HeadKey() []byte { - return []byte(headKey) -} - -func (inc *Incrementing) ValueKey(id EntityID) []byte { - return PrefixKeyString(valueKey, id.Bytes()) -} diff --git a/types/store/incrementing_test.go b/types/store/incrementing_test.go deleted file mode 100755 index c769e0d..0000000 --- a/types/store/incrementing_test.go +++ /dev/null @@ -1,64 +0,0 @@ -package store - -import ( - "testing" - - "github.com/stretchr/testify/assert" - dbm "github.com/tendermint/tm-db" - - "github.com/tendermint/dex-demo/testutil/testflags" - - "github.com/cosmos/cosmos-sdk/codec" -) - -type incrementingTest struct { - ID EntityID - Foo string - Bar int -} - -func (it *incrementingTest) GetID() EntityID { - return it.ID -} - -func (it *incrementingTest) SetID(id EntityID) { - it.ID = id -} - -func TestIncrementing(t *testing.T) { - testflags.UnitTest(t) - db := dbm.NewMemDB() - inc := NewIncrementing(db, codec.New()) - data := incrementingTest{ - ID: NewEntityID(1), - Foo: "hello", - Bar: 1, - } - - err := inc.Insert(&data) - assert.Error(t, err) - assert.Contains(t, err.Error(), "id must be zero") - - data.ID = NewEntityID(0) - err = inc.Insert(&data) - assert.NoError(t, err) - - var retrieved incrementingTest - err = inc.ByID(data.ID, &retrieved) - assert.NoError(t, err) - assert.Equal(t, "hello", retrieved.Foo) - assert.Equal(t, 1, retrieved.Bar) - assert.True(t, NewEntityID(1).Equals(retrieved.ID)) - assert.True(t, inc.HasID(retrieved.ID)) - - err = inc.ByID(NewEntityID(999), &retrieved) - assert.Error(t, err) - assert.Contains(t, err.Error(), "not found") - - data.ID = NewEntityID(0) - err = inc.Insert(&data) - assert.NoError(t, err) - expID := NewEntityID(2) - assert.True(t, inc.HasID(expID)) - assert.True(t, expID.Equals(inc.HeadID())) -} diff --git a/types/store/keys.go b/types/store/keys.go deleted file mode 100755 index 067b29b..0000000 --- a/types/store/keys.go +++ /dev/null @@ -1,53 +0,0 @@ -package store - -import ( - "bytes" - "encoding/binary" -) - -func PrefixKeyString(prefix string, subkeys ...[]byte) []byte { - buf := [][]byte{[]byte(prefix)} - return PrefixKeyBytes(append(buf, subkeys...)...) -} - -func PrefixKeyBytes(subkeys ...[]byte) []byte { - if len(subkeys) == 0 { - return []byte{} - } - - var buf bytes.Buffer - buf.Write(subkeys[0]) - - if len(subkeys) > 1 { - for _, sk := range subkeys[1:] { - if len(sk) == 0 { - continue - } - - buf.WriteRune('/') - buf.Write(sk) - } - } - - return buf.Bytes() -} - -func IntSubkey(subkey int) []byte { - if subkey < 0 { - panic("cannot use negative numbers in subkeys") - } - return Uint64Subkey(uint64(subkey)) -} - -func Int64Subkey(subkey int64) []byte { - if subkey < 0 { - panic("cannot use negative numbers in subkeys") - } - return Uint64Subkey(uint64(subkey)) -} - -func Uint64Subkey(subkey uint64) []byte { - b := make([]byte, 8, 8) - binary.BigEndian.PutUint64(b, subkey) - return b -} diff --git a/types/store/keys_test.go b/types/store/keys_test.go deleted file mode 100755 index b4e5ce5..0000000 --- a/types/store/keys_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package store - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/tendermint/dex-demo/testutil/testflags" -) - -func TestPrefixKey(t *testing.T) { - testflags.UnitTest(t) - out1 := PrefixKeyString("fooprefix") - assert.Equal(t, "fooprefix", string(out1)) - out2 := PrefixKeyString("fooprefix", []byte("sub1"), []byte("sub2")) - assert.Equal(t, "fooprefix/sub1/sub2", string(out2)) -} diff --git a/types/store/prefix_iterator.go b/types/store/prefix_iterator.go deleted file mode 100755 index b5f9d4a..0000000 --- a/types/store/prefix_iterator.go +++ /dev/null @@ -1,13 +0,0 @@ -package store - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func KVStorePrefixIterator(kvs KVStore, prefix []byte) sdk.Iterator { - return kvs.Iterator(prefix, sdk.PrefixEndBytes(prefix)) -} - -func KVStoreReversePrefixIterator(kvs KVStore, prefix []byte) sdk.Iterator { - return kvs.ReverseIterator(prefix, sdk.PrefixEndBytes(prefix)) -} diff --git a/types/store/prefixed.go b/types/store/prefixed.go deleted file mode 100755 index c76f138..0000000 --- a/types/store/prefixed.go +++ /dev/null @@ -1,39 +0,0 @@ -package store - -import sdk "github.com/cosmos/cosmos-sdk/types" - -type Prefixed struct { - backend KVStore - prefix []byte -} - -func NewPrefixed(backend KVStore, prefix []byte) *Prefixed { - return &Prefixed{ - backend: backend, - prefix: prefix, - } -} - -func (p *Prefixed) Get(key []byte) []byte { - return p.backend.Get(PrefixKeyBytes(p.prefix, key)) -} - -func (p *Prefixed) Has(key []byte) bool { - return p.backend.Has(PrefixKeyBytes(p.prefix, key)) -} - -func (p *Prefixed) Set(key, value []byte) { - p.backend.Set(PrefixKeyBytes(p.prefix, key), value) -} - -func (p *Prefixed) Delete(key []byte) { - p.backend.Delete(PrefixKeyBytes(p.prefix, key)) -} - -func (p *Prefixed) Iterator(start, end []byte) sdk.Iterator { - return p.backend.Iterator(PrefixKeyBytes(p.prefix, start), PrefixKeyBytes(p.prefix, end)) -} - -func (p *Prefixed) ReverseIterator(start, end []byte) sdk.Iterator { - return p.backend.ReverseIterator(PrefixKeyBytes(p.prefix, start), PrefixKeyBytes(p.prefix, end)) -} diff --git a/types/store/prefixed_test.go b/types/store/prefixed_test.go deleted file mode 100755 index 5b1251d..0000000 --- a/types/store/prefixed_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package store - -import ( - "bytes" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/tendermint/dex-demo/testutil/testflags" - - "github.com/cosmos/cosmos-sdk/types" -) - -type lastCall struct { - key []byte - start []byte - end []byte -} - -type dumbKVStore struct { - last lastCall -} - -func (d *dumbKVStore) Get(key []byte) []byte { - d.last = lastCall{key: key} - return nil -} - -func (d *dumbKVStore) Has(key []byte) bool { - d.last = lastCall{key: key} - return true -} - -func (d *dumbKVStore) Set(key, value []byte) { - d.last = lastCall{key: key} -} - -func (d *dumbKVStore) Delete(key []byte) { - d.last = lastCall{key: key} -} - -func (d *dumbKVStore) Iterator(start, end []byte) types.Iterator { - d.last = lastCall{start: start, end: end} - return nil -} - -func (d *dumbKVStore) ReverseIterator(start, end []byte) types.Iterator { - d.last = lastCall{start: start, end: end} - return nil -} - -func TestPrefixed(t *testing.T) { - testflags.UnitTest(t) - kvs := &dumbKVStore{} - pref := NewPrefixed(kvs, []byte{0x44}) - - pref.Get([]byte{0x01}) - assert.True(t, bytes.Equal([]byte{0x44, 0x2F, 0x01}, kvs.last.key)) - - pref.Has([]byte{0x02}) - assert.True(t, bytes.Equal([]byte{0x44, 0x2F, 0x02}, kvs.last.key)) - - pref.Set([]byte{0x03}, nil) - assert.True(t, bytes.Equal([]byte{0x44, 0x2F, 0x03}, kvs.last.key)) - - pref.Delete([]byte{0x04}) - assert.True(t, bytes.Equal([]byte{0x44, 0x2F, 0x04}, kvs.last.key)) - - pref.Iterator([]byte{0x05}, []byte{0x06}) - assert.True(t, bytes.Equal([]byte{0x44, 0x2F, 0x05}, kvs.last.start)) - assert.True(t, bytes.Equal([]byte{0x44, 0x2F, 0x06}, kvs.last.end)) - - pref.ReverseIterator([]byte{0x07}, []byte{0x08}) - assert.True(t, bytes.Equal([]byte{0x44, 0x2F, 0x07}, kvs.last.start)) - assert.True(t, bytes.Equal([]byte{0x44, 0x2F, 0x08}, kvs.last.end)) -} diff --git a/x/asset/client/cli/tx.go b/x/asset/client/cli/tx.go index eafa85b..0e19c10 100755 --- a/x/asset/client/cli/tx.go +++ b/x/asset/client/cli/tx.go @@ -2,9 +2,7 @@ package cli import ( "github.com/spf13/cobra" - "github.com/tendermint/dex-demo/pkg/cliutil" - "github.com/tendermint/dex-demo/types/store" "github.com/tendermint/dex-demo/x/asset/types" "github.com/cosmos/cosmos-sdk/codec" @@ -22,7 +20,7 @@ func GetCmdMint(cdc *codec.Codec) *cobra.Command { return err } - msg := types.NewMsgMint(store.NewEntityIDFromString(args[0]), ctx.GetFromAddress(), sdk.NewUintFromString(args[1])) + msg := types.NewMsgMint(sdk.NewUintFromString(args[0]), ctx.GetFromAddress(), sdk.NewUintFromString(args[1])) return cliutil.ValidateAndBroadcast(ctx, bldr, msg) }, } @@ -38,7 +36,7 @@ func GetCmdBurn(cdc *codec.Codec) *cobra.Command { if err != nil { return err } - msg := types.NewMsgBurn(store.NewEntityIDFromString(args[0]), ctx.GetFromAddress(), sdk.NewUintFromString(args[1])) + msg := types.NewMsgBurn(sdk.NewUintFromString(args[0]), ctx.GetFromAddress(), sdk.NewUintFromString(args[1])) return cliutil.ValidateAndBroadcast(ctx, bldr, msg) }, } @@ -60,7 +58,7 @@ func GetCmdTransfer(cdc *codec.Codec) *cobra.Command { return err } - msg := types.NewMsgTransfer(store.NewEntityIDFromString(args[1]), ctx.GetFromAddress(), toAddr, sdk.NewUintFromString(args[2])) + msg := types.NewMsgTransfer(sdk.NewUintFromString(args[1]), ctx.GetFromAddress(), toAddr, sdk.NewUintFromString(args[2])) return cliutil.ValidateAndBroadcast(ctx, bldr, msg) }, } diff --git a/x/asset/genesis.go b/x/asset/genesis.go index 57685e1..5d7cceb 100755 --- a/x/asset/genesis.go +++ b/x/asset/genesis.go @@ -2,10 +2,8 @@ package asset import ( "errors" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/tendermint/dex-demo/types/store" "github.com/tendermint/dex-demo/x/asset/types" ) @@ -18,11 +16,11 @@ func NewGenesisState(assets []types.Asset) GenesisState { } func ValidateGenesis(data GenesisState) error { - currentId := store.ZeroEntityID + currentId := sdk.ZeroUint() for _, asset := range data.Assets { - currentId = currentId.Inc() - if !currentId.Equals(asset.ID) { + currentId = currentId.Add(sdk.OneUint()) + if !currentId.Equal(asset.ID) { return errors.New("Invalid Asset: ID must monotonically increase.") } if asset.Name == "" { @@ -43,14 +41,14 @@ func DefaultGenesisState() GenesisState { return GenesisState{ Assets: []types.Asset{ { - ID: store.NewEntityID(1), + ID: sdk.OneUint(), Name: "UEX Staking Token", Symbol: "UEX", CirculatingSupply: sdk.NewUintFromString("40000000000000000000000000"), TotalSupply: sdk.NewUintFromString("1000000000000000000000000000"), }, { - ID: store.NewEntityID(2), + ID: sdk.NewUint(2), Name: "Test Token", Symbol: "TEST", CirculatingSupply: sdk.NewUintFromString("40000000000000000000000000"), diff --git a/x/asset/keeper.go b/x/asset/keeper.go index b9683b1..280ed2c 100755 --- a/x/asset/keeper.go +++ b/x/asset/keeper.go @@ -1,8 +1,10 @@ package asset import ( + "github.com/tendermint/dex-demo/embedded/store" "github.com/tendermint/dex-demo/pkg/log" - "github.com/tendermint/dex-demo/types/store" + "github.com/tendermint/dex-demo/storeutil" + "github.com/tendermint/dex-demo/types/errs" "github.com/tendermint/dex-demo/x/asset/types" "github.com/cosmos/cosmos-sdk/codec" @@ -45,35 +47,35 @@ func (k Keeper) Create(ctx sdk.Context, name string, symbol string, owner sdk.Ac sdk.ZeroUint(), totalSupply, ) - err := store.SetNotExists(ctx, k.storeKey, k.cdc, assetKey(id), asset) + err := errs.WrapOrNil(storeutil.Create(ctx, k.storeKey, k.cdc, assetKey(id), asset)) return asset, err } func (k Keeper) Inject(ctx sdk.Context, asset types.Asset) { - seq := store.GetSeq(ctx, k.storeKey, []byte(seqKey)) + seq := storeutil.GetSeq(ctx, k.storeKey, []byte(seqKey)) - if !asset.ID.Dec().Equals(seq) { + if !asset.ID.Sub(sdk.OneUint()).Equal(seq) { panic("Invalid asset ID.") } k.incrementSeq(ctx) - if err := store.SetNotExists(ctx, k.storeKey, k.cdc, assetKey(asset.ID), asset); err != nil { + if err := storeutil.Create(ctx, k.storeKey, k.cdc, assetKey(asset.ID), asset); err != nil { panic(err) } } func (k Keeper) Set(ctx sdk.Context, asset types.Asset) sdk.Error { - return store.SetExists(ctx, k.storeKey, k.cdc, assetKey(asset.ID), asset) + return errs.WrapNotFound(storeutil.Update(ctx, k.storeKey, k.cdc, assetKey(asset.ID), asset)) } -func (k Keeper) Get(ctx sdk.Context, id store.EntityID) (types.Asset, sdk.Error) { +func (k Keeper) Get(ctx sdk.Context, id sdk.Uint) (types.Asset, sdk.Error) { var a types.Asset - err := store.Get(ctx, k.storeKey, k.cdc, assetKey(id), &a) + err := errs.WrapNotFound(storeutil.Get(ctx, k.storeKey, k.cdc, assetKey(id), &a)) return a, err } -func (k Keeper) Has(ctx sdk.Context, id store.EntityID) bool { - return store.Has(ctx, k.storeKey, assetKey(id)) +func (k Keeper) Has(ctx sdk.Context, id sdk.Uint) bool { + return storeutil.Has(ctx, k.storeKey, assetKey(id)) } func (k Keeper) Iterator(ctx sdk.Context, cb IteratorCB) { @@ -92,7 +94,7 @@ func (k Keeper) Iterator(ctx sdk.Context, cb IteratorCB) { } } -func (k Keeper) Mint(ctx sdk.Context, id store.EntityID, quantity sdk.Uint) sdk.Error { +func (k Keeper) Mint(ctx sdk.Context, id sdk.Uint, quantity sdk.Uint) sdk.Error { asset, err := k.Get(ctx, id) if err != nil { return err @@ -119,7 +121,7 @@ func (k Keeper) Mint(ctx sdk.Context, id store.EntityID, quantity sdk.Uint) sdk. return k.Set(ctx, asset) } -func (k Keeper) Burn(ctx sdk.Context, id store.EntityID, burner sdk.AccAddress, quantity sdk.Uint) sdk.Error { +func (k Keeper) Burn(ctx sdk.Context, id sdk.Uint, burner sdk.AccAddress, quantity sdk.Uint) sdk.Error { asset, err := k.Get(ctx, id) if err != nil { return err @@ -137,7 +139,7 @@ func (k Keeper) Burn(ctx sdk.Context, id store.EntityID, burner sdk.AccAddress, return k.Set(ctx, asset) } -func (k Keeper) Transfer(ctx sdk.Context, id store.EntityID, from sdk.AccAddress, to sdk.AccAddress, quantity sdk.Uint) sdk.Error { +func (k Keeper) Transfer(ctx sdk.Context, id sdk.Uint, from sdk.AccAddress, to sdk.AccAddress, quantity sdk.Uint) sdk.Error { asset, err := k.Get(ctx, id) if err != nil { return err @@ -145,7 +147,7 @@ func (k Keeper) Transfer(ctx sdk.Context, id store.EntityID, from sdk.AccAddress return k.bankKeeper.SendCoins(ctx, from, to, types.Coins(asset.ID, quantity)) } -func (k Keeper) TransferFromOwner(ctx sdk.Context, id store.EntityID, to sdk.AccAddress, quantity sdk.Uint) sdk.Error { +func (k Keeper) TransferFromOwner(ctx sdk.Context, id sdk.Uint, to sdk.AccAddress, quantity sdk.Uint) sdk.Error { asset, err := k.Get(ctx, id) if err != nil { return err @@ -153,17 +155,17 @@ func (k Keeper) TransferFromOwner(ctx sdk.Context, id store.EntityID, to sdk.Acc return k.bankKeeper.SendCoins(ctx, asset.Owner, to, types.Coins(asset.ID, quantity)) } -func (k Keeper) Balance(ctx sdk.Context, id store.EntityID, owner sdk.AccAddress) sdk.Uint { +func (k Keeper) Balance(ctx sdk.Context, id sdk.Uint, owner sdk.AccAddress) sdk.Uint { coins := k.bankKeeper.GetCoins(ctx, owner) out := coins.AmountOf(store.FormatDenom(id)) return sdk.NewUintFromBigInt(out.BigInt()) } -func (k Keeper) incrementSeq(ctx sdk.Context) store.EntityID { - assetNum := store.IncrementSeq(ctx, k.storeKey, []byte(seqKey)) - return store.EntityID(assetNum) +func (k Keeper) incrementSeq(ctx sdk.Context) sdk.Uint { + assetNum := storeutil.IncrementSeq(ctx, k.storeKey, []byte(seqKey)) + return assetNum } -func assetKey(id store.EntityID) []byte { - return store.PrefixKeyString(valKey, id.Bytes()) +func assetKey(id sdk.Uint) []byte { + return storeutil.PrefixKeyString(valKey, storeutil.SDKUintSubkey(id)) } diff --git a/x/asset/types/msgs.go b/x/asset/types/msgs.go index 4e89bde..8359cce 100755 --- a/x/asset/types/msgs.go +++ b/x/asset/types/msgs.go @@ -1,11 +1,9 @@ package types import ( + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/dex-demo/pkg/serde" "github.com/tendermint/dex-demo/types/errs" - "github.com/tendermint/dex-demo/types/store" - - sdk "github.com/cosmos/cosmos-sdk/types" ) type MsgCreate struct { @@ -16,12 +14,12 @@ type MsgCreate struct { } type MsgMint struct { - ID store.EntityID + ID sdk.Uint Minter sdk.AccAddress Amount sdk.Uint } -func NewMsgMint(id store.EntityID, minter sdk.AccAddress, amount sdk.Uint) MsgMint { +func NewMsgMint(id sdk.Uint, minter sdk.AccAddress, amount sdk.Uint) MsgMint { return MsgMint{ ID: id, Minter: minter, @@ -38,7 +36,7 @@ func (msg MsgMint) Type() string { } func (msg MsgMint) ValidateBasic() sdk.Error { - if !msg.ID.IsDefined() { + if msg.ID.IsZero() { return errs.ErrNotFound("asset ID must exist") } if msg.Minter.Empty() { @@ -56,12 +54,12 @@ func (msg MsgMint) GetSigners() []sdk.AccAddress { } type MsgBurn struct { - ID store.EntityID + ID sdk.Uint Burner sdk.AccAddress Amount sdk.Uint } -func NewMsgBurn(id store.EntityID, burner sdk.AccAddress, amount sdk.Uint) MsgBurn { +func NewMsgBurn(id sdk.Uint, burner sdk.AccAddress, amount sdk.Uint) MsgBurn { return MsgBurn{ ID: id, Burner: burner, @@ -78,7 +76,7 @@ func (msg MsgBurn) Type() string { } func (msg MsgBurn) ValidateBasic() sdk.Error { - if !msg.ID.IsDefined() { + if msg.ID.IsZero() { return errs.ErrNotFound("asset ID must exist") } if msg.Burner.Empty() { @@ -96,13 +94,13 @@ func (msg MsgBurn) GetSigners() []sdk.AccAddress { } type MsgTransfer struct { - ID store.EntityID + ID sdk.Uint From sdk.AccAddress To sdk.AccAddress Amount sdk.Uint } -func NewMsgTransfer(id store.EntityID, from sdk.AccAddress, to sdk.AccAddress, amount sdk.Uint) MsgTransfer { +func NewMsgTransfer(id sdk.Uint, from sdk.AccAddress, to sdk.AccAddress, amount sdk.Uint) MsgTransfer { return MsgTransfer{ ID: id, From: from, @@ -120,7 +118,7 @@ func (msg MsgTransfer) Type() string { } func (msg MsgTransfer) ValidateBasic() sdk.Error { - if !msg.ID.IsDefined() { + if msg.ID.IsZero() { return errs.ErrNotFound("asset ID must exist") } if msg.From.Empty() || msg.To.Empty() { diff --git a/x/asset/types/types.go b/x/asset/types/types.go index a6d4cee..75abb9f 100755 --- a/x/asset/types/types.go +++ b/x/asset/types/types.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/tendermint/dex-demo/types/store" + "github.com/tendermint/dex-demo/embedded/store" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -16,7 +16,7 @@ const ( ) type Asset struct { - ID store.EntityID `json:"id"` + ID sdk.Uint `json:"id"` Name string `json:"name"` Symbol string `json:"symbol"` Owner sdk.AccAddress `json:"owner"` @@ -33,7 +33,7 @@ Circulating Supply: %s, TotalSupply: %s"`, a.ID, a.Name, a.Symbol, a.Owner, a.CirculatingSupply, a.TotalSupply)) } -func New(id store.EntityID, name string, symbol string, owner sdk.AccAddress, circSup sdk.Uint, totalSup sdk.Uint) Asset { +func New(id sdk.Uint, name string, symbol string, owner sdk.AccAddress, circSup sdk.Uint, totalSup sdk.Uint) Asset { return Asset{ ID: id, Name: name, @@ -44,10 +44,10 @@ func New(id store.EntityID, name string, symbol string, owner sdk.AccAddress, ci } } -func Coin(id store.EntityID, quantity sdk.Uint) sdk.Coin { +func Coin(id sdk.Uint, quantity sdk.Uint) sdk.Coin { return store.FormatCoin(id, quantity) } -func Coins(id store.EntityID, quantity sdk.Uint) sdk.Coins { +func Coins(id sdk.Uint, quantity sdk.Uint) sdk.Coins { return sdk.NewCoins(Coin(id, quantity)) } diff --git a/x/market/genesis.go b/x/market/genesis.go index 2f9b0ee..88eaec7 100755 --- a/x/market/genesis.go +++ b/x/market/genesis.go @@ -2,10 +2,8 @@ package market import ( "errors" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/tendermint/dex-demo/types/store" "github.com/tendermint/dex-demo/x/market/types" ) @@ -18,10 +16,10 @@ func NewGenesisState(markets []types.Market) GenesisState { } func ValidateGenesis(data GenesisState) error { - currentId := store.ZeroEntityID + currentId := sdk.ZeroUint() for _, market := range data.Markets { - currentId = currentId.Inc() - if !currentId.Equals(market.ID) { + currentId = currentId.Add(sdk.OneUint()) + if !currentId.Equal(market.ID) { return errors.New("Invalid Market: ID must monotonically increase.") } if market.BaseAssetID.IsZero() { @@ -39,9 +37,9 @@ func DefaultGenesisState() GenesisState { return GenesisState{ Markets: []types.Market{ { - ID: store.NewEntityID(1), - BaseAssetID: store.NewEntityID(2), - QuoteAssetID: store.NewEntityID(1), + ID: sdk.OneUint(), + BaseAssetID: sdk.NewUint(2), + QuoteAssetID: sdk.OneUint(), }, }, } diff --git a/x/market/keeper.go b/x/market/keeper.go index 78cd899..7dc6f41 100755 --- a/x/market/keeper.go +++ b/x/market/keeper.go @@ -2,8 +2,8 @@ package market import ( "fmt" - - "github.com/tendermint/dex-demo/types/store" + "github.com/tendermint/dex-demo/storeutil" + "github.com/tendermint/dex-demo/types/errs" "github.com/tendermint/dex-demo/x/asset" "github.com/tendermint/dex-demo/x/market/types" @@ -32,14 +32,14 @@ func NewKeeper(sk sdk.StoreKey, ak asset.Keeper, cdc *codec.Codec) Keeper { } } -func (k Keeper) Create(ctx sdk.Context, baseAsset store.EntityID, quoteAsset store.EntityID) types.Market { - id := store.IncrementSeq(ctx, k.storeKey, []byte(seqKey)) +func (k Keeper) Create(ctx sdk.Context, baseAsset sdk.Uint, quoteAsset sdk.Uint) types.Market { + id := storeutil.IncrementSeq(ctx, k.storeKey, []byte(seqKey)) market := types.Market{ ID: id, BaseAssetID: baseAsset, QuoteAssetID: quoteAsset, } - err := store.SetNotExists(ctx, k.storeKey, k.cdc, marketKey(id), market) + err := storeutil.Create(ctx, k.storeKey, k.cdc, marketKey(id), market) // should never happen, implies consensus // or storage bug if err != nil { @@ -49,25 +49,25 @@ func (k Keeper) Create(ctx sdk.Context, baseAsset store.EntityID, quoteAsset sto } func (k Keeper) Inject(ctx sdk.Context, market types.Market) { - seq := store.GetSeq(ctx, k.storeKey, []byte(seqKey)) + seq := storeutil.GetSeq(ctx, k.storeKey, []byte(seqKey)) - if !market.ID.Dec().Equals(seq) { + if !market.ID.Sub(sdk.OneUint()).Equal(seq) { panic("Invalid asset ID.") } - store.IncrementSeq(ctx, k.storeKey, []byte(seqKey)) - if err := store.SetNotExists(ctx, k.storeKey, k.cdc, marketKey(market.ID), market); err != nil { + storeutil.IncrementSeq(ctx, k.storeKey, []byte(seqKey)) + if err := storeutil.Create(ctx, k.storeKey, k.cdc, marketKey(market.ID), market); err != nil { panic(err) } } -func (k Keeper) Get(ctx sdk.Context, id store.EntityID) (types.Market, sdk.Error) { +func (k Keeper) Get(ctx sdk.Context, id sdk.Uint) (types.Market, sdk.Error) { var m types.Market - err := store.Get(ctx, k.storeKey, k.cdc, marketKey(id), &m) + err := errs.WrapNotFound(storeutil.Get(ctx, k.storeKey, k.cdc, marketKey(id), &m)) return m, err } -func (k Keeper) Pair(ctx sdk.Context, id store.EntityID) (string, sdk.Error) { +func (k Keeper) Pair(ctx sdk.Context, id sdk.Uint) (string, sdk.Error) { mkt, err := k.Get(ctx, id) if err != nil { return "", err @@ -84,8 +84,8 @@ func (k Keeper) Pair(ctx sdk.Context, id store.EntityID) (string, sdk.Error) { return fmt.Sprintf("%s/%s", base.Symbol, quote.Symbol), nil } -func (k Keeper) Has(ctx sdk.Context, id store.EntityID) bool { - return store.Has(ctx, k.storeKey, marketKey(id)) +func (k Keeper) Has(ctx sdk.Context, id sdk.Uint) bool { + return storeutil.Has(ctx, k.storeKey, marketKey(id)) } func (k Keeper) Iterator(ctx sdk.Context, cb IteratorCB) { @@ -104,8 +104,8 @@ func (k Keeper) Iterator(ctx sdk.Context, cb IteratorCB) { } } -func marketKey(id store.EntityID) []byte { - return store.PrefixKeyString(valKey, id.Bytes()) +func marketKey(id sdk.Uint) []byte { + return storeutil.PrefixKeyString(valKey, storeutil.SDKUintSubkey(id)) } func NewHandler(k Keeper) sdk.Handler { diff --git a/x/market/keeper_test.go b/x/market/keeper_test.go index 4dab9e7..33eb724 100755 --- a/x/market/keeper_test.go +++ b/x/market/keeper_test.go @@ -9,7 +9,6 @@ import ( "github.com/tendermint/dex-demo/testutil" "github.com/tendermint/dex-demo/testutil/mockapp" "github.com/tendermint/dex-demo/testutil/testflags" - "github.com/tendermint/dex-demo/types/store" "github.com/tendermint/dex-demo/x/market/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -24,7 +23,7 @@ func TestKeeper(t *testing.T) { require.NoError(t, err) mkt := app.MarketKeeper.Create(app.Ctx, asset1.ID, asset2.ID) expMkt := types.Market{ - ID: store.NewEntityID(1), + ID: sdk.OneUint(), BaseAssetID: asset1.ID, QuoteAssetID: asset2.ID, } diff --git a/x/market/types/querier.go b/x/market/types/querier.go index d1ec835..1de62ec 100644 --- a/x/market/types/querier.go +++ b/x/market/types/querier.go @@ -2,16 +2,14 @@ package types import ( "bytes" - + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/olekukonko/tablewriter" - - "github.com/tendermint/dex-demo/types/store" ) type NamedMarket struct { - ID store.EntityID - BaseAssetID store.EntityID - QuoteAssetID store.EntityID + ID sdk.Uint + BaseAssetID sdk.Uint + QuoteAssetID sdk.Uint Name string } diff --git a/x/market/types/types.go b/x/market/types/types.go index 99f3357..0542385 100755 --- a/x/market/types/types.go +++ b/x/market/types/types.go @@ -1,7 +1,7 @@ package types import ( - "github.com/tendermint/dex-demo/types/store" + sdk "github.com/cosmos/cosmos-sdk/types" ) const ( @@ -11,12 +11,12 @@ const ( ) type Market struct { - ID store.EntityID - BaseAssetID store.EntityID - QuoteAssetID store.EntityID + ID sdk.Uint + BaseAssetID sdk.Uint + QuoteAssetID sdk.Uint } -func New(id store.EntityID, baseAsset store.EntityID, quoteAsset store.EntityID) Market { +func New(id sdk.Uint, baseAsset sdk.Uint, quoteAsset sdk.Uint) Market { return Market{ ID: id, BaseAssetID: baseAsset, diff --git a/x/order/client/cli/tx.go b/x/order/client/cli/tx.go index c85e163..2f235c2 100755 --- a/x/order/client/cli/tx.go +++ b/x/order/client/cli/tx.go @@ -10,7 +10,6 @@ import ( "github.com/tendermint/dex-demo/pkg/cliutil" "github.com/tendermint/dex-demo/pkg/matcheng" - "github.com/tendermint/dex-demo/types/store" "github.com/tendermint/dex-demo/x/order/types" "github.com/cosmos/cosmos-sdk/codec" @@ -28,7 +27,7 @@ func GetCmdPost(cdc *codec.Codec) *cobra.Command { return err } - marketID := store.NewEntityIDFromString(args[0]) + marketID := sdk.NewUintFromString(args[0]) var direction matcheng.Direction dirArg := strings.ToLower(args[1]) if dirArg == "bid" { @@ -72,7 +71,7 @@ func GetCmdCancel(cdc *codec.Codec) *cobra.Command { return err } - orderID := store.NewEntityIDFromString(args[0]) + orderID := sdk.NewUintFromString(args[0]) msg := types.NewMsgCancel(ctx.GetFromAddress(), orderID) return cliutil.ValidateAndBroadcast(ctx, bldr, msg) }, diff --git a/x/order/keeper.go b/x/order/keeper.go index a67482e..ee8014b 100755 --- a/x/order/keeper.go +++ b/x/order/keeper.go @@ -2,8 +2,9 @@ package order import ( "github.com/tendermint/dex-demo/pkg/matcheng" + "github.com/tendermint/dex-demo/storeutil" "github.com/tendermint/dex-demo/types" - "github.com/tendermint/dex-demo/types/store" + "github.com/tendermint/dex-demo/types/errs" "github.com/tendermint/dex-demo/x/asset" assettypes "github.com/tendermint/dex-demo/x/asset/types" "github.com/tendermint/dex-demo/x/market" @@ -41,7 +42,7 @@ func NewKeeper(bk bank.Keeper, mk market.Keeper, ak asset.Keeper, sk sdk.StoreKe } } -func (k Keeper) Post(ctx sdk.Context, owner sdk.AccAddress, mktID store.EntityID, direction matcheng.Direction, price sdk.Uint, quantity sdk.Uint, tif uint16) (types3.Order, sdk.Error) { +func (k Keeper) Post(ctx sdk.Context, owner sdk.AccAddress, mktID sdk.Uint, direction matcheng.Direction, price sdk.Uint, quantity sdk.Uint, tif uint16) (types3.Order, sdk.Error) { var err sdk.Error mkt, err := k.marketKeeper.Get(ctx, mktID) if err != nil { @@ -83,7 +84,7 @@ func (k Keeper) Post(ctx sdk.Context, owner sdk.AccAddress, mktID store.EntityID ) } -func (k Keeper) Create(ctx sdk.Context, owner sdk.AccAddress, marketID store.EntityID, direction matcheng.Direction, price sdk.Uint, quantity sdk.Uint, tif uint16) (types3.Order, sdk.Error) { +func (k Keeper) Create(ctx sdk.Context, owner sdk.AccAddress, marketID sdk.Uint, direction matcheng.Direction, price sdk.Uint, quantity sdk.Uint, tif uint16) (types3.Order, sdk.Error) { id := k.incrementSeq(ctx) order := types3.Order{ ID: id, @@ -95,7 +96,7 @@ func (k Keeper) Create(ctx sdk.Context, owner sdk.AccAddress, marketID store.Ent TimeInForceBlocks: tif, CreatedBlock: ctx.BlockHeight(), } - err := store.SetNotExists(ctx, k.storeKey, k.cdc, orderKey(id), order) + err := storeutil.Create(ctx, k.storeKey, k.cdc, orderKey(id), order) _ = k.queue.Publish(types.OrderCreated{ ID: order.ID, Owner: order.Owner, @@ -107,10 +108,10 @@ func (k Keeper) Create(ctx sdk.Context, owner sdk.AccAddress, marketID store.Ent CreatedBlock: order.CreatedBlock, }) - return order, err + return order, errs.WrapOrNil(err) } -func (k Keeper) Cancel(ctx sdk.Context, id store.EntityID) sdk.Error { +func (k Keeper) Cancel(ctx sdk.Context, id sdk.Uint) sdk.Error { var err sdk.Error ord, err := k.Get(ctx, id) if err != nil { @@ -155,26 +156,26 @@ func (k Keeper) Cancel(ctx sdk.Context, id store.EntityID) sdk.Error { return k.Del(ctx, ord.ID) } -func (k Keeper) Get(ctx sdk.Context, id store.EntityID) (types3.Order, sdk.Error) { +func (k Keeper) Get(ctx sdk.Context, id sdk.Uint) (types3.Order, sdk.Error) { var out types3.Order - err := store.Get(ctx, k.storeKey, k.cdc, orderKey(id), &out) - return out, err + err := storeutil.Get(ctx, k.storeKey, k.cdc, orderKey(id), &out) + return out, errs.WrapNotFound(err) } func (k Keeper) Set(ctx sdk.Context, order types3.Order) sdk.Error { - return store.SetExists(ctx, k.storeKey, k.cdc, orderKey(order.ID), order) + return errs.WrapOrNil(storeutil.Update(ctx, k.storeKey, k.cdc, orderKey(order.ID), order)) } -func (k Keeper) Has(ctx sdk.Context, id store.EntityID) bool { - return store.Has(ctx, k.storeKey, orderKey(id)) +func (k Keeper) Has(ctx sdk.Context, id sdk.Uint) bool { + return storeutil.Has(ctx, k.storeKey, orderKey(id)) } -func (k Keeper) Del(ctx sdk.Context, id store.EntityID) sdk.Error { - return store.Del(ctx, k.storeKey, orderKey(id)) +func (k Keeper) Del(ctx sdk.Context, id sdk.Uint) sdk.Error { + return errs.WrapNotFound(storeutil.Del(ctx, k.storeKey, orderKey(id))) } -func (k Keeper) incrementSeq(ctx sdk.Context) store.EntityID { - return store.IncrementSeq(ctx, k.storeKey, []byte(seqKey)) +func (k Keeper) incrementSeq(ctx sdk.Context) sdk.Uint { + return storeutil.IncrementSeq(ctx, k.storeKey, []byte(seqKey)) } func (k Keeper) Iterator(ctx sdk.Context, cb IteratorCB) { @@ -202,6 +203,6 @@ func (k Keeper) doIterator(iter sdk.Iterator, cb IteratorCB) { } } -func orderKey(id store.EntityID) []byte { - return store.PrefixKeyString(valKey, id.Bytes()) +func orderKey(id sdk.Uint) []byte { + return storeutil.PrefixKeyString(valKey, storeutil.SDKUintSubkey(id)) } diff --git a/x/order/keeper_test.go b/x/order/keeper_test.go index e81a81b..8a979ba 100755 --- a/x/order/keeper_test.go +++ b/x/order/keeper_test.go @@ -11,7 +11,6 @@ import ( "github.com/tendermint/dex-demo/testutil/mockapp" "github.com/tendermint/dex-demo/testutil/testflags" "github.com/tendermint/dex-demo/types/errs" - "github.com/tendermint/dex-demo/types/store" "github.com/tendermint/dex-demo/x/asset/types" types2 "github.com/tendermint/dex-demo/x/market/types" types4 "github.com/tendermint/dex-demo/x/order/types" @@ -21,7 +20,7 @@ import ( type testCtx struct { ctx sdk.Context - marketID store.EntityID + marketID sdk.Uint owner sdk.AccAddress buyer sdk.AccAddress seller sdk.AccAddress @@ -35,7 +34,7 @@ func TestKeeper_Post(t *testing.T) { testflags.UnitTest(t) t.Run("returns an error for a nonexistent market", func(t *testing.T) { ctx := setupTest(t) - _, err := ctx.app.OrderKeeper.Post(ctx.ctx, ctx.buyer, ctx.marketID.Inc(), matcheng.Bid, testutil.ToBaseUnits(1), testutil.ToBaseUnits(10), 599) + _, err := ctx.app.OrderKeeper.Post(ctx.ctx, ctx.buyer, ctx.marketID.Add(sdk.OneUint()), matcheng.Bid, testutil.ToBaseUnits(1), testutil.ToBaseUnits(10), 599) assert.Error(t, err) assert.Equal(t, err.Code(), errs.CodeNotFound) }) @@ -80,7 +79,7 @@ func TestKeeper_Cancel(t *testing.T) { testflags.UnitTest(t) t.Run("returns an error for a nonexistent order", func(t *testing.T) { ctx := setupTest(t) - _, err := ctx.app.OrderKeeper.Post(ctx.ctx, ctx.buyer, store.NewEntityID(0), matcheng.Bid, testutil.ToBaseUnits(2), testutil.ToBaseUnits(10), 599) + _, err := ctx.app.OrderKeeper.Post(ctx.ctx, ctx.buyer, sdk.ZeroUint(), matcheng.Bid, testutil.ToBaseUnits(2), testutil.ToBaseUnits(10), 599) assert.Error(t, err) assert.Equal(t, err.Code(), errs.CodeNotFound) }) @@ -105,25 +104,25 @@ func TestKeeper_Iteration(t *testing.T) { last, err := ctx.app.OrderKeeper.Post(ctx.ctx, ctx.buyer, ctx.marketID, matcheng.Bid, testutil.ToBaseUnits(2), testutil.ToBaseUnits(10), 599) require.NoError(t, err) - var coll []store.EntityID + var coll []sdk.Uint ctx.app.OrderKeeper.Iterator(ctx.ctx, func(order types4.Order) bool { - if order.ID.Equals(last.ID) { + if order.ID.Equal(last.ID) { return false } coll = append(coll, order.ID) return true }) - assert.EqualValues(t, []store.EntityID{store.NewEntityID(1), store.NewEntityID(2)}, coll) + assert.EqualValues(t, []sdk.Uint{sdk.OneUint(), sdk.NewUint(2)}, coll) - coll = make([]store.EntityID, 0) + coll = make([]sdk.Uint, 0) ctx.app.OrderKeeper.ReverseIterator(ctx.ctx, func(order types4.Order) bool { - if order.ID.Equals(first.ID) { + if order.ID.Equal(first.ID) { return false } coll = append(coll, order.ID) return true }) - assert.EqualValues(t, []store.EntityID{store.NewEntityID(3), store.NewEntityID(2)}, coll) + assert.EqualValues(t, []sdk.Uint{sdk.NewUint(3), sdk.NewUint(2)}, coll) } func setupTest(t *testing.T) *testCtx { diff --git a/x/order/types/msgs.go b/x/order/types/msgs.go index b24aed2..0bb17b5 100755 --- a/x/order/types/msgs.go +++ b/x/order/types/msgs.go @@ -1,23 +1,21 @@ package types import ( + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/dex-demo/pkg/matcheng" "github.com/tendermint/dex-demo/pkg/serde" - "github.com/tendermint/dex-demo/types/store" - - sdk "github.com/cosmos/cosmos-sdk/types" ) type MsgPost struct { Owner sdk.AccAddress - MarketID store.EntityID + MarketID sdk.Uint Direction matcheng.Direction Price sdk.Uint Quantity sdk.Uint TimeInForce uint16 } -func NewMsgPost(owner sdk.AccAddress, marketID store.EntityID, direction matcheng.Direction, price sdk.Uint, quantity sdk.Uint, tif uint16) MsgPost { +func NewMsgPost(owner sdk.AccAddress, marketID sdk.Uint, direction matcheng.Direction, price sdk.Uint, quantity sdk.Uint, tif uint16) MsgPost { return MsgPost{ Owner: owner, MarketID: marketID, @@ -37,7 +35,7 @@ func (msg MsgPost) Type() string { } func (msg MsgPost) ValidateBasic() sdk.Error { - if !msg.MarketID.IsDefined() { + if msg.MarketID.IsZero() { return sdk.ErrUnauthorized("invalid market ID") } if msg.Price.IsZero() { @@ -65,10 +63,10 @@ func (msg MsgPost) GetSigners() []sdk.AccAddress { type MsgCancel struct { Owner sdk.AccAddress - OrderID store.EntityID + OrderID sdk.Uint } -func NewMsgCancel(owner sdk.AccAddress, orderID store.EntityID) MsgCancel { +func NewMsgCancel(owner sdk.AccAddress, orderID sdk.Uint) MsgCancel { return MsgCancel{ Owner: owner, OrderID: orderID, @@ -87,7 +85,7 @@ func (msg MsgCancel) ValidateBasic() sdk.Error { if msg.Owner.Empty() { return sdk.ErrUnauthorized("owner cannot be empty") } - if !msg.OrderID.IsDefined() { + if msg.OrderID.IsZero() { return sdk.ErrInternal("invalid order ID") } return nil diff --git a/x/order/types/types.go b/x/order/types/types.go index 8134cd2..b7277fc 100755 --- a/x/order/types/types.go +++ b/x/order/types/types.go @@ -1,10 +1,8 @@ package types 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" ) const ( @@ -16,9 +14,9 @@ const ( const MaxTimeInForce = 600 type Order struct { - ID store.EntityID `json:"id"` + ID sdk.Uint `json:"id"` Owner sdk.AccAddress `json:"owner"` - MarketID store.EntityID `json:"market"` + MarketID sdk.Uint `json:"market"` Direction matcheng.Direction `json:"direction"` Price sdk.Uint `json:"price"` Quantity sdk.Uint `json:"quantity"` @@ -26,7 +24,7 @@ type Order struct { CreatedBlock int64 `json:"created_block"` } -func New(owner sdk.AccAddress, marketID store.EntityID, direction matcheng.Direction, price sdk.Uint, quantity sdk.Uint, tif uint16, created int64) Order { +func New(owner sdk.AccAddress, marketID sdk.Uint, direction matcheng.Direction, price sdk.Uint, quantity sdk.Uint, tif uint16, created int64) Order { return Order{ Owner: owner, MarketID: marketID,