Skip to content

Commit da987ba

Browse files
committed
Fix duplicate instancing of Root contract
1 parent a1db537 commit da987ba

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main/java/com/brunoarruda/hyperdcpabe/blockchain/BlockchainConnection.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,31 @@ public BlockchainConnection(String networkURL, Map<String, String> contractAddre
8787

8888
public Map<String, String> deployContracts(Credentials credentials) {
8989
try {
90-
SmartDCPABERoot contractRoot = SmartDCPABERoot.deploy(web3j, credentials, dgp).send();
91-
String rootAddress = contractRoot.getContractAddress();
92-
9390
scRoot = SmartDCPABERoot.deploy(web3j, credentials, dgp).send();
91+
String rootAddress = scRoot.getContractAddress();
92+
9493
scAuthority = SmartDCPABEAuthority.deploy(web3j, credentials, dgp, rootAddress).send();
9594
scFiles = SmartDCPABEFiles.deploy(web3j, credentials, dgp, rootAddress).send();
9695
scKeys = SmartDCPABEKeys.deploy(web3j, credentials, dgp, rootAddress).send();
9796
scRequests = SmartDCPABERequests.deploy(web3j, credentials, dgp, rootAddress).send();
9897
scUsers = SmartDCPABEUsers.deploy(web3j, credentials, dgp, rootAddress).send();
9998
scUtility = SmartDCPABEUtility.deploy(web3j, credentials, dgp, rootAddress).send();
10099

100+
contractAddress.put("Root", rootAddress);
101101
contractAddress.put("Authority", scAuthority.getContractAddress());
102102
contractAddress.put("Files", scFiles.getContractAddress());
103103
contractAddress.put("Keys", scKeys.getContractAddress());
104104
contractAddress.put("Requests", scRequests.getContractAddress());
105105
contractAddress.put("Users", scUsers.getContractAddress());
106106
contractAddress.put("Utility", scUtility.getContractAddress());
107107

108-
List<String> addressList = Arrays.asList(contractAddress.values().toArray(new String[0]));
108+
List<String> addressList = new ArrayList<String>();
109109
List<BigInteger> indexes = new ArrayList<BigInteger>();
110-
Arrays.asList(0, 1, 2, 3, 4, 5).forEach(val -> indexes.add(BigInteger.valueOf(val)));
110+
String[] keys = {"Authority", "Files", "Keys", "Requests", "Users", "Utility"};
111+
for (int i = 0; i < keys.length; i++) {
112+
addressList.add(contractAddress.get(keys[i]));
113+
indexes.add(BigInteger.valueOf(i));
114+
}
111115
scRoot.setAllContracts(indexes, addressList).send();
112116
} catch (Exception e) {
113117
e.printStackTrace();

0 commit comments

Comments
 (0)