Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J 16
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
22_23-J 16
22_23-J 16
Commits
3f3416e6
Commit
3f3416e6
authored
Jan 28, 2023
by
Kiridena I.T.K_IT19981840
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'Issue-NFT-to-practitioner' into 'master'
Issuing NFT completed See merge request
!17
parents
f521cdff
047439a7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
114 additions
and
49 deletions
+114
-49
ExpressBackend/route/patient-routes/nft-route.js
ExpressBackend/route/patient-routes/nft-route.js
+114
-49
No files found.
ExpressBackend/route/patient-routes/nft-route.js
View file @
3f3416e6
...
...
@@ -272,59 +272,124 @@ router.post("/", async (req, res) => {
});
//add the EHR content to IPFS and get the hash
ipfs
.
add
(
htmlString
)
.
then
((
response
)
=>
{
.
add
(
htmlString
.
toString
()
)
.
then
(
async
(
response
)
=>
{
let
ipfsContentCID
=
response
.
toString
();
//!Use this when getting EHR
// request.post(
// {
// url: "https://ipfs.infura.io:5001/api/v0/cat",
// qs: {
// arg: hash,
// },
// headers: {
// Authorization:
// "Basic " +
// Buffer.from(
// process.env.IPFSPROJECTID + ":" + process.env.IPFSAPIKEY
// ).toString("base64"),
// },
// },
// (error, response, body) => {
// if (error) {
// console.log(error);
// } else {
// //create the PDF document for EHR
// let path = `./patientehr/` + decryptedPatientKey + `-EHR.pdf`;
// let pdfOptions = {
// path: path,
// format: "A4",
// };
// htmlpdf
// .create(htmlString, pdfOptions)
// .then((buff) => {
// console.log("PDF created");
// })
// .catch((errorWhenGeneratingPDF) => {
// console.log(
// "Error when generating PDF : " + errorWhenGeneratingPDF
// );
// console.log(
// "/patient/createnft - NFT creation and sharing failed"
// );
// return res.status(500).json({
// message:
// "Error when generating PDF : " +
// errorWhenGeneratingPDF,
// });
// });
// }
// }
// );
//TODO: create NFT request
request
.
post
(
{
url
:
"
https://ipfs.infura.io:5001/api/v0/cat
"
,
qs
:
{
arg
:
ipfsContentCID
,
},
headers
:
{
Authorization
:
"
Basic
"
+
Buffer
.
from
(
process
.
env
.
IPFSPROJECTID
+
"
:
"
+
process
.
env
.
IPFSAPIKEY
).
toString
(
"
base64
"
),
},
},
(
error
,
response
,
body
)
=>
{
if
(
error
)
{
console
.
log
(
error
);
}
else
{
//create the PDF document for EHR
let
path
=
`./patientehr/`
+
decryptedPatientKey
+
`-EHR.pdf`
;
let
pdfOptions
=
{
path
:
path
,
format
:
"
A4
"
,
};
htmlpdf
.
create
(
htmlString
,
pdfOptions
)
.
then
((
buff
)
=>
{
console
.
log
(
"
PDF created
"
);
})
.
catch
((
errorWhenGeneratingPDF
)
=>
{
console
.
log
(
"
Error when generating PDF :
"
+
errorWhenGeneratingPDF
);
console
.
log
(
"
/patient/createnft - NFT creation and sharing failed
"
);
return
res
.
status
(
500
).
json
({
message
:
"
Error when generating PDF :
"
+
errorWhenGeneratingPDF
,
});
});
}
}
);
//load the patient account
const
userSourceKeyPair
=
StellarSDK
.
Keypair
.
fromSecret
(
decryptedPatientSeed
);
const
userPublicKey
=
userSourceKeyPair
.
publicKey
();
const
server
=
new
StellarSDK
.
Server
(
process
.
env
.
STELLARTESTNET
);
const
account
=
await
server
.
loadAccount
(
userPublicKey
);
const
fee
=
await
server
.
fetchBaseFee
();
const
issueNFTTxn
=
new
StellarSDK
.
TransactionBuilder
(
account
,
{
fee
,
networkPassphrase
:
StellarSDK
.
Networks
.
TESTNET
,
})
.
addMemo
(
StellarSDK
.
Memo
.
text
(
"
Issue NFT
"
))
.
addOperation
(
StellarSDK
.
Operation
.
payment
({
asset
:
new
StellarSDK
.
Asset
(
"
NFTEHR
"
,
decryptedPatientKey
),
amount
:
"
1
"
,
destination
:
decryptedPractitionerKey
,
})
)
.
addOperation
(
StellarSDK
.
Operation
.
manageData
({
name
:
"
NFTEHR
"
,
value
:
ipfsContentCID
,
})
)
.
setTimeout
(
30
)
.
build
();
//sign transaction
issueNFTTxn
.
sign
(
userSourceKeyPair
);
//send transaction to blockchain
try
{
const
transactionResult
=
await
server
.
submitTransaction
(
issueNFTTxn
);
console
.
log
(
"
NFT issued : HASH :
"
+
transactionResult
.
hash
);
console
.
log
(
"
View NFT issued transaction at : https://horizon-testnet.stellar.org/transactions/
"
+
transactionResult
.
hash
);
res
.
status
(
200
).
json
({
message
:
"
NFT EHR issued successfully
"
,
hash
:
transactionResult
.
hash
,
});
console
.
log
(
"
/patient/createnft - NFT creation and sharing success
"
);
}
catch
(
errorWhenIssuingNFT
)
{
console
.
log
(
"
Error when issuing NFT :
"
+
errorWhenIssuingNFT
);
console
.
log
(
"
/patient/createnft - NFT creation and sharing failed
"
);
return
res
.
status
(
500
).
json
({
message
:
"
Error when issuing NFT :
"
+
errorWhenIssuingNFT
,
});
}
})
.
catch
((
errorWhenAddingToIPFS
)
=>
{
console
.
log
(
errorWhenAddingToIPFS
);
console
.
log
(
"
Error when adding records to IPFS :
"
+
errorWhenAddingToIPFS
);
console
.
log
(
"
/patient/createnft - NFT creation and sharing failed
"
);
return
res
.
status
(
500
).
json
({
message
:
"
Error when adding records to IPFS :
"
+
errorWhenAddingToIPFS
,
});
});
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment