Skip to content

Commit

Permalink
feat: add custom network constructor and fix leftovers (#171)
Browse files Browse the repository at this point in the history
* build: bump core deps

* build: bump chain core types

* fix: remove orderbook v1 interface definitions and fix imports

* build: bump injective-core dep

* build: bump injective-core dep

* fix: remove core dependency

* chore: add NewNetwork constructor

* chore: go mod tidy

* fix: fix merge errors and copy types
  • Loading branch information
mmeloni authored Nov 2, 2023
1 parent 3ac4c12 commit b40a48c
Show file tree
Hide file tree
Showing 91 changed files with 2,184 additions and 2,500 deletions.
14 changes: 9 additions & 5 deletions chain/exchange/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion chain/peggy/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions client/common/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,16 @@ func LoadNetwork(name string, node string) Network {
return Network{}
}

// NewNetwork returns a new Network instance with all cookie assistants disabled.
// It can be used to setup a custom environment from scratch.
func NewNetwork() Network {
return Network{
chainCookieAssistant: &DisabledCookieAssistant{},
exchangeCookieAssistant: &DisabledCookieAssistant{},
explorerCookieAssistant: &DisabledCookieAssistant{},
}
}

func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
Expand Down
96 changes: 0 additions & 96 deletions client/exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ import (
type ExchangeClient interface {
QueryClient() *grpc.ClientConn
GetDerivativeMarket(ctx context.Context, marketId string) (derivativeExchangePB.MarketResponse, error)
GetDerivativeOrderbook(ctx context.Context, marketId string) (derivativeExchangePB.OrderbookResponse, error)
GetDerivativeOrderbooks(ctx context.Context, marketIds []string) (derivativeExchangePB.OrderbooksResponse, error)
GetDerivativeOrderbookV2(ctx context.Context, marketId string) (derivativeExchangePB.OrderbookV2Response, error)
GetDerivativeOrderbooksV2(ctx context.Context, marketIds []string) (derivativeExchangePB.OrderbooksV2Response, error)
// StreamDerivativeOrderbook deprecated API
StreamDerivativeOrderbook(ctx context.Context, marketIds []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrderbookClient, error)
StreamDerivativeOrderbookV2(ctx context.Context, marketIds []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrderbookV2Client, error)
StreamDerivativeOrderbookUpdate(ctx context.Context, marketIds []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrderbookUpdateClient, error)
StreamDerivativeMarket(ctx context.Context, marketIds []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamMarketClient, error)
Expand Down Expand Up @@ -62,12 +59,9 @@ type ExchangeClient interface {
GetPortfolio(ctx context.Context, accountAddress string) (accountPB.PortfolioResponse, error)
GetRewards(ctx context.Context, req accountPB.RewardsRequest) (accountPB.RewardsResponse, error)
GetSpotOrders(ctx context.Context, req spotExchangePB.OrdersRequest) (spotExchangePB.OrdersResponse, error)
GetSpotOrderbook(ctx context.Context, marketId string) (spotExchangePB.OrderbookResponse, error)
GetSpotOrderbooks(ctx context.Context, marketIds []string) (spotExchangePB.OrderbooksResponse, error)
GetSpotOrderbookV2(ctx context.Context, marketId string) (spotExchangePB.OrderbookV2Response, error)
GetSpotOrderbooksV2(ctx context.Context, marketIds []string) (spotExchangePB.OrderbooksV2Response, error)
// StreamSpotOrderbook deprecated API
StreamSpotOrderbook(ctx context.Context, marketIds []string) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrderbookClient, error)
StreamSpotOrderbookV2(ctx context.Context, marketIds []string) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrderbookV2Client, error)
StreamSpotOrderbookUpdate(ctx context.Context, marketIds []string) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrderbookUpdateClient, error)
GetSpotMarkets(ctx context.Context, req spotExchangePB.MarketsRequest) (spotExchangePB.MarketsResponse, error)
Expand Down Expand Up @@ -219,36 +213,6 @@ func (c *exchangeClient) GetDerivativeLiquidablePositions(ctx context.Context, r
return *res, nil
}

func (c *exchangeClient) GetDerivativeOrderbook(ctx context.Context, marketId string) (derivativeExchangePB.OrderbookResponse, error) {
req := derivativeExchangePB.OrderbookRequest{
MarketId: marketId,
}

ctx = c.getCookie(ctx)
res, err := c.derivativeExchangeClient.Orderbook(ctx, &req)
if err != nil {
fmt.Println(err)
return derivativeExchangePB.OrderbookResponse{}, err
}

return *res, nil
}

func (c *exchangeClient) GetDerivativeOrderbooks(ctx context.Context, marketIds []string) (derivativeExchangePB.OrderbooksResponse, error) {
req := derivativeExchangePB.OrderbooksRequest{
MarketIds: marketIds,
}

ctx = c.getCookie(ctx)
res, err := c.derivativeExchangeClient.Orderbooks(ctx, &req)
if err != nil {
fmt.Println(err)
return derivativeExchangePB.OrderbooksResponse{}, err
}

return *res, nil
}

func (c *exchangeClient) GetDerivativeOrderbookV2(ctx context.Context, marketId string) (derivativeExchangePB.OrderbookV2Response, error) {
req := derivativeExchangePB.OrderbookV2Request{
MarketId: marketId,
Expand Down Expand Up @@ -279,21 +243,6 @@ func (c *exchangeClient) GetDerivativeOrderbooksV2(ctx context.Context, marketId
return *res, nil
}

func (c *exchangeClient) StreamDerivativeOrderbook(ctx context.Context, marketIds []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrderbookClient, error) {
req := derivativeExchangePB.StreamOrderbookRequest{
MarketIds: marketIds,
}

ctx = c.getCookie(ctx)
stream, err := c.derivativeExchangeClient.StreamOrderbook(ctx, &req)
if err != nil {
fmt.Println(err)
return nil, err
}

return stream, nil
}

func (c *exchangeClient) StreamDerivativeOrderbookV2(ctx context.Context, marketIds []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrderbookV2Client, error) {
req := derivativeExchangePB.StreamOrderbookV2Request{
MarketIds: marketIds,
Expand Down Expand Up @@ -702,21 +651,6 @@ func (c *exchangeClient) GetSpotOrders(ctx context.Context, req spotExchangePB.O
return *res, nil
}

func (c *exchangeClient) GetSpotOrderbook(ctx context.Context, marketId string) (spotExchangePB.OrderbookResponse, error) {
req := spotExchangePB.OrderbookRequest{
MarketId: marketId,
}

ctx = c.getCookie(ctx)
res, err := c.spotExchangeClient.Orderbook(ctx, &req)
if err != nil {
fmt.Println(err)
return spotExchangePB.OrderbookResponse{}, err
}

return *res, nil
}

func (c *exchangeClient) GetSpotOrderbookV2(ctx context.Context, marketId string) (spotExchangePB.OrderbookV2Response, error) {
req := spotExchangePB.OrderbookV2Request{
MarketId: marketId,
Expand All @@ -732,21 +666,6 @@ func (c *exchangeClient) GetSpotOrderbookV2(ctx context.Context, marketId string
return *res, nil
}

func (c *exchangeClient) GetSpotOrderbooks(ctx context.Context, marketIds []string) (spotExchangePB.OrderbooksResponse, error) {
req := spotExchangePB.OrderbooksRequest{
MarketIds: marketIds,
}

ctx = c.getCookie(ctx)
res, err := c.spotExchangeClient.Orderbooks(ctx, &req)
if err != nil {
fmt.Println(err)
return spotExchangePB.OrderbooksResponse{}, err
}

return *res, nil
}

func (c *exchangeClient) GetSpotOrderbooksV2(ctx context.Context, marketIds []string) (spotExchangePB.OrderbooksV2Response, error) {
req := spotExchangePB.OrderbooksV2Request{
MarketIds: marketIds,
Expand Down Expand Up @@ -777,21 +696,6 @@ func (c *exchangeClient) StreamSpotOrderbookUpdate(ctx context.Context, marketId
return stream, nil
}

func (c *exchangeClient) StreamSpotOrderbook(ctx context.Context, marketIds []string) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrderbookClient, error) {
req := spotExchangePB.StreamOrderbookRequest{
MarketIds: marketIds,
}

ctx = c.getCookie(ctx)
stream, err := c.spotExchangeClient.StreamOrderbook(ctx, &req)
if err != nil {
fmt.Println(err)
return nil, err
}

return stream, nil
}

func (c *exchangeClient) StreamSpotOrderbookV2(ctx context.Context, marketIds []string) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrderbookV2Client, error) {
req := spotExchangePB.StreamOrderbookV2Request{
MarketIds: marketIds,
Expand Down
2 changes: 1 addition & 1 deletion examples/chain/33_GetBlock/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
clientCtx, cancelFn := context.WithCancel(context.Background())
defer cancelFn()

res, err := tmClient.GetBlock(clientCtx, 50000)
res, err := tmClient.GetBlock(clientCtx, 15478013)
if err != nil {
fmt.Println(err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/exchange/spot/13_Orderbooks/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {

ctx := context.Background()
marketIds := []string{"0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0"}
res, err := exchangeClient.GetSpotOrderbooks(ctx, marketIds)
res, err := exchangeClient.GetSpotOrderbooksV2(ctx, marketIds)
if err != nil {
fmt.Println(err)
}
Expand Down
4 changes: 2 additions & 2 deletions exchange/accounts_rpc/pb/injective_accounts_rpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b40a48c

Please sign in to comment.