Skip to content

Commit b62740c

Browse files
[FAB-13798] New interfaces
Change-Id: Iae4feff52035131d3ee9c31051c305de6b453fa9 Signed-off-by: gennady <[email protected]>
1 parent 8235149 commit b62740c

File tree

7 files changed

+166
-1
lines changed

7 files changed

+166
-1
lines changed

fabric-chaincode-shim/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

0 commit comments

Comments
 (0)