diff --git a/.travis.yml b/.travis.yml
index 9c5679b..3b15523 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,6 +4,9 @@ jdk:
- oraclejdk8
install: true
+before_script:
+ - mvn install:install-file -Dfile=$TRAVIS_BUILD_DIR/libs/java-crypto-conditions-2.0.0-SNAPSHOT.jar -DgroupId=org.interledger -DartifactId=java-crypto-conditions -Dversion=2.0.0-SNAPSHOT -Dpackaging=jar
+
branches:
only:
- master
diff --git a/pom.xml b/pom.xml
index d48bf7f..78b399b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,11 +68,6 @@
commons-codec
1.10
-
- org.json
- json
- 20170516
-
com.google.code.gson
gson
diff --git a/src/main/java/com/authenteq/api/TransactionsApi.java b/src/main/java/com/authenteq/api/TransactionsApi.java
index 3874258..bfb6a27 100644
--- a/src/main/java/com/authenteq/api/TransactionsApi.java
+++ b/src/main/java/com/authenteq/api/TransactionsApi.java
@@ -10,7 +10,6 @@
import com.authenteq.util.NetworkUtils;
import okhttp3.RequestBody;
import okhttp3.Response;
-import org.json.JSONException;
import java.io.IOException;
import java.util.logging.Logger;
@@ -75,20 +74,16 @@ public static Transaction getTransactionById(String id) throws IOException {
* @param operation
* the operation
* @return the transactions by asset id
- * @throws JSONException
- * the JSON exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static Transactions getTransactionsByAssetId(String assetId, Operations operation)
- throws JSONException, IOException {
+ throws IOException {
LOGGER.info("getTransactionsByAssetId Call :" + assetId + " operation " + operation);
Response response = NetworkUtils.sendGetRequest(
BigChainDBGlobals.getBaseUrl() + BigchainDbApi.TRANSACTIONS + "?asset_id=" + assetId + "&operation=" + operation);
String body = response.body().string();
response.close();
return JsonUtils.fromJson(body, Transactions.class);
-
}
-
}
diff --git a/src/main/java/com/authenteq/builders/BigchainDbConfigBuilder.java b/src/main/java/com/authenteq/builders/BigchainDbConfigBuilder.java
index 92729fd..4752f50 100644
--- a/src/main/java/com/authenteq/builders/BigchainDbConfigBuilder.java
+++ b/src/main/java/com/authenteq/builders/BigchainDbConfigBuilder.java
@@ -8,7 +8,6 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
-import com.authenteq.api.AccountApi;
import com.authenteq.constants.BigchainDbApi;
import com.authenteq.model.ApiEndpoints;
import com.authenteq.model.BigChainDBGlobals;
@@ -25,9 +24,8 @@
* The Class BigchainDbConfigBuilder.
*/
public class BigchainDbConfigBuilder {
-
- private static final Logger LOGGER = Logger.getLogger(AccountApi.class.getName());
-
+
+ private static final Logger LOGGER = Logger.getLogger(BigchainDbConfigBuilder.class.getName());
/**
* Instantiates a new bigchain db config builder.
*/
@@ -74,11 +72,6 @@ public interface ITokens {
* Setup.
*/
void setup();
-
- /**
- * Setup.
- */
-
}
/**
diff --git a/src/main/java/com/authenteq/builders/BigchainDbTransactionBuilder.java b/src/main/java/com/authenteq/builders/BigchainDbTransactionBuilder.java
index f221dc5..daf8f45 100644
--- a/src/main/java/com/authenteq/builders/BigchainDbTransactionBuilder.java
+++ b/src/main/java/com/authenteq/builders/BigchainDbTransactionBuilder.java
@@ -1,24 +1,24 @@
package com.authenteq.builders;
import java.io.IOException;
-import java.lang.reflect.Type;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Signature;
import java.security.SignatureException;
-import java.util.Map;
-import java.util.TreeMap;
+import java.util.logging.Logger;
+
+import com.authenteq.json.strategy.TransactionDeserializer;
+import com.authenteq.json.strategy.TransactionsDeserializer;
+import com.google.gson.*;
import org.apache.commons.codec.binary.Base64;
import org.bouncycastle.jcajce.provider.digest.SHA3;
import org.interledger.cryptoconditions.types.Ed25519Sha256Condition;
import org.interledger.cryptoconditions.types.Ed25519Sha256Fulfillment;
-import org.json.JSONObject;
import com.authenteq.api.TransactionsApi;
import com.authenteq.constants.Operations;
import com.authenteq.model.Asset;
import com.authenteq.model.Condition;
-import com.authenteq.model.DataModel;
import com.authenteq.model.Details;
import com.authenteq.model.FulFill;
import com.authenteq.model.Input;
@@ -28,8 +28,6 @@
import com.authenteq.util.DriverUtils;
import com.authenteq.util.JsonUtils;
import com.authenteq.util.KeyPairUtils;
-import com.google.gson.JsonObject;
-import com.google.gson.reflect.TypeToken;
import net.i2p.crypto.eddsa.EdDSAEngine;
import net.i2p.crypto.eddsa.EdDSAPrivateKey;
import net.i2p.crypto.eddsa.EdDSAPublicKey;
@@ -38,7 +36,8 @@
* The Class BigchainDbTransactionBuilder.
*/
public class BigchainDbTransactionBuilder {
-
+ private static final Logger LOGGER = Logger.getLogger( BigchainDbTransactionBuilder.class.getName() );
+
/**
* Instantiates a new bigchain db transaction builder.
*/
@@ -68,7 +67,7 @@ public interface ITransactionAttributes {
*/
ITransactionAttributes operation(Operations operation);
- /**
+ /*
* Adds the asset.
*
* @param key
@@ -77,7 +76,9 @@ public interface ITransactionAttributes {
* the value
* @return the i asset meta data
*/
- ITransactionAttributes addAsset(String key, String value);
+ //ITransactionAttributes addAsset(String key, String value);
+
+ ITransactionAttributes addAssetDataClass( Class assetDataClass, JsonDeserializer> jsonDeserializer );
ITransactionAttributes addOutput(String amount, EdDSAPublicKey... publicKey);
@@ -91,17 +92,6 @@ public interface ITransactionAttributes {
ITransactionAttributes addInput(String fullfillment, FulFill fullFill, EdDSAPublicKey publicKey);
- /**
- * Adds the meta data.
- *
- * @param key
- * the key
- * @param value
- * the value
- * @return the i asset meta data
- */
- ITransactionAttributes addMetaData(String key, String value);
-
/**
* Adds the assets.
*
@@ -109,43 +99,34 @@ public interface ITransactionAttributes {
* the assets
* @return the i asset meta data
*/
- ITransactionAttributes addAssets(Map assets);
-
- /**
- * Adds the assets.
- *
- * @param obj
- * the obj
- * @return the i asset meta data
- */
- ITransactionAttributes addAssets(DataModel obj);
+ ITransactionAttributes addAssets( Object assets, Class assetsDataClass );
/**
* Adds the meta data.
*
- * @param metadata
- * the metadata
+ * @param metaData
+ * the json object
* @return the i asset meta data
*/
- ITransactionAttributes addMetaData(Map metadata);
+ ITransactionAttributes addMetaData( Object metaData );
/**
- * Adds the meta data.
+ * Add the class and deserializer for metadata
*
- * @param obj
- * the obj
- * @return the i asset meta data
+ * @param metaDataClass the class of the metadata object
+ * @param jsonDeserializer the deserializer
+ * @return
*/
- ITransactionAttributes addMetaData(DataModel obj);
+ ITransactionAttributes addMetaDataClassDeserializer( Class metaDataClass, JsonDeserializer> jsonDeserializer );
/**
- * Adds the meta data.
+ * Add the class and serializer for metadata
*
- * @param jsonObject
- * the json object
- * @return the i asset meta data
+ * @param metaDataClass the class of the metadata object
+ * @param jsonSerializer the deserializer
+ * @return
*/
- ITransactionAttributes addMetaData(JsonObject jsonObject);
+ ITransactionAttributes addMetaDataClassSerializer( Class metaDataClass, JsonSerializer> jsonSerializer );
/**
* Builds the.
@@ -220,9 +201,11 @@ public interface IBuild {
public static class Builder implements ITransactionAttributes, IBuild {
/** The metadata. */
- private Map metadata = null;
+ private Object metadata = null;
+
/** The assets. */
- private Map assets = new TreeMap();
+ private Object assets = null;
+ private Class assetsDataClass = null;
/** The public key. */
private EdDSAPublicKey publicKey;
@@ -280,12 +263,7 @@ public ITransactionAttributes addOutput(String amount, EdDSAPublicKey... publicK
@Override
public ITransactionAttributes addInput(String fullfillment, FulFill fullFill) {
- Input input = new Input();
- input.setFullFillment(fullfillment);
- input.setFulFills(fullFill);
- input.addOwner(KeyPairUtils.encodePublicKeyInBase58(publicKey));
- this.transaction.addInput(input);
- return this;
+ return addInput( fullfillment, fullFill, this.publicKey );
}
@Override
@@ -310,71 +288,35 @@ public ITransactionAttributes addInput(String fullfillment, FulFill fullFill, Ed
return this;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * com.authenteq.builders.BigchainDbTransactionBuilder.IAssetMetaData#
- * addAsset(java.lang.String, java.lang.String)
- */
- @Override
- public ITransactionAttributes addAsset(String key, String value) {
- this.assets.put(key, value);
- return this;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.authenteq.builders.BigchainDbTransactionBuilder.IAssetMetaData#
- * addMetaData(java.lang.String, java.lang.String)
- */
- @Override
- public ITransactionAttributes addMetaData(String key, String value) {
- if (this.metadata == null)
- this.metadata = new TreeMap();
- this.metadata.put(key, value);
+ public ITransactionAttributes addAssetDataClass( Class assetDataClass, JsonDeserializer> jsonDeserializer )
+ {
return this;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * com.authenteq.builders.BigchainDbTransactionBuilder.IAssetMetaData#
- * addAssets(java.util.Map)
+ /**
+ * Add
+ * @param metaDataClass the class of the metadata object
+ * @param jsonDeserializer the deserializer
+ * @return self
*/
@Override
- public ITransactionAttributes addAssets(Map assets) {
- this.assets.putAll(assets);
+ public ITransactionAttributes addMetaDataClassDeserializer( Class metaDataClass, JsonDeserializer> jsonDeserializer )
+ {
+ TransactionDeserializer.setMetaDataClass( metaDataClass );
+ TransactionsDeserializer.setMetaDataClass( metaDataClass );
+ JsonUtils.addTypeAdapterDeserializer( metaDataClass, jsonDeserializer );
return this;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * com.authenteq.builders.BigchainDbTransactionBuilder.IAssetMetaData#
- * addMetaData(java.util.Map)
- */
- @Override
- public ITransactionAttributes addMetaData(Map metadata) {
- if( this.metadata == null )
- this.metadata = new TreeMap();
- this.metadata.putAll(metadata);
+ public ITransactionAttributes addMetaDataClassSerializer( Class metaDataClass, JsonSerializer> jsonSerializer )
+ {
+ JsonUtils.addTypeAdapterSerializer( metaDataClass, jsonSerializer );
return this;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * com.authenteq.builders.BigchainDbTransactionBuilder.IAssetMetaData#
- * addMetaData(com.google.gson.JsonObject)
- */
- @Override
- public ITransactionAttributes addMetaData(JsonObject jsonObject) {
+ public ITransactionAttributes addMetaData( Object object )
+ {
+ this.metadata = object;
return this;
}
@@ -415,22 +357,19 @@ public IBuild build(EdDSAPublicKey publicKey) {
this.transaction.setOperation("CREATE");
}
- this.transaction.setAsset(new Asset(this.assets));
+ this.transaction.setAsset(new Asset(this.assets, this.assetsDataClass));
this.transaction.setMetaData(this.metadata);
this.transaction.setVersion("1.0");
- // Workaround to pop out the field.
- JSONObject transactionJObject = DriverUtils.makeSelfSorting(new JSONObject(this.transaction.toString()));
- transactionJObject.remove("id"); // no need before we sign
+ String temp = this.transaction.toHashInput();
+ LOGGER.info( "TO BE HASHED ---->\n" + temp + "\n<" );
+ JsonObject transactionJObject = DriverUtils.makeSelfSortingGson( temp );
SHA3.DigestSHA3 md = new SHA3.DigestSHA3(256);
md.update(transactionJObject.toString().getBytes());
String id = DriverUtils.getHex(md.digest());
this.transaction.setId(id);
- // we need it after.
- transactionJObject.accumulate("id", id);
- this.transaction = JsonUtils.fromJson(DriverUtils.makeSelfSorting(transactionJObject).toString(),
- Transaction.class);
+
return this;
}
@@ -450,7 +389,7 @@ private void sign(EdDSAPrivateKey privateKey)
throws InvalidKeyException, SignatureException, NoSuchAlgorithmException {
// signing the transaction
- JSONObject transactionJObject = DriverUtils.makeSelfSorting(new JSONObject(this.transaction.toString()));
+ JsonObject transactionJObject = DriverUtils.makeSelfSortingGson(this.transaction.toString());
Signature edDsaSigner = new EdDSAEngine(MessageDigest.getInstance("SHA-512"));
edDsaSigner.initSign(privateKey);
edDsaSigner.update(transactionJObject.toString().getBytes());
@@ -459,7 +398,6 @@ private void sign(EdDSAPrivateKey privateKey)
this.transaction.getInputs().get(0)
.setFullFillment(Base64.encodeBase64URLSafeString(fulfillment.getEncoded()));
this.transaction.setSigned(true);
-
}
/*
@@ -532,37 +470,18 @@ public Transaction sendTransaction() throws IOException {
return this.transaction;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * com.authenteq.builders.BigchainDbTransactionBuilder.IAssetMetaData#
- * addAssets(com.authenteq.model.DataModel)
- */
- @Override
- public ITransactionAttributes addAssets(DataModel obj) {
- Type mapType = new TypeToken