Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #178 from awjh-ibm/loc-0.2.5-fixes
Browse files Browse the repository at this point in the history
Fixes for 0.2.5
  • Loading branch information
awjh-ibm authored May 30, 2018
2 parents 540cccc + 358e78a commit 5a80979
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 54 deletions.
77 changes: 42 additions & 35 deletions packages/letters-of-credit-network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ Navigate to the **Test** tab and then submit a `CreateDemoParticipants` transact

```
{
"$class": "org.acme.loc.CreateDemoParticipants"
"$class": "org.example.loc.CreateDemoParticipants"
}
```

Navigate to the ID registry and generate IDs for:

```
org.acme.loc.Customer#alice
org.acme.loc.Customer#bob
org.acme.loc.BankEmployee#matias
org.acme.loc.BankEmployee#ella
org.example.loc.Customer#alice
org.example.loc.Customer#bob
org.example.loc.BankEmployee#matias
org.example.loc.BankEmployee#ella
```

Select to Alice to be your identity.
Expand All @@ -67,10 +67,10 @@ Navigate to the **Test** tab and then submit an `InitialApplication` transaction

```
{
"$class": "org.acme.loc.InitialApplication",
"$class": "org.example.loc.InitialApplication",
"letterId": "LETTER-REF-123",
"applicant": "resource:org.acme.loc.Customer#alice",
"beneficiary": "resource:org.acme.loc.Customer#bob",
"applicant": "resource:org.example.loc.Customer#alice",
"beneficiary": "resource:org.example.loc.Customer#bob",
"rules": [
{
"ruleId": "LETTER-REF-123-RULE-1",
Expand All @@ -82,7 +82,7 @@ Navigate to the **Test** tab and then submit an `InitialApplication` transaction
}
],
"productDetails": {
"$class": "org.acme.loc.ProductDetails",
"$class": "org.example.loc.ProductDetails",
"productType": "Computers",
"quantity": 100,
"pricePerUnit": 450
Expand All @@ -102,8 +102,8 @@ Submit a `SuggestChanges` transaction to change the rules:

```
{
"$class": "org.acme.loc.SuggestChanges",
"loc": "resource:org.acme.loc.LetterOfCredit#4572",
"$class": "org.example.loc.SuggestChanges",
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123",
"rules": [
{
"ruleId": "LETTER-REF-123-RULE-1",
Expand All @@ -114,7 +114,7 @@ Submit a `SuggestChanges` transaction to change the rules:
"ruleText": "The computers will be received within 15 days"
}
],
"suggestingParty": "resource:org.acme.loc.BankEmployee#matias"
"suggestingParty": "resource:org.example.loc.BankEmployee#matias"
}
```

Expand All @@ -126,31 +126,33 @@ Use the ID registry to select Alice to be your identity.

Review the changes made to the letter of credit by selecting the `LetterOfCredit` asset. Alice agrees with the changes and decides she will approve.

Approve the letter by submitting an `ApproveTransaction`:
Approve the letter by submitting an `Approve` transaction:

```
{
"$class": "org.acme.loc.Approve",
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123",
"approvingParty": "resource:org.acme.loc.Customer#alice"
"$class": "org.example.loc.Approve",
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123",
"approvingParty": "resource:org.example.loc.Customer#alice"
}
```

This transaction adds Alice to the array of parties in the `approval` field of the `LetterOfCredit` asset.

---

Use the ID registry to select Ella to be your identity.
Use the ID registry to select Ella to be your identity.

**NOTE:** Alice doesn't have permission to see Ella and therefore you must switch via admin first.

Ella works at Bob's bank. Review the letter of credit by selecting the `LetterOfCredit` asset. Ella decides that the letter of credit is acceptable to her bank and that she will approve the request.

Approve the letter by submitting an `ApproveTransaction`:
Approve the letter by submitting an `Approve` transaction:

```
{
"$class": "org.acme.loc.Approve",
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123",
"approvingParty": "resource:org.acme.loc.BankEmployee#ella"
"$class": "org.example.loc.Approve",
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123",
"approvingParty": "resource:org.example.loc.BankEmployee#ella"
}
```

Expand All @@ -162,26 +164,26 @@ Use the ID registry to select Bob to be your identity.

Bob reviews the letter of credit to ensure that it matches with his and Alice's agreement. He notices that the rules don't quite match the agreement however he still decides to accept the letter of credit and go through with the deal.

Approve the letter by submitting an `ApproveTransaction`:
Approve the letter by submitting an `Approve` transaction:

```
{
"$class": "org.acme.loc.Approve",
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123",
"approvingParty": "resource:org.acme.loc.Customer#bob"
"$class": "org.example.loc.Approve",
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123",
"approvingParty": "resource:org.example.loc.Customer#bob"
}
```

This transaction adds Bob to the array of parties in the `approval` field of the `LetterOfCredit` asset. As now all the parties have submitted their approval the `status` field is also updated to be `APPROVED`. At this point no participant may reject or suggest changes to the letter. Further participants (e.g. other bank employees) are also blocked from adding their approval.

Bob manufactures the computers and gives ships them. He updates the `LetterOfCredit` asset to add proof that he has shipped the goods.
Bob manufactures the computers and ships them. He updates the `LetterOfCredit` asset to add proof that he has shipped the goods.

Submit a `ShipProduct` transaction:

```
{
"$class": "org.acme.loc.ShipProduct",
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123",
"$class": "org.example.loc.ShipProduct",
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123",
"evidence": "337478411cab754ce47fcaa72ec1d0f6"
}
```
Expand All @@ -198,8 +200,8 @@ Submit a `ReceiveProduct` transaction:

```
{
"$class": "org.acme.loc.ReceiveProduct",
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123"
"$class": "org.example.loc.ReceiveProduct",
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123"
}
```

Expand All @@ -215,8 +217,8 @@ Submit a `ReadyForPayment` transaction:

```
{
"$class": "org.acme.loc.ReadyForPayment",
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123"
"$class": "org.example.loc.ReadyForPayment",
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123"
}
```

Expand All @@ -226,18 +228,23 @@ This transaction updates the `status` of the letter of credit to be `READY_FOR_P

Use the ID registry to select Ella to be your identity.

**NOTE:** Matias doesn't have permission to see Ella and therefore you must switch via admin first.

Ella having received the funds from Alice's bank can close the letter of credit and deposit the funds in Bob's bank account.

Submit a `Close` transaction:

```
{
"$class": "org.acme.loc.Close",
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123",
"$class": "org.example.loc.Close",
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123",
"closeReason": "Payment made"
}
```

This transaction updates the `status` of the letter to be `CLOSED`. The letter is now complete and no further transactions can take place.

This business network has been used to create demo application that simulate the scenario above. You can find more detail on these at https://github.com/hyperledger/composer-sample-applications/tree/master/packages/letters-of-credit
This business network has been used to create demo application that simulate the scenario above. You can find more detail on these at https://github.com/hyperledger/composer-sample-applications/tree/master/packages/letters-of-credit

## License <a name="license"></a>
Hyperledger Project source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file. Hyperledger Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0), available at http://creativecommons.org/licenses/by/4.0/.
46 changes: 34 additions & 12 deletions packages/letters-of-credit-network/lib/logic.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

/* global getFactory getAssetRegistry getParticipantRegistry emit */

/**
* Create the LOC asset
* @param {org.example.loc.InitialApplication} initalAppliation - the InitialApplication transaction
* @transaction
*/
async function initialApplication(application) {
async function initialApplication(application) { // eslint-disable-line no-unused-vars
const factory = getFactory();
const namespace = 'org.example.loc';

Expand Down Expand Up @@ -35,7 +51,7 @@ async function initialApplication(application) {
* @param {org.example.loc.Approve} approve - the Approve transaction
* @transaction
*/
async function approve(approveRequest) {
async function approve(approveRequest) { // eslint-disable-line no-unused-vars
const factory = getFactory();
const namespace = 'org.example.loc';

Expand All @@ -49,7 +65,13 @@ async function approve(approveRequest) {
throw new Error ('This person has already approved this letter of credit');
} else if (approveRequest.approvingParty.getType() === 'BankEmployee') {
letter.approval.forEach((approvingParty) => {
if (approvingParty.getType() === 'BankEmployee' && approvingParty.bank.getIdentifier() === approveRequest.approvingParty.bank.getIdentifier()) {
let bankApproved = false;
try {
bankApproved = approvingParty.getType() === 'BankEmployee' && approvingParty.bank.getIdentifier() === approveRequest.approvingParty.bank.getIdentifier();
} catch (err) {
// ignore error as they don't have rights to access that participant
}
if (bankApproved) {
throw new Error('Your bank has already approved of this request');
}
});
Expand Down Expand Up @@ -77,7 +99,7 @@ async function approve(approveRequest) {
* @param {org.example.loc.Reject} reject - the Reject transaction
* @transaction
*/
async function reject(rejectRequest) {
async function reject(rejectRequest) { // eslint-disable-line no-unused-vars
const factory = getFactory();
const namespace = 'org.example.loc';

Expand All @@ -86,7 +108,7 @@ async function reject(rejectRequest) {
if (letter.status === 'CLOSED' || letter.status === 'REJECTED') {
throw new Error('This letter of credit has already been closed');
} else if (letter.status === 'APPROVED') {
throw new Error('This letter of credit has already been approved');
throw new Error('This letter of credit has already been approved');
} else {
letter.status = 'REJECTED';
letter.closeReason = rejectRequest.closeReason;
Expand All @@ -108,7 +130,7 @@ async function reject(rejectRequest) {
* @param {org.example.loc.SuggestChanges} suggestChanges - the SuggestChanges transaction
* @transaction
*/
async function suggestChanges(changeRequest) {
async function suggestChanges(changeRequest) { // eslint-disable-line no-unused-vars
const factory = getFactory();
const namespace = 'org.example.loc';

Expand All @@ -117,7 +139,7 @@ async function suggestChanges(changeRequest) {
if (letter.status === 'CLOSED' || letter.status === 'REJECTED') {
throw new Error ('This letter of credit has already been closed');
} else if (letter.status === 'APPROVED') {
throw new Error('This letter of credit has already been approved');
throw new Error('This letter of credit has already been approved');
} else if (letter.status === 'SHIPPED' || letter.status === 'RECEIVED' || letter.status === 'READY_FOR_PAYMENT') {
throw new Error ('The product has already been shipped');
} else {
Expand All @@ -144,7 +166,7 @@ async function suggestChanges(changeRequest) {
* @param {org.example.loc.ShipProduct} shipProduct - the ShipProduct transaction
* @transaction
*/
async function shipProduct(shipRequest) {
async function shipProduct(shipRequest) { // eslint-disable-line no-unused-vars
const factory = getFactory();
const namespace = 'org.example.loc';

Expand Down Expand Up @@ -176,7 +198,7 @@ async function shipProduct(shipRequest) {
* @param {org.example.loc.ReceiveProduct} receiveProduct - the ReceiveProduct transaction
* @transaction
*/
async function receiveProduct(receiveRequest) {
async function receiveProduct(receiveRequest) { // eslint-disable-line no-unused-vars
const factory = getFactory();
const namespace = 'org.example.loc';

Expand Down Expand Up @@ -208,7 +230,7 @@ async function receiveProduct(receiveRequest) {
* @param {org.example.loc.ReadyForPayment} readyForPayment - the ReadyForPayment transaction
* @transaction
*/
async function readyForPayment(paymentRequest) {
async function readyForPayment(paymentRequest) { // eslint-disable-line no-unused-vars
const factory = getFactory();
const namespace = 'org.example.loc';

Expand Down Expand Up @@ -239,7 +261,7 @@ async function readyForPayment(paymentRequest) {
* @param {org.example.loc.Close} close - the Close transaction
* @transaction
*/
async function close(closeRequest) {
async function close(closeRequest) { // eslint-disable-line no-unused-vars
const factory = getFactory();
const namespace = 'org.example.loc';

Expand Down Expand Up @@ -270,7 +292,7 @@ async function close(closeRequest) {
* @param {org.example.loc.CreateDemoParticipants} createDemoParticipants - the CreateDemoParticipants transaction
* @transaction
*/
async function createDemoParticipants() {
async function createDemoParticipants() { // eslint-disable-line no-unused-vars
const factory = getFactory();
const namespace = 'org.example.loc';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/**
* New model file
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace org.example.loc

// ENUMS
Expand Down
Loading

0 comments on commit 5a80979

Please sign in to comment.