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

Commit 5a80979

Browse files
authored
Merge pull request #178 from awjh-ibm/loc-0.2.5-fixes
Fixes for 0.2.5
2 parents 540cccc + 358e78a commit 5a80979

File tree

6 files changed

+196
-54
lines changed

6 files changed

+196
-54
lines changed

packages/letters-of-credit-network/README.md

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ Navigate to the **Test** tab and then submit a `CreateDemoParticipants` transact
4444

4545
```
4646
{
47-
"$class": "org.acme.loc.CreateDemoParticipants"
47+
"$class": "org.example.loc.CreateDemoParticipants"
4848
}
4949
```
5050

5151
Navigate to the ID registry and generate IDs for:
5252

5353
```
54-
org.acme.loc.Customer#alice
55-
org.acme.loc.Customer#bob
56-
org.acme.loc.BankEmployee#matias
57-
org.acme.loc.BankEmployee#ella
54+
org.example.loc.Customer#alice
55+
org.example.loc.Customer#bob
56+
org.example.loc.BankEmployee#matias
57+
org.example.loc.BankEmployee#ella
5858
```
5959

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

6868
```
6969
{
70-
"$class": "org.acme.loc.InitialApplication",
70+
"$class": "org.example.loc.InitialApplication",
7171
"letterId": "LETTER-REF-123",
72-
"applicant": "resource:org.acme.loc.Customer#alice",
73-
"beneficiary": "resource:org.acme.loc.Customer#bob",
72+
"applicant": "resource:org.example.loc.Customer#alice",
73+
"beneficiary": "resource:org.example.loc.Customer#bob",
7474
"rules": [
7575
{
7676
"ruleId": "LETTER-REF-123-RULE-1",
@@ -82,7 +82,7 @@ Navigate to the **Test** tab and then submit an `InitialApplication` transaction
8282
}
8383
],
8484
"productDetails": {
85-
"$class": "org.acme.loc.ProductDetails",
85+
"$class": "org.example.loc.ProductDetails",
8686
"productType": "Computers",
8787
"quantity": 100,
8888
"pricePerUnit": 450
@@ -102,8 +102,8 @@ Submit a `SuggestChanges` transaction to change the rules:
102102

103103
```
104104
{
105-
"$class": "org.acme.loc.SuggestChanges",
106-
"loc": "resource:org.acme.loc.LetterOfCredit#4572",
105+
"$class": "org.example.loc.SuggestChanges",
106+
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123",
107107
"rules": [
108108
{
109109
"ruleId": "LETTER-REF-123-RULE-1",
@@ -114,7 +114,7 @@ Submit a `SuggestChanges` transaction to change the rules:
114114
"ruleText": "The computers will be received within 15 days"
115115
}
116116
],
117-
"suggestingParty": "resource:org.acme.loc.BankEmployee#matias"
117+
"suggestingParty": "resource:org.example.loc.BankEmployee#matias"
118118
}
119119
```
120120

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

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

129-
Approve the letter by submitting an `ApproveTransaction`:
129+
Approve the letter by submitting an `Approve` transaction:
130130

131131
```
132132
{
133-
"$class": "org.acme.loc.Approve",
134-
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123",
135-
"approvingParty": "resource:org.acme.loc.Customer#alice"
133+
"$class": "org.example.loc.Approve",
134+
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123",
135+
"approvingParty": "resource:org.example.loc.Customer#alice"
136136
}
137137
```
138138

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

141141
---
142142

143-
Use the ID registry to select Ella to be your identity.
143+
Use the ID registry to select Ella to be your identity.
144+
145+
**NOTE:** Alice doesn't have permission to see Ella and therefore you must switch via admin first.
144146

145147
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.
146148

147-
Approve the letter by submitting an `ApproveTransaction`:
149+
Approve the letter by submitting an `Approve` transaction:
148150

149151
```
150152
{
151-
"$class": "org.acme.loc.Approve",
152-
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123",
153-
"approvingParty": "resource:org.acme.loc.BankEmployee#ella"
153+
"$class": "org.example.loc.Approve",
154+
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123",
155+
"approvingParty": "resource:org.example.loc.BankEmployee#ella"
154156
}
155157
```
156158

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

163165
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.
164166

165-
Approve the letter by submitting an `ApproveTransaction`:
167+
Approve the letter by submitting an `Approve` transaction:
166168

167169
```
168170
{
169-
"$class": "org.acme.loc.Approve",
170-
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123",
171-
"approvingParty": "resource:org.acme.loc.Customer#bob"
171+
"$class": "org.example.loc.Approve",
172+
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123",
173+
"approvingParty": "resource:org.example.loc.Customer#bob"
172174
}
173175
```
174176

175177
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.
176178

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

179181
Submit a `ShipProduct` transaction:
180182

181183
```
182184
{
183-
"$class": "org.acme.loc.ShipProduct",
184-
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123",
185+
"$class": "org.example.loc.ShipProduct",
186+
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123",
185187
"evidence": "337478411cab754ce47fcaa72ec1d0f6"
186188
}
187189
```
@@ -198,8 +200,8 @@ Submit a `ReceiveProduct` transaction:
198200

199201
```
200202
{
201-
"$class": "org.acme.loc.ReceiveProduct",
202-
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123"
203+
"$class": "org.example.loc.ReceiveProduct",
204+
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123"
203205
}
204206
```
205207

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

216218
```
217219
{
218-
"$class": "org.acme.loc.ReadyForPayment",
219-
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123"
220+
"$class": "org.example.loc.ReadyForPayment",
221+
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123"
220222
}
221223
```
222224

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

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

231+
**NOTE:** Matias doesn't have permission to see Ella and therefore you must switch via admin first.
232+
229233
Ella having received the funds from Alice's bank can close the letter of credit and deposit the funds in Bob's bank account.
230234

231235
Submit a `Close` transaction:
232236

233237
```
234238
{
235-
"$class": "org.acme.loc.Close",
236-
"loc": "resource:org.acme.loc.LetterOfCredit#LETTER-REF-123",
239+
"$class": "org.example.loc.Close",
240+
"loc": "resource:org.example.loc.LetterOfCredit#LETTER-REF-123",
237241
"closeReason": "Payment made"
238242
}
239243
```
240244

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

243-
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
247+
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
248+
249+
## License <a name="license"></a>
250+
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/.

packages/letters-of-credit-network/lib/logic.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
115
'use strict';
216

17+
/* global getFactory getAssetRegistry getParticipantRegistry emit */
18+
319
/**
420
* Create the LOC asset
521
* @param {org.example.loc.InitialApplication} initalAppliation - the InitialApplication transaction
622
* @transaction
723
*/
8-
async function initialApplication(application) {
24+
async function initialApplication(application) { // eslint-disable-line no-unused-vars
925
const factory = getFactory();
1026
const namespace = 'org.example.loc';
1127

@@ -35,7 +51,7 @@ async function initialApplication(application) {
3551
* @param {org.example.loc.Approve} approve - the Approve transaction
3652
* @transaction
3753
*/
38-
async function approve(approveRequest) {
54+
async function approve(approveRequest) { // eslint-disable-line no-unused-vars
3955
const factory = getFactory();
4056
const namespace = 'org.example.loc';
4157

@@ -49,7 +65,13 @@ async function approve(approveRequest) {
4965
throw new Error ('This person has already approved this letter of credit');
5066
} else if (approveRequest.approvingParty.getType() === 'BankEmployee') {
5167
letter.approval.forEach((approvingParty) => {
52-
if (approvingParty.getType() === 'BankEmployee' && approvingParty.bank.getIdentifier() === approveRequest.approvingParty.bank.getIdentifier()) {
68+
let bankApproved = false;
69+
try {
70+
bankApproved = approvingParty.getType() === 'BankEmployee' && approvingParty.bank.getIdentifier() === approveRequest.approvingParty.bank.getIdentifier();
71+
} catch (err) {
72+
// ignore error as they don't have rights to access that participant
73+
}
74+
if (bankApproved) {
5375
throw new Error('Your bank has already approved of this request');
5476
}
5577
});
@@ -77,7 +99,7 @@ async function approve(approveRequest) {
7799
* @param {org.example.loc.Reject} reject - the Reject transaction
78100
* @transaction
79101
*/
80-
async function reject(rejectRequest) {
102+
async function reject(rejectRequest) { // eslint-disable-line no-unused-vars
81103
const factory = getFactory();
82104
const namespace = 'org.example.loc';
83105

@@ -86,7 +108,7 @@ async function reject(rejectRequest) {
86108
if (letter.status === 'CLOSED' || letter.status === 'REJECTED') {
87109
throw new Error('This letter of credit has already been closed');
88110
} else if (letter.status === 'APPROVED') {
89-
throw new Error('This letter of credit has already been approved');
111+
throw new Error('This letter of credit has already been approved');
90112
} else {
91113
letter.status = 'REJECTED';
92114
letter.closeReason = rejectRequest.closeReason;
@@ -108,7 +130,7 @@ async function reject(rejectRequest) {
108130
* @param {org.example.loc.SuggestChanges} suggestChanges - the SuggestChanges transaction
109131
* @transaction
110132
*/
111-
async function suggestChanges(changeRequest) {
133+
async function suggestChanges(changeRequest) { // eslint-disable-line no-unused-vars
112134
const factory = getFactory();
113135
const namespace = 'org.example.loc';
114136

@@ -117,7 +139,7 @@ async function suggestChanges(changeRequest) {
117139
if (letter.status === 'CLOSED' || letter.status === 'REJECTED') {
118140
throw new Error ('This letter of credit has already been closed');
119141
} else if (letter.status === 'APPROVED') {
120-
throw new Error('This letter of credit has already been approved');
142+
throw new Error('This letter of credit has already been approved');
121143
} else if (letter.status === 'SHIPPED' || letter.status === 'RECEIVED' || letter.status === 'READY_FOR_PAYMENT') {
122144
throw new Error ('The product has already been shipped');
123145
} else {
@@ -144,7 +166,7 @@ async function suggestChanges(changeRequest) {
144166
* @param {org.example.loc.ShipProduct} shipProduct - the ShipProduct transaction
145167
* @transaction
146168
*/
147-
async function shipProduct(shipRequest) {
169+
async function shipProduct(shipRequest) { // eslint-disable-line no-unused-vars
148170
const factory = getFactory();
149171
const namespace = 'org.example.loc';
150172

@@ -176,7 +198,7 @@ async function shipProduct(shipRequest) {
176198
* @param {org.example.loc.ReceiveProduct} receiveProduct - the ReceiveProduct transaction
177199
* @transaction
178200
*/
179-
async function receiveProduct(receiveRequest) {
201+
async function receiveProduct(receiveRequest) { // eslint-disable-line no-unused-vars
180202
const factory = getFactory();
181203
const namespace = 'org.example.loc';
182204

@@ -208,7 +230,7 @@ async function receiveProduct(receiveRequest) {
208230
* @param {org.example.loc.ReadyForPayment} readyForPayment - the ReadyForPayment transaction
209231
* @transaction
210232
*/
211-
async function readyForPayment(paymentRequest) {
233+
async function readyForPayment(paymentRequest) { // eslint-disable-line no-unused-vars
212234
const factory = getFactory();
213235
const namespace = 'org.example.loc';
214236

@@ -239,7 +261,7 @@ async function readyForPayment(paymentRequest) {
239261
* @param {org.example.loc.Close} close - the Close transaction
240262
* @transaction
241263
*/
242-
async function close(closeRequest) {
264+
async function close(closeRequest) { // eslint-disable-line no-unused-vars
243265
const factory = getFactory();
244266
const namespace = 'org.example.loc';
245267

@@ -270,7 +292,7 @@ async function close(closeRequest) {
270292
* @param {org.example.loc.CreateDemoParticipants} createDemoParticipants - the CreateDemoParticipants transaction
271293
* @transaction
272294
*/
273-
async function createDemoParticipants() {
295+
async function createDemoParticipants() { // eslint-disable-line no-unused-vars
274296
const factory = getFactory();
275297
const namespace = 'org.example.loc';
276298

packages/letters-of-credit-network/models/org.acme.loc.cto renamed to packages/letters-of-credit-network/models/org.example.loc.cto

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
/**
2-
* New model file
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
313
*/
4-
14+
515
namespace org.example.loc
616

717
// ENUMS

0 commit comments

Comments
 (0)