@@ -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// ============================================================================================================================
4942func 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// ============================================================================================================================
8571func 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// ============================================================================================================================
11288func 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
150117func 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
243204func 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, ®ulator) //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, ®ulator) //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