|
@@ -1,15 +1,29 @@
|
|
|
import 'dotenv/config'
|
|
import 'dotenv/config'
|
|
|
|
|
+import grpc from "grpc"
|
|
|
import express from "express"
|
|
import express from "express"
|
|
|
import bodyParser from "body-parser"
|
|
import bodyParser from "body-parser"
|
|
|
import basicAuth from "express-basic-auth"
|
|
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();
|
|
const app = express();
|
|
|
app.use(bodyParser.json());
|
|
app.use(bodyParser.json());
|
|
|
app.use(basicAuth({
|
|
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 CHAIN4ALL_SERVICE_PORT = process.env.CHAIN4ALL_SERVICE_PORT || 3000;
|
|
|
const IROHA_API_HOST = process.env.IROHA_API_HOST || "http://localhost";
|
|
const IROHA_API_HOST = process.env.IROHA_API_HOST || "http://localhost";
|
|
|
const IROHA_API_PORT = process.env.IROHA_API_PORT || 5000;
|
|
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) {
|
|
if (!req.body.txHash) {
|
|
|
res.status(400);
|
|
res.status(400);
|
|
|
throw Error(JSON.stringify({ error: { name: "Error, request body has no \"txHash\" property!" } }));
|
|
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) {
|
|
catch (err) {
|
|
|
next(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) {
|
|
function getArea(extent) {
|
|
|
let y1 = extent[0][1];
|
|
let y1 = extent[0][1];
|
|
|
let y4 = extent[3][1];
|
|
let y4 = extent[3][1];
|