// Copyright 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -----------------------------------------------------------------------------

syntax = "proto3";
option java_multiple_files = true;
option java_package = "sawtooth.sdk.protobuf";
option go_package = "processor_pb2";

import "transaction.proto";


// The registration request from the transaction processor to the
// validator/executor
message TpRegisterRequest {

    // A settled upon name for the capabilities of the transaction processor.
    // For example: intkey, xo
    string family = 1;

    // The version supported.  For example:
    //      1.0  for version 1.0
    //      2.1  for version 2.1
    string version = 2;

    // The namespaces this transaction processor expects to interact with
    // when processing transactions matching this specification; will be
    // enforced by the state API on the validator.
    repeated string namespaces = 4;

    // The maximum number of transactions that this transaction processor can
    // handle at once.
    uint32 max_occupancy = 5;
}

// A response sent from the validator to the transaction processor
// acknowledging the registration
message TpRegisterResponse {
    enum Status {
        STATUS_UNSET = 0;
        OK = 1;
        ERROR = 2;
    }

    Status status = 1;
}

// The unregistration request from the transaction processor to the
// validator/executor. The correct handlers are determined from the
// zeromq identity of the tp, on the validator side.
message TpUnregisterRequest {

}

// A response sent from the validator to the transaction processor
// acknowledging the unregistration
message TpUnregisterResponse {
    enum Status {
        STATUS_UNSET = 0;
        OK = 1;
        ERROR = 2;
    }

    Status status = 1;
}


// The request from the validator/executor of the transaction processor
// to verify a transaction.
message TpProcessRequest {
    TransactionHeader header = 1;  // The transaction header
    bytes payload = 2;  // The transaction payload
    string signature = 3;  // The transaction header_signature
    string context_id = 4; // The context_id for state requests.
}


// The response from the transaction processor to the validator/executor
// used to respond about the validity of a transaction
message TpProcessResponse {
    enum Status {
        STATUS_UNSET = 0;
        OK = 1;
        INVALID_TRANSACTION = 2;
        INTERNAL_ERROR = 3;
    }

    Status status = 1;

    // A message to include on responses in the cases where
    // status is either INVALID_TRANSACTION or INTERNAL_ERROR
    string message = 2;

    // Information that may be included with the response.
    // This information is an opaque, application-specific encoded block of
    // data that will be propagated back to the transaction submitter.
    bytes extended_data = 3;
}
