diff --git a/.classpath b/.classpath
index b19e9cbbb..1eed87618 100644
--- a/.classpath
+++ b/.classpath
@@ -15,7 +15,6 @@
-
@@ -73,5 +72,6 @@
+
diff --git a/bundle/build.xml b/bundle/build.xml
index 650dab60a..42969ba49 100644
--- a/bundle/build.xml
+++ b/bundle/build.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/core/build.xml b/core/build.xml
index ca9dd66fb..b8abbef63 100644
--- a/core/build.xml
+++ b/core/build.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/core/ivy.xml b/core/ivy.xml
index 9dc3ce6cc..4d54ee9cb 100644
--- a/core/ivy.xml
+++ b/core/ivy.xml
@@ -29,7 +29,7 @@
-
+
diff --git a/core/src/main/java/i5/las2peer/registry/ReadWriteRegistryClient.java b/core/src/main/java/i5/las2peer/registry/ReadWriteRegistryClient.java
index 6bf1776de..db0142048 100644
--- a/core/src/main/java/i5/las2peer/registry/ReadWriteRegistryClient.java
+++ b/core/src/main/java/i5/las2peer/registry/ReadWriteRegistryClient.java
@@ -1,6 +1,7 @@
package i5.las2peer.registry;
import java.io.IOException;
+import java.lang.reflect.Constructor;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
@@ -9,13 +10,17 @@
import org.web3j.abi.datatypes.Function;
import org.web3j.crypto.Credentials;
+import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.Response;
import org.web3j.protocol.core.methods.request.Transaction;
import org.web3j.protocol.core.methods.response.EthSendTransaction;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.exceptions.TransactionException;
+import org.web3j.tx.Contract;
import org.web3j.tx.FastRawTransactionManager;
import org.web3j.tx.Transfer;
+import org.web3j.tx.gas.ContractGasProvider;
+import org.web3j.tx.gas.StaticGasProvider;
import org.web3j.utils.Convert;
import org.web3j.utils.Convert.Unit;
@@ -225,7 +230,7 @@ public String addUserRating(EthereumAgent receivingAgent, Integer rating) throws
}
public boolean hasReputationProfile(String profileName)
- throws EthereumException {
+ throws EthereumException {
Boolean hasProfile = Boolean.FALSE;
try {
hasProfile = contracts.reputationRegistry.hasProfile(profileName).sendAsync().get();
@@ -245,7 +250,7 @@ public boolean hasReputationProfile(String profileName)
* @param agent Ethereum agent of the service author
*/
public void registerService(String serviceName, EthereumAgent agent) throws EthereumException,
- AgentLockedException {
+ AgentLockedException {
byte[] authorName = Util.padAndConvertString(agent.getLoginName(), 32);
final Function function = new Function(ServiceRegistry.FUNC_REGISTER,
@@ -257,7 +262,7 @@ public void registerService(String serviceName, EthereumAgent agent) throws Ethe
try {
contracts.serviceRegistry.delegatedRegister(serviceName, authorName, consentee, signature).sendAsync()
- .get();
+ .get();
} catch (Exception e) {
throw new EthereumException("Failed to register service", e);
}
@@ -347,12 +352,12 @@ public void releaseService(String serviceName, int versionMajor, int versionMino
* @param nodeId identifier of the node running the deployment
*/
public void announceDeployment(String servicePackageName, String serviceClassName,
- int versionMajor, int versionMinor, int versionPatch,
- String nodeId) throws EthereumException {
+ int versionMajor, int versionMinor, int versionPatch,
+ String nodeId) throws EthereumException {
try {
contracts.serviceRegistry.announceDeployment(servicePackageName, serviceClassName,
- BigInteger.valueOf(versionMajor), BigInteger.valueOf(versionMinor), BigInteger.valueOf(versionPatch),
- nodeId).sendAsync().get();
+ BigInteger.valueOf(versionMajor), BigInteger.valueOf(versionMinor), BigInteger.valueOf(versionPatch),
+ nodeId).sendAsync().get();
} catch (Exception e) {
throw new EthereumException("Failed to submit service deployment announcement ("
+ "DEBUG: " + serviceClassName + ", " + e.getMessage() + ")", e);
@@ -374,12 +379,12 @@ public void announceDeployment(String servicePackageName, String serviceClassNam
// TODO: is there a more elegant way? referencing the tx is possible of course
// but not really preferable
public void announceDeploymentEnd(String servicePackageName, String serviceClassName,
- int versionMajor, int versionMinor, int versionPatch,
- String nodeId) throws EthereumException {
+ int versionMajor, int versionMinor, int versionPatch,
+ String nodeId) throws EthereumException {
try {
contracts.serviceRegistry.announceDeploymentEnd(servicePackageName, serviceClassName,
- BigInteger.valueOf(versionMajor), BigInteger.valueOf(versionMinor), BigInteger.valueOf(versionPatch),
- nodeId).sendAsync().get();
+ BigInteger.valueOf(versionMajor), BigInteger.valueOf(versionMinor), BigInteger.valueOf(versionPatch),
+ nodeId).sendAsync().get();
} catch (Exception e) {
throw new EthereumException("Failed to submit service deployment *end* announcement ("
+ "DEBUG: " + serviceClassName + ", " + e.getMessage() + ")", e);
@@ -392,10 +397,10 @@ public String sendEtherManaged(String senderAddress, String recipientAddress, Bi
BigInteger gasPrice = GAS_PRICE;
BigInteger gasLimit = GAS_LIMIT_ETHER_TX;
logger.info("[ETH] Preparing raw transaction between accounts...");
-
+
Transfer transfer = new Transfer(this.web3j, this.contracts.transactionManager);
-
+
@@ -443,7 +448,7 @@ public String sendEtherManaged(String senderAddress, String recipientAddress, Bi
@Deprecated
public TransactionReceipt sendEther(String senderAddress, String recipientAddress, BigInteger valueInWei)
throws EthereumException {
-
+
TransactionReceipt txR;
String txHash;
BigInteger nonce = BigInteger.valueOf(-1);
@@ -468,12 +473,12 @@ public TransactionReceipt sendEther(String senderAddress, String recipientAddres
throw new EthereumException("Eth Transaction Error [" + error.getCode() + "]: " + error.getMessage());
}
txHash = ethSendTransaction.getTransactionHash();
-
+
if (txHash.length() < 2) {
throw new EthereumException("Could not create ethereum transaction");
}
-
+
logger.info("[ETH] waiting for receipt on [" + txHash + "]... ");
txR = waitForReceipt(txHash);
@@ -512,6 +517,32 @@ public String sendEtherFromCoinbase(String recipientAddress, BigInteger valueInW
logger.info("[ETH] Sending Faucet Transaction");
return sendEtherManaged(coinbase, recipientAddress, valueInWei);
}
-
-
+
+ public T deploySmartContract(Class contractClass, String contractBinary) {
+ T contract = null;
+ try {
+ contract = T.deployRemoteCall(contractClass, web3j, credentials, gasPrice, gasLimit, contractBinary, "", BigInteger.ZERO).send();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return contract;
+ }
+
+ public T loadSmartContract(Class contractClass, String contractAddress) {
+ T contract = null;
+ try {
+ Constructor constructor = contractClass.getDeclaredConstructor(
+ String.class,
+ Web3j.class,
+ Credentials.class,
+ ContractGasProvider.class);
+ constructor.setAccessible(true);
+ contract = constructor.newInstance(contractAddress, web3j, credentials, new StaticGasProvider(gasPrice, gasLimit));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return contract;
+ }
}
diff --git a/core/src/main/java/i5/las2peer/serialization/XmlTools.java b/core/src/main/java/i5/las2peer/serialization/XmlTools.java
index ba6201cbc..01f43eab8 100644
--- a/core/src/main/java/i5/las2peer/serialization/XmlTools.java
+++ b/core/src/main/java/i5/las2peer/serialization/XmlTools.java
@@ -5,6 +5,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -162,6 +164,35 @@ public static Element getOptionalElement(Element parent, String tagName) throws
return null;
}
}
+
+ /**
+ * Gets all elements with the given child tag from given parent XML element.
+ *
+ * @param parent The parent XML element.
+ * @param tagName The tag name of the child elements. CASE SENSITIVE
+ * @return Returns the child elements with the given tag name or null if no child matches the given tag name.
+ * @throws MalformedXMLException If it's not a node itself.
+ */
+ public static List getElementList(Element parent, String tagName) throws MalformedXMLException {
+ NodeList nodeList = parent.getElementsByTagName(tagName);
+ int len = nodeList.getLength();
+ if (len > 0) {
+ ArrayList elements = new ArrayList<>();
+ for (int i = 0; i < len; i++) {
+ org.w3c.dom.Node firstNode = nodeList.item(i);
+ short nodeType = firstNode.getNodeType();
+ if (nodeType != org.w3c.dom.Node.ELEMENT_NODE) {
+ throw new MalformedXMLException(
+ "Node type (" + nodeType + ") is not type element (" + org.w3c.dom.Node.ELEMENT_NODE + ")");
+ }
+ elements.add((Element) firstNode);
+ }
+ return elements;
+ } else {
+ // no child elements with tag name found
+ return null;
+ }
+ }
public static String escapeString(String str) {
return str.replace("&", "&").replace("'", "'").replace("<", "<").replace(">", ">");
diff --git a/restmapper/build.xml b/restmapper/build.xml
index 29f5b82d7..59bbc4576 100644
--- a/restmapper/build.xml
+++ b/restmapper/build.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/webconnector/build.xml b/webconnector/build.xml
index bd993433d..eea2e9d7b 100644
--- a/webconnector/build.xml
+++ b/webconnector/build.xml
@@ -4,7 +4,7 @@
-
+