Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit f383575

Browse files
committed
adding readme updates, removing stale comments from chaincode
1 parent 8af7ee6 commit f383575

4 files changed

Lines changed: 35 additions & 287 deletions

File tree

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ This is targeted towards Maximo users that have assets that may be managed by th
66

77
When the reader has completed this Code Pattern, they will understand how to leverage Maximo Automation Scripts to propagate changes to a blockchain ledger.
88

9-
<img src="https://i.imgur.com/lKeuzAn.png">
10-
<!-- ![Architecture](https://i.imgur.com/lKeuzAn.png) -->
11-
9+
<img src="https://developer.ibm.com/developer/patterns/tracking-maximo-managed-asset-transactions-across-a-business-network/images/architecture.png">
1210

1311
# Components
1412

@@ -60,7 +58,7 @@ wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-darwin-386.zip
6058
unzip -d /usr/local/bin/ ngrok-stable*zip
6159
6260
# Start ngrok server to forward traffic to port 8000
63-
ngrok http 8000
61+
ngrok http 3000
6462
```
6563

6664
You should see some output like so. Take note of the public URL (http://a6fe75e8.ngrok.io in this example).
@@ -73,19 +71,23 @@ Session Expires 7 hours, 59 minutes
7371
Version 2.3.35
7472
Region United States (us)
7573
Web Interface http://127.0.0.1:4040
76-
Forwarding http://a6fe75e8.ngrok.io -> http://localhost:8000
77-
Forwarding https://a6fe75e8.ngrok.io -> http://localhost:8000
74+
Forwarding http://a6fe75e8.ngrok.io -> http://localhost:3000
75+
Forwarding https://a6fe75e8.ngrok.io -> http://localhost:3000
7876
7977
Connections ttl opn rt1 rt5 p50 p90
8078
0 0 0.00 0.00 0.00 0.00
8179
```
8280

83-
Replace the `url` variable with your ngrok URL (here)[https://github.com/IBM/blockchain-maximo/blob/master/maximo_automation_scripts/work_order_script.py#L57]
81+
Replace the `url` variable with your ngrok URL [here](https://github.com/IBM/blockchain-maximo/blob/master/maximo_automation_scripts/work_order_script.py#L57)
8482

8583
## 2. Create Automation Script in Maximo
8684

87-
Login to Maximo Dashboard
85+
Login to Maximo Dashboard. If using the SaaS trial, click the "Go to Start Center" button
86+
87+
<img src="https://i.imgur.com/18AnxBk.png">
8888

89+
90+
We should then see the main view like so
8991
<img src="https://i.imgur.com/PdqHYup.png">
9092

9193
In the "Find Navigation Item" input box, search for the "Automation Scripts" option.
@@ -131,6 +133,12 @@ Click "Save Work Order". We will return to this section once the blockchain ledg
131133

132134
## 4. Deploy Blockchain Ledger
133135

136+
Clone repository using the git cli
137+
138+
```
139+
git clone https://github.com/IBM/blockchain-maximo
140+
```
141+
134142
Add the following entries to your `/etc/hosts` file.
135143

136144
```
@@ -162,13 +170,6 @@ b85f8b60ea6a hyperledger/fabric-ca
162170

163171
## 5. Deploy Web Application
164172

165-
Clone repository using the git cli
166-
167-
```
168-
git clone https://github.com/IBM/blockchain-maximo
169-
```
170-
171-
172173
### Install Node.js packages
173174

174175
If expecting to run this application locally, please install [Node.js](https://nodejs.org/en/) and NPM. Windows users can use the installer at the link [here](https://nodejs.org/en/download/)

chaincode/write_ledger.go

Lines changed: 2 additions & 271 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ import (
3838

3939
// ============================================================================================================================
4040
// write() - genric write variable into ledger
41-
//
42-
// Shows Off PutState() - writting a key/value into the ledger
43-
//
44-
// Inputs - Array of strings
45-
// 0 , 1
46-
// key , value
47-
// "abc" , "test"
4841
// ============================================================================================================================
4942
func write(stub shim.ChaincodeStubInterface, args []string) pb.Response {
5043
var key, value string
@@ -74,13 +67,6 @@ func write(stub shim.ChaincodeStubInterface, args []string) pb.Response {
7467

7568
// ============================================================================================================================
7669
// delete_marble() - remove a marble from state and from marble index
77-
//
78-
// Shows Off DelState() - "removing"" a key/value from the ledger
79-
//
80-
// Inputs - Array of strings
81-
// 0 , 1
82-
// id , authed_by_company
83-
// "m999999999", "united marbles"
8470
// ============================================================================================================================
8571
func delete(stub shim.ChaincodeStubInterface, args []string) (pb.Response) {
8672
fmt.Println("starting delete")
@@ -98,16 +84,6 @@ func delete(stub shim.ChaincodeStubInterface, args []string) (pb.Response) {
9884

9985
// ============================================================================================================================
10086
// Init Product - create a new asset, store into chaincode state
101-
//
102-
// Shows off building a key's JSON value manually
103-
//
104-
// Inputs - Array of strings
105-
106-
// 0 , 1 , 2 , 3 , 4 , 5 , 6
107-
// id , loan amount , borrower_info , , state , interest , balance due , grade
108-
// "m999999999", "545,000" , object deliquent/in payment , 3.0 , 520,000 , BBB
109-
// credit/income verification/debt to income,
110-
11187
// ============================================================================================================================
11288
func init_asset(stub shim.ChaincodeStubInterface, args []string) (pb.Response) {
11389
var err error
@@ -137,15 +113,6 @@ func init_asset(stub shim.ChaincodeStubInterface, args []string) (pb.Response) {
137113
return shim.Success(nil)
138114
}
139115

140-
141-
// update_asset
142-
143-
// args.add("workorder1")
144-
// args.add("failing")
145-
// args.add("vendor1")
146-
// args.add("asset1")
147-
148-
149116
// this should be called by automation scripts from maximo
150117
func init_work_order(stub shim.ChaincodeStubInterface, args []string) (pb.Response) {
151118
var err error
@@ -174,6 +141,7 @@ func init_work_order(stub shim.ChaincodeStubInterface, args []string) (pb.Respon
174141
fmt.Println("registering wo vendor")
175142

176143
var user User
144+
// allow user to provide id from UI instead of randomly generating one TODO
177145
rand.Seed(time.Now().UnixNano())
178146
id_num := strconv.Itoa(rand.Intn(10000))
179147
user.Id = "user" + id_num
@@ -230,14 +198,7 @@ func update_work_order(stub shim.ChaincodeStubInterface, args []string) (pb.Resp
230198
return shim.Success(nil)
231199
}
232200
// ============================================================================================================================
233-
// Init Owner - create a new owner aka end user, store into chaincode state
234-
//
235-
// Shows off building key's value from GoLang Structure
236-
//
237-
// Inputs - Array of Strings
238-
// 0 , 1 , 2
239-
// owner id , username, company
240-
// "o9999999999999", bob", "united marbles"
201+
// Init Meter - register a new meter, store into chaincode state
241202
// ============================================================================================================================
242203

243204
func init_meter(stub shim.ChaincodeStubInterface, args []string) pb.Response {
@@ -329,233 +290,3 @@ func init_user(stub shim.ChaincodeStubInterface, args []string) pb.Response {
329290
fmt.Println("- end init_user")
330291
return shim.Success(nil)
331292
}
332-
333-
/*
334-
func init_asset_listing(stub shim.ChaincodeStubInterface, args []string) pb.Response {
335-
var err error
336-
fmt.Println("starting init_asset_listing")
337-
338-
//input sanitation
339-
err = sanitize_arguments(args)
340-
if err != nil {
341-
return shim.Error(err.Error())
342-
}
343-
// user.ObjectType = "asset_user"
344-
asset_listing_id := args[0]
345-
supplier_id := args[1]
346-
// asset_ids := args[2] // Expecting JSON array of asset ids. TODO, csv would probably be easier?
347-
348-
assetListing := ProductListingContract{}
349-
assetListing.Id = asset_listing_id
350-
assetListing.Status = "INITIALREQUEST"
351-
assetListing.Owner = supplier_id
352-
assetListing.Supplier = supplier_id
353-
assetListing.OwnerType = "Supplier"
354-
355-
numProducts := len(args) - 2
356-
var assets = make([]string, numProducts)
357-
// all array elements after first 2 are parsed as asset ids
358-
for i := 2; i < len(args); i++ {
359-
assets[i - 2] = args[i]
360-
}
361-
assetListing.Products = assets //csv.NewReader(asset_ids) //json.Unmarshal(asset_ids)
362-
363-
// TODO? update asset location to same as supplier
364-
// supplierAsBytes, err := stub.GetState(supplier_id)
365-
// supplier := Supplier{}
366-
// err = json.Unmarshal(supplierAsBytes, &supplier) //un stringify it aka JSON.parse()
367-
// if err != nil {
368-
// return shim.Error("Error loading supplier")
369-
// }
370-
assetListingAsBytes, _ := json.Marshal(assetListing) //convert to array of bytes
371-
err = stub.PutState(asset_listing_id, assetListingAsBytes) //store owner by its Id
372-
if err != nil {
373-
fmt.Println("Could not store asset listing")
374-
return shim.Error(err.Error())
375-
}
376-
fmt.Println("- end init_asset_listing")
377-
return shim.Success(nil)
378-
}
379-
380-
func init_regulator(stub shim.ChaincodeStubInterface, args []string) pb.Response {
381-
var err error
382-
fmt.Println("starting init_regulator")
383-
384-
//input sanitation
385-
err = sanitize_arguments(args)
386-
if err != nil {
387-
return shim.Error(err.Error())
388-
}
389-
// regulator_id := args[0]
390-
regulator := Regulator{}
391-
regulator.Id = args[0]
392-
regulator.countryId = args[1]
393-
regulatorAsBytes, _ := json.Marshal(regulator) //convert to array of bytes
394-
err = stub.PutState(regulator.Id, regulatorAsBytes) //store owner by its Id
395-
if err != nil {
396-
fmt.Println("Could not store regulator")
397-
return shim.Error(err.Error())
398-
}
399-
fmt.Println("- end init_regulator")
400-
return shim.Success(nil)
401-
}
402-
403-
func transfer_asset_listing(stub shim.ChaincodeStubInterface, args []string) pb.Response {
404-
var err error
405-
fmt.Println("-starting transfer_asset_listing")
406-
//input sanitation
407-
err = sanitize_arguments(args)
408-
if err != nil {
409-
return shim.Error(err.Error())
410-
}
411-
asset_listing_id := args[0]
412-
new_owner_id := args[1]
413-
// user_type := args[1]
414-
// user_id := args[1]
415-
// retailer_id := args[2]
416-
417-
assetListingAsBytes, err := stub.GetState(asset_listing_id)
418-
assetListing := ProductListingContract{}
419-
err = json.Unmarshal(assetListingAsBytes, &assetListing) //un stringify it aka JSON.parse()
420-
if err != nil {
421-
fmt.Println(string(assetListingAsBytes))
422-
return shim.Error(err.Error())
423-
}
424-
assetListing.Owner = new_owner_id
425-
if (strings.ToLower(assetListing.OwnerType) == "supplier") {
426-
assetListing.OwnerType = "Importer"
427-
assetListing.Status = "EXEMPTCHECKREQ"
428-
assetListing.Owner = new_owner_id
429-
430-
} else if ( strings.ToLower(assetListing.OwnerType) == "importer" ) {
431-
assetListing.OwnerType = "Retailer"
432-
if ( assetListing.Status == "EXEMPTCHECKREQ" ){
433-
return shim.Error("Products in listing need to be checked by regulator.")
434-
} else if ( assetListing.Status == "HAZARDANALYSISCHECKREQ" ){
435-
return shim.Error("Products cannot be transferred as they've been flagged by regulator.")
436-
}
437-
retailerAsBytes, err := stub.GetState(new_owner_id)
438-
retailer := Retailer{}
439-
err = json.Unmarshal(retailerAsBytes, &retailer) //un stringify it aka JSON.parse()
440-
if err != nil {
441-
fmt.Println(string(retailerAsBytes))
442-
return shim.Error(err.Error())
443-
}
444-
// _, assets := json.Marshal(assetListing.Products)
445-
for _, asset := range assetListing.Products {
446-
retailer.Products = append(retailer.Products, asset)
447-
}
448-
retailerAsBytes, _ = json.Marshal(retailer) //convert to array of bytes
449-
err = stub.PutState(new_owner_id, retailerAsBytes) //rewrite the marble with id as key
450-
if err != nil {
451-
return shim.Error(err.Error())
452-
}
453-
} else {
454-
return shim.Error("Invalid user type provided.")
455-
}
456-
assetListingAsBytes, _ = json.Marshal(assetListing) //convert to array of bytes
457-
err = stub.PutState(asset_listing_id, assetListingAsBytes) //store owner by its Id
458-
if err != nil {
459-
fmt.Println("Could not store asset listing")
460-
return shim.Error(err.Error())
461-
}
462-
fmt.Println("- end transfer_asset_listing")
463-
return shim.Success(nil)
464-
}
465-
466-
func update_exempted_list(stub shim.ChaincodeStubInterface, args []string) pb.Response {
467-
fmt.Println("- start update_exempted_list")
468-
// ["regulator1", "org", "org1", "org2"..]
469-
// add list of exempted orgs or assets to regulator
470-
regulator_id := args[0]
471-
exempted_type := args[1]
472-
// all remaining args are list of ids
473-
474-
475-
regulatorAsBytes, err := stub.GetState(regulator_id)
476-
regulator := Regulator{}
477-
err = json.Unmarshal(regulatorAsBytes, &regulator) //un stringify it aka JSON.parse()
478-
if err != nil {
479-
return shim.Error(err.Error())
480-
}
481-
482-
numIds := len(args) - 2
483-
ids := make([]string, numIds)
484-
// all array elements after first 2 are parsed as asset ids
485-
for i := 2; i < len(args); i++ {
486-
ids[i - 2] = args[i]
487-
}
488-
489-
// TODO, should probably append list
490-
if (exempted_type == "org") {
491-
regulator.ExemptedOrgIds = ids
492-
} else if (exempted_type == "asset") {
493-
regulator.ExemptedProductIds = ids
494-
}
495-
496-
regulatorAsBytes, _ = json.Marshal(regulator) //convert to array of bytes
497-
err = stub.PutState(regulator_id, regulatorAsBytes) //store owner by its Id
498-
if err != nil {
499-
fmt.Println("Could not store regulator")
500-
return shim.Error(err.Error())
501-
}
502-
fmt.Println("- end update_exempted_list")
503-
return shim.Success(nil)
504-
505-
}
506-
507-
func check_assets(stub shim.ChaincodeStubInterface, args []string) pb.Response {
508-
asset_listing_id := args[0]
509-
regulator_id := args[1]
510-
511-
assetListingAsBytes, err := stub.GetState(asset_listing_id)
512-
assetListing := ProductListingContract{}
513-
err = json.Unmarshal(assetListingAsBytes, &assetListing) //un stringify it aka JSON.parse()
514-
if err != nil {
515-
return shim.Error(err.Error())
516-
}
517-
518-
supplierAsBytes, err := stub.GetState(assetListing.Supplier)
519-
supplier := Supplier{}
520-
err = json.Unmarshal(supplierAsBytes, &supplier) //un stringify it aka JSON.parse()
521-
if err != nil {
522-
return shim.Error(err.Error())
523-
}
524-
525-
regulatorAsBytes, err := stub.GetState(regulator_id)
526-
regulator := Regulator{}
527-
err = json.Unmarshal(regulatorAsBytes, &regulator) //un stringify it aka JSON.parse()
528-
if err != nil {
529-
return shim.Error(err.Error())
530-
}
531-
532-
if (assetListing.Status != "EXEMPTCHECKREQ" && assetListing.Status != "HAZARDANALYSISCHECKREQ"){
533-
return shim.Error("Invalid state, listing cannot be checked");
534-
}
535-
536-
check := true
537-
if (assetListing.Status=="EXEMPTCHECKREQ"){
538-
// check if the supplier org is exempted by regulator
539-
540-
for _, orgId := range regulator.ExemptedOrgIds {
541-
if ( supplier.orgId == orgId ) {
542-
check = false
543-
}
544-
}
545-
}
546-
547-
if (check) {
548-
assetListing.Status="CHECKCOMPLETED"
549-
} else {
550-
assetListing.Status="HAZARDANALYSISCHECKREQ"
551-
}
552-
553-
assetListingAsBytes, _ = json.Marshal(assetListing) //convert to array of bytes
554-
err = stub.PutState(asset_listing_id, assetListingAsBytes) //rewrite the marble with id as key
555-
if err != nil {
556-
return shim.Error(err.Error())
557-
}
558-
fmt.Println("- end check_assets")
559-
return shim.Success(nil)
560-
}
561-
*/

0 commit comments

Comments
 (0)