org.hyperledger.fabric.contract.execution.impl.ContractExecutionService Maven / Gradle / Ivy
/*
* Copyright 2019 IBM All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.fabric.contract.execution.impl;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.hyperledger.fabric.contract.Context;
import org.hyperledger.fabric.contract.ContractInterface;
import org.hyperledger.fabric.contract.ContractRuntimeException;
import org.hyperledger.fabric.contract.execution.ExecutionService;
import org.hyperledger.fabric.contract.execution.InvocationRequest;
import org.hyperledger.fabric.contract.execution.SerializerInterface;
import org.hyperledger.fabric.contract.metadata.TypeSchema;
import org.hyperledger.fabric.contract.routing.ParameterDefinition;
import org.hyperledger.fabric.contract.routing.TxFunction;
import org.hyperledger.fabric.shim.Chaincode;
import org.hyperledger.fabric.shim.ChaincodeException;
import org.hyperledger.fabric.shim.ChaincodeStub;
import org.hyperledger.fabric.shim.ResponseUtils;
public class ContractExecutionService implements ExecutionService {
private static Logger logger = Logger.getLogger(ContractExecutionService.class.getName());
private final SerializerInterface serializer;
private Map proxies = new HashMap<>();
/**
* @param serializer
*/
public ContractExecutionService(final SerializerInterface serializer) {
this.serializer = serializer;
}
/**
*
*/
@Override
public Chaincode.Response executeRequest(final TxFunction txFn, final InvocationRequest req, final ChaincodeStub stub) {
logger.fine(() -> "Routing Request" + txFn);
final TxFunction.Routing rd = txFn.getRouting();
Chaincode.Response response;
try {
final ContractInterface contractObject = rd.getContractInstance();
final Context context = contractObject.createContext(stub);
final List