Skip to content

Instantly share code, notes, and snippets.

@aschmidt75
Created April 16, 2019 13:37
Show Gist options
  • Save aschmidt75/fcd2ab098adde44f5411cb7c23343fd3 to your computer and use it in GitHub Desktop.
Save aschmidt75/fcd2ab098adde44f5411cb7c23343fd3 to your computer and use it in GitHub Desktop.
func (r registry) create(stub shim.ChaincodeStubInterface, item interface{}) (string, error) {
idStr, err := newID(stub, r.typeStr)
if err != nil {
return "", errors.New("internal error generating index key")
}
ck, err := getShipmentKey(stub, idStr)
if err != nil {
return "", errors.New("internal error generating composite key")
}
data, err := json.Marshal(&item)
if err != nil {
return "", errors.New("internal JSON marshal error")
}
err = stub.PutState(ck, []byte(data))
if err != nil {
return "", errors.New("internal error writing world state")
}
return ck, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment