// Assume contract instance A is applying for contract instance B... module NaiveDAC{ function initDAC(req){ // public keys of contract instances that a contract instance has accepted // public key -> DOI | remark Global.acceptList = { }; // public keys of contract instances that a contract instance is being applied for // public key -> DOI | remark Global.appliedList = { }; // DOIs of contract instances that a contract instance is applying for // DOI -> remark Global.applyingDOIList = { }; // Public key of the owner of a contract instance Global.owner = req; } // B accepts one application from public key "req" export function accept(req){ if (requester == Global.owner){ Global.acceptList[req] = Global.appliedList[req]; if (Global.appliedList[req] != undefined){ Global.appliedList[req] = undefined; } return true; } return false; } // B cancels one application from public key "req" export function cancel(req){ if (requester == Global.owner){ Global.appliedList[req] = Global.acceptList[req]; if (Global.acceptList[req] != undefined){ Global.acceptList[req] = undefined; } return true; } return false; } // B is being applied for "remark" reason by a public "requester" and "requesterDOI" export function applied(remark){ if (remark != undefined && requester != undefined && requesterDOI != undefined){ Global.appliedList[requester] = requesterDOI + "|" + remark; return "success"; } return "failed"; } // A is applying for "targetDOI" for "remark" reason export function applying(args){ args = JSON.parse(args); if (args.remark != undefined && args.targetDOI != undefined){ Global.applyingDOIList[args.targetDOI] = args.remark; return executeContractByDOI(args.targetDOI, "applied", args.remark); } return "failed"; } export function loadResource(arg){ return Global.Resources.loadAsString(arg); } export function isOwner(arg){ return Global.owner==requester; } export function getAppliedList(arg){ return JSON.stringify(Global.appliedList); } export function getAcceptList(arg){ return JSON.stringify(Global.acceptList); } export function getApplyingDOIList(arg){ return JSON.stringify(Global.applyingDOIList); } // check if public "requester" has the permission of B export function appliedHasPermission(arg){ return (Global.acceptList[requester]!=undefined); } // check if "req" has the permission of B export function checkPermission(req){ return (Global.acceptList[req]!=undefined); } // check if A with "pubkey" has the permission of B with "targetDOI" export function applyingHasPermission(targetDOI){ return executeContractByDOI(targetDOI, "appliedHasPermission"); } }