Kaynağa Gözat

add private key for transaction signature

kunickyd 3 yıl önce
ebeveyn
işleme
3b9d0aaea5
1 değiştirilmiş dosya ile 9 ekleme ve 6 silme
  1. 9 6
      app.js

+ 9 - 6
app.js

@@ -76,10 +76,16 @@ app.post("/buy", async (req, res) => {
         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,
@@ -96,8 +102,9 @@ app.post("/buy", async (req, res) => {
 
     res.status(irohaResponse.status);
 
-    if(!irohaResponse.ok){
-        res.send(irohaResponse);
+    if (!irohaResponse.ok) {
+        res.send(await irohaResponse.json());
+        return;
     }
 
     let irohaResponseJson = await irohaResponse.json();
@@ -143,11 +150,7 @@ function getPrice(extent) {
 
 function error(err, req, res, next) { //TODO: add custom Exception class
     console.log(err);
-
-    if (!res.status) {
         res.status(500);
-    }
-
     res.send(err.message);
 }