Ver Fonte

load_tx_details

kunickyd há 3 anos atrás
pai
commit
728294b738
2 ficheiros alterados com 58 adições e 4 exclusões
  1. 55 3
      app.js
  2. 3 1
      package.json

+ 55 - 3
app.js

@@ -1,15 +1,29 @@
 import 'dotenv/config'
+import grpc from "grpc"
 import express from "express"
 import bodyParser from "body-parser"
 import basicAuth from "express-basic-auth"
+import {
+    CommandService_v1Client as CommandService,
+    QueryService_v1Client as QueryService
+} from 'iroha-helpers/lib/proto/endpoint_grpc_pb.js'
+
+import iroha from 'iroha-helpers'
 
 const app = express();
 app.use(bodyParser.json());
 app.use(basicAuth({
-    users : { 'admin' : 'superPasswd' },
-    challange : true
+    users: { 'admin': 'superPasswd' },
+    challange: true
 }));
 
+const IROHA_ADMIN_PRIV = "f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70";
+const IROHA_ADMIN = "admin@test";
+const IROHA_ADDRESS = "localhost:50051";
+const commandService = new CommandService(IROHA_ADDRESS, grpc.credentials.createInsecure());
+const queryService = new QueryService(IROHA_ADDRESS, grpc.credentials.createInsecure());
+
+
 const CHAIN4ALL_SERVICE_PORT = process.env.CHAIN4ALL_SERVICE_PORT || 3000;
 const IROHA_API_HOST = process.env.IROHA_API_HOST || "http://localhost";
 const IROHA_API_PORT = process.env.IROHA_API_PORT || 5000;
@@ -44,13 +58,51 @@ app.post("/buy", async (req, res, next) => {
         if (!req.body.txHash) {
             res.status(400);
             throw Error(JSON.stringify({ error: { name: "Error, request body has no \"txHash\" property!" } }));
-        }                
+        }
+
+        //TODO load from headers, or something like that??
+        if (!req.body.user) { 
+            res.status(400);
+            throw Error(JSON.stringify({ error: { name: "Error, request body has no \"user\" property!" } }));
+        }
+
+        let txDetail = await getTransactionDetail(req.body.txHash, "kunicykd@test");
+
+        if()
     }
     catch (err) {
         next(err);
     }
 });
 
+function isTransacationValid(){
+    
+}
+
+async function getTransactionDetail(txHash, user) {
+    let quer = await iroha.queries.getAccountTransactions({
+        privateKey: IROHA_ADMIN_PRIV,
+        creatorAccountId: 'admin@test',
+        queryService,
+        timeoutLimit: 5000
+    }, {
+        accountId: user,
+        pageSize: 10,
+        firstTxHash: txHash,
+        ordering: {
+            field: undefined,
+            direction: undefined
+        },
+        firstTxTime: undefined,
+        lastTxTime: undefined,
+        firstTxHeight: 1,
+        lastTxHeight: 3
+    });
+
+    //TODO find better way to look for transferAssets command in transaction
+    return quer.transactionsList[0].payload.reducedPayload.commandsList[0].transferAsset; 
+}
+
 function getArea(extent) {
     let y1 = extent[0][1];
     let y4 = extent[3][1];

+ 3 - 1
package.json

@@ -14,7 +14,9 @@
     "body-parser": "^1.19.1",
     "dotenv": "^14.2.0",
     "express": "^4.17.2",
-    "express-basic-auth": "^1.2.1"
+    "express-basic-auth": "^1.2.1",
+    "grpc": "^1.24.11",
+    "iroha-helpers": "^1.3.0"
   },
   "devDependencies": {
     "nodemon": "^2.0.15"