This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func trackingDataPointRegistry() registry { | |
return registry{ | |
typeStr: "TrackingDataPoint", | |
typeRT: reflect.TypeOf(&TrackingDataPoint{}), | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type registry struct { | |
typeStr string | |
typeRT reflect.Type | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type registryInterface interface { | |
// key creates a composite key from an id | |
key(stub shim.ChaincodeStubInterface, id string) (string, error) | |
// creates a new data item by marshaling into JSON. Returns | |
// ID of newly created item. | |
create(stub shim.ChaincodeStubInterface, item interface{}) (string, error) | |
// get retrieves an item by its ID | |
get(stub shim.ChaincodeStubInterface, id string) (string, interface{}, error) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cc := &PreciousCargoChaincode{ | |
// all functions as InvocationHandlers | |
handlers: map[string]reflect.Type{ | |
"submitShipment": reflect.TypeOf((*submitShipmentInvocation)(nil)).Elem(), | |
"getShipment": reflect.TypeOf((*getShipmentInvocation)(nil)).Elem(), | |
"registerIndividualParticipant": reflect.TypeOf((*registerIndividualParticipantInvocation)(nil)).Elem(), | |
"getIndividualParticipant": reflect.TypeOf((*getIndividualParticipantInvocation)(nil)).Elem(), | |
"registerShipmentCo": reflect.TypeOf((*registerShipmentCoInvocation)(nil)).Elem(), | |
}, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type PreciousCargoChaincode struct { | |
// map function names to function implementation types | |
handlers map[string]reflect.Type | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type submitShipmentInvocation struct { | |
// input argument | |
arg submitShipmentArg | |
// intermediates | |
shipperKey, fromKey, toKey string | |
submittedAtParsed time.Time | |
// result | |
res submitShipmentResult |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (cci *PreciousCargoChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { | |
function, _ := stub.GetFunctionAndParameters() | |
if invType, found := cci.handlers[function]; found { | |
// from invType as reflect.Type, create a new object and | |
// cast its interface to InvocationHandler. | |
inv := reflect.New(invType).Interface().(InvocationHandler) | |
// let it check its input | |
if err := inv.checkParseArguments(stub); err != nil { | |
return shim.Error(err.Error()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type InvocationHandler interface { | |
checkParseArguments(stub shim.ChaincodeStubInterface) error | |
process(stub shim.ChaincodeStubInterface) error | |
getResponse(stub shim.ChaincodeStubInterface) interface{} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (cci *PreciousCargoChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { | |
function, args := stub.GetFunctionAndParameters() | |
if function == "registerParticipant" { | |
if len(args) != 1 { | |
return shim.Error("expecting JSON input as first param") | |
} | |
// (1) parse input | |
arg := struct { | |
Name string `json:"name"` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string) pb.Response { | |
... | |
} |