// Copyright the Hyperledger Fabric contributors. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";

option java_package = "org.hyperledger.fabric.protos.peer.lifecycle";
option go_package = "github.com/hyperledger/fabric-protos-go/peer/lifecycle";

package lifecycle;

import "peer/collection.proto";

// InstallChaincodeArgs is the message used as the argument to
// '_lifecycle.InstallChaincode'.
message InstallChaincodeArgs {
    bytes chaincode_install_package = 1; // This should be a marshaled lifecycle.ChaincodePackage
}

// InstallChaincodeArgs is the message returned by
// '_lifecycle.InstallChaincode'.
message InstallChaincodeResult {
    string package_id = 1;
    string label = 2;
}

// QueryInstalledChaincodeArgs is the message used as arguments
// '_lifecycle.QueryInstalledChaincode'
message QueryInstalledChaincodeArgs {
    string package_id = 1;
}

// QueryInstalledChaincodeResult is the message returned by
// '_lifecycle.QueryInstalledChaincode'
message QueryInstalledChaincodeResult {
    string package_id = 1;
    string label = 2;
    map<string, References> references = 3;

    message References {
        repeated Chaincode chaincodes = 1;
    }

    message Chaincode {
        string name = 1;
        string version = 2;
    }
}

// GetInstalledChaincodePackageArgs is the message used as the argument to
// '_lifecycle.GetInstalledChaincodePackage'.
message GetInstalledChaincodePackageArgs {
    string package_id = 1;
}

// GetInstalledChaincodePackageResult is the message returned by
// '_lifecycle.GetInstalledChaincodePackage'.
message GetInstalledChaincodePackageResult {
    bytes chaincode_install_package = 1;
}

// QueryInstalledChaincodesArgs currently is an empty argument to
// '_lifecycle.QueryInstalledChaincodes'.   In the future, it may be
// extended to have parameters.
message QueryInstalledChaincodesArgs {
}

// QueryInstalledChaincodesResult is the message returned by
// '_lifecycle.QueryInstalledChaincodes'.  It returns a list of installed
// chaincodes, including a map of channel name to chaincode name and version
// pairs of chaincode definitions that reference this chaincode package.
message QueryInstalledChaincodesResult {
    message InstalledChaincode {
        string package_id = 1;
        string label = 2;
        map<string, References> references = 3;
    }

    message References {
        repeated Chaincode chaincodes = 1;
    }

    message Chaincode {
        string name = 1;
        string version = 2;
    }

    repeated InstalledChaincode installed_chaincodes = 1;
}

// ApproveChaincodeDefinitionForMyOrgArgs is the message used as arguments to
// `_lifecycle.ApproveChaincodeDefinitionForMyOrg`.
message ApproveChaincodeDefinitionForMyOrgArgs {
    int64 sequence = 1;
    string name = 2;
    string version = 3;
    string endorsement_plugin = 4;
    string validation_plugin = 5;
    bytes validation_parameter = 6;
    protos.CollectionConfigPackage collections = 7;
    bool init_required = 8;
    ChaincodeSource source = 9;
}

message ChaincodeSource {
    message Unavailable {}

    message Local {
        string package_id = 1;
    }

    oneof Type {
        Unavailable unavailable = 1;
        Local local_package = 2;
    }
}

// ApproveChaincodeDefinitionForMyOrgResult is the message returned by
// `_lifecycle.ApproveChaincodeDefinitionForMyOrg`. Currently it returns
// nothing, but may be extended in the future.
message ApproveChaincodeDefinitionForMyOrgResult {
}

// CommitChaincodeDefinitionArgs is the message used as arguments to
// `_lifecycle.CommitChaincodeDefinition`.
message CommitChaincodeDefinitionArgs {
    int64 sequence = 1;
    string name = 2;
    string version = 3;
    string endorsement_plugin = 4;
    string validation_plugin = 5;
    bytes validation_parameter = 6;
    protos.CollectionConfigPackage collections = 7;
    bool init_required = 8;
}

