This is an automated email from the ASF dual-hosted git repository.

smihaylov pushed a commit to branch tendermint
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-dta.git


The following commit(s) were added to refs/heads/tendermint by this push:
     new 2932457  Rename HTTP endpoints /order1 to /order and /order/secret1 to 
/order/secret
2932457 is described below

commit 2932457e7b6084852439a87e9fbea690ae8b5d11
Author: Stanislav Mihaylov <[email protected]>
AuthorDate: Wed Oct 9 09:54:25 2019 +0300

    Rename HTTP endpoints /order1 to /order and /order/secret1 to /order/secret
    
    Add HTTP client
---
 pkg/api/client.go           | 117 ++++++++++++++++++++++++++++++++++++++++++++
 pkg/defaultservice/order.go |  10 ++--
 pkg/endpoints/endpoints.go  |  20 ++++----
 pkg/service/service.go      |   4 +-
 4 files changed, 133 insertions(+), 18 deletions(-)

diff --git a/pkg/api/client.go b/pkg/api/client.go
new file mode 100644
index 0000000..4d3ab6d
--- /dev/null
+++ b/pkg/api/client.go
@@ -0,0 +1,117 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+/*
+Package api - service integration and contract types
+*/
+package api
+
+import (
+       "context"
+       "net/http"
+
+       "github.com/apache/incubator-milagro-dta/libs/logger"
+       "github.com/apache/incubator-milagro-dta/libs/transport"
+)
+
+var (
+       apiVersion = "v1"
+)
+
+// ClientService interface
+type ClientService interface {
+       Order(token string, req *OrderRequest) (*OrderResponse, error)
+       OrderSecret(token string, req *OrderSecretRequest) 
(*OrderSecretResponse, error)
+       Status(token string) (*StatusResponse, error)
+}
+
+// MilagroClientService - implements Service Interface
+type MilagroClientService struct {
+       endpoints transport.ClientEndpoints
+}
+
+// ClientEndpoints return only the exported endpoints
+func ClientEndpoints() transport.HTTPEndpoints {
+       return transport.HTTPEndpoints{
+               "Order": {
+                       Path:        "/" + apiVersion + "/order",
+                       Method:      http.MethodPost,
+                       NewRequest:  func() interface{} { return 
&OrderRequest{} },
+                       NewResponse: func() interface{} { return 
&OrderResponse{} },
+               },
+               "OrderSecret": {
+                       Path:        "/" + apiVersion + "/order/secret",
+                       Method:      http.MethodPost,
+                       NewRequest:  func() interface{} { return 
&OrderSecretRequest{} },
+                       NewResponse: func() interface{} { return 
&OrderSecretResponse{} },
+               },
+               "Status": {
+                       Path:        "/" + apiVersion + "/status",
+                       Method:      http.MethodGet,
+                       NewResponse: func() interface{} { return 
&StatusResponse{} },
+               },
+       }
+}
+
+// NewHTTPClient returns Service backed by an HTTP server living at the remote 
instance
+func NewHTTPClient(instance string, logger *logger.Logger) (ClientService, 
error) {
+       clientEndpoints, err := transport.NewHTTPClient(instance, 
ClientEndpoints(), logger)
+       return MilagroClientService{clientEndpoints}, err
+
+}
+
+// Order makes a request for a new order
+func (c MilagroClientService) Order(token string, req *OrderRequest) 
(*OrderResponse, error) {
+       endpoint := c.endpoints["Order"]
+       ctx := context.Background()
+       ctx = transport.SetJWTAuthHeader(ctx, token)
+
+       resp, err := endpoint(ctx, req)
+       if err != nil {
+               return nil, err
+       }
+
+       return resp.(*OrderResponse), nil
+}
+
+// OrderSecret makes a request for initiate the order secret
+func (c MilagroClientService) OrderSecret(token string, req 
*OrderSecretRequest) (*OrderSecretResponse, error) {
+       endpoint := c.endpoints["OrderSecret"]
+       ctx := context.Background()
+       ctx = transport.SetJWTAuthHeader(ctx, token)
+
+       resp, err := endpoint(ctx, req)
+       if err != nil {
+               return nil, err
+       }
+
+       return resp.(*OrderSecretResponse), nil
+}
+
+//Status - Allows a client to see the status of the server that it is 
connecting too
+func (c MilagroClientService) Status(token string) (*StatusResponse, error) {
+       endpoint := c.endpoints["Status"]
+       ctx := context.Background()
+       ctx = transport.SetJWTAuthHeader(ctx, token)
+
+       resp, err := endpoint(ctx, nil)
+       if err != nil {
+               return nil, err
+       }
+
+       return resp.(*StatusResponse), nil
+}
diff --git a/pkg/defaultservice/order.go b/pkg/defaultservice/order.go
index 6ed4f5e..d5fc403 100644
--- a/pkg/defaultservice/order.go
+++ b/pkg/defaultservice/order.go
@@ -128,8 +128,8 @@ func (s *Service) ProduceFinalSecret(seed, sikeSK []byte, 
order, orderPart4 *doc
        return finalPrivateKey, finalPublicKey, nil, err
 }
 
-// Order1 -
-func (s *Service) Order1(req *api.OrderRequest) (string, error) {
+// Order creates a new deposit order
+func (s *Service) Order(req *api.OrderRequest) (string, error) {
        if err := s.Plugin.ValidateOrderRequest(req); err != nil {
                return "", err
        }
@@ -177,8 +177,8 @@ func (s *Service) Order1(req *api.OrderRequest) (string, 
error) {
        return order.Reference, nil
 }
 
-// OrderSecret1 -
-func (s *Service) OrderSecret1(req *api.OrderSecretRequest) (string, error) {
+// OrderSecret initiates the process for retreiving the order secret
+func (s *Service) OrderSecret(req *api.OrderSecretRequest) (string, error) {
        orderReference := req.OrderReference
        var previousOrderHash string
        if err := s.Store.Get("order", orderReference, &previousOrderHash); err 
!= nil {
@@ -219,8 +219,6 @@ func (s *Service) OrderSecret1(req *api.OrderSecretRequest) 
(string, error) {
                return "", err
        }
 
-       _ = tx
-
        order := &documents.OrderDoc{}
        err = documents.DecodeOrderDocument(tx.Payload, previousOrderHash, 
order, sikeSK, nodeID, remoteIDDoc.BLSPublicKey)
        if err != nil {
diff --git a/pkg/endpoints/endpoints.go b/pkg/endpoints/endpoints.go
index 237e3c2..e046d83 100644
--- a/pkg/endpoints/endpoints.go
+++ b/pkg/endpoints/endpoints.go
@@ -49,9 +49,9 @@ func Endpoints(svc service.Service, corsAllow string, 
authorizer transport.Autho
        principalEndpoints := transport.HTTPEndpoints{
 
                "Order1": {
-                       Path:        "/" + apiVersion + "/order1",
+                       Path:        "/" + apiVersion + "/order",
                        Method:      http.MethodPost,
-                       Endpoint:    MakeOrder1Endpoint(svc, logger),
+                       Endpoint:    MakeOrderEndpoint(svc, logger),
                        NewRequest:  func() interface{} { return 
&api.OrderRequest{} },
                        NewResponse: func() interface{} { return 
&api.OrderResponse{} },
                        Options: transport.ServerOptions(
@@ -90,9 +90,9 @@ func Endpoints(svc service.Service, corsAllow string, 
authorizer transport.Autho
                        },
                },
                "OrderSecret1": {
-                       Path:        "/" + apiVersion + "/order/secret1",
+                       Path:        "/" + apiVersion + "/order/secret",
                        Method:      http.MethodPost,
-                       Endpoint:    MakeOrderSecret1Endpoint(svc, logger),
+                       Endpoint:    MakeOrderSecretEndpoint(svc, logger),
                        NewRequest:  func() interface{} { return 
&api.OrderSecretRequest{} },
                        NewResponse: func() interface{} { return 
&api.OrderSecretResponse{} },
                        Options: transport.ServerOptions(
@@ -199,8 +199,8 @@ func MakeGetOrderEndpoint(m service.Service, log 
*logger.Logger) endpoint.Endpoi
        }
 }
 
-//MakeOrder1Endpoint -
-func MakeOrder1Endpoint(m service.Service, log *logger.Logger) 
endpoint.Endpoint {
+//MakeOrderEndpoint -
+func MakeOrderEndpoint(m service.Service, log *logger.Logger) 
endpoint.Endpoint {
        return func(ctx context.Context, request interface{}) (response 
interface{}, err error) {
                req, ok := request.(*api.OrderRequest)
                if !ok {
@@ -210,12 +210,12 @@ func MakeOrder1Endpoint(m service.Service, log 
*logger.Logger) endpoint.Endpoint
                        return "", err
                }
                debugRequest(ctx, req, log)
-               return m.Order1(req)
+               return m.Order(req)
        }
 }
 
-//MakeOrderSecret1Endpoint -
-func MakeOrderSecret1Endpoint(m service.Service, log *logger.Logger) 
endpoint.Endpoint {
+//MakeOrderSecretEndpoint -
+func MakeOrderSecretEndpoint(m service.Service, log *logger.Logger) 
endpoint.Endpoint {
        return func(ctx context.Context, request interface{}) (response 
interface{}, err error) {
                req, ok := request.(*api.OrderSecretRequest)
                if !ok {
@@ -225,7 +225,7 @@ func MakeOrderSecret1Endpoint(m service.Service, log 
*logger.Logger) endpoint.En
                        return "", err
                }
                debugRequest(ctx, req, log)
-               return m.OrderSecret1(req)
+               return m.OrderSecret(req)
        }
 }
 
diff --git a/pkg/service/service.go b/pkg/service/service.go
index 1949ed0..44c0f2e 100644
--- a/pkg/service/service.go
+++ b/pkg/service/service.go
@@ -32,8 +32,8 @@ type Service interface {
        OrderList(req *api.OrderListRequest) (*api.OrderListResponse, error)
 
        //Order processing - REST access to create an Order & Redeem
-       OrderSecret1(req *api.OrderSecretRequest) (string, error)
-       Order1(req *api.OrderRequest) (string, error)
+       Order(req *api.OrderRequest) (string, error)
+       OrderSecret(req *api.OrderSecretRequest) (string, error)
 
        //Fullfill processing
        FulfillOrder(tx *api.BlockChainTX) (string, error)

Reply via email to