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
05c2472c
Commit
05c2472c
authored
Apr 06, 2023
by
Ishini Kiridena
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IPFS recording of weekly practitioner records
parent
1a13b9ee
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
122 additions
and
119 deletions
+122
-119
ExpressBackend/route/practitioner-routes/records-route.js
ExpressBackend/route/practitioner-routes/records-route.js
+122
-119
No files found.
ExpressBackend/route/practitioner-routes/records-route.js
View file @
05c2472c
...
...
@@ -4,7 +4,9 @@ const DecryptWithServerKey = require("./../../services/decryptionservice");
const
PractitionerPatientCount
=
require
(
"
../../model/practitioner/practitioner-patient
"
);
const
StellarSDK
=
require
(
"
stellar-sdk
"
);
const
{
TimeoutInfinite
}
=
require
(
"
stellar-sdk
"
);
const
IPFS
=
require
(
"
ipfs-infura
"
);
const
LIMIT
=
64
;
const
EncryptionService
=
require
(
"
./../../services/encryptionservice
"
);
router
.
post
(
"
/
"
,
async
(
req
,
res
)
=>
{
// const decryptedPatientPubKey = DecryptWithServerKey(req.body.patient);
...
...
@@ -38,28 +40,26 @@ router.post("/", async (req, res) => {
const
server
=
new
StellarSDK
.
Server
(
process
.
env
.
STELLARTESTNET
);
const
account
=
await
server
.
loadAccount
(
userPublicKey
);
const
fee
=
await
server
.
fetchBaseFee
();
let
operations
=
[];
//check the length of the record string
if
(
records
.
length
>
LIMIT
)
{
for
(
let
i
=
0
;
i
<
records
.
length
;
i
+=
LIMIT
)
{
// recordChunks.push(records.substring(i, i + LIMIT));
operations
.
push
(
StellarSDK
.
Operation
.
manageData
({
name
:
i
.
toString
(),
value
:
records
.
substring
(
i
,
i
+
LIMIT
),
})
);
}
}
else
{
//Build one manage data operation
operations
.
push
(
StellarSDK
.
Operation
.
manageData
({
name
:
"
0
"
,
value
:
records
.
toString
(),
})
//encrypt the weekly records using practitioner BC secret key
const
encryptedRec
=
EncryptionService
.
EncryptWithStellarSeed
(
req
.
body
.
practitionerseed
);
}
//create the IPFS instance
const
ipfs
=
new
IPFS
({
host
:
process
.
env
.
IPFSHOST
,
port
:
process
.
env
.
IPFSPORT
,
protocol
:
process
.
env
.
IPFSPROTOCOL
,
projectId
:
process
.
env
.
IPFSPROJECTID
,
projectSecret
:
process
.
env
.
IPFSAPIKEY
,
});
//add the weekly records to IPFS
ipfs
.
add
(
encryptedRec
)
.
then
(
async
(
response
)
=>
{
let
ipfsContentCID
=
response
.
toString
();
//build the transaction
const
transaction
=
new
StellarSDK
.
TransactionBuilder
(
account
,
{
...
...
@@ -67,12 +67,6 @@ router.post("/", async (req, res) => {
networkPassphrase
:
StellarSDK
.
Networks
.
TESTNET
,
})
.
addMemo
(
StellarSDK
.
Memo
.
text
(
"
Record
"
+
currentCount
.
toString
()))
.
addOperation
(
StellarSDK
.
Operation
.
manageData
({
name
:
"
Length
"
,
value
:
operations
.
length
.
toString
(),
})
)
.
addOperation
(
StellarSDK
.
Operation
.
manageData
({
name
:
"
Timestamp
"
,
...
...
@@ -87,26 +81,20 @@ router.post("/", async (req, res) => {
)
.
addOperation
(
StellarSDK
.
Operation
.
manageData
({
name
:
"
Count
"
,
value
:
currentCount
.
toString
(),
name
:
"
CID
"
,
value
:
ipfsContentCID
.
toString
(),
})
)
.
setTimeout
(
30
)
.
build
();
//loop through the operations array and append to the transaction
// for (let i = 0; i < operations.length; i++) {
// transaction
// .addOperation(operations[i])
// .setTimeout(TimeoutInfinite)
// .build();
// }
//sign the transaction
transaction
.
sign
(
userSourceKeyPair
);
//send the transaction to the blockchain
try
{
const
transactionResult
=
await
server
.
submitTransaction
(
transaction
);
const
transactionResult
=
await
server
.
submitTransaction
(
transaction
);
console
.
log
(
"
Weekly record transaction added to blockchain : HASH :
"
+
transactionResult
.
hash
...
...
@@ -138,7 +126,8 @@ router.post("/", async (req, res) => {
});
}
else
{
console
.
log
(
"
Weekly record transaction saved to database :
"
+
updateCounter
"
Weekly record transaction saved to database :
"
+
updateCounter
);
res
.
status
(
200
).
json
({
message
:
"
Weekly record transaction saved to blockchain
"
,
...
...
@@ -176,6 +165,20 @@ router.post("/", async (req, res) => {
"
/practitioner/records - adding practitioner records failed
"
);
}
})
.
catch
((
errorWhenAddingToIPFS
)
=>
{
console
.
log
(
"
Error when adding weekly record to IPFS :
"
+
errorWhenAddingToIPFS
);
console
.
log
(
"
/practitioner/records - adding practitioner records failed
"
);
res
.
status
(
400
).
json
({
message
:
"
Error when adding weekly record to IPFS :
"
+
errorWhenAddingToIPFS
,
});
});
}
}
catch
(
errorWhenGettingCount
)
{
console
.
log
(
...
...
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