RequestedInfo

After the insuree reports a loss, the next step is for the broker to return RequestedInfo, as follows:

func (c *ClaimContract) RequestedInfo(stub shim.ChaincodeStubInterface, args []string) pb.Response {
return c.UpdateClaim(stub, args, "RequestedInfo")
}
func (c *ClaimContract) UpdateClaim(stub shim.ChaincodeStubInterface, args []string, currentStatus string) pb.Response {
claimId := args[0]
comment := args[1]
claimBytes, err := stub.GetState(claimId)
claim := Claim{}
err = json.Unmarshal(claimBytes, &claim)
if err != nil {
return shim.Error(err.Error())
}
if currentStatus == "RequestedInfo" && claim.Status != "ReportLost" {
claim.Status = "Error"
fmt.Printf("Claim is not initialized yet")
return shim.Error(err.Error())
} else if currentStatus == "SubmitClaim" && claim.Status != "RequestedInfo" {
claim.Status = "Error"
fmt.Printf("Claim must be in RequestedInfo status")
return shim.Error(err.Error())
} else if currentStatus == "ConfirmClaimSubmission" && claim.Status != "SubmitClaim" {
claim.Status = "Error"
fmt.Printf("Claim must be in Submit Claim status")
return shim.Error(err.Error())
} else if currentStatus == "ApproveClaim" && claim.Status != "ConfirmClaimSubmission" {
claim.Status = "Error"
fmt.Printf("Claim must be in Confirm Claim Submission status")
return shim.Error(err.Error())
}
claim.Comment = comment
if currentStatus == "RequestedInfo" {
insurerId := args[2]
claim.InsurerId = insurerId
}
currentts := time.Now()
claim.ProcessAt = currentts.Format("2006-01-02 15:04:05")
claim.Status = currentStatus
claimBytes0, _ := json.Marshal(claim)
err = stub.PutState(claimId, claimBytes0)
if err != nil {
return shim.Error(err.Error())
}
return shim.Success(claimBytes0)
}

Since the remaining process functions are quite similar, we define UpdateClaim as a common function to share with the remaining steps.

The UpdateClaim function first gets claimId and the current participant comment from input arguments. It then queries and gets a claim from the blockchain to decode the claim data and turns it into a JSON string—json.Unmarshal(claimBytes, &claim).

Before updating the claim content, it will validate the input claim status and make sure it is on the expected step. If all goes well, we will update the claim status, participant comment, and process time.

Finally, we update the claim data with claimId as a key on the ledger.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset