Chaincodeは、次のAPIに準拠する必要があります。
pb.Response
がある
// Chaincode interface must be implemented by all chaincodes. The fabric runs
// the transactions by calling these functions as specified.
type Chaincode interface {
// Init is called during Instantiate transaction after the chaincode container
// has been established for the first time, allowing the chaincode to
// initialize its internal data
Init(stub ChaincodeStubInterface) pb.Response
// Invoke is called to update or query the ledger in a proposal transaction.
// Updated state variables are not committed to the ledger until the
// transaction is committed.
Invoke(stub ChaincodeStubInterface) pb.Response
}
:
// A response with a representation similar to an HTTP response that can
// be used within another message.
type Response struct {
// A status code that should follow the HTTP status codes.
Status int32 `protobuf:"varint,1,opt,name=status" json:"status,omitempty"`
// A message associated with the response code.
Message string `protobuf:"bytes,2,opt,name=message" json:"message,omitempty"`
// A payload that can be used to include metadata with this response.
Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"`
}
Chaincodeシムはresponse.goで定義されたエラーと成功ステータスを返すようにファサードの機能を提供します。したがって、あなたがexampleのために、バッククライアント側にエラーを通知して転送するために異なる応答タイプを使用することができ、あなたのchaincodeに流れをimplementtingながら:あなたは間違ったパラメータでchaincodeを起動しようとする場合
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
fmt.Println("ex02 Invoke")
function, args := stub.GetFunctionAndParameters()
if function == "invoke" {
// Make payment of X units from A to B
return t.invoke(stub, args)
} else if function == "delete" {
// Deletes an entity from its state
return t.delete(stub, args)
} else if function == "query" {
// the old "Query" is now implemtned in invoke
return t.query(stub, args)
}
return shim.Error("Invalid invoke function name. Expecting \"invoke\" \"delete\" \"query\"")
}
してもエラーで応答しますセット。後で、エラーがあるかどうかを確認するために応答を検査することもできます。また、発生したことの詳細をメッセージで応答することもできます。