Skip to content

Commit

Permalink
removed code smell: repeated method from smart contract
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-huang committed Apr 9, 2018
1 parent d34a612 commit a3e1b75
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 69 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
* `/KYCBackendServer` contains the backend server, which interfaces with the blockchain and handles cryptography
* `/kyc-admin-app` contains the application used by the service to obtain and verify new customer requests

## Installation and Development
* Always develop on Composer Playground (in the demo, at http://173.193.98:31080). When done, export as `.bna`
* Extract the `.bna`: Using `7z` or equivalent, run `7z e -o./hyperledger devtest.bna` or equivalent.
* Extract the contents of `blocktrace/hyperledger` with the extracted `.bna`, and re-run `generate_jsdoc.bat`.
* Finally, `git add`/`commit`/`push`.

## Description
* Development repository for Blocktrace, a Hyperledger Fabric blockchain back-end supporting remote and decentralized identity verification for businesses to securely onboard customers with no hassle
* Deployed on IBM Cloud using Kubernetes
* REST server and RESTful API at 173.193.102.98:31090/explorer
* REST server and RESTful API at https://173.193.102.98:31090/explorer

## About

Expand Down
Binary file modified hyperledger/devtest-https.bna
Binary file not shown.
4 changes: 2 additions & 2 deletions hyperledger/docs/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="script.js.html">script.js</a>, <a href="script.js.html#line173">line 173</a>
<a href="script.js.html">script.js</a>, <a href="script.js.html#line150">line 150</a>
</li></ul></dd>


Expand Down Expand Up @@ -802,7 +802,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Apr 03 2018 20:24:57 GMT+0800 (Malay Peninsula Standard Time)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Apr 09 2018 14:56:55 GMT+0800 (Malay Peninsula Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion hyperledger/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Apr 03 2018 20:24:57 GMT+0800 (Malay Peninsula Standard Time)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Apr 09 2018 14:56:55 GMT+0800 (Malay Peninsula Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
45 changes: 12 additions & 33 deletions hyperledger/docs/script.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,7 @@ <h1 class="page-title">Source: script.js</h1>
* @transaction
*/
function grantAccess(userGrantAccess) {

return getParticipantRegistry('org.acme.biznet.User')
.then(function (userRegistry) {
return userRegistry.get(userGrantAccess.hashed_id);
})
.then(function (existingUser) {

// Update the access rights
var existingAccessValue = existingUser.access;
existingUser.access = true;

// Update the registry.
getParticipantRegistry('org.acme.biznet.User')
.then(function(userRegistry) {
return userRegistry.update(existingUser);
});

// Emit an event for the new user creation.
var event = getFactory().newEvent('org.acme.biznet', 'UserAccessRightsChanged');
event.user = existingUser;
event.oldValue = existingAccessValue;
event.newValue = existingUser.access;
emit(event);
});
modifyAccess(userGrantAccess.hashed_id, true);
}

/**
Expand All @@ -199,16 +176,22 @@ <h1 class="page-title">Source: script.js</h1>
* @transaction
*/
function revokeAccess(userRevokeAccess) {
modifyAccess(userRevokeAccess.hashed_id, false);
}

return getParticipantRegistry('org.acme.biznet.User')
/*
Internal private functions
*/
function modifyAccess(hashed_id, modifier) {
return getParticipantRegistry('org.acme.biznet.User')
.then(function (userRegistry) {
return userRegistry.get(userRevokeAccess.hashed_id);
return userRegistry.get(hashed_id);
})
.then(function (existingUser) {

// Update the access rights
var existingAccessValue = existingUser.access;
existingUser.access = false;
existingUser.access = modifier;

// Update the registry.
getParticipantRegistry('org.acme.biznet.User')
Expand All @@ -223,11 +206,7 @@ <h1 class="page-title">Source: script.js</h1>
event.newValue = existingUser.access;
emit(event);
});
}

/*
Internal private functions
*/</code></pre>
}</code></pre>
</article>
</section>

Expand All @@ -243,7 +222,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Apr 03 2018 20:24:56 GMT+0800 (Malay Peninsula Standard Time)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Apr 09 2018 14:56:55 GMT+0800 (Malay Peninsula Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
43 changes: 11 additions & 32 deletions hyperledger/lib/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,30 +138,7 @@ function updateUserEncryptedData(updateUserEncryptedData) {
* @transaction
*/
function grantAccess(userGrantAccess) {

return getParticipantRegistry('org.acme.biznet.User')
.then(function (userRegistry) {
return userRegistry.get(userGrantAccess.hashed_id);
})
.then(function (existingUser) {

// Update the access rights
var existingAccessValue = existingUser.access;
existingUser.access = true;

// Update the registry.
getParticipantRegistry('org.acme.biznet.User')
.then(function(userRegistry) {
return userRegistry.update(existingUser);
});

// Emit an event for the new user creation.
var event = getFactory().newEvent('org.acme.biznet', 'UserAccessRightsChanged');
event.user = existingUser;
event.oldValue = existingAccessValue;
event.newValue = existingUser.access;
emit(event);
});
modifyAccess(userGrantAccess.hashed_id, true);
}

/**
Expand All @@ -171,16 +148,22 @@ function grantAccess(userGrantAccess) {
* @transaction
*/
function revokeAccess(userRevokeAccess) {
modifyAccess(userRevokeAccess.hashed_id, false);
}

return getParticipantRegistry('org.acme.biznet.User')
/*
Internal private functions
*/
function modifyAccess(hashed_id, modifier) {
return getParticipantRegistry('org.acme.biznet.User')
.then(function (userRegistry) {
return userRegistry.get(userRevokeAccess.hashed_id);
return userRegistry.get(hashed_id);
})
.then(function (existingUser) {

// Update the access rights
var existingAccessValue = existingUser.access;
existingUser.access = false;
existingUser.access = modifier;

// Update the registry.
getParticipantRegistry('org.acme.biznet.User')
Expand All @@ -195,8 +178,4 @@ function revokeAccess(userRevokeAccess) {
event.newValue = existingUser.access;
emit(event);
});
}

/*
Internal private functions
*/
}

0 comments on commit a3e1b75

Please sign in to comment.