March 2019
Intermediate to advanced
636 pages
27h 50m
English
Next, we'll implement the Init function. Init() allows the chaincode to initialize the insuree data to start the claim request. In our case, we will set up and register the insuree person information, as follows:
func (c *ClaimContract) Init(stub shim.ChaincodeStubInterface) pb.Response { args := stub.GetStringArgs() if len(args) != 5 { return shim.Error("Incorrect arguments. Expecting a key and a value") } insureeId := args[0] firstName := args[1] lastName := args[2] ssn := args[3] policyNumber := args[4] insureeData := Insuree{ Id: insureeId, FirstName: firstName, LastName: lastName, SSN: ssn, PolicyNumber: policyNumber} insureeBytes, _ := json.Marshal(insureeData) err := stub.PutState(insureeId, insureeBytes) ...Read now
Unlock full access