You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@milagro.apache.org by sm...@apache.org on 2019/10/10 07:43:28 UTC

[incubator-milagro-dta] branch tendermint updated: Order and OrderSecret responses as JSON

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 4e01aa9  Order and OrderSecret responses as JSON
     new fffc70d  Merge branch 'tendermint' of github.com:apache/incubator-milagro-dta into tendermint
4e01aa9 is described below

commit 4e01aa99e20a12e20b135dacac1e226720a35c49
Author: Stanislav Mihaylov <sm...@gmail.com>
AuthorDate: Thu Oct 10 10:30:35 2019 +0300

    Order and OrderSecret responses as JSON
---
 cmd/servicetester/tendertest1.sh | 35 +++++++++++++++++++++++++++++++++--
 pkg/endpoints/endpoints.go       | 20 ++++++++++++++++++--
 2 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/cmd/servicetester/tendertest1.sh b/cmd/servicetester/tendertest1.sh
index cffef3a..b9d2f8c 100755
--- a/cmd/servicetester/tendertest1.sh
+++ b/cmd/servicetester/tendertest1.sh
@@ -1,8 +1,39 @@
-ref=$(curl -s -X POST "127.0.0.1:5556/v1/order1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":\"8zxdWSXs6dDYpqbNrGQsH2kBWPVgcj9WhanddrCzHZjk\",\"extension\":{\"coin\":\"0\"}}")
+#! /bin/bash
+
+apiVersion="v1"
+defaultURL="http://localhost:5556"
+apiURL="${1:-$defaultURL}"
+
+echo "DTA URL: $apiURL"
+
+statusOutput=$(curl -s -X GET "$apiURL/$apiVersion/status")
+identity=$(echo $statusOutput | jq -r .nodeCID)
+plugin=$(echo $statusOutput | jq -r .plugin)
+
+if [ -z "${identity}" ]; then
+  echo "Server Not Running"
+  exit 1
+fi
+
+benID="${2:-$identity}"
+
+echo "DTA Plugin: $plugin"
+echo "DTA ID: $identity"
+echo "BeneficiaryID: $benID"
+
+
+respOrder=$(curl -s -X POST "$apiURL/$apiVersion/order" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":\"$benID\",\"extension\":{\"coin\":\"0\"}}")
+
+orderRef=$(echo $respOrder | jq '.orderReference')
+if [ -z "${orderRef}" ]; then
+	echo "Create order invalid response"
+	exit 1
+fi
+
 
 #sleep long enough for blockchain to catch up
 sleep 4
 
-curl -X POST "127.0.0.1:5556/v1/order/secret1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$ref,\"beneficiaryIDDocumentCID\":\"8zxdWSXs6dDYpqbNrGQsH2kBWPVgcj9WhanddrCzHZjk\"}"
+curl -X POST "$apiURL/$apiVersion/order/secret" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$orderRef,\"beneficiaryIDDocumentCID\":\"$benID\"}"
 
 
diff --git a/pkg/endpoints/endpoints.go b/pkg/endpoints/endpoints.go
index e046d83..52daf7e 100644
--- a/pkg/endpoints/endpoints.go
+++ b/pkg/endpoints/endpoints.go
@@ -210,7 +210,15 @@ func MakeOrderEndpoint(m service.Service, log *logger.Logger) endpoint.Endpoint
 			return "", err
 		}
 		debugRequest(ctx, req, log)
-		return m.Order(req)
+
+		orderRef, err := m.Order(req)
+		if err != nil {
+			return nil, err
+		}
+
+		return &api.OrderResponse{
+			OrderReference: orderRef,
+		}, nil
 	}
 }
 
@@ -225,7 +233,15 @@ func MakeOrderSecretEndpoint(m service.Service, log *logger.Logger) endpoint.End
 			return "", err
 		}
 		debugRequest(ctx, req, log)
-		return m.OrderSecret(req)
+
+		orderRef, err := m.OrderSecret(req)
+		if err != nil {
+			return nil, err
+		}
+
+		return &api.OrderSecretResponse{
+			OrderReference: orderRef,
+		}, nil
 	}
 }