File tree Expand file tree Collapse file tree 7 files changed +166
-1
lines changed
src/main/java/org/hyperledger/fabric/contract Expand file tree Collapse file tree 7 files changed +166
-1
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,9 @@ jacocoTestCoverageVerification {
6363 element = ' CLASS'
6464 excludes = [' org.hyperledger.fabric.shim.helper.Channel' ,
6565 ' org.hyperledger.fabric.shim.impl.Handler' ,
66- ' org.hyperledger.fabric.shim.impl.ChaincodeSupportStream.1' ]
66+ ' org.hyperledger.fabric.shim.impl.ChaincodeSupportStream.1' ,
67+ ' org.hyperledger.fabric.contract.ContractRouter' ,
68+ ' org.hyperledger.fabric.contract.routing.TransactionType' ]
6769 limit {
6870 minimum = 0.86
6971 }
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright IBM Corp., DTCC All Rights Reserved.
3+
4+ SPDX-License-Identifier: Apache-2.0
5+ */
6+
7+ package org .hyperledger .fabric .contract ;
8+
9+ import org .hyperledger .fabric .contract .execution .ExecutionService ;
10+ import org .hyperledger .fabric .contract .routing .ContractScanner ;
11+ import org .hyperledger .fabric .shim .ChaincodeBase ;
12+ import org .hyperledger .fabric .shim .ChaincodeStub ;
13+
14+ /**
15+ * Router class routes Init/Invoke requests to contracts.
16+ * Implements {@link org.hyperledger.fabric.shim.Chaincode} interface.
17+ */
18+ public class ContractRouter extends ChaincodeBase {
19+
20+ private ContractScanner scanner ;
21+ private ExecutionService executor ;
22+
23+ public ContractRouter () {
24+ }
25+
26+ public void findAllContracts () {
27+
28+ }
29+
30+ public void startRouting (String [] args ) {
31+ start (args );
32+ }
33+
34+ @ Override
35+ public Response init (ChaincodeStub stub ) {
36+ return newErrorResponse ();
37+ }
38+
39+ @ Override
40+ public Response invoke (ChaincodeStub stub ) {
41+ return newErrorResponse ();
42+ }
43+
44+ public static void main (String [] args ) {
45+ ContractRouter cfc = new ContractRouter ();
46+ cfc .findAllContracts ();
47+ cfc .startRouting (args );
48+ }
49+ }
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright IBM Corp., DTCC All Rights Reserved.
3+
4+ SPDX-License-Identifier: Apache-2.0
5+ */
6+
7+ package org .hyperledger .fabric .contract .execution ;
8+
9+ import org .hyperledger .fabric .contract .routing .Routing ;
10+ import org .hyperledger .fabric .shim .Chaincode ;
11+
12+ /**
13+ * Service that executes {@link InvocationRequest} (wrapped INit/Invoke + extra data) using routing information {@link Routing}
14+ */
15+ public interface ExecutionService {
16+
17+ Chaincode .Response executeRequest (Routing rd , InvocationRequest req );
18+ }
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright IBM Corp., DTCC All Rights Reserved.
3+
4+ SPDX-License-Identifier: Apache-2.0
5+ */
6+
7+ package org .hyperledger .fabric .contract .execution ;
8+
9+ import java .util .List ;
10+
11+ /**
12+ * All information needed to find {@link org.hyperledger.fabric.contract.annotation.Contract} and invoke the request
13+ */
14+ public interface InvocationRequest {
15+ String DEFAULT_NAMESPACE = "default" ;
16+
17+ String getNamespace ();
18+ String getMethod ();
19+ List <byte []> getArgs ();
20+ String getRequestName ();
21+ }
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright IBM Corp., DTCC All Rights Reserved.
3+
4+ SPDX-License-Identifier: Apache-2.0
5+ */
6+
7+ package org .hyperledger .fabric .contract .routing ;
8+
9+ import org .hyperledger .fabric .contract .execution .InvocationRequest ;
10+
11+ /**
12+ * Scan and keep all chaincode requests -> contract routing information
13+ */
14+ public interface ContractScanner {
15+
16+ /**
17+ * Scan classpath for all contracts and build routing information for all contracts
18+ * @throws IllegalAccessException
19+ * @throws InstantiationException
20+ */
21+ void findAndSetContracts () throws IllegalAccessException , InstantiationException ;
22+
23+ /**
24+ * Get routing information {@link Routing} based on info from {@link InvocationRequest}
25+ * @param req
26+ * @return
27+ */
28+ Routing getRouting (InvocationRequest req );
29+
30+ /**
31+ * In case no specific {@link Routing}, get default {@link Routing}
32+ * @param req
33+ * @return
34+ */
35+ Routing getDefaultRouting (InvocationRequest req );
36+ }
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright IBM Corp., DTCC All Rights Reserved.
3+
4+ SPDX-License-Identifier: Apache-2.0
5+ */
6+
7+ package org .hyperledger .fabric .contract .routing ;
8+
9+ import org .hyperledger .fabric .contract .ContractInterface ;
10+
11+ import java .lang .reflect .Method ;
12+
13+ /**
14+ * Routing information for each contract method
15+ */
16+ public interface Routing {
17+
18+ ContractInterface getContractObject ();
19+
20+ Method getMethod ();
21+
22+ Class getContractClass ();
23+
24+ TransactionType getType ();
25+
26+ }
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright IBM Corp., DTCC All Rights Reserved.
3+
4+ SPDX-License-Identifier: Apache-2.0
5+ */
6+ package org .hyperledger .fabric .contract .routing ;
7+
8+ public enum TransactionType {
9+ INIT ,
10+ INVOKE ,
11+ QUERY ,
12+ DEFAULT
13+ }
You can’t perform that action at this time.
0 commit comments