Skip to content

Instantly share code, notes, and snippets.

@MichalZalecki MichalZalecki/prescriptions.go Secret
Last active Jul 30, 2018

Embed
What would you like to do?
type SmartContract struct {
}
func (s *SmartContract) Init(stub shim.ChaincodeStubInterface) peer.Response {
return shim.Success(nil)
}
func (s *SmartContract) Invoke(stub shim.ChaincodeStubInterface) peer.Response {
fn, args := stub.GetFunctionAndParameters()
if fn == "initLedger" {
return s.initLedger(stub)
} else if fn == "addPrescription" {
return s.addPrescription(stub, args)
} else if fn == "getPrescription" {
return s.getPrescription(stub, args)
} else if fn == "transferPrescription" {
return s.transferPrescription(stub, args)
}
return shim.Error("Invalid function name.")
}
func (s *SmartContract) initLedger(stub shim.ChaincodeStubInterface) peer.Response {
prescriptions := []Prescription{
Prescription{Patient: "PAT0", Doctor: "DOC0", Expires: "2018-07-17 14:01:52"},
}
for i, prescription := range prescriptions {
prescriptionAsBytes, _ := json.Marshal(prescription)
stub.PutPrivateData("healthcarePrescriptions", "PRE"+strconv.Itoa(i), prescriptionAsBytes)
}
return shim.Success(nil)
}
func main() {
err := shim.Start(new(SmartContract))
if err != nil {
fmt.Printf("Error starting SmartContract chaincode: %s", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.