/*
Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

syntax = "proto3";

package protos;
option java_package = "org.hyperledger.fabric.protos.peer";
option go_package = "github.com/hyperledger/fabric/protos/peer";
import "chaincode_event.proto";
import "proposal.proto";
import "../google/protobuf/timestamp.proto";


message ChaincodeMessage {

    enum Type {
        UNDEFINED = 0;
        REGISTER = 1;
        REGISTERED = 2;
        INIT = 3;
        READY = 4;
        TRANSACTION = 5;
        COMPLETED = 6;
        ERROR = 7;
        GET_STATE = 8;
        PUT_STATE = 9;
        DEL_STATE = 10;
        INVOKE_CHAINCODE = 11;
        RESPONSE = 13;
        GET_STATE_BY_RANGE = 14;
        GET_QUERY_RESULT = 15;
        QUERY_STATE_NEXT = 16;
        QUERY_STATE_CLOSE = 17;
        KEEPALIVE = 18;
        GET_HISTORY_FOR_KEY = 19;
    }

    Type type = 1;
    google.protobuf.Timestamp timestamp = 2;
    bytes payload = 3;
    string txid = 4;

    SignedProposal proposal = 5;

    //event emitted by chaincode. Used only with Init or Invoke.
    // This event is then stored (currently)
    //with Block.NonHashData.TransactionResult
    ChaincodeEvent chaincode_event = 6;

    //channel id
    string channel_id = 7;
}

// TODO: We need to finalize the design on chaincode container
// compatibility upon upgrade, see FAB-5777.

message GetState {
    string key = 1;
    string collection = 2;
}

message PutState {
    string key = 1;
    bytes value = 2;
    string collection = 3;
}

message DelState {
    string key = 1;
    string collection = 2;
}

message GetStateByRange {
    string startKey = 1;
    string endKey = 2;
    string collection = 3;
}

message GetQueryResult {
    string query = 1;
    string collection = 2;
}

message GetHistoryForKey {
    string key = 1;
}

message QueryStateNext {
    string id = 1;
}

message QueryStateClose {
    string id = 1;
}

message QueryResultBytes {
    bytes resultBytes = 1;
}

message QueryResponse {
    repeated QueryResultBytes results = 1;
    bool has_more = 2;
    string id = 3;
}

// Interface that provides support to chaincode execution. ChaincodeContext
// provides the context necessary for the server to respond appropriately.
service ChaincodeSupport {

    rpc Register(stream ChaincodeMessage) returns (stream ChaincodeMessage) {}


}
