Commit 032fb63a authored by Somaia Amin's avatar Somaia Amin
Browse files

updated logic.js

parent db6c0e4a
......@@ -71,6 +71,20 @@ async function createAuditAcquisitionReq(tx) {
let event = getFactory().newEvent('org.auditchain', 'NewAuditAcquisitionReq');
event.detail = "Request for: " + tx.auditID;
emit(event);
const ipfsEncURL = await getNativeAPI().invokeChaincode('auditchain', ['AcquiredAudit', 'Asset','org.auditchain.AcquiredAudit', tx.auditID, tx.pubKey, tx.proofOfPayment], 'composerchannel');
if (!ipfsEncURL) throw "Error in Retrieving IPFS URL";
return getAssetRegistry('org.auditchain.AcquiredAudit')
.then(
function(assetRegistry){
var factory = getFactory();
var existingAsset = factory.get(tx.auditID);
existingAsset.ipfsEncURL = ipfsEncURL;
return assetRegistry.update(existingAsset);
}
);
}
).catch(function (error) {
let event = getFactory().newEvent('org.auditchain', 'NewAuditAcquisitionReq');
......@@ -85,69 +99,25 @@ async function createAuditAcquisitionReq(tx) {
* @transaction
*/
async function repToAuditReq(tx) {
/*
o Integer replyID
o Integer requestID
o Integer auditID
o String ipfsEncURL
o String encSymKey
*/
return getAssetRegistry('org.auditchain.AcquiredAudit')
.then(
function(assetRegistry){
var factory = getFactory();
var inputAsset = factory.newResource('org.auditchain', 'AcquiredAudit', tx.auditID);
inputAsset.encSymKey = tx.pubKey;
//tx.proofOfPayment ???
return assetRegistry.add(inputAsset);
}
).then(
function(){
let event = getFactory().newEvent('org.auditchain', 'NewAuditAcquisitionRep');
event.detail = "Reply for: " + tx.auditID;
emit(event);
}
).catch(function (error) {
let event = getFactory().newEvent('org.auditchain', 'NewAuditAcquisitionRep');
event.detail = "Failure for: " + tx.auditID;
emit(event);
});
}
try{
//check how to verify the proofofpayment here
//integrate with ipfs here
var ipfsEncURL = tx.proofOfPayment + "IPFS";
let event = getFactory().newEvent('org.auditchain', 'NewAuditAcquisitionRep');
event.detail = "Reply for: " + tx.auditID;
emit(event);
return ipfsEncURL;
}
catch(error){
let event = getFactory().newEvent('org.auditchain', 'NewAuditAcquisitionRep');
event.detail = "Failure for: " + tx.auditID;
emit(event);
/**
* Sample transaction
* @param {org.auditchain.SampleTransaction} sampleTransaction
* @transaction
*/
async function sampleTransaction(tx) {
// Save the old value of the asset.
const oldValue = tx.asset.value;
// Update the asset with the new value.
tx.asset.value = tx.newValue;
// Get the asset registry for the asset.
const assetRegistry = await getAssetRegistry('org.auditchain.SampleAsset');
// Update the asset in the asset registry.
await assetRegistry.update(tx.asset);
// Emit an event for the modified asset.
let event = getFactory().newEvent('org.auditchain', 'SampleEvent');
event.asset = tx.asset;
event.oldValue = oldValue;
event.newValue = tx.newValue;
emit(event);
}
return null;
}
}
\ No newline at end of file
......@@ -76,11 +76,6 @@ transaction RepToAuditReq {
o String proofOfPayment
}
transaction UpdateAcquiredAudit {
o String auditID
o String ipfsEncURL
}
event NewAuditAcquisitionReq {
o String detail
}
......
Supports Markdown
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