Commit 852d7861 authored by Kiridena I.T.K_IT19981840's avatar Kiridena I.T.K_IT19981840

Merge branch 'asset-code-generation-on-request' into 'master'

asset code generation moved to request done

See merge request !25
parents 47e650dd b39f5116
......@@ -8,7 +8,6 @@ const Patient = new mongoose.Schema({
rsa: String,
genesishash: String,
currenthash: String,
keysequence: String,
issuerpk: String,
issuersk: String,
timestamp: String,
......
......@@ -289,14 +289,6 @@ router.post("/", async (req, res) => {
const b64RSApk = btoa(RSAPK);
const b64RSAsk = btoa(RSASK);
var newAssetCode = "";
//generate NFT sequence NO as asset ID
GenerateRandomAssetCode()
.then(async (assetCode) => {
newAssetCode = assetCode;
console.log("New asset code generated : ", newAssetCode);
//generate new account
try {
const result = await GenerateKeyPairAndCreateAccount();
......@@ -313,21 +305,14 @@ router.post("/", async (req, res) => {
genesishash: genesisTxnResult.hash,
currenthash: genesisTxnResult.hash,
timestamp: timestamp,
keysequence: newAssetCode,
issuerpk: EncryptionService.EncryptWithServerKey(
result.publicKey
),
issuersk: EncryptionService.EncryptWithServerKey(
result.privateKey
),
issuerpk: EncryptionService.EncryptWithServerKey(result.publicKey),
issuersk: EncryptionService.EncryptWithServerKey(result.privateKey),
});
//save the user collection object to the database
try {
const saveUserInCollection = await userCollectionObject.save();
console.log(
"User details added to the DB " + saveUserInCollection
);
console.log("User details added to the DB " + saveUserInCollection);
console.log("Public key: " + userKeyPair.publicKey());
console.log("Secret: " + userKeyPair.secret());
res.status(200).json({
......@@ -373,20 +358,6 @@ router.post("/", async (req, res) => {
"/patient/register - register patient details unsuccessful"
);
}
})
.catch((errWhenGeneratingAssetCode) => {
console.log(
"Error when generating asset code : " + errWhenGeneratingAssetCode
);
res.status(500).json({
message:
"Error when generating asset code : " +
errWhenGeneratingAssetCode,
});
console.log(
"/patient/register - register patient details unsuccessful"
);
});
} catch (error) {
console.log(
"Error when sending genesis transaction to blockchain: " + error
......
const express = require("express");
const router = express.Router();
const GetIssuerAndAssetCode = require("./../../services/assetCodeGetterFromDB");
const GetIssuer = require("./../../services/assetCodeGetterFromDB");
const DecryptWithServerKey = require("./../../services/decryptionservice");
const StellarSdk = require("stellar-sdk");
const CreateTrustline = require("./../../services/trustlineCreator");
const NFTRequest = require("./../../model/stellar/nftRequests");
const GenerateRandomAssetCode = require("./../../services/assetCodeGenerator");
require("dotenv").config();
router.post("/", async (req, res) => {
......@@ -13,14 +14,15 @@ router.post("/", async (req, res) => {
const patientKey = req.body.patient;
const practitionerRSA = req.body.practitionerrsa;
//take the current asset code and the issuer key for the patient from the data base
const assetAndIssuer = await GetIssuerAndAssetCode("patients", patientKey);
//take the issuer key for the patient from the data base
const issuerRes = await GetIssuer("patients", patientKey);
console.log("AC", assetAndIssuer.assetCode);
console.log("IP", DecryptWithServerKey(assetAndIssuer.issuerKey));
const assetCode = assetAndIssuer.assetCode;
const issuerPK = DecryptWithServerKey(assetAndIssuer.issuerKey);
//Generate the asset code
GenerateRandomAssetCode()
.then((assetCode) => {
console.log("AC", assetCode);
console.log("IP", DecryptWithServerKey(issuerRes.issuerKey));
const issuerPK = DecryptWithServerKey(issuerRes.issuerKey);
CreateTrustline(assetCode, issuerPK, practitionerSK)
.then(async (result) => {
......@@ -61,6 +63,18 @@ router.post("/", async (req, res) => {
error,
});
});
})
.catch((errWhenGeneratingAssetCode) => {
console.log(
"Failed to generate asset code : ",
errWhenGeneratingAssetCode
);
console.log("/practitioner/requestnft - requesting NFT failed");
return res.status(500).json({
message: "Failed to generate asset code : ",
errWhenGeneratingAssetCode,
});
});
});
module.exports = router;
const MongoClient = require("mongodb").MongoClient;
async function GetIssuerAndAssetCode(collectionName, publicKey) {
async function GetIssuer(collectionName, publicKey) {
const uri = process.env.DATABASE_URL;
const client = new MongoClient(uri, {
useNewUrlParser: true,
......@@ -19,10 +19,9 @@ async function GetIssuerAndAssetCode(collectionName, publicKey) {
return {
issuerKey: result.issuerpk,
assetCode: result.keysequence,
};
} finally {
await client.close();
}
}
module.exports = GetIssuerAndAssetCode;
module.exports = GetIssuer;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment