Переглянути джерело

remove iroha-rest-api reference

kunickyd 3 роки тому
батько
коміт
ed2528b9f9
1 змінених файлів з 3 додано та 105 видалено
  1. 3 105
      app.js

+ 3 - 105
app.js

@@ -1,5 +1,4 @@
 import 'dotenv/config'
-import fetch from "node-fetch"
 import express from "express"
 import bodyParser from "body-parser"
 import basicAuth from "express-basic-auth"
@@ -34,48 +33,6 @@ app.post("/price", (req, res) => {
     }
 });
 
-app.get("/users/:userId/assets", async (req, res, next) => {
-    try {
-        let irohaResponse = await fetchUsersAssets(req.params.userId);
-
-        res.status(irohaResponse.status);
-
-        if (irohaResponse.headers.get("content-length") < 1) {
-            res.send();
-        }
-        else {
-            res.send(await irohaResponse.json());
-        }
-    }
-    catch (err) {
-        next(err);
-    }
-});
-
-app.get("/users/:userId/assets/:assetId", async (req, res, next) => {
-    try {
-        let irohaResponse = await fetchUsersAssets(req.params.userId);
-        let irohaResponseJson = await irohaResponse.json();        
-        let assets = irohaResponseJson.assets;
-
-        let parsedAssetName = "";
-        let i = 0;
-        for (i; i < assets.length; i++) {
-            parsedAssetName = assets[i].assetId.split('#')[0];
-            if (parsedAssetName === req.params.assetId) {
-                res.status(200);
-                res.send(assets[i]);
-                return;
-            }
-        }
-
-        res.status(204);
-        res.send();
-    } catch (err) {
-        next(err);
-    }
-});
-
 app.post("/buy", async (req, res, next) => {
 
     try {
@@ -84,73 +41,16 @@ app.post("/buy", async (req, res, next) => {
             throw Error(JSON.stringify({ error: { name: "Error, request has no body!" } }));
         }
 
-        if (!req.body.extent) {
-            res.status(400);
-            throw Error(JSON.stringify({ error: { name: "Error, request body has no \"extent\" property!" } }));
-        }
-
-        if (!req.body.user) {
+        if (!req.body.txHash) {
             res.status(400);
-            throw Error(JSON.stringify({ error: { name: "Error, request body has no \"user\" property!" } }));
-        }
-
-        if (!req.body.privateKey) {
-            res.status(400);
-            throw Error(JSON.stringify({ error: { name: "Error, user must provide \"privateKey\" to sign transaction!" } }));
-        }
-
-        let price = getPrice(req.body.extent);
-
-        // let irohaResponse = await forwardBuyRequest(
-        //     {
-        //         privateKey: req.body.privateKey,
-        //         transfers: [
-        //             {
-        //                 asset: IROHA_ASSET + "#" + IROHA_DOMAIN,
-        //                 source: req.body.user + "@" + IROHA_DOMAIN,
-        //                 destination: DATA_OWNER + "@" + IROHA_DOMAIN,
-        //                 description: "test", //TODO: compose uniform description
-        //                 amount: price
-        //             }
-        //         ]
-        //     }
-        // );
-
-        let data = "https://gis.lesprojekt.cz/chain4all/raster_112233.tif"; //TODO implement data extraction 
-
-        // res.status(irohaResponse.status);
-
-        // if (!irohaResponse.ok) {
-        //     res.send(await irohaResponse.json());
-        //     return;
-        // }
-
-        // let irohaResponseJson = await irohaResponse.json();
-
-        res.send({
-            dataUrl: data,
-            transactionHash: "91edf4700823a82ee8f57889cb620094cd1f5bb68d1273b093b17d128e62a590"//irohaResponseJson.transactionHash 
-        });
+            throw Error(JSON.stringify({ error: { name: "Error, request body has no \"txHash\" property!" } }));
+        }                
     }
     catch (err) {
         next(err);
     }
 });
 
-async function forwardBuyRequest(body) {
-    return await fetch(IROHA_API_HOST + ':' + IROHA_API_PORT + '/assets/transfer/',
-        {
-            method: 'POST',
-            body: JSON.stringify(body),
-            headers: { 'Content-Type': 'application/json' }
-        }
-    );
-}
-
-async function fetchUsersAssets(userId) {
-    return await fetch(IROHA_API_HOST + ':' + IROHA_API_PORT + '/accounts/' + userId + '@' + IROHA_DOMAIN + '/assets/');
-}
-
 function getArea(extent) {
     let y1 = extent[0][1];
     let y4 = extent[3][1];
@@ -176,8 +76,6 @@ function errorMiddleware(err, req, res, next) { //TODO: add custom Exception cla
 
 app.use(errorMiddleware);
 
-
-
 app.listen(CHAIN4ALL_SERVICE_PORT, () => {
     console.log(`Listening at http://localhost:${CHAIN4ALL_SERVICE_PORT}`)
 });