code.vegaprotocol.io/vega@v0.79.0/datanode/api/trading.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package api
    17  
    18  import (
    19  	"context"
    20  	"time"
    21  
    22  	"code.vegaprotocol.io/vega/datanode/metrics"
    23  	protoapi "code.vegaprotocol.io/vega/protos/vega/api/v1"
    24  
    25  	"github.com/pkg/errors"
    26  )
    27  
    28  const defaultRequestTimeout = time.Second * 5
    29  
    30  // CoreServiceClient ...
    31  //
    32  //go:generate go run github.com/golang/mock/mockgen -destination mocks/core_service_client_mock.go -package mocks code.vegaprotocol.io/vega/datanode/api CoreServiceClient
    33  type CoreServiceClient interface {
    34  	protoapi.CoreServiceClient
    35  }
    36  
    37  // core service acts as a proxy to the trading service in core node.
    38  type coreProxyService struct {
    39  	protoapi.UnimplementedCoreServiceServer
    40  	conf Config
    41  
    42  	coreServiceClient CoreServiceClient
    43  	eventObserver     *eventObserver
    44  }
    45  
    46  func (t *coreProxyService) SubmitTransaction(ctx context.Context, req *protoapi.SubmitTransactionRequest) (*protoapi.SubmitTransactionResponse, error) {
    47  	ctx, cancel := context.WithTimeout(ctx, defaultRequestTimeout)
    48  	defer cancel()
    49  
    50  	return t.coreServiceClient.SubmitTransaction(ctx, req)
    51  }
    52  
    53  func (t *coreProxyService) SubmitRawTransaction(ctx context.Context, req *protoapi.SubmitRawTransactionRequest) (*protoapi.SubmitRawTransactionResponse, error) {
    54  	ctx, cancel := context.WithTimeout(ctx, defaultRequestTimeout)
    55  	defer cancel()
    56  
    57  	return t.coreServiceClient.SubmitRawTransaction(ctx, req)
    58  }
    59  
    60  func (t *coreProxyService) CheckTransaction(ctx context.Context, req *protoapi.CheckTransactionRequest) (*protoapi.CheckTransactionResponse, error) {
    61  	ctx, cancel := context.WithTimeout(ctx, defaultRequestTimeout)
    62  	defer cancel()
    63  
    64  	return t.coreServiceClient.CheckTransaction(ctx, req)
    65  }
    66  
    67  func (t *coreProxyService) CheckRawTransaction(ctx context.Context, req *protoapi.CheckRawTransactionRequest) (*protoapi.CheckRawTransactionResponse, error) {
    68  	ctx, cancel := context.WithTimeout(ctx, defaultRequestTimeout)
    69  	defer cancel()
    70  
    71  	return t.coreServiceClient.CheckRawTransaction(ctx, req)
    72  }
    73  
    74  func (t *coreProxyService) LastBlockHeight(ctx context.Context, req *protoapi.LastBlockHeightRequest) (*protoapi.LastBlockHeightResponse, error) {
    75  	ctx, cancel := context.WithTimeout(ctx, defaultRequestTimeout)
    76  	defer cancel()
    77  
    78  	return t.coreServiceClient.LastBlockHeight(ctx, req)
    79  }
    80  
    81  func (t *coreProxyService) GetVegaTime(ctx context.Context, req *protoapi.GetVegaTimeRequest) (*protoapi.GetVegaTimeResponse, error) {
    82  	ctx, cancel := context.WithTimeout(ctx, defaultRequestTimeout)
    83  	defer cancel()
    84  
    85  	return t.coreServiceClient.GetVegaTime(ctx, req)
    86  }
    87  
    88  func (t *coreProxyService) Statistics(ctx context.Context, req *protoapi.StatisticsRequest) (*protoapi.StatisticsResponse, error) {
    89  	ctx, cancel := context.WithTimeout(ctx, defaultRequestTimeout)
    90  	defer cancel()
    91  
    92  	return t.coreServiceClient.Statistics(ctx, req)
    93  }
    94  
    95  func (t *coreProxyService) ObserveEventBus(
    96  	stream protoapi.CoreService_ObserveEventBusServer,
    97  ) error {
    98  	defer metrics.StartActiveSubscriptionCountGRPC("EventBus")()
    99  	return t.eventObserver.ObserveEventBus(stream)
   100  }
   101  
   102  func (t *coreProxyService) PropagateChainEvent(ctx context.Context, req *protoapi.PropagateChainEventRequest) (*protoapi.PropagateChainEventResponse, error) {
   103  	return nil, errors.New("unimplemented")
   104  }
   105  
   106  func (t *coreProxyService) GetSpamStatistics(ctx context.Context, in *protoapi.GetSpamStatisticsRequest) (*protoapi.GetSpamStatisticsResponse, error) {
   107  	defer metrics.StartActiveSubscriptionCountGRPC("GetSpamStatistics")()
   108  	return t.coreServiceClient.GetSpamStatistics(ctx, in)
   109  }