diff --git a/sample-project-gradle-master/bin/.gitignore b/sample-project-gradle-master/bin/.gitignore index b318177dcb9e9cae91f4df87a0d5e27a05c642a2..cf1db2eed3105aa86842b8dff99b9083d9257a5f 100644 --- a/sample-project-gradle-master/bin/.gitignore +++ b/sample-project-gradle-master/bin/.gitignore @@ -1,3 +1 @@ -/logback.xml /org/ -/solidity/ diff --git a/sample-project-gradle-master/src/main/java/org/web3j/sample/Application.java b/sample-project-gradle-master/src/main/java/org/web3j/sample/Application.java index 65e44e64e029fb7719342e313afb6236a8b12ae8..e5f14f05cbd916599f9f8a0858de0f912b55857e 100644 --- a/sample-project-gradle-master/src/main/java/org/web3j/sample/Application.java +++ b/sample-project-gradle-master/src/main/java/org/web3j/sample/Application.java @@ -109,6 +109,8 @@ public class Application { //Check the contract on Etherscan website log.info("View contract at https://ropsten.etherscan.io/address/" + contractAddress); + +// Test some method provided by web3j library // String adro = contract.getDeployedAddress("1"); // String adrt = contract.getDeployedAddress("2"); // String adrtr = contract.getDeployedAddress("3"); @@ -120,13 +122,18 @@ public class Application { // log.info("Smart Contract deployed to address: " + contractAddress); // log.info("View contract at https://ropsten.etherscan.io/address/" + contractAddress); - //Add user to the access control list + //Add authorized users to the access control list TransactionReceipt userone = contract.addUser("0xFC87F1c9459A4e15731d004EbD923821f89AA007").send(); - //TransactionReceipt userthree = contract.addUser("0xcdA6722bCf8a428129007e6d3DabfDdC233a0070").send(); TransactionReceipt usertwo = contract.addUser("0xbA719536EEDeA5F0eE74469160E03CA709CD7309").send(); + //TransactionReceipt userthree = contract.addUser("0xcdA6722bCf8a428129007e6d3DabfDdC233a0070").send(); + + //Get the owners address log.info("Owner: " + contract.owner().send()); - log.info("Access:" + contract.isUser("0xbA719536EEDeA5F0eE74469160E03CA709CD7309"). send()); - log.info("Access:" + contract.isUser("0xcdA6722bCf8a428129007e6d3DabfDdC233a0070"). send()); + //See if a user address is authorized to gain access + log.info("Is this user authorised to gain access: " + contract.isUser("0xbA719536EEDeA5F0eE74469160E03CA709CD7309"). send()); + log.info("Is this user authorised to gain access: " + contract.isUser("0xcdA6722bCf8a428129007e6d3DabfDdC233a0070"). send()); + + //Check how many users are now included in the baseData! At the moment must be no user in the baseData storage log.info("Number of Users in the baseData: " + contract.getUserCount().send()); //System.out.println(contract.owner().send()); @@ -135,7 +142,8 @@ public class Application { // log.info("New User added to the baseData!" + "The number of users now is: " + contract.getUserCount().send() // + " The new user's id is: " + event.userId); } - //Get and Set User details + //Insert data to the baseData contract storage + //Get and Insert User details //User #1 TransactionReceipt transactionReceipt = contract.insertUser("0xFC87F1c9459A4e15731d004EbD923821f89AA007", "thesis@uos.ac.uk", BigInteger.valueOf(20), "me", BigInteger.valueOf(1), BigInteger.valueOf(200000)).send(); //User #2 @@ -151,10 +159,12 @@ public class Application { //Send the results and print them //log.info("User Info: " + contract.getUser("0xFC87F1c9459A4e15731d004EbD923821f89AA007").send()); + + //Retrieve Data if you are authorised user! log.info("User #:" + contract.getUser("0xFC87F1c9459A4e15731d004EbD923821f89AA007").send().getValue3() + " Info: " + contract.getUser("0xFC87F1c9459A4e15731d004EbD923821f89AA007").send()); + //Retrieve single field log.info("User Email: " + contract.getUser("0xFC87F1c9459A4e15731d004EbD923821f89AA007").send().getValue1()); log.info("User #:" + contract.getUser("0xbA719536EEDeA5F0eE74469160E03CA709CD7309").send().getValue3() + " Info: " + contract.getUser("0xbA719536EEDeA5F0eE74469160E03CA709CD7309").send()); - //String name = contract.getUser("0xFC87F1c9459A4e15731d004EbD923821f89AA007").send().getValue0(); log.info("User Name: " + contract.getUser("0xFC87F1c9459A4e15731d004EbD923821f89AA007").send().getValue2()); //Get number of users and print it