// CommitChaincodeDefinitionResult is the message returned by
// `_lifecycle.CommitChaincodeDefinition`. Currently it returns
// nothing, but may be extended in the future.
message CommitChaincodeDefinitionResult {
}

// CheckCommitReadinessArgs is the message used as arguments to
// `_lifecycle.CheckCommitReadiness`.
message CheckCommitReadinessArgs {
    int64 sequence = 1;
    string name = 2;
    string version = 3;
    string endorsement_plugin = 4;
    string validation_plugin = 5;
    bytes validation_parameter = 6;
    protos.CollectionConfigPackage collections = 7;
    bool init_required = 8;
}

// CheckCommitReadinessResult is the message returned by
// `_lifecycle.CheckCommitReadiness`. It returns a map of
// orgs to their approval (true/false) for the definition
// supplied as args. Additionally, it returns a map of
// parameter mismatches between each organization's
// approved definition and the definition supplied as args.
message CheckCommitReadinessResult{
    map<string, bool> approvals = 1;

    message Mismatches {
        repeated string items = 1;
    }
    map<string, Mismatches> mismatches = 2;
}

// QueryApprovedChaincodeDefinitionArgs is the message used as arguments to
// `_lifecycle.QueryApprovedChaincodeDefinition`.
message QueryApprovedChaincodeDefinitionArgs {
    string name = 1;
    int64 sequence = 2;
}

// QueryApprovedChaincodeDefinitionResult is the message returned by
// `_lifecycle.QueryApprovedChaincodeDefinition`.
message QueryApprovedChaincodeDefinitionResult {
    int64 sequence = 1;
    string version = 2;
    string endorsement_plugin = 3;
    string validation_plugin = 4;
    bytes validation_parameter = 5;
    protos.CollectionConfigPackage collections = 6;
    bool init_required = 7;
    ChaincodeSource source = 8;
}

// QueryApprovedChaincodeDefinitionsArgs is the message used as arguments to
// `_lifecycle.QueryApprovedChaincodeDefinitions`.
message QueryApprovedChaincodeDefinitionsArgs  { }

// QueryApprovedChaincodeDefinitionsResult is the message returned by
// `_lifecycle.QueryApprovedChaincodeDefinitions`.
message QueryApprovedChaincodeDefinitionsResult {
    message ApprovedChaincodeDefinition {
        string name = 1;
        int64 sequence = 2;
        string version = 3;
        string endorsement_plugin = 4;
        string validation_plugin = 5;
        bytes validation_parameter = 6;
        protos.CollectionConfigPackage collections = 7;
        bool init_required = 8;
        ChaincodeSource source = 9;
    }
    repeated ApprovedChaincodeDefinition approved_chaincode_definitions = 1;
}

// QueryChaincodeDefinitionArgs is the message used as arguments to
// `_lifecycle.QueryChaincodeDefinition`.
message QueryChaincodeDefinitionArgs {
    string name = 1;
}

// QueryChaincodeDefinitionResult is the message returned by
// `_lifecycle.QueryChaincodeDefinition`.
message QueryChaincodeDefinitionResult {
    int64 sequence = 1;
    string version = 2;
    string endorsement_plugin = 3;
    string validation_plugin = 4;
    bytes validation_parameter = 5;
    protos.CollectionConfigPackage collections = 6;
    bool init_required = 7;
    map<string,bool> approvals = 8;
}

// QueryChaincodeDefinitionsArgs is the message used as arguments to
// `_lifecycle.QueryChaincodeDefinitions`.
message QueryChaincodeDefinitionsArgs { }

// QueryChaincodeDefinitionsResult is the message returned by
// `_lifecycle.QueryChaincodeDefinitions`.
message QueryChaincodeDefinitionsResult {
    message ChaincodeDefinition {
        string name = 1;
        int64 sequence = 2;
        string version = 3;
        string endorsement_plugin = 4;
        string validation_plugin = 5;
        bytes validation_parameter = 6;
        protos.CollectionConfigPackage collections = 7;
        bool init_required = 8;
    }
    repeated ChaincodeDefinition chaincode_definitions = 1;
}
