diff --git a/gradle.properties b/gradle.properties index 1053dd5..5bfcab3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,8 +17,8 @@ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -VERSION_NAME=0.4.4 -VERSION_CODE=6 +VERSION_NAME=0.4.6 +VERSION_CODE=9 GROUP=com.github.bilthon POM_DESCRIPTION=A Java library for mobile app Developers; Graphene/Bitshares blockchain. diff --git a/graphenej/build.gradle b/graphenej/build.gradle index 64f87e8..0d30268 100644 --- a/graphenej/build.gradle +++ b/graphenej/build.gradle @@ -1,5 +1,5 @@ -group 'de.bitsharesmunich' -version '0.4.4' +group 'cy.agorise' +version '0.4.6' apply plugin: 'com.android.library' apply from: 'maven-push.gradle' @@ -21,9 +21,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 24 - versionCode 6 - versionName "0.4.4" - + versionCode 9 + versionName "0.4.6" vectorDrawables.useSupportLibrary = true } buildTypes { diff --git a/graphenej/src/main/AndroidManifest.xml b/graphenej/src/main/AndroidManifest.xml index b86d91f..4df96c3 100644 --- a/graphenej/src/main/AndroidManifest.xml +++ b/graphenej/src/main/AndroidManifest.xml @@ -1,9 +1,8 @@ - + package="cy.agorise.graphenej" + android:versionCode="9" + android:versionName="0.4.6" > \ No newline at end of file diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/AccountOptions.java b/graphenej/src/main/java/cy/agorise/graphenej/AccountOptions.java similarity index 96% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/AccountOptions.java rename to graphenej/src/main/java/cy/agorise/graphenej/AccountOptions.java index 43c060e..3a58cab 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/AccountOptions.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/AccountOptions.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.common.primitives.Bytes; import com.google.gson.JsonArray; @@ -12,8 +12,8 @@ import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; -import de.bitsharesmunich.graphenej.errors.MalformedAddressException; -import de.bitsharesmunich.graphenej.interfaces.GrapheneSerializable; +import cy.agorise.graphenej.errors.MalformedAddressException; +import cy.agorise.graphenej.interfaces.GrapheneSerializable; /** * Created by nelson on 12/5/16. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Address.java b/graphenej/src/main/java/cy/agorise/graphenej/Address.java similarity index 94% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/Address.java rename to graphenej/src/main/java/cy/agorise/graphenej/Address.java index b2c9ed0..0a60048 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Address.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/Address.java @@ -1,7 +1,7 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.common.primitives.Bytes; -import de.bitsharesmunich.graphenej.errors.MalformedAddressException; +import cy.agorise.graphenej.errors.MalformedAddressException; import org.bitcoinj.core.Base58; import org.bitcoinj.core.ECKey; import org.spongycastle.crypto.digests.RIPEMD160Digest; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Asset.java b/graphenej/src/main/java/cy/agorise/graphenej/Asset.java similarity index 87% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/Asset.java rename to graphenej/src/main/java/cy/agorise/graphenej/Asset.java index 8ea2b77..880df66 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Asset.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/Asset.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.common.primitives.UnsignedLong; import com.google.gson.JsonDeserializationContext; @@ -10,7 +10,7 @@ import com.google.gson.JsonParseException; import java.lang.reflect.Type; /** - * Created by nelson on 11/9/16. + * Class used to represent a specific asset on the Graphene platform */ public class Asset extends GrapheneObject { public final static String TAG = "Asset"; @@ -83,6 +83,22 @@ public class Asset extends GrapheneObject { this.issuer = issuer; } + /** + * Copy constructor + * @param asset Another asset instance + */ + public Asset(Asset asset){ + super(asset.getObjectId()); + this.symbol = asset.getSymbol(); + this.precision = asset.getPrecision(); + this.issuer = asset.getIssuer(); + this.description = asset.getDescription(); + this.dynamic_asset_data_id = asset.getDynamicAssetDataId(); + this.options = asset.getAssetOptions(); + this.bitasset_data_id = asset.getBitassetId(); + this.mAssetType = asset.getAssetType(); + } + public String getSymbol(){ return this.symbol; } @@ -111,6 +127,14 @@ public class Asset extends GrapheneObject { return description; } + public String getDynamicAssetDataId() { + return dynamic_asset_data_id; + } + + public void setDynamicAssetDataId(String dynamic_asset_data_id) { + this.dynamic_asset_data_id = dynamic_asset_data_id; + } + public void setAssetOptions(AssetOptions options){ this.options = options; } diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/AssetAmount.java b/graphenej/src/main/java/cy/agorise/graphenej/AssetAmount.java similarity index 80% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/AssetAmount.java rename to graphenej/src/main/java/cy/agorise/graphenej/AssetAmount.java index cd0ea49..6ac3a7a 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/AssetAmount.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/AssetAmount.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.common.math.DoubleMath; import com.google.common.primitives.Bytes; @@ -17,14 +17,15 @@ import java.io.DataOutput; import java.io.DataOutputStream; import java.io.IOException; import java.lang.reflect.Type; +import java.math.BigDecimal; import java.math.RoundingMode; -import de.bitsharesmunich.graphenej.errors.IncompatibleOperation; -import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; -import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; +import cy.agorise.graphenej.errors.IncompatibleOperation; +import cy.agorise.graphenej.interfaces.ByteSerializable; +import cy.agorise.graphenej.interfaces.JsonSerializable; /** - * Created by nelson on 11/7/16. + * Class used to represent a specific amount of a certain asset */ public class AssetAmount implements ByteSerializable, JsonSerializable { /** @@ -36,11 +37,25 @@ public class AssetAmount implements ByteSerializable, JsonSerializable { private UnsignedLong amount; private Asset asset; + /** + * Class constructor + * @param amount The amount + * @param asset The asset + */ public AssetAmount(UnsignedLong amount, Asset asset){ this.amount = amount; this.asset = asset; } + /** + * Copy constructor + * @param assetAmount The other instance + */ + public AssetAmount(AssetAmount assetAmount){ + this.amount = UnsignedLong.valueOf(assetAmount.getAmount().toString()); + this.asset = new Asset(assetAmount.getAsset()); + } + /** * Adds two asset amounts. They must refer to the same Asset type. * @param other: The other AssetAmount to add to this. @@ -91,8 +106,10 @@ public class AssetAmount implements ByteSerializable, JsonSerializable { * @return The same AssetAmount instance, but with the changed amount value. */ public AssetAmount multiplyBy(double factor, RoundingMode roundingMode){ - this.amount = UnsignedLong.valueOf(DoubleMath.roundToLong(this.amount.longValue() * factor, roundingMode)); - return this; + BigDecimal originalAmount = new BigDecimal(amount.bigIntegerValue()); + BigDecimal decimalResult = originalAmount.multiply(new BigDecimal(factor)); + UnsignedLong resultingAmount = UnsignedLong.valueOf(DoubleMath.roundToBigInteger(decimalResult.doubleValue(), roundingMode)); + return new AssetAmount(resultingAmount, new Asset(asset)); } /** @@ -110,9 +127,11 @@ public class AssetAmount implements ByteSerializable, JsonSerializable { * @param divisor: The divisor * @return: The same AssetAMount instance, but with the divided amount value */ - public AssetAmount dividedBy(double divisor, RoundingMode roundingMode){ - this.amount = UnsignedLong.valueOf(DoubleMath.roundToLong(this.amount.longValue() / divisor, roundingMode)); - return this; + public AssetAmount divideBy(double divisor, RoundingMode roundingMode){ + BigDecimal originalAmount = new BigDecimal(amount.bigIntegerValue()); + BigDecimal decimalAmount = originalAmount.divide(new BigDecimal(divisor), 18, RoundingMode.HALF_UP); + UnsignedLong resultingAmount = UnsignedLong.valueOf(DoubleMath.roundToBigInteger(decimalAmount.doubleValue(), roundingMode)); + return new AssetAmount(resultingAmount, new Asset(asset)); } @@ -122,8 +141,8 @@ public class AssetAmount implements ByteSerializable, JsonSerializable { * @param divisor: The divisor * @return: The same AssetAMount instance, but with the divided amount value */ - public AssetAmount dividedBy(double divisor){ - return this.dividedBy(divisor, RoundingMode.HALF_DOWN); + public AssetAmount divideBy(double divisor){ + return this.divideBy(divisor, RoundingMode.HALF_DOWN); } public void setAmount(UnsignedLong amount){ @@ -136,6 +155,10 @@ public class AssetAmount implements ByteSerializable, JsonSerializable { public Asset getAsset(){ return this.asset; } + public void setAsset(Asset asset){ + this.asset = asset; + } + @Override public byte[] toBytes() { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/AssetOptions.java b/graphenej/src/main/java/cy/agorise/graphenej/AssetOptions.java similarity index 98% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/AssetOptions.java rename to graphenej/src/main/java/cy/agorise/graphenej/AssetOptions.java index 06fee0b..8ed4205 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/AssetOptions.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/AssetOptions.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.common.primitives.UnsignedLong; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Authority.java b/graphenej/src/main/java/cy/agorise/graphenej/Authority.java similarity index 98% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/Authority.java rename to graphenej/src/main/java/cy/agorise/graphenej/Authority.java index 3bd4dc2..7c2f02e 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Authority.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/Authority.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.common.primitives.Bytes; import com.google.gson.JsonArray; @@ -13,8 +13,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import de.bitsharesmunich.graphenej.errors.MalformedAddressException; -import de.bitsharesmunich.graphenej.interfaces.GrapheneSerializable; +import cy.agorise.graphenej.errors.MalformedAddressException; +import cy.agorise.graphenej.interfaces.GrapheneSerializable; /** * Class used to represent the weighted set of keys and accounts that must approve operations. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/AuthorityType.java b/graphenej/src/main/java/cy/agorise/graphenej/AuthorityType.java similarity index 85% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/AuthorityType.java rename to graphenej/src/main/java/cy/agorise/graphenej/AuthorityType.java index ab0faa8..2fb52b8 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/AuthorityType.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/AuthorityType.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; /** * Enum-type used to specify the different roles of an authority. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/BIP39.java b/graphenej/src/main/java/cy/agorise/graphenej/BIP39.java similarity index 98% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/BIP39.java rename to graphenej/src/main/java/cy/agorise/graphenej/BIP39.java index ecb532d..fa882be 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/BIP39.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/BIP39.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import java.util.Arrays; import org.bitcoinj.core.Base58; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/BaseOperation.java b/graphenej/src/main/java/cy/agorise/graphenej/BaseOperation.java similarity index 82% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/BaseOperation.java rename to graphenej/src/main/java/cy/agorise/graphenej/BaseOperation.java index 9a727cd..bafbea9 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/BaseOperation.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/BaseOperation.java @@ -1,9 +1,9 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.gson.JsonArray; import com.google.gson.JsonElement; -import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; -import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; +import cy.agorise.graphenej.interfaces.ByteSerializable; +import cy.agorise.graphenej.interfaces.JsonSerializable; /** * Created by nelson on 11/5/16. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/BlockData.java b/graphenej/src/main/java/cy/agorise/graphenej/BlockData.java similarity index 97% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/BlockData.java rename to graphenej/src/main/java/cy/agorise/graphenej/BlockData.java index 4a65917..d8457f5 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/BlockData.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/BlockData.java @@ -1,6 +1,6 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; -import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; +import cy.agorise.graphenej.interfaces.ByteSerializable; /** * This class encapsulates all block-related information needed in order to build a valid transaction. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/BrainKey.java b/graphenej/src/main/java/cy/agorise/graphenej/BrainKey.java similarity index 97% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/BrainKey.java rename to graphenej/src/main/java/cy/agorise/graphenej/BrainKey.java index 7812ee9..e54e3b7 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/BrainKey.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/BrainKey.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import org.bitcoinj.core.DumpedPrivateKey; import org.bitcoinj.core.ECKey; @@ -10,7 +10,7 @@ import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.ArrayList; -import de.bitsharesmunich.graphenej.crypto.SecureRandomGenerator; +import cy.agorise.graphenej.crypto.SecureRandomGenerator; /** * Class used to encapsulate all BrainKey-related operations. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Chains.java b/graphenej/src/main/java/cy/agorise/graphenej/Chains.java similarity index 93% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/Chains.java rename to graphenej/src/main/java/cy/agorise/graphenej/Chains.java index 775bbf2..c26a7e1 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Chains.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/Chains.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; /** * Created by nelson on 11/8/16. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Converter.java b/graphenej/src/main/java/cy/agorise/graphenej/Converter.java similarity index 97% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/Converter.java rename to graphenej/src/main/java/cy/agorise/graphenej/Converter.java index 257c422..f0706f6 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Converter.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/Converter.java @@ -1,10 +1,10 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import java.math.BigDecimal; import java.math.MathContext; -import de.bitsharesmunich.graphenej.errors.IncompleteAssetError; -import de.bitsharesmunich.graphenej.models.BucketObject; +import cy.agorise.graphenej.errors.IncompleteAssetError; +import cy.agorise.graphenej.models.BucketObject; /** * Generic converter class used to translate the market information contained in a BucketObject and/or Price instances. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Extensions.java b/graphenej/src/main/java/cy/agorise/graphenej/Extensions.java similarity index 83% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/Extensions.java rename to graphenej/src/main/java/cy/agorise/graphenej/Extensions.java index 1848855..ada71a3 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Extensions.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/Extensions.java @@ -1,9 +1,9 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.gson.JsonArray; import com.google.gson.JsonElement; -import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; -import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; +import cy.agorise.graphenej.interfaces.ByteSerializable; +import cy.agorise.graphenej.interfaces.JsonSerializable; import java.util.ArrayList; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/FileBin.java b/graphenej/src/main/java/cy/agorise/graphenej/FileBin.java similarity index 98% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/FileBin.java rename to graphenej/src/main/java/cy/agorise/graphenej/FileBin.java index 703102f..0eb0711 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/FileBin.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/FileBin.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; @@ -13,8 +13,8 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; -import de.bitsharesmunich.graphenej.crypto.SecureRandomStrengthener; -import de.bitsharesmunich.graphenej.models.backup.WalletBackup; +import cy.agorise.graphenej.crypto.SecureRandomStrengthener; +import cy.agorise.graphenej.models.backup.WalletBackup; /** * Class to manage the backup files diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java b/graphenej/src/main/java/cy/agorise/graphenej/GrapheneObject.java similarity index 99% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java rename to graphenej/src/main/java/cy/agorise/graphenej/GrapheneObject.java index aaee8b5..072355b 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/GrapheneObject.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.gson.annotations.Expose; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Invoice.java b/graphenej/src/main/java/cy/agorise/graphenej/Invoice.java similarity index 96% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/Invoice.java rename to graphenej/src/main/java/cy/agorise/graphenej/Invoice.java index cdd7364..7b1dc37 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Invoice.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/Invoice.java @@ -1,11 +1,11 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.gson.Gson; import com.google.gson.JsonElement; import org.bitcoinj.core.Base58; -import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; +import cy.agorise.graphenej.interfaces.JsonSerializable; /** * Class used to handle invoice generation, compression and QR-Code data derivation, diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/LimitOrder.java b/graphenej/src/main/java/cy/agorise/graphenej/LimitOrder.java similarity index 92% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/LimitOrder.java rename to graphenej/src/main/java/cy/agorise/graphenej/LimitOrder.java index 77d5d7c..50a5c33 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/LimitOrder.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/LimitOrder.java @@ -1,5 +1,6 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; +import com.google.common.primitives.UnsignedLong; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; @@ -12,7 +13,7 @@ import java.io.DataOutputStream; import java.io.IOException; import java.lang.reflect.Type; -import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; +import cy.agorise.graphenej.interfaces.ByteSerializable; /** * @@ -28,7 +29,7 @@ public class LimitOrder extends GrapheneObject implements ByteSerializable { private String expiration; private UserAccount seller; - private long forSale; + private UnsignedLong forSale; private long deferredFee; private Price sellPrice; @@ -52,11 +53,11 @@ public class LimitOrder extends GrapheneObject implements ByteSerializable { this.seller = seller; } - public long getForSale() { + public UnsignedLong getForSale() { return forSale; } - public void setForSale(long forSale) { + public void setForSale(UnsignedLong forSale) { this.forSale = forSale; } @@ -127,7 +128,7 @@ public class LimitOrder extends GrapheneObject implements ByteSerializable { LimitOrder limitOrder = new LimitOrder(id); limitOrder.setExpiration(expiration); limitOrder.setSeller(seller); - limitOrder.setForSale(Long.parseLong(forSale)); + limitOrder.setForSale(UnsignedLong.valueOf(forSale)); limitOrder.setSellPrice(price); limitOrder.setDeferredFee(deferredFee); return limitOrder; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/LineItem.java b/graphenej/src/main/java/cy/agorise/graphenej/LineItem.java similarity index 95% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/LineItem.java rename to graphenej/src/main/java/cy/agorise/graphenej/LineItem.java index 9b58fdb..7442ca9 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/LineItem.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/LineItem.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; /** * Created by nelson on 1/11/17. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/MarketTrade.java b/graphenej/src/main/java/cy/agorise/graphenej/MarketTrade.java similarity index 80% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/MarketTrade.java rename to graphenej/src/main/java/cy/agorise/graphenej/MarketTrade.java index c5aa841..a97220e 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/MarketTrade.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/MarketTrade.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; /** * diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/ObjectType.java b/graphenej/src/main/java/cy/agorise/graphenej/ObjectType.java similarity index 99% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/ObjectType.java rename to graphenej/src/main/java/cy/agorise/graphenej/ObjectType.java index 537eaf1..ee1ce37 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/ObjectType.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/ObjectType.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; /** * Enum type used to list all possible object types and obtain their space + type id diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/OperationType.java b/graphenej/src/main/java/cy/agorise/graphenej/OperationType.java similarity index 97% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/OperationType.java rename to graphenej/src/main/java/cy/agorise/graphenej/OperationType.java index 36d9f52..9ea093d 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/OperationType.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/OperationType.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; /** * Enum type used to keep track of all the operation types and their corresponding ids. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Optional.java b/graphenej/src/main/java/cy/agorise/graphenej/Optional.java similarity index 87% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/Optional.java rename to graphenej/src/main/java/cy/agorise/graphenej/Optional.java index 8f48c5e..c32c83a 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Optional.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/Optional.java @@ -1,9 +1,9 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.gson.JsonElement; -import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; -import de.bitsharesmunich.graphenej.interfaces.GrapheneSerializable; +import cy.agorise.graphenej.interfaces.ByteSerializable; +import cy.agorise.graphenej.interfaces.GrapheneSerializable; /** * Container template class used whenever we have an optional field. diff --git a/graphenej/src/main/java/cy/agorise/graphenej/OrderBook.java b/graphenej/src/main/java/cy/agorise/graphenej/OrderBook.java new file mode 100644 index 0000000..f383a08 --- /dev/null +++ b/graphenej/src/main/java/cy/agorise/graphenej/OrderBook.java @@ -0,0 +1,135 @@ +package cy.agorise.graphenej; + +import com.google.common.primitives.UnsignedLong; + +import java.util.List; + +import cy.agorise.graphenej.operations.LimitOrderCreateOperation; + +/** + * This class will maintain a snapshot of the order book between two assets. + * + * It also provides a handy method that should return the appropriate LimitOrderCreateOperation + * object needed in case the user wants to perform market-priced operations. + * + * It is important to keep the order book updated, ideally by listening to blockchain events, + * and calling the 'update' method. + * + */ +public class OrderBook { + private List limitOrders; + + public OrderBook(List limitOrders){ + this.limitOrders = limitOrders; + } + + /** + * Replaces the current limit order by the list provided as parameter. + * @param limitOrders: New list of orders + */ + public void update(List limitOrders){ + this.limitOrders = limitOrders; + } + + public void update(LimitOrder limitOrder){ + //TODO: Implement the method that will update a single limit order from the order book + } + + /** + * High level method used to exchange a specific amount of an asset (The base) for another + * one (The quote) at market value. + * + * It should analyze the order book and figure out the optimal amount of the base asset to give + * away in order to obtain the desired amount of the quote asset. + * + * @param seller: User account of the seller, used to build the limit order create operation + * @param myBaseAsset: The asset the user is willing to give away + * @param myQuoteAmount: The amount of a given asset the user wants + * @param expiration: The expiration time of the limit order + * + * @return An instance of the LimitOrderCreateOperation class, which is ready to be broadcasted. + */ + public LimitOrderCreateOperation exchange(UserAccount seller, Asset myBaseAsset, AssetAmount myQuoteAmount, int expiration){ + AssetAmount toSell = new AssetAmount(calculateRequiredBase(myQuoteAmount), myBaseAsset); + AssetAmount toReceive = myQuoteAmount; + LimitOrderCreateOperation buyOrder = new LimitOrderCreateOperation(seller, toSell, toReceive, expiration, true); + + return buyOrder; + } + + public LimitOrderCreateOperation exchange(UserAccount seller, AssetAmount baseAmount, Asset quoteAsset, int expiration){ + AssetAmount minToReceive = new AssetAmount(calculateObtainedQuote(baseAmount), quoteAsset); + return new LimitOrderCreateOperation(seller, baseAmount, minToReceive, expiration, true); + } + + /** + * Method that calculates the amount of an asset that we will obtain (the quote amount) if we trade + * a known fixed amount of the asset we already have (the base amount). + * + * @param baseAmount The fixed amount of the asset we have and want to sell + * @return The equivalent amount to receive in exchange of the base amount + */ + public UnsignedLong calculateObtainedQuote(AssetAmount baseAmount){ + UnsignedLong myBase = baseAmount.getAmount(); + UnsignedLong obtainedQuote = UnsignedLong.ZERO; + for(int i = 0; i < limitOrders.size() && myBase.compareTo(UnsignedLong.ZERO) > 0; i++){ + LimitOrder order = limitOrders.get(i); + + // Checking to make sure the order matches our needs + if(order.getSellPrice().quote.getAsset().equals(baseAmount.getAsset())){ + UnsignedLong orderBase = order.getSellPrice().base.getAmount(); + UnsignedLong orderQuote = order.getSellPrice().quote.getAmount(); + UnsignedLong availableBase = order.getForSale(); + + UnsignedLong myQuote = UnsignedLong.valueOf((long)(myBase.times(orderBase).doubleValue() / (orderQuote.doubleValue()))); + if(myQuote.compareTo(availableBase) > 0){ + // We consume this order entirely + // myBase = myBase - (for_sale) * (order_quote / order_base) + myBase = myBase.minus(availableBase.times(orderQuote).dividedBy(orderBase)); + // We need more than this order can offer us, but have to take in consideration how much there really is. + // (order base / order quote) x (available order base / order base) + UnsignedLong thisBatch = UnsignedLong.valueOf((long)(orderBase.times(availableBase).doubleValue() / orderQuote.times(orderBase).doubleValue())); + obtainedQuote = obtainedQuote.plus(thisBatch); + }else{ + // This order consumes all our base asset + // obtained_quote = obtained_quote + (my base * order_base / order_quote) + obtainedQuote = obtainedQuote.plus(myBase.times(orderBase).dividedBy(orderQuote)); + myBase = UnsignedLong.ZERO; + } + } + } + return obtainedQuote; + } + + /** + * Method that calculates the amount of an asset that we will consume (the base amount) if we want to obtain + * a known fixed amount of another asset (the quote amount). + * @param quoteAmount The fixed amount of an asset that we want to obtain + * @return The amount of an asset we already have that will be consumed by the trade + */ + public UnsignedLong calculateRequiredBase(AssetAmount quoteAmount){ + UnsignedLong myQuote = quoteAmount.getAmount(); + UnsignedLong obtainedBase = UnsignedLong.ZERO; + for(int i = 0; i < limitOrders.size() && myQuote.compareTo(UnsignedLong.ZERO) > 0; i++){ + LimitOrder order = limitOrders.get(i); + + // Checking to make sure the order matches our needs + if(order.getSellPrice().base.getAsset().equals(quoteAmount.getAsset())){ + UnsignedLong orderBase = order.getSellPrice().base.getAmount(); + UnsignedLong orderQuote = order.getSellPrice().quote.getAmount(); + UnsignedLong forSale = order.getForSale(); + + if(forSale.compareTo(myQuote) > 0){ + // Found an order that fills our requirements + obtainedBase = obtainedBase.plus(UnsignedLong.valueOf((long) (myQuote.doubleValue() * orderQuote.doubleValue() / orderBase.doubleValue()))); + myQuote = UnsignedLong.ZERO; + }else{ + // Found an order that partially fills our needs + obtainedBase = obtainedBase.plus(UnsignedLong.valueOf((long) (forSale.doubleValue() * orderQuote.doubleValue() / orderBase.doubleValue()))); + myQuote = myQuote.minus(forSale); + } + } + } + return obtainedBase; + } +} diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Price.java b/graphenej/src/main/java/cy/agorise/graphenej/Price.java similarity index 77% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/Price.java rename to graphenej/src/main/java/cy/agorise/graphenej/Price.java index 78e6948..f45c56c 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Price.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/Price.java @@ -1,11 +1,4 @@ -package de.bitsharesmunich.graphenej; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; - -import java.lang.reflect.Type; +package cy.agorise.graphenej; /** * The price struct stores asset prices in the Graphene system. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/PublicKey.java b/graphenej/src/main/java/cy/agorise/graphenej/PublicKey.java similarity index 92% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/PublicKey.java rename to graphenej/src/main/java/cy/agorise/graphenej/PublicKey.java index 5b9e7eb..f20f648 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/PublicKey.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/PublicKey.java @@ -1,11 +1,11 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import org.bitcoinj.core.ECKey; import org.spongycastle.math.ec.ECPoint; import java.io.Serializable; -import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; +import cy.agorise.graphenej.interfaces.ByteSerializable; /** * Created by nelson on 11/30/16. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/RPC.java b/graphenej/src/main/java/cy/agorise/graphenej/RPC.java similarity index 95% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/RPC.java rename to graphenej/src/main/java/cy/agorise/graphenej/RPC.java index 2375925..ea6c509 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/RPC.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/RPC.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; /** * Created by nelson on 11/16/16. @@ -25,6 +25,7 @@ public class RPC { public static final String GET_ACCOUNT_BALANCES = "get_account_balances"; public static final String CALL_LOOKUP_ASSET_SYMBOLS = "lookup_asset_symbols"; public static final String CALL_GET_BLOCK_HEADER = "get_block_header"; + public static final String CALL_GET_BLOCK = "get_block"; public static final String CALL_GET_LIMIT_ORDERS = "get_limit_orders"; public static final String CALL_GET_TRADE_HISTORY = "get_trade_history"; public static final String CALL_GET_MARKET_HISTORY = "get_market_history"; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Transaction.java b/graphenej/src/main/java/cy/agorise/graphenej/Transaction.java similarity index 89% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/Transaction.java rename to graphenej/src/main/java/cy/agorise/graphenej/Transaction.java index 9c8ca5b..acf5412 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Transaction.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/Transaction.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.common.primitives.Bytes; import com.google.gson.GsonBuilder; @@ -24,10 +24,11 @@ import java.util.Date; import java.util.List; import java.util.TimeZone; -import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; -import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; -import de.bitsharesmunich.graphenej.operations.LimitOrderCreateOperation; -import de.bitsharesmunich.graphenej.operations.TransferOperation; +import cy.agorise.graphenej.interfaces.ByteSerializable; +import cy.agorise.graphenej.interfaces.JsonSerializable; +import cy.agorise.graphenej.operations.CustomOperation; +import cy.agorise.graphenej.operations.LimitOrderCreateOperation; +import cy.agorise.graphenej.operations.TransferOperation; /** * Class used to represent a generic Graphene transaction. @@ -45,29 +46,43 @@ public class Transaction implements ByteSerializable, JsonSerializable { public static final String KEY_REF_BLOCK_NUM = "ref_block_num"; public static final String KEY_REF_BLOCK_PREFIX = "ref_block_prefix"; + // Using the bitshares mainnet chain id by default + private byte[] chainId = Util.hexToBytes(Chains.BITSHARES.CHAIN_ID); private ECKey privateKey; private BlockData blockData; private List operations; private Extensions extensions; /** - * Transaction constructor. - * @param privateKey : Instance of a ECKey containing the private key that will be used to sign this transaction. - * @param blockData : Block data containing important information used to sign a transaction. - * @param operationList : List of operations to include in the transaction. + * Transaction constructor + * @param chainId The chain id + * @param privateKey Private key used to sign this transaction + * @param blockData Block data + * @param operations List of operations contained in this transaction */ - public Transaction(ECKey privateKey, BlockData blockData, List operationList){ + public Transaction(byte[] chainId, ECKey privateKey, BlockData blockData, List operations){ + this.chainId = chainId; this.privateKey = privateKey; this.blockData = blockData; - this.operations = operationList; + this.operations = operations; this.extensions = new Extensions(); } /** * Transaction constructor. - * @param wif: The user's private key in the base58 format. - * @param block_data: Block data containing important information used to sign a transaction. - * @param operation_list: List of operations to include in the transaction. + * @param privateKey Instance of a ECKey containing the private key that will be used to sign this transaction. + * @param blockData Block data containing important information used to sign a transaction. + * @param operationList List of operations to include in the transaction. + */ + public Transaction(ECKey privateKey, BlockData blockData, List operationList){ + this(Util.hexToBytes(Chains.BITSHARES.CHAIN_ID), privateKey, blockData, operationList); + } + + /** + * Transaction constructor. + * @param wif The user's private key in the base58 format. + * @param block_data Block data containing important information used to sign a transaction. + * @param operation_list List of operations to include in the transaction. */ public Transaction(String wif, BlockData block_data, List operation_list){ this(DumpedPrivateKey.fromBase58(null, wif).getKey(), block_data, operation_list); @@ -76,8 +91,8 @@ public class Transaction implements ByteSerializable, JsonSerializable { /** * Constructor used to build a Transaction object without a private key. This kind of object * is used to represent a transaction data that we don't intend to serialize and sign. - * @param blockData: Block data instance, containing information about the location of this transaction in the blockchain. - * @param operationList: The list of operations included in this transaction. + * @param blockData Block data instance, containing information about the location of this transaction in the blockchain. + * @param operationList The list of operations included in this transaction. */ public Transaction(BlockData blockData, List operationList){ this.blockData = blockData; @@ -86,7 +101,7 @@ public class Transaction implements ByteSerializable, JsonSerializable { /** * Updates the block data - * @param blockData: New block data + * @param blockData New block data */ public void setBlockData(BlockData blockData){ this.blockData = blockData; @@ -161,6 +176,18 @@ public class Transaction implements ByteSerializable, JsonSerializable { return sigData; } + public void setChainId(String chainId){ + this.chainId = Util.hexToBytes(chainId); + } + + public void setChainId(byte[] chainId){ + this.chainId = chainId; + } + + public byte[] getChainId(){ + return this.chainId; + } + /** * Method that creates a serialized byte array with compact information about this transaction * that is needed for the creation of a signature. @@ -169,7 +196,7 @@ public class Transaction implements ByteSerializable, JsonSerializable { public byte[] toBytes(){ // Creating a List of Bytes and adding the first bytes from the chain apiId List byteArray = new ArrayList(); - byteArray.addAll(Bytes.asList(Util.hexToBytes(Chains.BITSHARES.CHAIN_ID))); + byteArray.addAll(Bytes.asList(chainId)); // Adding the block data byteArray.addAll(Bytes.asList(this.blockData.toBytes())); @@ -343,7 +370,7 @@ public class Transaction implements ByteSerializable, JsonSerializable { } else if (operationId == OperationType.WORKER_CREATE_OPERATION.ordinal()) { //TODO: Add operation deserialization support } else if (operationId == OperationType.CUSTOM_OPERATION.ordinal()) { - //TODO: Add operation deserialization support + operation = context.deserialize(jsonOperation, CustomOperation.class); } else if (operationId == OperationType.ASSERT_OPERATION.ordinal()) { //TODO: Add operation deserialization support } else if (operationId == OperationType.BALANCE_CLAIM_OPERATION.ordinal()) { diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/UserAccount.java b/graphenej/src/main/java/cy/agorise/graphenej/UserAccount.java similarity index 98% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/UserAccount.java rename to graphenej/src/main/java/cy/agorise/graphenej/UserAccount.java index 4ad4b12..dee9197 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/UserAccount.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/UserAccount.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -19,8 +19,8 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; -import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; +import cy.agorise.graphenej.interfaces.ByteSerializable; +import cy.agorise.graphenej.interfaces.JsonSerializable; /** * Class that represents a graphene user account. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Util.java b/graphenej/src/main/java/cy/agorise/graphenej/Util.java similarity index 91% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/Util.java rename to graphenej/src/main/java/cy/agorise/graphenej/Util.java index 98fd493..4f80a85 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Util.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/Util.java @@ -1,7 +1,22 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.common.primitives.Bytes; -import org.tukaani.xz.*; +import com.google.common.primitives.UnsignedLong; + +import org.spongycastle.crypto.DataLengthException; +import org.spongycastle.crypto.InvalidCipherTextException; +import org.spongycastle.crypto.engines.AESFastEngine; +import org.spongycastle.crypto.modes.CBCBlockCipher; +import org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher; +import org.spongycastle.crypto.params.KeyParameter; +import org.spongycastle.crypto.params.ParametersWithIV; +import org.tukaani.xz.CorruptedInputException; +import org.tukaani.xz.FinishableOutputStream; +import org.tukaani.xz.LZMA2Options; +import org.tukaani.xz.LZMAInputStream; +import org.tukaani.xz.LZMAOutputStream; +import org.tukaani.xz.XZInputStream; +import org.tukaani.xz.XZOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -11,15 +26,10 @@ import java.nio.ByteBuffer; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import org.spongycastle.crypto.DataLengthException; -import org.spongycastle.crypto.InvalidCipherTextException; -import org.spongycastle.crypto.engines.AESFastEngine; -import org.spongycastle.crypto.modes.CBCBlockCipher; -import org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher; -import org.spongycastle.crypto.params.KeyParameter; -import org.spongycastle.crypto.params.ParametersWithIV; /** * Class used to encapsulate common utility methods @@ -84,6 +94,26 @@ public class Util { return buffer.array(); } + /** + * Serializes long value to a byte array. + * @param data Long value. + * @return Array of bytes. + */ + public static byte[] serializeLongToBytes(long data) { + List bytes = new LinkedList<>(); + long value = data; + do { + byte b = (byte)(value & 0x7F); + value >>= 7; + if (value != 0) { + b |= 0x80; + } + bytes.add(b); + } while (value != 0); + + return Bytes.toArray(bytes); + } + /** * Utility function that compresses data using the LZMA algorithm. * @param inputBytes Input bytes of the data to be compressed. @@ -210,6 +240,15 @@ public class Util { return ByteBuffer.allocate(Long.SIZE / 8).putLong(Long.reverseBytes(input)).array(); } + /** + * Same operation as in the revertInteger function, but with an UnsignedLong object as argument. + * @param input An UnsignedLong class instance + * @return The array of bytes that represent this value in the reverse format. + */ + public static byte[] revertUnsignedLong(UnsignedLong input){ + return ByteBuffer.allocate(Long.SIZE / 8).putLong(Long.reverseBytes(input.longValue())).array(); + } + public static byte[] revertBytes(byte[] array){ byte[] reverted = new byte[array.length]; for(int i = 0; i < reverted.length; i++){ diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Varint.java b/graphenej/src/main/java/cy/agorise/graphenej/Varint.java similarity index 99% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/Varint.java rename to graphenej/src/main/java/cy/agorise/graphenej/Varint.java index c06e05a..0206fdc 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Varint.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/Varint.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import java.io.DataInput; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Vote.java b/graphenej/src/main/java/cy/agorise/graphenej/Vote.java similarity index 87% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/Vote.java rename to graphenej/src/main/java/cy/agorise/graphenej/Vote.java index 7c50a90..cd22b71 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Vote.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/Vote.java @@ -1,6 +1,6 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; -import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; +import cy.agorise.graphenej.interfaces.ByteSerializable; /** * Created by nelson on 12/5/16. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/BaseGrapheneHandler.java b/graphenej/src/main/java/cy/agorise/graphenej/api/BaseGrapheneHandler.java similarity index 90% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/BaseGrapheneHandler.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/BaseGrapheneHandler.java index 80d7e2b..9a203b6 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/BaseGrapheneHandler.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/BaseGrapheneHandler.java @@ -1,14 +1,12 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketAdapter; import com.neovisionaries.ws.client.WebSocketException; -import org.w3c.dom.Node; - -import de.bitsharesmunich.graphenej.interfaces.NodeErrorListener; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.BaseResponse; +import cy.agorise.graphenej.interfaces.NodeErrorListener; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.BaseResponse; /** * Base class that should be extended by any implementation of a specific request to the full node. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountBalances.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetAccountBalances.java similarity index 87% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountBalances.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/GetAccountBalances.java index 41f6287..5d65de3 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountBalances.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetAccountBalances.java @@ -1,16 +1,9 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketFrame; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.WitnessResponse; import java.io.Serializable; import java.lang.reflect.Type; @@ -18,6 +11,14 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.WitnessResponse; + /** * Class that implements get_account_balances request handler. * @@ -71,12 +72,14 @@ public class GetAccountBalances extends BaseGrapheneHandler { public void onConnected(WebSocket websocket, Map> headers) throws Exception { ArrayList params = new ArrayList<>(); ArrayList assetList = new ArrayList<>(); - for(Asset asset : mAssetList){ - assetList.add(asset.getObjectId()); + if(mAssetList != null){ + for(Asset asset : mAssetList){ + assetList.add(asset.getObjectId()); + } } params.add(mUserAccount.getObjectId()); params.add(assetList); - ApiCall apiCall = new ApiCall(0, RPC.GET_ACCOUNT_BALANCES, params, RPC.VERSION, 0); + ApiCall apiCall = new ApiCall(0, RPC.GET_ACCOUNT_BALANCES, params, RPC.VERSION, requestId); websocket.sendText(apiCall.toJsonString()); } diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetAccountByName.java similarity index 89% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/GetAccountByName.java index d11634f..f2f38f0 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetAccountByName.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -11,13 +11,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import de.bitsharesmunich.graphenej.AccountOptions; -import de.bitsharesmunich.graphenej.Authority; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.AccountProperties; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.AccountOptions; +import cy.agorise.graphenej.Authority; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.AccountProperties; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.WitnessResponse; /** * Class that implements get_account_by_name request handler. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountHistory.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetAccountHistory.java similarity index 82% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountHistory.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/GetAccountHistory.java index 061cedc..76549a2 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountHistory.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetAccountHistory.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; /** * Created by nelson on 12/26/16. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccounts.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetAccounts.java similarity index 91% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccounts.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/GetAccounts.java index 9350ee5..50f38e7 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccounts.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetAccounts.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -11,14 +11,14 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import de.bitsharesmunich.graphenej.AccountOptions; -import de.bitsharesmunich.graphenej.Authority; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.AccountProperties; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.AccountOptions; +import cy.agorise.graphenej.Authority; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.AccountProperties; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.WitnessResponse; /** * Class that implements get_accounts request handler. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAllAssetHolders.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetAllAssetHolders.java similarity index 95% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAllAssetHolders.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/GetAllAssetHolders.java index 4147bc5..110aefb 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAllAssetHolders.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetAllAssetHolders.java @@ -1,13 +1,13 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketFrame; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.*; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.*; import java.io.Serializable; import java.lang.reflect.Type; diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/GetBlock.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetBlock.java new file mode 100644 index 0000000..7d3e882 --- /dev/null +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetBlock.java @@ -0,0 +1,112 @@ +package cy.agorise.graphenej.api; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; +import com.neovisionaries.ws.client.WebSocket; +import com.neovisionaries.ws.client.WebSocketFrame; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.Transaction; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.Block; +import cy.agorise.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.operations.CustomOperation; +import cy.agorise.graphenej.operations.LimitOrderCreateOperation; +import cy.agorise.graphenej.operations.TransferOperation; + +import java.io.Serializable; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class GetBlock extends BaseGrapheneHandler { + + private final static int LOGIN_ID = 1; + private final static int GET_DATABASE_ID = 2; + private final static int GET_BLOCK_ID = 3; + + private long blockNumber; + private WitnessResponseListener mListener; + + private int currentId = LOGIN_ID; + + private boolean mOneTime; + + public GetBlock(long blockNumber, boolean oneTime, WitnessResponseListener listener){ + super(listener); + this.blockNumber = blockNumber; + this.mOneTime = oneTime; + this.mListener = listener; + } + + public GetBlock(long blockNumber, WitnessResponseListener listener){ + this(blockNumber, true, listener); + } + + @Override + public void onConnected(WebSocket websocket, Map> headers) throws Exception { + ArrayList loginParams = new ArrayList<>(); + loginParams.add(null); + loginParams.add(null); + ApiCall loginCall = new ApiCall(1, RPC.CALL_LOGIN, loginParams, RPC.VERSION, currentId); + websocket.sendText(loginCall.toJsonString()); + } + + @Override + public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception { + String response = frame.getPayloadText(); + System.out.println("<<< "+response); + + Gson gson = new Gson(); + BaseResponse baseResponse = gson.fromJson(response, BaseResponse.class); + if(baseResponse.error != null){ + mListener.onError(baseResponse.error); + if(mOneTime){ + websocket.disconnect(); + } + } else { + currentId++; + ArrayList emptyParams = new ArrayList<>(); + if (baseResponse.id == LOGIN_ID) { + ApiCall getDatabaseId = new ApiCall(1, RPC.CALL_DATABASE, emptyParams, RPC.VERSION, currentId); + websocket.sendText(getDatabaseId.toJsonString()); + } else if (baseResponse.id == GET_DATABASE_ID) { + Type ApiIdResponse = new TypeToken>() {}.getType(); + WitnessResponse witnessResponse = gson.fromJson(response, ApiIdResponse); + Integer apiId = witnessResponse.result; + + ArrayList params = new ArrayList<>(); + String blockNum = String.format("%d", this.blockNumber); + params.add(blockNum); + + ApiCall loginCall = new ApiCall(apiId, RPC.CALL_GET_BLOCK, params, RPC.VERSION, currentId); + websocket.sendText(loginCall.toJsonString()); + } else if (baseResponse.id == GET_BLOCK_ID) { + Type BlockResponse = new TypeToken>(){}.getType(); + gson = new GsonBuilder() + .registerTypeAdapter(Transaction.class, new Transaction.TransactionDeserializer()) + .registerTypeAdapter(TransferOperation.class, new TransferOperation.TransferDeserializer()) + .registerTypeAdapter(LimitOrderCreateOperation.class, new LimitOrderCreateOperation.LimitOrderCreateDeserializer()) + .registerTypeAdapter(CustomOperation.class, new CustomOperation.CustomOperationDeserializer()) + .registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer()) + .create(); + WitnessResponse blockResponse = gson.fromJson(response, BlockResponse); + mListener.onSuccess(blockResponse); + if (mOneTime) { + websocket.disconnect(); + } + } + } + + } + + @Override + public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception { + if(frame.isTextFrame()) + System.out.println(">>> "+frame.getPayloadText()); + } +} diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetBlockHeader.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetBlockHeader.java similarity index 92% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetBlockHeader.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/GetBlockHeader.java index cb59103..d373b83 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetBlockHeader.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetBlockHeader.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -11,12 +11,12 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.BlockHeader; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.BlockHeader; +import cy.agorise.graphenej.models.WitnessResponse; /** * Class that implements get_block_header request handler. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetKeyReferences.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetKeyReferences.java similarity index 93% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetKeyReferences.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/GetKeyReferences.java index 576d6a6..aa2266e 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetKeyReferences.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetKeyReferences.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -11,12 +11,12 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import de.bitsharesmunich.graphenej.Address; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.Address; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.WitnessResponse; /** * Class that implements get_key_references request handler. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetLimitOrders.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetLimitOrders.java similarity index 91% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetLimitOrders.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/GetLimitOrders.java index 3327ff7..ea67512 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetLimitOrders.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetLimitOrders.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -12,14 +12,14 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.LimitOrder; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.LimitOrder; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.WitnessResponse; /** * Class that implements get_limit_orders request handler. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetMarketHistory.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetMarketHistory.java similarity index 95% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetMarketHistory.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/GetMarketHistory.java index 06e2a7f..488486a 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetMarketHistory.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetMarketHistory.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -14,13 +14,13 @@ import java.util.Date; import java.util.List; import java.util.Map; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.BucketObject; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.BucketObject; +import cy.agorise.graphenej.models.WitnessResponse; /** * Class that implements get_market_history request handler. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetObjects.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetObjects.java similarity index 89% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetObjects.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/GetObjects.java index 9c34966..ab65206 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetObjects.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetObjects.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -15,17 +15,17 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import de.bitsharesmunich.graphenej.AccountOptions; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.Authority; -import de.bitsharesmunich.graphenej.GrapheneObject; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.BitAssetData; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.AccountOptions; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.Authority; +import cy.agorise.graphenej.GrapheneObject; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.BitAssetData; +import cy.agorise.graphenej.models.WitnessResponse; /** * diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRelativeAccountHistory.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetRelativeAccountHistory.java similarity index 93% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRelativeAccountHistory.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/GetRelativeAccountHistory.java index 32da128..935618f 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRelativeAccountHistory.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetRelativeAccountHistory.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -12,16 +12,16 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.HistoricalTransfer; -import de.bitsharesmunich.graphenej.models.WitnessResponse; -import de.bitsharesmunich.graphenej.objects.Memo; -import de.bitsharesmunich.graphenej.operations.TransferOperation; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.HistoricalTransfer; +import cy.agorise.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.objects.Memo; +import cy.agorise.graphenej.operations.TransferOperation; /** * Class used to encapsulate the communication sequence used to retrieve the transaction history of diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetRequiredFees.java similarity index 88% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/GetRequiredFees.java index 553c95d..5879a99 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetRequiredFees.java @@ -1,20 +1,19 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.WitnessResponse; import com.neovisionaries.ws.client.WebSocket; -import com.neovisionaries.ws.client.WebSocketAdapter; import com.neovisionaries.ws.client.WebSocketException; import com.neovisionaries.ws.client.WebSocketFrame; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.BaseOperation; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.BaseOperation; import java.io.Serializable; import java.lang.reflect.Type; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetTradeHistory.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetTradeHistory.java similarity index 93% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetTradeHistory.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/GetTradeHistory.java index dde5665..327a04d 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetTradeHistory.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetTradeHistory.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -11,11 +11,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import de.bitsharesmunich.graphenej.MarketTrade; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.MarketTrade; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.WitnessResponse; /** * Class that implements get_trade_history request handler. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/ListAssets.java b/graphenej/src/main/java/cy/agorise/graphenej/api/ListAssets.java similarity index 95% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/ListAssets.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/ListAssets.java index 28fb6bb..df85ac3 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/ListAssets.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/ListAssets.java @@ -1,14 +1,14 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketFrame; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.WitnessResponse; import java.io.Serializable; import java.lang.reflect.Type; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java b/graphenej/src/main/java/cy/agorise/graphenej/api/LookupAccounts.java similarity index 94% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/LookupAccounts.java index 97ab2bf..afae255 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/LookupAccounts.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -11,11 +11,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.WitnessResponse; /** * Class that implements lookup_accounts request handler. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAssetSymbols.java b/graphenej/src/main/java/cy/agorise/graphenej/api/LookupAssetSymbols.java similarity index 80% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAssetSymbols.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/LookupAssetSymbols.java index 2a649d0..d467dde 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAssetSymbols.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/LookupAssetSymbols.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -11,11 +11,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.WitnessResponse; /** * Class that implements lookup_asset_symbols request handler. @@ -28,7 +28,7 @@ import de.bitsharesmunich.graphenej.models.WitnessResponse; */ public class LookupAssetSymbols extends BaseGrapheneHandler { private WitnessResponseListener mListener; - private List assets; + private List assets; private boolean mOneTime; @@ -42,7 +42,7 @@ public class LookupAssetSymbols extends BaseGrapheneHandler { * be implemented by the party interested in being notified about the * success/failure of the operation. */ - public LookupAssetSymbols(List assets, boolean oneTime, WitnessResponseListener listener){ + public LookupAssetSymbols(List assets, boolean oneTime, WitnessResponseListener listener){ super(listener); this.assets = assets; this.mOneTime = oneTime; @@ -57,7 +57,7 @@ public class LookupAssetSymbols extends BaseGrapheneHandler { * be implemented by the party interested in being notified about the * success/failure of the operation. */ - public LookupAssetSymbols(List assets, WitnessResponseListener listener){ + public LookupAssetSymbols(List assets, WitnessResponseListener listener){ this(assets, true, listener); } @@ -65,8 +65,13 @@ public class LookupAssetSymbols extends BaseGrapheneHandler { public void onConnected(WebSocket websocket, Map> headers) throws Exception { ArrayList params = new ArrayList<>(); ArrayList subArray = new ArrayList<>(); - for(Asset asset : this.assets){ - subArray.add(asset.getObjectId()); + for(int i = 0; i < assets.size(); i++){ + Object obj = assets.get(i); + if(obj instanceof String){ + subArray.add((String) obj); + }else{ + subArray.add(((Asset) obj).getObjectId()); + } params.add(subArray); } ApiCall loginCall = new ApiCall(0, RPC.CALL_LOOKUP_ASSET_SYMBOLS, params, RPC.VERSION, 0); diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/SubscriptionMessagesHub.java b/graphenej/src/main/java/cy/agorise/graphenej/api/SubscriptionMessagesHub.java similarity index 79% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/SubscriptionMessagesHub.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/SubscriptionMessagesHub.java index 2be0780..1509be3 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/SubscriptionMessagesHub.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/SubscriptionMessagesHub.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -13,22 +13,22 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.Transaction; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.errors.RepeatedRequestIdException; -import de.bitsharesmunich.graphenej.interfaces.NodeErrorListener; -import de.bitsharesmunich.graphenej.interfaces.SubscriptionHub; -import de.bitsharesmunich.graphenej.interfaces.SubscriptionListener; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.DynamicGlobalProperties; -import de.bitsharesmunich.graphenej.models.SubscriptionResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; -import de.bitsharesmunich.graphenej.objects.Memo; -import de.bitsharesmunich.graphenej.operations.LimitOrderCreateOperation; -import de.bitsharesmunich.graphenej.operations.TransferOperation; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.Transaction; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.errors.RepeatedRequestIdException; +import cy.agorise.graphenej.interfaces.NodeErrorListener; +import cy.agorise.graphenej.interfaces.SubscriptionHub; +import cy.agorise.graphenej.interfaces.SubscriptionListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.DynamicGlobalProperties; +import cy.agorise.graphenej.models.SubscriptionResponse; +import cy.agorise.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.objects.Memo; +import cy.agorise.graphenej.operations.CustomOperation; +import cy.agorise.graphenej.operations.LimitOrderCreateOperation; +import cy.agorise.graphenej.operations.TransferOperation; /** * A WebSocket adapter prepared to be used as a basic dispatch hub for subscription messages. @@ -60,6 +60,7 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs private int databaseApiId = -1; private int subscriptionCounter = 0; private HashMap mHandlerMap = new HashMap<>(); + private List pendingHandlerList = new ArrayList<>(); // State variables private boolean isUnsubscribing; @@ -89,6 +90,7 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs builder.registerTypeAdapter(Transaction.class, new Transaction.TransactionDeserializer()); builder.registerTypeAdapter(TransferOperation.class, new TransferOperation.TransferDeserializer()); builder.registerTypeAdapter(LimitOrderCreateOperation.class, new LimitOrderCreateOperation.LimitOrderCreateDeserializer()); + builder.registerTypeAdapter(CustomOperation.class, new CustomOperation.CustomOperationDeserializer()); builder.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer()); builder.registerTypeAdapter(UserAccount.class, new UserAccount.UserAccountSimpleDeserializer()); builder.registerTypeAdapter(DynamicGlobalProperties.class, new DynamicGlobalProperties.DynamicGlobalPropertiesDeserializer()); @@ -141,17 +143,29 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs String message = frame.getPayloadText(); System.out.println("<< "+message); if(currentId == LOGIN_ID){ + currentId = GET_DATABASE_ID; ArrayList emptyParams = new ArrayList<>(); ApiCall getDatabaseId = new ApiCall(1, RPC.CALL_DATABASE, emptyParams, RPC.VERSION, currentId); websocket.sendText(getDatabaseId.toJsonString()); - currentId++; }else if(currentId == GET_DATABASE_ID){ Type ApiIdResponse = new TypeToken>() {}.getType(); WitnessResponse witnessResponse = gson.fromJson(message, ApiIdResponse); databaseApiId = witnessResponse.result; - subscribe(); - } else if(currentId == SUBSCRIPTION_REQUEST){ + // Subscribing only if the clearFilter parameter is true + if(clearFilter){ + subscribe(); + } + + // Dispatching the onConnected event to every pending handler + if(pendingHandlerList.size() > 0){ + for(BaseGrapheneHandler handler : pendingHandlerList){ + handler.setRequestId(++currentId); + dispatchConnectionEvent(handler); + } + pendingHandlerList.clear(); + } + } else if(currentId >= SUBSCRIPTION_REQUEST){ List subscriptionListeners = mSubscriptionDeserializer.getSubscriptionListeners(); if(!isUnsubscribing){ @@ -205,12 +219,12 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs private void subscribe(){ isUnsubscribing = false; + currentId++; ArrayList subscriptionParams = new ArrayList<>(); subscriptionParams.add(String.format("%d", SUBSCRIPTION_NOTIFICATION)); subscriptionParams.add(clearFilter); - ApiCall getDatabaseId = new ApiCall(databaseApiId, RPC.CALL_SET_SUBSCRIBE_CALLBACK, subscriptionParams, RPC.VERSION, SUBSCRIPTION_REQUEST); + ApiCall getDatabaseId = new ApiCall(databaseApiId, RPC.CALL_SET_SUBSCRIBE_CALLBACK, subscriptionParams, RPC.VERSION, currentId); mWebsocket.sendText(getDatabaseId.toJsonString()); - currentId = SUBSCRIPTION_REQUEST; } /** @@ -236,7 +250,8 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs isSubscribed = false; isUnsubscribing = true; - ApiCall unsubscribe = new ApiCall(databaseApiId, RPC.CALL_CANCEL_ALL_SUBSCRIPTIONS, new ArrayList(), RPC.VERSION, SUBSCRIPTION_REQUEST); + currentId++; + ApiCall unsubscribe = new ApiCall(databaseApiId, RPC.CALL_CANCEL_ALL_SUBSCRIPTIONS, new ArrayList(), RPC.VERSION, currentId); mWebsocket.sendText(unsubscribe.toJsonString()); // Clearing all subscription listeners @@ -264,13 +279,26 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs subscriptionCounter = 0; } - public void addRequestHandler(BaseGrapheneHandler handler) throws RepeatedRequestIdException { - if(mHandlerMap.get(handler.getRequestId()) != null){ - throw new RepeatedRequestIdException("Already registered handler with id: "+handler.getRequestId()); + /** + * Adds a handler either to the map of handlers or to a list of pending ones + * @param handler The handler of a given request + * @throws RepeatedRequestIdException + */ + public void addRequestHandler(BaseGrapheneHandler handler) { + if(mWebsocket != null && currentId > SUBSCRIPTION_REQUEST){ + handler.setRequestId(++currentId); + mHandlerMap.put(handler.getRequestId(), handler); + dispatchConnectionEvent(handler); + }else{ + pendingHandlerList.add(handler); } + } - mHandlerMap.put(handler.getRequestId(), handler); - + /** + * Informing a handler that we have a connection with the full node. + * @param handler Handler that should be notified. + */ + private void dispatchConnectionEvent(BaseGrapheneHandler handler){ try { // Artificially calling the 'onConnected' method of the handler. // The underlying websocket was already connected, but from the WebSocketAdapter @@ -279,6 +307,13 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs } catch (Exception e) { System.out.println("Exception. Msg: "+e.getMessage()); System.out.println("Exception type: "+e); + for(StackTraceElement el : e.getStackTrace()){ + System.out.println(String.format("at %s.%s(%s:%s)", + el.getClassName(), + el.getMethodName(), + el.getFileName(), + el.getLineNumber())); + } } } } diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/TransactionBroadcastSequence.java b/graphenej/src/main/java/cy/agorise/graphenej/api/TransactionBroadcastSequence.java similarity index 93% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/TransactionBroadcastSequence.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/TransactionBroadcastSequence.java index 6064df5..0b17939 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/TransactionBroadcastSequence.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/TransactionBroadcastSequence.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -13,16 +13,16 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.BlockData; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.Transaction; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.DynamicGlobalProperties; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.BlockData; +import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.Transaction; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.ApiCall; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.DynamicGlobalProperties; +import cy.agorise.graphenej.models.WitnessResponse; /** * Class that will handle the transaction publication procedure. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/android/NodeConnection.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NodeConnection.java similarity index 72% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/android/NodeConnection.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/android/NodeConnection.java index 3bd90e8..9958aaf 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/android/NodeConnection.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NodeConnection.java @@ -1,14 +1,13 @@ -package de.bitsharesmunich.graphenej.api.android; +package cy.agorise.graphenej.api.android; import java.util.ArrayList; import java.util.List; -import de.bitsharesmunich.graphenej.api.BaseGrapheneHandler; -import de.bitsharesmunich.graphenej.api.SubscriptionMessagesHub; -import de.bitsharesmunich.graphenej.errors.RepeatedRequestIdException; -import de.bitsharesmunich.graphenej.interfaces.NodeErrorListener; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.BaseResponse; +import cy.agorise.graphenej.api.BaseGrapheneHandler; +import cy.agorise.graphenej.api.SubscriptionMessagesHub; +import cy.agorise.graphenej.errors.RepeatedRequestIdException; +import cy.agorise.graphenej.interfaces.NodeErrorListener; +import cy.agorise.graphenej.models.BaseResponse; /** * Class used to encapsulate all connections that should be done to a node (with node hop support). @@ -17,10 +16,12 @@ import de.bitsharesmunich.graphenej.models.BaseResponse; * be used as a singleton under an application. */ public class NodeConnection { + /** * List of URLs of the nodes */ private List mUrlList; + /** * Index of the current node from the list */ @@ -28,8 +29,11 @@ public class NodeConnection { private WebsocketWorkerThread mThread; private SubscriptionMessagesHub mMessagesHub; private long requestCounter = SubscriptionMessagesHub.MANUAL_SUBSCRIPTION_ID + 1; - private WitnessResponseListener mErrorListener; + private NodeErrorListener mErrorListener; + /** + * Singleton instance + */ private static NodeConnection instance; private String mUser; @@ -56,7 +60,6 @@ public class NodeConnection { * @param url: URL of the node */ public void addNodeUrl(String url){ - System.out.println("addNodeUrl: "+url); this.mUrlList.add(url); } @@ -67,8 +70,7 @@ public class NodeConnection { * @param urlList: List of URLs of the nodes */ public void addNodeUrls(List urlList){ - List newList = new ArrayList(mUrlList); - newList.addAll(urlList); + mUrlList.addAll(urlList); } /** @@ -91,7 +93,7 @@ public class NodeConnection { @Override public void onError(BaseResponse.Error error) { System.out.println("NodeConnect Error. Msg: "+error); - + mUrlIndex++; connect(mUser, mPassword, mSubscribe, mErrorListener); } }; @@ -113,19 +115,24 @@ public class NodeConnection { * should be implemented by the party interested in being notified * about the failure of the desired broadcast operation. */ - public void connect(String user, String password, boolean subscribe, WitnessResponseListener errorListener) { - if(this.mUrlList.size() > 0){ - mUser = user; - mPassword = password; - mSubscribe = subscribe; - System.out.println("Connecting to: "+ this.mUrlList.get(mUrlIndex)); - mErrorListener = errorListener; - mThread = new WebsocketWorkerThread(this.mUrlList.get(mUrlIndex), mInternalErrorListener); - mUrlIndex = mUrlIndex + 1 % this.mUrlList.size(); + public void connect(String user, String password, boolean subscribe, NodeErrorListener errorListener) { + if(mUrlList.size() > 0){ + if(mUrlIndex < mUrlList.size()){ + System.out.println("Connecting to: "+ this.mUrlList.get(mUrlIndex)); + mUser = user; + mPassword = password; + mSubscribe = subscribe; + mErrorListener = errorListener; + mThread = new WebsocketWorkerThread(this.mUrlList.get(mUrlIndex), mInternalErrorListener); - mMessagesHub = new SubscriptionMessagesHub(user, password, subscribe, mInternalErrorListener); - mThread.addListener(mMessagesHub); - mThread.start(); + mMessagesHub = new SubscriptionMessagesHub(user, password, subscribe, mInternalErrorListener); + mThread.addListener(mMessagesHub); + mThread.start(); + }else{ + errorListener.onError(new BaseResponse.Error("Can't connect, ran out of URLs!")); + } + }else{ + errorListener.onError(new BaseResponse.Error("Can't connect, missing URL")); } } diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/android/WebsocketWorkerThread.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/WebsocketWorkerThread.java similarity index 84% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/api/android/WebsocketWorkerThread.java rename to graphenej/src/main/java/cy/agorise/graphenej/api/android/WebsocketWorkerThread.java index 76db5e0..d8d45a7 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/android/WebsocketWorkerThread.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/WebsocketWorkerThread.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api.android; +package cy.agorise.graphenej.api.android; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketException; @@ -10,9 +10,9 @@ import java.security.NoSuchAlgorithmException; import javax.net.ssl.SSLContext; -import de.bitsharesmunich.graphenej.interfaces.NodeErrorListener; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.test.NaiveSSLContext; +import cy.agorise.graphenej.interfaces.NodeErrorListener; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.test.NaiveSSLContext; /** * Class used to encapsulate the thread where the WebSocket does the requests. @@ -63,6 +63,7 @@ public class WebsocketWorkerThread extends Thread { * about the failure of the connection. */ public WebsocketWorkerThread(String url, NodeErrorListener errorListener){ + mErrorListener = errorListener; try { WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(TIMEOUT); @@ -74,13 +75,18 @@ public class WebsocketWorkerThread extends Thread { } mWebSocket = factory.createSocket(url); - mErrorListener = errorListener; } catch (IOException e) { System.out.println("IOException. Msg: "+e.getMessage()); + mErrorListener.onError(new BaseResponse.Error(e.getMessage())); } catch(NullPointerException e){ System.out.println("NullPointerException at WebsocketWorkerThreas. Msg: "+e.getMessage()); + mErrorListener.onError(new BaseResponse.Error(e.getMessage())); } catch (NoSuchAlgorithmException e) { System.out.println("NoSuchAlgorithmException. Msg: "+e.getMessage()); + mErrorListener.onError(new BaseResponse.Error(e.getMessage())); + } catch(IllegalArgumentException e){ + System.out.println("IllegalArgumentException. Msg: "+e.getMessage()); + mErrorListener.onError(new BaseResponse.Error(e.getMessage())); } } diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/brainkeydict.txt b/graphenej/src/main/java/cy/agorise/graphenej/brainkeydict.txt similarity index 100% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/brainkeydict.txt rename to graphenej/src/main/java/cy/agorise/graphenej/brainkeydict.txt diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/AndroidRandomSource.java b/graphenej/src/main/java/cy/agorise/graphenej/crypto/AndroidRandomSource.java similarity index 98% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/AndroidRandomSource.java rename to graphenej/src/main/java/cy/agorise/graphenej/crypto/AndroidRandomSource.java index 0e3863b..d98486b 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/AndroidRandomSource.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/crypto/AndroidRandomSource.java @@ -32,7 +32,7 @@ * fitness for a particular purpose and non-infringement. */ -package de.bitsharesmunich.graphenej.crypto; +package cy.agorise.graphenej.crypto; import java.io.DataInputStream; import java.io.File; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/EntropySource.java b/graphenej/src/main/java/cy/agorise/graphenej/crypto/EntropySource.java similarity index 92% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/EntropySource.java rename to graphenej/src/main/java/cy/agorise/graphenej/crypto/EntropySource.java index 6c07b43..04d4d18 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/EntropySource.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/crypto/EntropySource.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.crypto; +package cy.agorise.graphenej.crypto; import java.nio.ByteBuffer; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/RandomSource.java b/graphenej/src/main/java/cy/agorise/graphenej/crypto/RandomSource.java similarity index 94% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/RandomSource.java rename to graphenej/src/main/java/cy/agorise/graphenej/crypto/RandomSource.java index aaf4940..117714d 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/RandomSource.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/crypto/RandomSource.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package de.bitsharesmunich.graphenej.crypto; +package cy.agorise.graphenej.crypto; public interface RandomSource { /** diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/SecureRandomGenerator.java b/graphenej/src/main/java/cy/agorise/graphenej/crypto/SecureRandomGenerator.java similarity index 90% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/SecureRandomGenerator.java rename to graphenej/src/main/java/cy/agorise/graphenej/crypto/SecureRandomGenerator.java index 5c7a3fa..6cbb960 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/SecureRandomGenerator.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/crypto/SecureRandomGenerator.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.crypto; +package cy.agorise.graphenej.crypto; import java.security.SecureRandom; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/SecureRandomStrengthener.java b/graphenej/src/main/java/cy/agorise/graphenej/crypto/SecureRandomStrengthener.java similarity index 99% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/SecureRandomStrengthener.java rename to graphenej/src/main/java/cy/agorise/graphenej/crypto/SecureRandomStrengthener.java index 093cffd..e35d2ff 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/crypto/SecureRandomStrengthener.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/crypto/SecureRandomStrengthener.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.crypto; +package cy.agorise.graphenej.crypto; import java.nio.ByteBuffer; import java.security.DigestException; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/ChecksumException.java b/graphenej/src/main/java/cy/agorise/graphenej/errors/ChecksumException.java similarity index 79% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/ChecksumException.java rename to graphenej/src/main/java/cy/agorise/graphenej/errors/ChecksumException.java index 394002b..84805d3 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/ChecksumException.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/errors/ChecksumException.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.errors; +package cy.agorise.graphenej.errors; /** * Created by nelson on 12/20/16. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/IncompatibleOperation.java b/graphenej/src/main/java/cy/agorise/graphenej/errors/IncompatibleOperation.java similarity index 80% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/IncompatibleOperation.java rename to graphenej/src/main/java/cy/agorise/graphenej/errors/IncompatibleOperation.java index 5f80ece..410c79a 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/IncompatibleOperation.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/errors/IncompatibleOperation.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.errors; +package cy.agorise.graphenej.errors; /** * Created by nelson on 1/18/17. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/IncompleteAssetError.java b/graphenej/src/main/java/cy/agorise/graphenej/errors/IncompleteAssetError.java similarity index 89% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/IncompleteAssetError.java rename to graphenej/src/main/java/cy/agorise/graphenej/errors/IncompleteAssetError.java index 9b5ee2a..1bbee6a 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/IncompleteAssetError.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/errors/IncompleteAssetError.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.errors; +package cy.agorise.graphenej.errors; /** * Created by nelson on 12/25/16. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/MalformedAddressException.java b/graphenej/src/main/java/cy/agorise/graphenej/errors/MalformedAddressException.java similarity index 80% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/MalformedAddressException.java rename to graphenej/src/main/java/cy/agorise/graphenej/errors/MalformedAddressException.java index 8348d3e..91c25b8 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/MalformedAddressException.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/errors/MalformedAddressException.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.errors; +package cy.agorise.graphenej.errors; /** * Created by nelson on 12/1/16. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/MalformedOperationException.java b/graphenej/src/main/java/cy/agorise/graphenej/errors/MalformedOperationException.java similarity index 80% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/MalformedOperationException.java rename to graphenej/src/main/java/cy/agorise/graphenej/errors/MalformedOperationException.java index 223f17c..f6b95b4 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/MalformedOperationException.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/errors/MalformedOperationException.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.errors; +package cy.agorise.graphenej.errors; /** * Created by nelson on 3/1/17. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/MalformedTransactionException.java b/graphenej/src/main/java/cy/agorise/graphenej/errors/MalformedTransactionException.java similarity index 81% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/MalformedTransactionException.java rename to graphenej/src/main/java/cy/agorise/graphenej/errors/MalformedTransactionException.java index 34e303e..22b1d39 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/MalformedTransactionException.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/errors/MalformedTransactionException.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.errors; +package cy.agorise.graphenej.errors; /** * Created by nelson on 11/14/16. diff --git a/graphenej/src/main/java/cy/agorise/graphenej/errors/RepeatedRequestIdException.java b/graphenej/src/main/java/cy/agorise/graphenej/errors/RepeatedRequestIdException.java new file mode 100644 index 0000000..ce8dd6f --- /dev/null +++ b/graphenej/src/main/java/cy/agorise/graphenej/errors/RepeatedRequestIdException.java @@ -0,0 +1,14 @@ +package cy.agorise.graphenej.errors; + +import cy.agorise.graphenej.api.BaseGrapheneHandler; + +/** + * Thrown by the {@link cy.agorise.graphenej.api.SubscriptionMessagesHub#addRequestHandler(BaseGrapheneHandler)} + * whenever the user tries to register a new handler with a previously registered id + */ + +public class RepeatedRequestIdException extends Exception { + public RepeatedRequestIdException(String message){ + super(message); + } +} diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/ByteSerializable.java b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/ByteSerializable.java similarity index 77% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/ByteSerializable.java rename to graphenej/src/main/java/cy/agorise/graphenej/interfaces/ByteSerializable.java index b60c6c1..7043f20 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/ByteSerializable.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/ByteSerializable.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.interfaces; +package cy.agorise.graphenej.interfaces; /** * Interface implemented by all entities for which makes sense to have a byte-array representation. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/GrapheneSerializable.java b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/GrapheneSerializable.java similarity index 78% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/GrapheneSerializable.java rename to graphenej/src/main/java/cy/agorise/graphenej/interfaces/GrapheneSerializable.java index 93eb781..f7e6d20 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/GrapheneSerializable.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/GrapheneSerializable.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.interfaces; +package cy.agorise.graphenej.interfaces; /** * Interface used to group both ByteSerializable and JsonSerializable interfaces. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/JsonSerializable.java b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/JsonSerializable.java similarity index 86% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/JsonSerializable.java rename to graphenej/src/main/java/cy/agorise/graphenej/interfaces/JsonSerializable.java index 5e64e4d..bb52407 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/JsonSerializable.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/JsonSerializable.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.interfaces; +package cy.agorise.graphenej.interfaces; import com.google.gson.JsonElement; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/NodeErrorListener.java b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/NodeErrorListener.java similarity index 60% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/NodeErrorListener.java rename to graphenej/src/main/java/cy/agorise/graphenej/interfaces/NodeErrorListener.java index f0386b7..f1afe60 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/NodeErrorListener.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/NodeErrorListener.java @@ -1,6 +1,6 @@ -package de.bitsharesmunich.graphenej.interfaces; +package cy.agorise.graphenej.interfaces; -import de.bitsharesmunich.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.BaseResponse; /** * Interface to be implemented by any listener to network errors. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/SubscriptionHub.java b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/SubscriptionHub.java similarity index 94% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/SubscriptionHub.java rename to graphenej/src/main/java/cy/agorise/graphenej/interfaces/SubscriptionHub.java index bca0df0..22c634f 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/SubscriptionHub.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/SubscriptionHub.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.interfaces; +package cy.agorise.graphenej.interfaces; import java.util.List; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/SubscriptionListener.java b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/SubscriptionListener.java similarity index 85% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/SubscriptionListener.java rename to graphenej/src/main/java/cy/agorise/graphenej/interfaces/SubscriptionListener.java index 9081991..3bd3f76 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/SubscriptionListener.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/SubscriptionListener.java @@ -1,7 +1,7 @@ -package de.bitsharesmunich.graphenej.interfaces; +package cy.agorise.graphenej.interfaces; -import de.bitsharesmunich.graphenej.ObjectType; -import de.bitsharesmunich.graphenej.models.SubscriptionResponse; +import cy.agorise.graphenej.ObjectType; +import cy.agorise.graphenej.models.SubscriptionResponse; /** * Generic interface that must be implemented by any class that wants to be informed about a specific diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/WitnessResponseListener.java b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/WitnessResponseListener.java similarity index 55% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/WitnessResponseListener.java rename to graphenej/src/main/java/cy/agorise/graphenej/interfaces/WitnessResponseListener.java index 0a25d0a..28f1eca 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/interfaces/WitnessResponseListener.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/interfaces/WitnessResponseListener.java @@ -1,7 +1,7 @@ -package de.bitsharesmunich.graphenej.interfaces; +package cy.agorise.graphenej.interfaces; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.WitnessResponse; /** * Class used to represent any listener to network requests. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/AccountBalanceUpdate.java b/graphenej/src/main/java/cy/agorise/graphenej/models/AccountBalanceUpdate.java similarity index 83% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/AccountBalanceUpdate.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/AccountBalanceUpdate.java index 739287b..d155ea7 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/AccountBalanceUpdate.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/AccountBalanceUpdate.java @@ -1,8 +1,8 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; import java.io.Serializable; -import de.bitsharesmunich.graphenej.GrapheneObject; +import cy.agorise.graphenej.GrapheneObject; /** * Created by nelson on 1/12/17. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/AccountProperties.java b/graphenej/src/main/java/cy/agorise/graphenej/models/AccountProperties.java similarity index 85% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/AccountProperties.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/AccountProperties.java index 44946f0..1a4a84f 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/AccountProperties.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/AccountProperties.java @@ -1,7 +1,7 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; -import de.bitsharesmunich.graphenej.AccountOptions; -import de.bitsharesmunich.graphenej.Authority; +import cy.agorise.graphenej.AccountOptions; +import cy.agorise.graphenej.Authority; /** * Created by nelson on 11/15/16. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/ApiCall.java b/graphenej/src/main/java/cy/agorise/graphenej/models/ApiCall.java similarity index 94% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/ApiCall.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/ApiCall.java index 2fbaa55..58707ae 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/ApiCall.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/ApiCall.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; @@ -6,13 +6,14 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; import java.io.Serializable; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; +import cy.agorise.graphenej.interfaces.JsonSerializable; + /** * Class used to build a Graphene websocket API call. * @see Websocket Calls & Notifications @@ -28,9 +29,9 @@ public class ApiCall implements JsonSerializable { public String jsonrpc; public List params; public int apiId; - public int sequenceId; + public long sequenceId; - public ApiCall(int apiId, String methodToCall, List params, String jsonrpc, int sequenceId){ + public ApiCall(int apiId, String methodToCall, List params, String jsonrpc, long sequenceId){ this.apiId = apiId; this.method = "call"; this.methodToCall = methodToCall; @@ -39,7 +40,7 @@ public class ApiCall implements JsonSerializable { this.sequenceId = sequenceId; } - public ApiCall(int apiId, String method, String methodToCall, List params, String jsonrpc, int sequenceId){ + public ApiCall(int apiId, String method, String methodToCall, List params, String jsonrpc, long sequenceId){ this.apiId = apiId; this.method = method; this.methodToCall = methodToCall; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/AssetFeed.java b/graphenej/src/main/java/cy/agorise/graphenej/models/AssetFeed.java similarity index 72% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/AssetFeed.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/AssetFeed.java index df7d686..66eef84 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/AssetFeed.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/AssetFeed.java @@ -1,6 +1,6 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; -import de.bitsharesmunich.graphenej.Price; +import cy.agorise.graphenej.Price; /** * Created by nelson on 1/9/17. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/AssetHolderCount.java b/graphenej/src/main/java/cy/agorise/graphenej/models/AssetHolderCount.java similarity index 90% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/AssetHolderCount.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/AssetHolderCount.java index 9de3ddc..6885415 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/AssetHolderCount.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/AssetHolderCount.java @@ -1,7 +1,7 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; import com.google.gson.*; -import de.bitsharesmunich.graphenej.Asset; +import cy.agorise.graphenej.Asset; import java.lang.reflect.Type; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BaseResponse.java b/graphenej/src/main/java/cy/agorise/graphenej/models/BaseResponse.java similarity index 92% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BaseResponse.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/BaseResponse.java index d4bb18c..50b7622 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BaseResponse.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/BaseResponse.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; /** * Created by nelson on 11/12/16. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BitAssetData.java b/graphenej/src/main/java/cy/agorise/graphenej/models/BitAssetData.java similarity index 80% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BitAssetData.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/BitAssetData.java index 5625a03..1d27222 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BitAssetData.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/BitAssetData.java @@ -1,7 +1,7 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; -import de.bitsharesmunich.graphenej.GrapheneObject; -import de.bitsharesmunich.graphenej.Price; +import cy.agorise.graphenej.GrapheneObject; +import cy.agorise.graphenej.Price; /** * This is the representation of the response from the 'get_objects' call with diff --git a/graphenej/src/main/java/cy/agorise/graphenej/models/Block.java b/graphenej/src/main/java/cy/agorise/graphenej/models/Block.java new file mode 100644 index 0000000..625d9d4 --- /dev/null +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/Block.java @@ -0,0 +1,71 @@ +package cy.agorise.graphenej.models; + +import cy.agorise.graphenej.Transaction; + +import java.util.List; + +public class Block { + private String previous; + private String timestamp; + private String witness; + private String transaction_merkle_root; + private Object[] extensions; + private String witness_signature; + private List transactions; + + public String getPrevious() { + return previous; + } + + public void setPrevious(String previous) { + this.previous = previous; + } + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public String getWitness() { + return witness; + } + + public void setWitness(String witness) { + this.witness = witness; + } + + public String getTransaction_merkle_root() { + return transaction_merkle_root; + } + + public void setTransaction_merkle_root(String transaction_merkle_root) { + this.transaction_merkle_root = transaction_merkle_root; + } + + public Object[] getExtensions() { + return extensions; + } + + public void setExtensions(Object[] extensions) { + this.extensions = extensions; + } + + public String getWitness_signature() { + return witness_signature; + } + + public void setWitness_signature(String witness_signature) { + this.witness_signature = witness_signature; + } + + public List getTransactions() { + return transactions; + } + + public void setTransactions(List transactions) { + this.transactions = transactions; + } +} diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BlockHeader.java b/graphenej/src/main/java/cy/agorise/graphenej/models/BlockHeader.java similarity index 83% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BlockHeader.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/BlockHeader.java index 4dc5e4f..9ebdef7 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BlockHeader.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/BlockHeader.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; /** * Created by nelson on 12/13/16. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BroadcastedTransaction.java b/graphenej/src/main/java/cy/agorise/graphenej/models/BroadcastedTransaction.java similarity index 66% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BroadcastedTransaction.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/BroadcastedTransaction.java index ee53101..90baa58 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BroadcastedTransaction.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/BroadcastedTransaction.java @@ -1,14 +1,9 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import de.bitsharesmunich.graphenej.GrapheneObject; -import de.bitsharesmunich.graphenej.Transaction; +import cy.agorise.graphenej.GrapheneObject; +import cy.agorise.graphenej.Transaction; import java.io.Serializable; -import java.lang.reflect.Type; /** * Created by nelson on 1/28/17. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BucketObject.java b/graphenej/src/main/java/cy/agorise/graphenej/models/BucketObject.java similarity index 97% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BucketObject.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/BucketObject.java index 96d3ecc..816befd 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/BucketObject.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/BucketObject.java @@ -1,7 +1,7 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; import com.google.gson.*; -import de.bitsharesmunich.graphenej.Asset; +import cy.agorise.graphenej.Asset; import java.lang.reflect.Type; import java.math.BigDecimal; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/DynamicGlobalProperties.java b/graphenej/src/main/java/cy/agorise/graphenej/models/DynamicGlobalProperties.java similarity index 97% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/DynamicGlobalProperties.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/DynamicGlobalProperties.java index e27cbc0..8c925e2 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/DynamicGlobalProperties.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/DynamicGlobalProperties.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; @@ -13,8 +13,8 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; -import de.bitsharesmunich.graphenej.GrapheneObject; -import de.bitsharesmunich.graphenej.Util; +import cy.agorise.graphenej.GrapheneObject; +import cy.agorise.graphenej.Util; /** * Class used to deserialize the 'result' field returned by the full node after making a call diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/HistoricalTransfer.java b/graphenej/src/main/java/cy/agorise/graphenej/models/HistoricalTransfer.java similarity index 92% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/HistoricalTransfer.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/HistoricalTransfer.java index 44d09c0..d14e5b8 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/HistoricalTransfer.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/HistoricalTransfer.java @@ -1,6 +1,6 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; -import de.bitsharesmunich.graphenej.operations.TransferOperation; +import cy.agorise.graphenej.operations.TransferOperation; /** diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/SubscriptionResponse.java b/graphenej/src/main/java/cy/agorise/graphenej/models/SubscriptionResponse.java similarity index 91% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/SubscriptionResponse.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/SubscriptionResponse.java index 3cb5f78..8edbfcd 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/SubscriptionResponse.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/SubscriptionResponse.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; import com.google.gson.JsonArray; import com.google.gson.JsonDeserializationContext; @@ -14,10 +14,10 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; -import de.bitsharesmunich.graphenej.GrapheneObject; -import de.bitsharesmunich.graphenej.ObjectType; -import de.bitsharesmunich.graphenej.Transaction; -import de.bitsharesmunich.graphenej.interfaces.SubscriptionListener; +import cy.agorise.graphenej.GrapheneObject; +import cy.agorise.graphenej.ObjectType; +import cy.agorise.graphenej.Transaction; +import cy.agorise.graphenej.interfaces.SubscriptionListener; /** * Class that represents a generic subscription response. @@ -111,13 +111,15 @@ public class SubscriptionResponse { * to be removed from the list. */ public void removeSubscriptionListener(SubscriptionListener subscriptionListener){ - int currentCount = listenerTypeCount.get(subscriptionListener.getInterestObjectType()); - if(currentCount != 0){ - this.listenerTypeCount.put(subscriptionListener.getInterestObjectType(), currentCount); - }else{ - System.out.println("Trying to remove subscription listener, but none is registered!"); + if(listenerTypeCount.containsKey(subscriptionListener.getInterestObjectType())){ + int currentCount = listenerTypeCount.get(subscriptionListener.getInterestObjectType()); + if(currentCount > 0){ + this.listenerTypeCount.put(subscriptionListener.getInterestObjectType(), currentCount - 1); + this.mListeners.remove(subscriptionListener); + }else{ + System.out.println("Trying to remove subscription listener, but none is registered!"); + } } - this.mListeners.remove(subscriptionListener); } /** diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/WitnessResponse.java b/graphenej/src/main/java/cy/agorise/graphenej/models/WitnessResponse.java similarity index 82% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/WitnessResponse.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/WitnessResponse.java index 0f7dc78..2cabae9 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/WitnessResponse.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/WitnessResponse.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.models; +package cy.agorise.graphenej.models; /** * Generic witness response diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/LinkedAccount.java b/graphenej/src/main/java/cy/agorise/graphenej/models/backup/LinkedAccount.java similarity index 92% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/LinkedAccount.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/backup/LinkedAccount.java index ff29243..5bdc52e 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/LinkedAccount.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/backup/LinkedAccount.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.models.backup; +package cy.agorise.graphenej.models.backup; /** * Class used to represent an entry in the "linked_accounts" field of the JSON-formatted backup file. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/PrivateKeyBackup.java b/graphenej/src/main/java/cy/agorise/graphenej/models/backup/PrivateKeyBackup.java similarity index 88% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/PrivateKeyBackup.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/backup/PrivateKeyBackup.java index 68d2f8b..aa77745 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/PrivateKeyBackup.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/backup/PrivateKeyBackup.java @@ -1,7 +1,7 @@ -package de.bitsharesmunich.graphenej.models.backup; +package cy.agorise.graphenej.models.backup; -import de.bitsharesmunich.graphenej.Address; -import de.bitsharesmunich.graphenej.Util; +import cy.agorise.graphenej.Address; +import cy.agorise.graphenej.Util; import org.bitcoinj.core.ECKey; /** diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/Wallet.java b/graphenej/src/main/java/cy/agorise/graphenej/models/backup/Wallet.java similarity index 95% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/Wallet.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/backup/Wallet.java index d4c5218..bfc61dd 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/Wallet.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/backup/Wallet.java @@ -1,11 +1,10 @@ -package de.bitsharesmunich.graphenej.models.backup; +package cy.agorise.graphenej.models.backup; -import de.bitsharesmunich.graphenej.Address; -import de.bitsharesmunich.graphenej.Util; -import de.bitsharesmunich.graphenej.crypto.SecureRandomGenerator; +import cy.agorise.graphenej.Address; +import cy.agorise.graphenej.Util; +import cy.agorise.graphenej.crypto.SecureRandomGenerator; import org.bitcoinj.core.ECKey; import org.bitcoinj.core.Sha256Hash; -import org.spongycastle.crypto.digests.SHA256Digest; import java.io.UnsupportedEncodingException; import java.security.SecureRandom; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/WalletBackup.java b/graphenej/src/main/java/cy/agorise/graphenej/models/backup/WalletBackup.java similarity index 96% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/WalletBackup.java rename to graphenej/src/main/java/cy/agorise/graphenej/models/backup/WalletBackup.java index 536c261..bac160f 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/WalletBackup.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/backup/WalletBackup.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.models.backup; +package cy.agorise.graphenej.models.backup; import java.util.List; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/objects/Memo.java b/graphenej/src/main/java/cy/agorise/graphenej/objects/Memo.java similarity index 72% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/objects/Memo.java rename to graphenej/src/main/java/cy/agorise/graphenej/objects/Memo.java index a618ba2..2f77218 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/objects/Memo.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/objects/Memo.java @@ -1,31 +1,35 @@ -package de.bitsharesmunich.graphenej.objects; +package cy.agorise.graphenej.objects; import com.google.common.primitives.Bytes; +import com.google.gson.Gson; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; - -import de.bitsharesmunich.graphenej.Address; -import de.bitsharesmunich.graphenej.PublicKey; -import de.bitsharesmunich.graphenej.Util; -import de.bitsharesmunich.graphenej.errors.ChecksumException; -import de.bitsharesmunich.graphenej.errors.MalformedAddressException; -import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; -import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; -import de.bitsharesmunich.graphenej.operations.TransferOperation; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; import org.bitcoinj.core.ECKey; import org.spongycastle.math.ec.ECPoint; import java.lang.reflect.Type; +import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; +import cy.agorise.graphenej.Address; +import cy.agorise.graphenej.PublicKey; +import cy.agorise.graphenej.Util; +import cy.agorise.graphenej.errors.ChecksumException; +import cy.agorise.graphenej.errors.MalformedAddressException; +import cy.agorise.graphenej.interfaces.ByteSerializable; +import cy.agorise.graphenej.interfaces.JsonSerializable; + /** - * Created by nelson on 11/9/16. + * Class used to represent a memo data structure + * {@url https://bitshares.org/doxygen/structgraphene_1_1chain_1_1memo__data.html} */ public class Memo implements ByteSerializable, JsonSerializable { public final static String TAG = "Memo"; @@ -36,7 +40,7 @@ public class Memo implements ByteSerializable, JsonSerializable { private Address from; private Address to; - private long nonce; + private BigInteger nonce; private byte[] message; private String plaintextMessage; @@ -67,7 +71,7 @@ public class Memo implements ByteSerializable, JsonSerializable { * @param nonce: Nonce used in the encryption. * @param message: Message in ciphertext. */ - public Memo(Address from, Address to, long nonce, byte[] message){ + public Memo(Address from, Address to, BigInteger nonce, byte[] message){ this.from = from; this.to = to; this.nonce = nonce; @@ -90,7 +94,7 @@ public class Memo implements ByteSerializable, JsonSerializable { return this.to; } - public long getNonce(){ + public BigInteger getNonce(){ return this.nonce; } @@ -113,14 +117,14 @@ public class Memo implements ByteSerializable, JsonSerializable { * @param message: Plaintext message. * @return: The encrypted version of the message. */ - public static byte[] encryptMessage(ECKey privateKey, PublicKey publicKey, long nonce, String message){ + public static byte[] encryptMessage(ECKey privateKey, PublicKey publicKey, BigInteger nonce, String message){ byte[] encrypted = null; try { MessageDigest sha256 = MessageDigest.getInstance("SHA-256"); MessageDigest sha512 = MessageDigest.getInstance("SHA-512"); // Getting nonce bytes - String stringNonce = String.format("%d", nonce); + String stringNonce = nonce.toString(); byte[] nonceBytes = Arrays.copyOfRange(Util.hexlify(stringNonce), 0, stringNonce.length()); // Getting shared secret @@ -154,7 +158,7 @@ public class Memo implements ByteSerializable, JsonSerializable { * @param message: Plaintext message. * @return: The encrypted version of the message. */ - public static byte[] encryptMessage(ECKey privateKey, Address destinationAddress, long nonce, String message){ + public static byte[] encryptMessage(ECKey privateKey, Address destinationAddress, BigInteger nonce, String message){ return encryptMessage(privateKey, destinationAddress.getPublicKey(), nonce, message); } @@ -168,14 +172,14 @@ public class Memo implements ByteSerializable, JsonSerializable { * @return: The plaintext version of the enrcrypted message. * @throws ChecksumException */ - public static String decryptMessage(ECKey privateKey, PublicKey publicKey, long nonce, byte[] message) throws ChecksumException { + public static String decryptMessage(ECKey privateKey, PublicKey publicKey, BigInteger nonce, byte[] message) throws ChecksumException { String plaintext = ""; try { MessageDigest sha256 = MessageDigest.getInstance("SHA-256"); MessageDigest sha512 = MessageDigest.getInstance("SHA-512"); // Getting nonce bytes - String stringNonce = String.format("%d", nonce); + String stringNonce = nonce.toString(); byte[] nonceBytes = Arrays.copyOfRange(Util.hexlify(stringNonce), 0, stringNonce.length()); // Getting shared secret @@ -215,7 +219,7 @@ public class Memo implements ByteSerializable, JsonSerializable { * @return: The plaintext version of the enrcrypted message. * @throws ChecksumException */ - public static String decryptMessage(ECKey privateKey, Address sourceAddress, long nonce, byte[] message) throws ChecksumException { + public static String decryptMessage(ECKey privateKey, Address sourceAddress, BigInteger nonce, byte[] message) throws ChecksumException { return decryptMessage(privateKey, sourceAddress.getPublicKey(), nonce, message); } @@ -236,7 +240,12 @@ public class Memo implements ByteSerializable, JsonSerializable { new byte[]{(byte) this.message.length}, this.message); } else { - byte[] nonceBytes = Util.revertLong(nonce); + + byte[] paddedNonceBytes = new byte[8]; + byte[] originalNonceBytes = nonce.toByteArray(); + System.arraycopy(originalNonceBytes, 0, paddedNonceBytes, 8 - originalNonceBytes.length, originalNonceBytes.length); + byte[] nonceBytes = Util.revertBytes(paddedNonceBytes); +// byte[] nonceBytes = Util.revertBytes(nonce.toByteArray()); ECPoint senderPoint = ECKey.compressPoint(from.getPublicKey().getKey().getPubKeyPoint()); PublicKey senderPublicKey = new PublicKey(ECKey.fromPublicOnly(senderPoint)); @@ -253,31 +262,62 @@ public class Memo implements ByteSerializable, JsonSerializable { } } + /** + * Converts a memo instance to a String. + * + * The nonce is always encoded as a decimal number in a string field. + * @return + */ @Override public String toJsonString() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + Gson gson = new Gson(); + return gson.toJson(toJson(true)); } + /** + * Converts a memo instance into a JsonElement. + * + * This method differs from the {@link #toJson(boolean)} in that here the nonce is encoded as an + * hexadecimal number, while in that one we offer the user to choose either the decimal or hexadecimal + * representations. + * + * @return JsonObject instance representing this memo + */ @Override public JsonElement toJsonObject() { JsonObject memoObject = new JsonObject(); if ((this.from == null) && (this.to == null)) { - // Public memo - // TODO: Add public memo support -// memoObject.addProperty(KEY_FROM, ""); -// memoObject.addProperty(KEY_TO, ""); -// memoObject.addProperty(KEY_NONCE, ""); -// memoObject.addProperty(KEY_MESSAGE, Util.bytesToHex(this.message)); + // TODO: Check if this public memo serialization is accepted + memoObject.addProperty(KEY_FROM, ""); + memoObject.addProperty(KEY_TO, ""); + memoObject.addProperty(KEY_NONCE, ""); + memoObject.addProperty(KEY_MESSAGE, Util.bytesToHex(this.message)); return null; }else{ memoObject.addProperty(KEY_FROM, this.from.toString()); memoObject.addProperty(KEY_TO, this.to.toString()); - memoObject.addProperty(KEY_NONCE, String.format("%d", this.nonce)); + memoObject.addProperty(KEY_NONCE, String.format("%x", this.nonce)); memoObject.addProperty(KEY_MESSAGE, Util.bytesToHex(this.message)); } return memoObject; } + /** + * Method that converts the memo into a JsonObject. + * + * @param decimal If true, the nonce is saved as string containing a decimal number representation. + * @return JsonObject instance representing this memo + */ + public JsonElement toJson(boolean decimal){ + JsonElement jsonElement = toJsonObject(); + if(decimal){ + JsonObject jsonObject = (JsonObject) jsonElement; + BigInteger nonce = new BigInteger(jsonObject.get(KEY_NONCE).getAsString(), 16); + jsonObject.addProperty(KEY_NONCE, nonce.toString()); + } + return jsonElement; + } + /** * Class used to deserialize a memo */ @@ -288,14 +328,19 @@ public class Memo implements ByteSerializable, JsonSerializable { JsonObject jsonObject = json.getAsJsonObject(); String fromAddress = jsonObject.get(KEY_FROM).getAsString(); String toAddress = jsonObject.get(KEY_TO).getAsString(); - long nonce = jsonObject.get(KEY_NONCE).getAsLong(); - String msg = jsonObject.get(KEY_MESSAGE).getAsString(); + // Apparently the nonce is always coming from the full node as a string containing a + // decimal number. This is at odds with the result of the #toJsonObject method + // which encodes this data in hexadecimal. + BigInteger nonce = new BigInteger(jsonObject.get(KEY_NONCE).getAsString(), 10); + + String msg = jsonObject.get(KEY_MESSAGE).getAsString(); Memo memo = null; try{ Address from = new Address(fromAddress); Address to = new Address(toAddress); byte[] message = Util.hexToBytes(msg); + memo = new Memo(from, to, nonce, message); }catch(MalformedAddressException e){ System.out.println("MalformedAddressException. Msg: "+e.getMessage()); @@ -303,4 +348,15 @@ public class Memo implements ByteSerializable, JsonSerializable { return memo; } } -} \ No newline at end of file + + /** + * Class used to serialize a memo + */ + public static class MemoSerializer implements JsonSerializer { + + @Override + public JsonElement serialize(Memo memo, Type typeOfSrc, JsonSerializationContext context) { + return memo.toJson(true); + } + } + } \ No newline at end of file diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/AccountUpdateOperation.java b/graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpdateOperation.java similarity index 97% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/AccountUpdateOperation.java rename to graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpdateOperation.java index 66a7310..b596ccf 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/AccountUpdateOperation.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpdateOperation.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.operations; +package cy.agorise.graphenej.operations; import com.google.common.primitives.Bytes; import com.google.common.primitives.UnsignedLong; @@ -6,7 +6,7 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import de.bitsharesmunich.graphenej.*; +import cy.agorise.graphenej.*; /** * Class used to encapsulate operations related to the ACCOUNT_UPDATE_OPERATION. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/AccountUpdateOperationBuilder.java b/graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpdateOperationBuilder.java similarity index 91% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/AccountUpdateOperationBuilder.java rename to graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpdateOperationBuilder.java index f7a088a..f0904e6 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/AccountUpdateOperationBuilder.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpdateOperationBuilder.java @@ -1,7 +1,7 @@ -package de.bitsharesmunich.graphenej.operations; +package cy.agorise.graphenej.operations; -import de.bitsharesmunich.graphenej.*; -import de.bitsharesmunich.graphenej.errors.MalformedOperationException; +import cy.agorise.graphenej.*; +import cy.agorise.graphenej.errors.MalformedOperationException; /** * Created by nelson on 3/1/17. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/BaseOperationBuilder.java b/graphenej/src/main/java/cy/agorise/graphenej/operations/BaseOperationBuilder.java similarity index 77% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/BaseOperationBuilder.java rename to graphenej/src/main/java/cy/agorise/graphenej/operations/BaseOperationBuilder.java index 82eed94..d2cd322 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/BaseOperationBuilder.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/operations/BaseOperationBuilder.java @@ -1,6 +1,6 @@ -package de.bitsharesmunich.graphenej.operations; +package cy.agorise.graphenej.operations; -import de.bitsharesmunich.graphenej.BaseOperation; +import cy.agorise.graphenej.BaseOperation; /** * Base template for all operation-specific factory classes. diff --git a/graphenej/src/main/java/cy/agorise/graphenej/operations/CustomOperation.java b/graphenej/src/main/java/cy/agorise/graphenej/operations/CustomOperation.java new file mode 100644 index 0000000..4678be0 --- /dev/null +++ b/graphenej/src/main/java/cy/agorise/graphenej/operations/CustomOperation.java @@ -0,0 +1,185 @@ +package cy.agorise.graphenej.operations; + +import com.google.common.primitives.Bytes; +import com.google.gson.*; +import cy.agorise.graphenej.*; + +import java.lang.reflect.Type; +import java.util.LinkedList; +import java.util.List; + +public class CustomOperation extends BaseOperation { + private static final String KEY_FEE = "fee"; + private static final String KEY_PAYER = "payer"; + private static final String KEY_REQUIRED_AUTHS = "required_auths"; + private static final String KEY_ID = "id"; + private static final String KEY_DATA = "data"; + + private AssetAmount fee; + private UserAccount payer; + private List requiredAuths; + private int operationId; + private String data; + + public CustomOperation(AssetAmount fee, UserAccount payer, int operationId, List requiredAuths, String data) { + super(OperationType.CUSTOM_OPERATION); + this.fee = fee; + this.payer = payer; + this.operationId = operationId; + this.requiredAuths = new LinkedList<>(); + if (requiredAuths != null) { + this.requiredAuths.addAll(requiredAuths); + } + this.data = data; + } + + public AssetAmount getFee() { + return fee; + } + + @Override + public void setFee(AssetAmount fee) { + this.fee = fee; + } + + public UserAccount getPayer() { + return payer; + } + + public void setPayer(UserAccount payer) { + this.payer = payer; + } + + public List getRequiredAuths() { + return requiredAuths; + } + + public void setRequiredAuths(List requiredAuths) { + this.requiredAuths = requiredAuths; + } + + public int getOperationId() { + return operationId; + } + + public void setOperationId(int operationId) { + this.operationId = operationId; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + @Override + public byte[] toBytes() { + byte[] feeBytes = fee.toBytes(); + byte[] payerBytes = payer.toBytes(); + List requiredAuthsSerialized = new LinkedList<>(); + if (this.requiredAuths != null) { + for (UserAccount userAccount : this.requiredAuths) { + requiredAuthsSerialized.addAll(Bytes.asList(userAccount.toBytes())); + } + } + byte[] requiredAuthsBytes = Bytes.toArray(requiredAuthsSerialized); + byte[] requiredAuthsLength = {(byte)this.requiredAuths.size()}; + byte[] operationIdBytes = Util.revertShort((short)operationId); + byte[] dataLength = Util.serializeLongToBytes(data.length()); + byte[] dataBytes = Util.hexlify(data); + + return Bytes.concat(feeBytes, payerBytes, requiredAuthsLength, requiredAuthsBytes, operationIdBytes, dataLength, dataBytes); + } + + @Override + public String toJsonString() { + return toJsonObject().toString(); + } + + @Override + public JsonElement toJsonObject() { + JsonArray array = new JsonArray(); + array.add(this.getId()); + + JsonObject jsonObject = new JsonObject(); + jsonObject.add(KEY_FEE, fee.toJsonObject()); + jsonObject.addProperty(KEY_PAYER, payer.getObjectId()); + JsonArray requiredAuthArray = new JsonArray(); + if (requiredAuths != null) { + for (UserAccount userAccount : requiredAuths) { + requiredAuthArray.add(userAccount.getObjectId()); + } + } + jsonObject.add(KEY_REQUIRED_AUTHS, requiredAuthArray); + jsonObject.addProperty(KEY_ID, operationId); + jsonObject.addProperty(KEY_DATA, Util.bytesToHex(Util.hexlify(data))); + + array.add(jsonObject); + + return array; + } + + /** + * Deserializer used to convert the JSON-formatted representation of a custom_operation + * into its java object version. + * + * The following is an example of the serialized form of this operation: + * + * [ + * 35, + * { + * "fee": { + * "amount": 100000, + * "asset_id": "1.3.0" + * }, + * "payer": "1.2.20", + * "required_auths": [ + * "1.2.20" + * ], + * "id": 61166, + * "data": "736f6d652064617461" + * } + * ] + */ + public static class CustomOperationDeserializer implements JsonDeserializer { + + @Override + public CustomOperation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + if (json.isJsonArray()){ + // This block is used just to check if we are in the first step of the deserialization + // when we are dealing with an array. + JsonArray serializedCustomOperation = json.getAsJsonArray(); + if (serializedCustomOperation.get(0).getAsInt() != OperationType.CUSTOM_OPERATION.ordinal()){ + // If the operation type does not correspond to a custom operation, we return null + return null; + } else { + // Calling itself recursively, this is only done once, so there will be no problems. + return context.deserialize(serializedCustomOperation.get(1), CustomOperation.class); + } + }else{ + // This block is called in the second recursion and takes care of deserializing the + // limit order data itself. + JsonObject jsonObject = json.getAsJsonObject(); + + AssetAmount fee = context.deserialize(jsonObject.get(KEY_FEE), AssetAmount.class); + String payerId = jsonObject.get(KEY_PAYER) .getAsString(); + UserAccount payer = new UserAccount(payerId); + List requiredAuths = new LinkedList<>(); + JsonElement requiredAuthsElement = jsonObject.get(KEY_REQUIRED_AUTHS); + if ((requiredAuthsElement != null) && (requiredAuthsElement.isJsonArray())) { + JsonArray requiredAuthsArray = requiredAuthsElement.getAsJsonArray(); + for (JsonElement jsonElement : requiredAuthsArray) { + String userAccountId = jsonElement.getAsString(); + requiredAuths.add(new UserAccount(userAccountId)); + } + } + int operationId = jsonObject.get(KEY_ID).getAsInt(); + String data = new String(Util.hexToBytes(jsonObject.get(KEY_DATA).getAsString())); + + return new CustomOperation(fee, payer, operationId, requiredAuths, data); + } + } + } +} diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/LimitOrderCancelOperation.java b/graphenej/src/main/java/cy/agorise/graphenej/operations/LimitOrderCancelOperation.java similarity index 95% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/LimitOrderCancelOperation.java rename to graphenej/src/main/java/cy/agorise/graphenej/operations/LimitOrderCancelOperation.java index 0334255..7b5065e 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/LimitOrderCancelOperation.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/operations/LimitOrderCancelOperation.java @@ -1,10 +1,10 @@ -package de.bitsharesmunich.graphenej.operations; +package cy.agorise.graphenej.operations; import com.google.common.primitives.Bytes; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import de.bitsharesmunich.graphenej.*; +import cy.agorise.graphenej.*; /** * Created by nelson on 3/21/17. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/LimitOrderCreateOperation.java b/graphenej/src/main/java/cy/agorise/graphenej/operations/LimitOrderCreateOperation.java similarity index 95% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/LimitOrderCreateOperation.java rename to graphenej/src/main/java/cy/agorise/graphenej/operations/LimitOrderCreateOperation.java index df3a5f7..773de4e 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/LimitOrderCreateOperation.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/operations/LimitOrderCreateOperation.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.operations; +package cy.agorise.graphenej.operations; import com.google.common.primitives.Bytes; import com.google.gson.JsonArray; @@ -15,11 +15,11 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.BaseOperation; -import de.bitsharesmunich.graphenej.OperationType; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.Util; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.BaseOperation; +import cy.agorise.graphenej.OperationType; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.Util; /** * Operation used to denote the creation of a limit order on the blockchain. @@ -208,7 +208,7 @@ public class LimitOrderCreateOperation extends BaseOperation { JsonObject jsonObject = json.getAsJsonObject(); AssetAmount fee = context.deserialize(jsonObject.get(KEY_FEE), AssetAmount.class); - UserAccount seller = context.deserialize(jsonObject.get(KEY_SELLER), UserAccount.class); + UserAccount seller = new UserAccount(jsonObject.get(KEY_SELLER).getAsString()); AssetAmount amountToSell = context.deserialize(jsonObject.get(KEY_AMOUNT_TO_SELL), AssetAmount.class); AssetAmount minToReceive = context.deserialize(jsonObject.get(KEY_MIN_TO_RECEIVE), AssetAmount.class); String expiration = jsonObject.get(KEY_EXPIRATION).getAsString(); diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/TransferOperation.java b/graphenej/src/main/java/cy/agorise/graphenej/operations/TransferOperation.java similarity index 92% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/TransferOperation.java rename to graphenej/src/main/java/cy/agorise/graphenej/operations/TransferOperation.java index 89d5b14..232a2a1 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/TransferOperation.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/operations/TransferOperation.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.operations; +package cy.agorise.graphenej.operations; import com.google.common.primitives.Bytes; import com.google.gson.GsonBuilder; @@ -13,11 +13,11 @@ import com.google.gson.JsonSerializer; import java.lang.reflect.Type; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.BaseOperation; -import de.bitsharesmunich.graphenej.OperationType; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.objects.Memo; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.BaseOperation; +import cy.agorise.graphenej.OperationType; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.objects.Memo; /** * Class used to encapsulate the TransferOperation operation related functionalities. @@ -121,20 +121,21 @@ public class TransferOperation extends BaseOperation { jsonObject.addProperty(KEY_FROM, from.getObjectId()); jsonObject.addProperty(KEY_TO, to.getObjectId()); jsonObject.add(KEY_AMOUNT, amount.toJsonObject()); - jsonObject.add(KEY_MEMO, memo.toJsonObject()); + if(memo.getByteMessage() != null) + jsonObject.add(KEY_MEMO, memo.toJsonObject()); jsonObject.add(KEY_EXTENSIONS, new JsonArray()); array.add(jsonObject); return array; } + /** + * Serializer used to convert this object into a {@link JsonElement} instance + */ public static class TransferSerializer implements JsonSerializer { @Override public JsonElement serialize(TransferOperation transfer, Type type, JsonSerializationContext jsonSerializationContext) { - JsonArray arrayRep = new JsonArray(); - arrayRep.add(transfer.getId()); - arrayRep.add(transfer.toJsonObject()); - return arrayRep; + return transfer.toJsonObject(); } } @@ -197,7 +198,6 @@ public class TransferOperation extends BaseOperation { Memo memo = context.deserialize(jsonObject.get(KEY_MEMO), Memo.class); transfer.setMemo(memo); } - return transfer; } } diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/TransferOperationBuilder.java b/graphenej/src/main/java/cy/agorise/graphenej/operations/TransferOperationBuilder.java similarity index 86% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/TransferOperationBuilder.java rename to graphenej/src/main/java/cy/agorise/graphenej/operations/TransferOperationBuilder.java index c080734..709589b 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/TransferOperationBuilder.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/operations/TransferOperationBuilder.java @@ -1,9 +1,9 @@ -package de.bitsharesmunich.graphenej.operations; +package cy.agorise.graphenej.operations; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.errors.MalformedOperationException; -import de.bitsharesmunich.graphenej.objects.Memo; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.errors.MalformedOperationException; +import cy.agorise.graphenej.objects.Memo; /** * Factory class used to build a transfer operation diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/test/NaiveSSLContext.java b/graphenej/src/main/java/cy/agorise/graphenej/test/NaiveSSLContext.java similarity index 98% rename from graphenej/src/main/java/de/bitsharesmunich/graphenej/test/NaiveSSLContext.java rename to graphenej/src/main/java/cy/agorise/graphenej/test/NaiveSSLContext.java index 8858aba..ac7c9a3 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/test/NaiveSSLContext.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/test/NaiveSSLContext.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.test; +package cy.agorise.graphenej.test; /* * Copyright (C) 2015 Neo Visionaries Inc. diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/OrderBook.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/OrderBook.java deleted file mode 100644 index 3615b0b..0000000 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/OrderBook.java +++ /dev/null @@ -1,98 +0,0 @@ -package de.bitsharesmunich.graphenej; - -import com.google.common.math.DoubleMath; -import com.google.common.primitives.UnsignedLong; - -import java.math.RoundingMode; -import java.util.List; - -import de.bitsharesmunich.graphenej.operations.LimitOrderCreateOperation; - -/** - * This class will maintain a snapshot of the order book between two assets. - * - * It also provides a handy method that should return the appropriate LimitOrderCreateOperation - * object needed in case the user wants to perform market-priced operations. - * - * It is important to keep the order book updated, ideally by listening to blockchain events, and calling the 'update' method. - * - * Created by nelson on 3/25/17. - */ -public class OrderBook { - private List limitOrders; - - public OrderBook(List limitOrders){ - this.limitOrders = limitOrders; - } - - /** - * Replaces the current limit order by the list provided as parameter. - * @param limitOrders: New list of orders - */ - public void update(List limitOrders){ - this.limitOrders = limitOrders; - } - - public void update(LimitOrder limitOrder){ - //TODO: Implement the method that will update a single limit order from the order book - } - - /** - * High level method used to exchange a specific amount of an asset (The base) for another - * one (The quote) at market value. - * - * It should analyze the order book and figure out the optimal amount of the base asset to give - * away in order to obtain the desired amount of the quote asset. - * - * @param seller: User account of the seller, used to build the limit order create operation - * @param myBaseAsset: The asset the user is willing to give away - * @param myQuoteAmount: The amount of a given asset the user wants - * @param expiration: The expiration time of the limit order - * - * @return An instance of the LimitOrderCreateOperation class, which is ready to be broadcasted. - */ - public LimitOrderCreateOperation exchange(UserAccount seller, Asset myBaseAsset, AssetAmount myQuoteAmount, int expiration){ - AssetAmount toSell = new AssetAmount(UnsignedLong.valueOf(calculateRequiredBase(myQuoteAmount)), myBaseAsset); - AssetAmount toReceive = myQuoteAmount; - LimitOrderCreateOperation buyOrder = new LimitOrderCreateOperation(seller, toSell, toReceive, expiration, true); - - return buyOrder; - } - - /** - * Given a specific amount of a desired asset, this method will calculate how much of the corresponding - * asset we need to offer to perform a successful transaction with the current order book. - * @param quoteAmount: The amount of the desired asset. - * @return: The minimum amount of the base asset that we need to give away - */ - public long calculateRequiredBase(AssetAmount quoteAmount){ - long totalBought = 0; - long totalSold = 0; - for(int i = 0; i < this.limitOrders.size() && totalBought < quoteAmount.getAmount().longValue(); i++){ - LimitOrder order = this.limitOrders.get(i); - - // If the base asset is the same as our quote asset, we have a match - if(order.getSellPrice().base.getAsset().getObjectId().equals(quoteAmount.getAsset().getObjectId())){ - // My quote amount, is the order's base amount - long orderAmount = order.getForSale(); - - // The amount of the quote asset we still need - long stillNeed = quoteAmount.getAmount().longValue() - totalBought; - - // If the offered amount is greater than what we still need, we exchange just what we need - if(orderAmount >= stillNeed) { - totalBought += stillNeed; - double additionalRatio = (double) stillNeed / (double) order.getSellPrice().base.getAmount().longValue(); - double additionalAmount = order.getSellPrice().quote.getAmount().longValue() * additionalRatio; - long longAdditional = DoubleMath.roundToLong(additionalAmount, RoundingMode.HALF_UP); - totalSold += longAdditional; - }else{ - // If the offered amount is less than what we need, we exchange the whole order - totalBought += orderAmount; - totalSold += order.getSellPrice().quote.getAmount().longValue(); - } - } - } - return totalSold; - } -} diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/RepeatedRequestIdException.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/RepeatedRequestIdException.java deleted file mode 100644 index 74c19e3..0000000 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/errors/RepeatedRequestIdException.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.bitsharesmunich.graphenej.errors; - -/** - * Created by nelson on 6/27/17. - */ - -public class RepeatedRequestIdException extends Exception { - - public RepeatedRequestIdException(String message){ - super(message); - } -} diff --git a/graphenej/src/test/java/cy/agorise/graphenej/AssetAmountTest.java b/graphenej/src/test/java/cy/agorise/graphenej/AssetAmountTest.java new file mode 100644 index 0000000..cdcddaa --- /dev/null +++ b/graphenej/src/test/java/cy/agorise/graphenej/AssetAmountTest.java @@ -0,0 +1,60 @@ +package cy.agorise.graphenej; + +import com.google.common.primitives.UnsignedLong; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; + +/** + * Testing AssetAmount operations. + */ +public class AssetAmountTest { + private final int LARGE_VALUE = 1000; + private final int SMALL_VALUE = 500; + private AssetAmount large; + private AssetAmount small; + private Asset testAsset = new Asset("1.3.0"); + + @Before + public void setUp(){ + large = new AssetAmount(UnsignedLong.valueOf(LARGE_VALUE), testAsset); + small = new AssetAmount(UnsignedLong.valueOf(SMALL_VALUE), testAsset); + } + + @Test + public void testSubtraction(){ + assertEquals(large.subtract(small).getAmount(), new AssetAmount(UnsignedLong.valueOf(LARGE_VALUE - SMALL_VALUE), testAsset).getAmount()); + assertEquals(small.subtract(large).getAmount(), new AssetAmount(UnsignedLong.valueOf(Math.abs(SMALL_VALUE - LARGE_VALUE)), testAsset).getAmount()); + } + + @Test + public void testMultiplication(){ + // Testing a simple multiplication by a double + AssetAmount result = large.multiplyBy(0.5); + assertEquals(500, result.getAmount().longValue()); + + // Testing the multiplication of a number that would normally give an overflow + AssetAmount max = new AssetAmount(UnsignedLong.valueOf(Long.MAX_VALUE), testAsset); + AssetAmount overMaxLong = max.multiplyBy(1.5); + assertEquals("13835058055282163712", overMaxLong.getAmount().toString(10)); + + assertNotSame("Making sure the result and original references point to different instances",result, large); + } + + @Test + public void testDivision(){ + // Testing a simple division by a double + AssetAmount result = large.divideBy(0.5); + assertEquals(2000, result.getAmount().longValue()); + + // Testing a division of a number that would normally give an overflow + AssetAmount max = new AssetAmount(UnsignedLong.valueOf(Long.MAX_VALUE), testAsset); + AssetAmount overMaxLong = max.divideBy(0.8); + assertEquals("11529215046068469760", overMaxLong.getAmount().toString()); + + assertNotSame("Making sure the result and original references point to different instances",result, large); + } +} \ No newline at end of file diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/AssetTest.java b/graphenej/src/test/java/cy/agorise/graphenej/AssetTest.java similarity index 85% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/AssetTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/AssetTest.java index 81d01dc..9bc4a15 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/AssetTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/AssetTest.java @@ -1,6 +1,4 @@ -package de.bitsharesmunich.graphenej; - -import org.junit.*; +package cy.agorise.graphenej; import static org.junit.Assert.*; diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/AuthorityTest.java b/graphenej/src/test/java/cy/agorise/graphenej/AuthorityTest.java similarity index 98% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/AuthorityTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/AuthorityTest.java index eb34c17..23109f1 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/AuthorityTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/AuthorityTest.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import org.junit.After; import org.junit.Before; diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/BrainKeyTest.java b/graphenej/src/test/java/cy/agorise/graphenej/BrainKeyTest.java similarity index 95% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/BrainKeyTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/BrainKeyTest.java index a534eb5..c0a1342 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/BrainKeyTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/BrainKeyTest.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import junit.framework.Assert; diff --git a/graphenej/src/test/java/cy/agorise/graphenej/KeyTest.java b/graphenej/src/test/java/cy/agorise/graphenej/KeyTest.java new file mode 100644 index 0000000..cd1ff32 --- /dev/null +++ b/graphenej/src/test/java/cy/agorise/graphenej/KeyTest.java @@ -0,0 +1,25 @@ +package cy.agorise.graphenej; + +import junit.framework.Assert; + +import org.bitcoinj.core.DumpedPrivateKey; +import org.bitcoinj.core.ECKey; +import org.junit.Test; + +/** + * Created by nelson on 11/2/17. + */ + +public class KeyTest { + + /** + * Testing key to address derivation + */ + @Test + public void testKeyToAddress(){ + String wif = "5J96pne45qWM1WpektoeazN6k9Mt93jQ7LyueRxFfEMTiy6yxjM"; + ECKey sourcePrivate = DumpedPrivateKey.fromBase58(null, wif).getKey(); + Address address = new Address(ECKey.fromPublicOnly(sourcePrivate.getPubKey())); + Assert.assertEquals("Generated address matches expected one", "BTS8RiFgs8HkcVPVobHLKEv6yL3iXcC9SWjbPVS15dDAXLG9GYhnY", address.toString()); + } +} diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/ObjectTypeTest.java b/graphenej/src/test/java/cy/agorise/graphenej/ObjectTypeTest.java similarity index 96% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/ObjectTypeTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/ObjectTypeTest.java index 915c313..b0ab3f8 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/ObjectTypeTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/ObjectTypeTest.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import junit.framework.Assert; diff --git a/graphenej/src/test/java/cy/agorise/graphenej/OrderBookTest.java b/graphenej/src/test/java/cy/agorise/graphenej/OrderBookTest.java new file mode 100644 index 0000000..befc032 --- /dev/null +++ b/graphenej/src/test/java/cy/agorise/graphenej/OrderBookTest.java @@ -0,0 +1,87 @@ +package cy.agorise.graphenej; + +import com.google.common.primitives.UnsignedLong; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +import org.junit.Assert; +import org.junit.Test; + +import java.lang.reflect.Type; +import java.util.List; + +import cy.agorise.graphenej.models.WitnessResponse; + +/** + * Testing the {@link OrderBook} class + */ + +public class OrderBookTest { + + @Test + public void testRequiredBase(){ + String serializedOrderBook = "{\"id\": 1,\"result\": [{\"id\": \"1.7.37284933\",\"expiration\": \"2018-11-17T00:03:49\",\"seller\": \"1.2.132823\",\"for_sale\": 10,\"sell_price\": {\"base\": {\"amount\": 1,\"asset_id\": \"1.3.121\"},\"quote\": {\"amount\": 10,\"asset_id\": \"1.3.0\"}},\"deferred_fee\": 0},{\"id\": \"1.7.37284933\",\"expiration\": \"2018-11-17T00:03:49\",\"seller\": \"1.2.132823\",\"for_sale\": 20,\"sell_price\": {\"base\": {\"amount\": 1,\"asset_id\": \"1.3.121\"},\"quote\": {\"amount\": 20,\"asset_id\": \"1.3.0\"}},\"deferred_fee\": 0}]}"; + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer()); + builder.registerTypeAdapter(UserAccount.class, new UserAccount.UserAccountSimpleDeserializer()); + builder.registerTypeAdapter(LimitOrder.class, new LimitOrder.LimitOrderDeserializer()); + Type GetLimitOrdersResponse = new TypeToken>>() {}.getType(); + WitnessResponse> witnessResponse = builder.create().fromJson(serializedOrderBook, GetLimitOrdersResponse); + List orders = witnessResponse.result; + OrderBook orderBook = new OrderBook(orders); + + + final Asset _quote = new Asset("1.3.121", "USD", 4); + final Asset _base = new Asset("1.3.0", "BTS", 5); + long _totalQuote = 14; + UnsignedLong _totalBase = orderBook.calculateRequiredBase(new AssetAmount(UnsignedLong.valueOf(_totalQuote), _quote)); + Assert.assertEquals("Should buy 10 at 10 and 4 at 20, which sums up to 180",180, _totalBase.longValue()); + System.out.println(String.format("Base: %s, Quote: %s", _base.getObjectId(), _quote.getObjectId())); + System.out.println(String.format("_totalQuote: %d, _totalBase: %d", _totalQuote, _totalBase.longValue())); + } + + @Test + public void testRequiredQuote(){ + String serializedOrderBook = "{\"id\":1,\"result\":[{\"id\":\"1.7.37284933\",\"expiration\":\"2018-11-17T00:03:49\",\"seller\":\"1.2.132823\",\"for_sale\":20,\"sell_price\":{\"base\":{\"amount\":20,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":0},{\"id\":\"1.7.37284933\",\"expiration\":\"2018-11-17T00:03:49\",\"seller\":\"1.2.132823\",\"for_sale\":100,\"sell_price\":{\"base\":{\"amount\":10,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":0}]}"; + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer()); + builder.registerTypeAdapter(UserAccount.class, new UserAccount.UserAccountSimpleDeserializer()); + builder.registerTypeAdapter(LimitOrder.class, new LimitOrder.LimitOrderDeserializer()); + Type GetLimitOrdersResponse = new TypeToken>>() {}.getType(); + WitnessResponse> witnessResponse = builder.create().fromJson(serializedOrderBook, GetLimitOrdersResponse); + List orders = witnessResponse.result; + OrderBook orderBook = new OrderBook(orders); + + + final Asset _base = new Asset("1.3.121", "USD", 4); + final Asset _quote = new Asset("1.3.0", "BTS", 5); + long _totalBase = 2; + UnsignedLong _totalQuote = orderBook.calculateObtainedQuote(new AssetAmount(UnsignedLong.valueOf(_totalBase), _base)); + Assert.assertEquals("Should be able to buy 20 on the first order and 10 on the second, totalling 30",30, _totalQuote.longValue()); + System.out.println(String.format("Base: %s, Quote: %s", _base.getObjectId(), _quote.getObjectId())); + System.out.println(String.format("_totalQuote: %d, _totalBase: %d", _totalQuote.longValue(), _totalQuote.longValue())); + } + + @Test + public void testRequiredQuoteReal(){ + String serializedOrderBook = "{\"id\":1,\"result\":[{\"id\":\"1.7.39826107\",\"expiration\":\"2022-11-29T04:26:23\",\"seller\":\"1.2.384119\",\"for_sale\":100000,\"sell_price\":{\"base\":{\"amount\":100000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":5930000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826091\",\"expiration\":\"2022-11-29T04:26:06\",\"seller\":\"1.2.384119\",\"for_sale\":100000,\"sell_price\":{\"base\":{\"amount\":100000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":5950000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39825780\",\"expiration\":\"2022-11-29T04:24:56\",\"seller\":\"1.2.384119\",\"for_sale\":100000,\"sell_price\":{\"base\":{\"amount\":100000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":5970000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39827059\",\"expiration\":\"2017-11-29T05:31:34\",\"seller\":\"1.2.359723\",\"for_sale\":357277,\"sell_price\":{\"base\":{\"amount\":357277,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":21355520,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39825610\",\"expiration\":\"2022-11-29T04:23:34\",\"seller\":\"1.2.384119\",\"for_sale\":100000,\"sell_price\":{\"base\":{\"amount\":100000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":5990000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826428\",\"expiration\":\"2022-11-29T04:28:45\",\"seller\":\"1.2.384119\",\"for_sale\":1000000,\"sell_price\":{\"base\":{\"amount\":1000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":59990000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39825045\",\"expiration\":\"2022-11-29T04:20:49\",\"seller\":\"1.2.7003\",\"for_sale\":35754092,\"sell_price\":{\"base\":{\"amount\":51008622,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":3060517320,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":0},{\"id\":\"1.7.39827034\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.398049\",\"for_sale\":226328,\"sell_price\":{\"base\":{\"amount\":226328,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":13635626,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826622\",\"expiration\":\"2022-11-29T04:30:07\",\"seller\":\"1.2.384119\",\"for_sale\":1000000,\"sell_price\":{\"base\":{\"amount\":1000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":61000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39825800\",\"expiration\":\"1963-11-25T22:31:44\",\"seller\":\"1.2.95758\",\"for_sale\":1515000,\"sell_price\":{\"base\":{\"amount\":1515000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":92750445,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39827058\",\"expiration\":\"1963-11-29T12:38:45\",\"seller\":\"1.2.36449\",\"for_sale\":75750000,\"sell_price\":{\"base\":{\"amount\":75750000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":\"4638289114\",\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826511\",\"expiration\":\"2017-12-06T04:29:04\",\"seller\":\"1.2.376473\",\"for_sale\":1516515,\"sell_price\":{\"base\":{\"amount\":1516515,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":92858549,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39822796\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.165710\",\"for_sale\":151500,\"sell_price\":{\"base\":{\"amount\":151500,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":9285855,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39791452\",\"expiration\":\"2022-11-29T01:16:22\",\"seller\":\"1.2.28914\",\"for_sale\":16200000,\"sell_price\":{\"base\":{\"amount\":16200000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":1000000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826697\",\"expiration\":\"2022-11-29T04:30:22\",\"seller\":\"1.2.384119\",\"for_sale\":1000000,\"sell_price\":{\"base\":{\"amount\":1000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":62000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39767436\",\"expiration\":\"2022-11-28T23:16:04\",\"seller\":\"1.2.408360\",\"for_sale\":17934080,\"sell_price\":{\"base\":{\"amount\":17934080,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":1112535980,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39770442\",\"expiration\":\"2022-11-28T23:27:12\",\"seller\":\"1.2.429094\",\"for_sale\":1052917,\"sell_price\":{\"base\":{\"amount\":1052917,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":66221194,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1227},{\"id\":\"1.7.39787848\",\"expiration\":\"2022-11-29T00:57:45\",\"seller\":\"1.2.408360\",\"for_sale\":19945106,\"sell_price\":{\"base\":{\"amount\":19945106,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":1256447949,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1257},{\"id\":\"1.7.39826299\",\"expiration\":\"2022-11-29T04:27:44\",\"seller\":\"1.2.384119\",\"for_sale\":3000000,\"sell_price\":{\"base\":{\"amount\":3000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":189000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39726192\",\"expiration\":\"2022-11-28T17:25:39\",\"seller\":\"1.2.398578\",\"for_sale\":316200,\"sell_price\":{\"base\":{\"amount\":316200,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":20000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39724878\",\"expiration\":\"2022-11-28T17:15:53\",\"seller\":\"1.2.472756\",\"for_sale\":5987987,\"sell_price\":{\"base\":{\"amount\":5987987,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":382024828,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39762644\",\"expiration\":\"2022-11-28T23:00:35\",\"seller\":\"1.2.465467\",\"for_sale\":1252843,\"sell_price\":{\"base\":{\"amount\":1252843,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":80000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39817965\",\"expiration\":\"2022-11-29T03:45:43\",\"seller\":\"1.2.384119\",\"for_sale\":3000000,\"sell_price\":{\"base\":{\"amount\":3000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":192000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39718037\",\"expiration\":\"2018-11-28T16:10:58\",\"seller\":\"1.2.132823\",\"for_sale\":1052528,\"sell_price\":{\"base\":{\"amount\":1052528,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":67641517,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39743004\",\"expiration\":\"2022-11-28T20:28:12\",\"seller\":\"1.2.182034\",\"for_sale\":1547001,\"sell_price\":{\"base\":{\"amount\":1547001,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":100000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39718531\",\"expiration\":\"2022-11-28T16:17:33\",\"seller\":\"1.2.424868\",\"for_sale\":100000000,\"sell_price\":{\"base\":{\"amount\":100000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":\"6464124111\",\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39715891\",\"expiration\":\"2022-11-28T15:45:45\",\"seller\":\"1.2.398578\",\"for_sale\":2000000,\"sell_price\":{\"base\":{\"amount\":2000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":129365483,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39819644\",\"expiration\":\"2022-11-29T03:55:12\",\"seller\":\"1.2.384119\",\"for_sale\":3000000,\"sell_price\":{\"base\":{\"amount\":3000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":195000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39711734\",\"expiration\":\"2022-11-28T15:08:31\",\"seller\":\"1.2.432748\",\"for_sale\":16620108,\"sell_price\":{\"base\":{\"amount\":17620000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":1149926586,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":0},{\"id\":\"1.7.39729717\",\"expiration\":\"2022-11-28T18:09:33\",\"seller\":\"1.2.467917\",\"for_sale\":53196,\"sell_price\":{\"base\":{\"amount\":53196,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":3485926,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39739105\",\"expiration\":\"2022-11-28T19:46:30\",\"seller\":\"1.2.450915\",\"for_sale\":1330000,\"sell_price\":{\"base\":{\"amount\":1330000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":87500000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826277\",\"expiration\":\"2022-11-29T04:27:27\",\"seller\":\"1.2.384119\",\"for_sale\":3000000,\"sell_price\":{\"base\":{\"amount\":3000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":198000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39709056\",\"expiration\":\"2022-11-28T14:33:54\",\"seller\":\"1.2.174467\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":330033003,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1221},{\"id\":\"1.7.39710371\",\"expiration\":\"2022-11-28T14:51:11\",\"seller\":\"1.2.424868\",\"for_sale\":50000000,\"sell_price\":{\"base\":{\"amount\":50000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":3309066843,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39645110\",\"expiration\":\"2022-11-28T05:57:36\",\"seller\":\"1.2.398578\",\"for_sale\":150000,\"sell_price\":{\"base\":{\"amount\":150000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":10000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39761502\",\"expiration\":\"2022-11-28T22:57:42\",\"seller\":\"1.2.101673\",\"for_sale\":43700400,\"sell_price\":{\"base\":{\"amount\":43700400,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":2913360000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39770621\",\"expiration\":\"2022-11-28T23:27:40\",\"seller\":\"1.2.445796\",\"for_sale\":11248500,\"sell_price\":{\"base\":{\"amount\":11248500,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":749900000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826381\",\"expiration\":\"2022-11-29T04:28:25\",\"seller\":\"1.2.384119\",\"for_sale\":3000000,\"sell_price\":{\"base\":{\"amount\":3000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":201000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39739797\",\"expiration\":\"2022-11-28T19:59:08\",\"seller\":\"1.2.444127\",\"for_sale\":952159,\"sell_price\":{\"base\":{\"amount\":952159,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":63839890,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39675312\",\"expiration\":\"2022-11-28T09:46:14\",\"seller\":\"1.2.398578\",\"for_sale\":740500,\"sell_price\":{\"base\":{\"amount\":740500,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":50000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39706939\",\"expiration\":\"2022-11-28T14:13:34\",\"seller\":\"1.2.443284\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":337837837,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39732387\",\"expiration\":\"2022-11-28T18:37:11\",\"seller\":\"1.2.384119\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":340000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39707139\",\"expiration\":\"2022-11-28T14:15:15\",\"seller\":\"1.2.443284\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":340136054,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39648077\",\"expiration\":\"2022-11-28T05:25:03\",\"seller\":\"1.2.161162\",\"for_sale\":4572310,\"sell_price\":{\"base\":{\"amount\":4572310,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":312529733,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39587569\",\"expiration\":\"2022-11-27T21:48:15\",\"seller\":\"1.2.449122\",\"for_sale\":2884418,\"sell_price\":{\"base\":{\"amount\":2884418,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":197553404,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39568900\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.166710\",\"for_sale\":15149,\"sell_price\":{\"base\":{\"amount\":15149,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":1039535,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39706235\",\"expiration\":\"2022-11-28T14:09:12\",\"seller\":\"1.2.443284\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":344827586,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39651001\",\"expiration\":\"2022-11-28T06:50:14\",\"seller\":\"1.2.398578\",\"for_sale\":290000,\"sell_price\":{\"base\":{\"amount\":290000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":20000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39774063\",\"expiration\":\"2022-11-28T23:40:02\",\"seller\":\"1.2.386019\",\"for_sale\":849700,\"sell_price\":{\"base\":{\"amount\":849700,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":58600000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39637259\",\"expiration\":\"2022-11-28T04:47:01\",\"seller\":\"1.2.452887\",\"for_sale\":28990,\"sell_price\":{\"base\":{\"amount\":28990,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":2000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39732395\",\"expiration\":\"2022-11-28T18:37:17\",\"seller\":\"1.2.384119\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":345000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39551534\",\"expiration\":\"2022-11-27T17:38:00\",\"seller\":\"1.2.33253\",\"for_sale\":179760,\"sell_price\":{\"base\":{\"amount\":179760,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":12441798,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39533002\",\"expiration\":\"2022-11-27T15:22:59\",\"seller\":\"1.2.388453\",\"for_sale\":933982,\"sell_price\":{\"base\":{\"amount\":2548625,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":176987851,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":0},{\"id\":\"1.7.39788915\",\"expiration\":\"1963-12-26T10:31:44\",\"seller\":\"1.2.92842\",\"for_sale\":9789859,\"sell_price\":{\"base\":{\"amount\":9789859,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":681535516,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39509337\",\"expiration\":\"2018-11-27T04:45:12\",\"seller\":\"1.2.465200\",\"for_sale\":14703,\"sell_price\":{\"base\":{\"amount\":28586,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":2000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":0},{\"id\":\"1.7.39732399\",\"expiration\":\"2022-11-28T18:37:28\",\"seller\":\"1.2.384119\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":350000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39739763\",\"expiration\":\"2022-11-28T19:58:55\",\"seller\":\"1.2.444127\",\"for_sale\":1210229,\"sell_price\":{\"base\":{\"amount\":1210229,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":85199944,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39724012\",\"expiration\":\"2022-11-28T17:07:09\",\"seller\":\"1.2.146567\",\"for_sale\":2000000,\"sell_price\":{\"base\":{\"amount\":2000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":141843971,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39574007\",\"expiration\":\"2022-11-27T19:40:39\",\"seller\":\"1.2.146567\",\"for_sale\":140901,\"sell_price\":{\"base\":{\"amount\":140901,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":10000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39732407\",\"expiration\":\"2022-11-28T18:37:34\",\"seller\":\"1.2.384119\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":355000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39588063\",\"expiration\":\"2022-11-27T21:51:29\",\"seller\":\"1.2.394864\",\"for_sale\":1500000,\"sell_price\":{\"base\":{\"amount\":1500000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":106759916,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39726395\",\"expiration\":\"2022-11-28T17:27:43\",\"seller\":\"1.2.25932\",\"for_sale\":159689,\"sell_price\":{\"base\":{\"amount\":159689,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":11365765,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1248},{\"id\":\"1.7.39713749\",\"expiration\":\"2022-11-28T15:28:20\",\"seller\":\"1.2.467917\",\"for_sale\":17410,\"sell_price\":{\"base\":{\"amount\":17410,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":1243567,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39706578\",\"expiration\":\"2022-11-28T14:11:13\",\"seller\":\"1.2.443284\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":357142857,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39816924\",\"expiration\":\"2022-11-29T03:40:12\",\"seller\":\"1.2.445451\",\"for_sale\":28000000,\"sell_price\":{\"base\":{\"amount\":28000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":2000000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39515307\",\"expiration\":\"2022-11-27T13:19:16\",\"seller\":\"1.2.168996\",\"for_sale\":1677733,\"sell_price\":{\"base\":{\"amount\":1677733,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":120000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39592929\",\"expiration\":\"2022-11-27T22:44:52\",\"seller\":\"1.2.406209\",\"for_sale\":195300,\"sell_price\":{\"base\":{\"amount\":195300,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":14000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39491714\",\"expiration\":\"2022-11-27T10:28:09\",\"seller\":\"1.2.435836\",\"for_sale\":5789525,\"sell_price\":{\"base\":{\"amount\":5789525,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":415284575,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39487775\",\"expiration\":\"2022-11-27T10:03:25\",\"seller\":\"1.2.392110\",\"for_sale\":63392638,\"sell_price\":{\"base\":{\"amount\":80000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":\"5738682718\",\"asset_id\":\"1.3.0\"}},\"deferred_fee\":0},{\"id\":\"1.7.39517335\",\"expiration\":\"2022-11-27T13:34:50\",\"seller\":\"1.2.441250\",\"for_sale\":2050000,\"sell_price\":{\"base\":{\"amount\":2050000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":147482014,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39787574\",\"expiration\":\"2022-11-29T00:56:04\",\"seller\":\"1.2.393319\",\"for_sale\":1389000,\"sell_price\":{\"base\":{\"amount\":1389000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":100000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39732410\",\"expiration\":\"2022-11-28T18:37:41\",\"seller\":\"1.2.384119\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":360000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39517481\",\"expiration\":\"2022-11-27T13:35:35\",\"seller\":\"1.2.441250\",\"for_sale\":2050000,\"sell_price\":{\"base\":{\"amount\":2050000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":148550724,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39732419\",\"expiration\":\"2022-11-28T18:37:46\",\"seller\":\"1.2.384119\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":365000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39435065\",\"expiration\":\"2022-11-27T05:09:48\",\"seller\":\"1.2.457023\",\"for_sale\":10000,\"sell_price\":{\"base\":{\"amount\":10000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":734000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39722683\",\"expiration\":\"2022-11-28T16:55:10\",\"seller\":\"1.2.203202\",\"for_sale\":190965,\"sell_price\":{\"base\":{\"amount\":190965,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":14016831,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39484129\",\"expiration\":\"2022-11-27T09:45:08\",\"seller\":\"1.2.28914\",\"for_sale\":6805000,\"sell_price\":{\"base\":{\"amount\":6805000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":500000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39418777\",\"expiration\":\"2022-11-27T03:18:07\",\"seller\":\"1.2.23586\",\"for_sale\":4000000,\"sell_price\":{\"base\":{\"amount\":4000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":294000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39726984\",\"expiration\":\"2022-11-28T17:33:46\",\"seller\":\"1.2.33175\",\"for_sale\":7048821,\"sell_price\":{\"base\":{\"amount\":7048821,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":518299472,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39649090\",\"expiration\":\"2022-11-28T06:31:01\",\"seller\":\"1.2.444127\",\"for_sale\":1176408,\"sell_price\":{\"base\":{\"amount\":1176408,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":86959941,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39732428\",\"expiration\":\"2022-11-28T18:37:52\",\"seller\":\"1.2.384119\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":370000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39728795\",\"expiration\":\"2022-11-28T17:56:51\",\"seller\":\"1.2.430356\",\"for_sale\":10302063,\"sell_price\":{\"base\":{\"amount\":10302063,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":763115777,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1236},{\"id\":\"1.7.39512722\",\"expiration\":\"2022-11-27T13:04:24\",\"seller\":\"1.2.169756\",\"for_sale\":4995000,\"sell_price\":{\"base\":{\"amount\":4995000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":370000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39418900\",\"expiration\":\"2022-11-27T03:18:58\",\"seller\":\"1.2.23586\",\"for_sale\":3270000,\"sell_price\":{\"base\":{\"amount\":3270000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":245250000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39497263\",\"expiration\":\"2022-11-27T11:11:47\",\"seller\":\"1.2.363509\",\"for_sale\":85806,\"sell_price\":{\"base\":{\"amount\":85806,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":6435450,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39732437\",\"expiration\":\"2022-11-28T18:37:58\",\"seller\":\"1.2.384119\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":375000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39509513\",\"expiration\":\"2022-11-27T12:47:47\",\"seller\":\"1.2.152063\",\"for_sale\":1055407,\"sell_price\":{\"base\":{\"amount\":1055407,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":79353909,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39592860\",\"expiration\":\"2022-11-27T22:43:27\",\"seller\":\"1.2.406209\",\"for_sale\":98420,\"sell_price\":{\"base\":{\"amount\":98420,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":7400000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39732443\",\"expiration\":\"2022-11-28T18:38:03\",\"seller\":\"1.2.384119\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":380000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39697357\",\"expiration\":\"2022-11-28T13:01:34\",\"seller\":\"1.2.474330\",\"for_sale\":393000,\"sell_price\":{\"base\":{\"amount\":393000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":30000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39169827\",\"expiration\":\"2022-11-25T21:52:00\",\"seller\":\"1.2.146567\",\"for_sale\":13090,\"sell_price\":{\"base\":{\"amount\":13090,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":1000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39186397\",\"expiration\":\"2022-11-25T23:51:05\",\"seller\":\"1.2.470440\",\"for_sale\":1308010,\"sell_price\":{\"base\":{\"amount\":1308010,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":100000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39237988\",\"expiration\":\"2022-11-26T05:55:59\",\"seller\":\"1.2.394864\",\"for_sale\":956021,\"sell_price\":{\"base\":{\"amount\":956021,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":73298499,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38477978\",\"expiration\":\"2022-11-22T11:09:49\",\"seller\":\"1.2.32432\",\"for_sale\":928572,\"sell_price\":{\"base\":{\"amount\":928572,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":71428571,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38324090\",\"expiration\":\"2022-11-21T21:13:54\",\"seller\":\"1.2.34866\",\"for_sale\":2363637,\"sell_price\":{\"base\":{\"amount\":2363637,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":181818181,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38323860\",\"expiration\":\"2022-11-21T21:11:28\",\"seller\":\"1.2.110360\",\"for_sale\":100000,\"sell_price\":{\"base\":{\"amount\":100000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":7692307,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38582244\",\"expiration\":\"2022-11-22T21:36:15\",\"seller\":\"1.2.307732\",\"for_sale\":975000,\"sell_price\":{\"base\":{\"amount\":975000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":75000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39534038\",\"expiration\":\"2022-11-27T15:32:58\",\"seller\":\"1.2.89816\",\"for_sale\":26000000,\"sell_price\":{\"base\":{\"amount\":26000000,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":2000000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39419038\",\"expiration\":\"2022-11-27T03:19:36\",\"seller\":\"1.2.23586\",\"for_sale\":3624500,\"sell_price\":{\"base\":{\"amount\":3624500,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":279086500,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38309073\",\"expiration\":\"2022-11-21T19:37:30\",\"seller\":\"1.2.165359\",\"for_sale\":518520,\"sell_price\":{\"base\":{\"amount\":518520,\"asset_id\":\"1.3.121\"},\"quote\":{\"amount\":40000000,\"asset_id\":\"1.3.0\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826987\",\"expiration\":\"2022-11-28T04:31:28\",\"seller\":\"1.2.126225\",\"for_sale\":5637462,\"sell_price\":{\"base\":{\"amount\":5837574,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":100000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":0},{\"id\":\"1.7.39826962\",\"expiration\":\"2022-11-28T04:31:25\",\"seller\":\"1.2.116747\",\"for_sale\":29187564,\"sell_price\":{\"base\":{\"amount\":29187564,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":499999,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826504\",\"expiration\":\"2022-11-29T04:29:06\",\"seller\":\"1.2.470016\",\"for_sale\":4423746,\"sell_price\":{\"base\":{\"amount\":4423746,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":75782,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826958\",\"expiration\":\"1963-11-25T23:31:44\",\"seller\":\"1.2.442895\",\"for_sale\":151718210,\"sell_price\":{\"base\":{\"amount\":151718210,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":2600566,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39825989\",\"expiration\":\"1963-11-25T17:31:44\",\"seller\":\"1.2.359372\",\"for_sale\":70741090,\"sell_price\":{\"base\":{\"amount\":70741090,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1214423,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826801\",\"expiration\":\"1963-11-25T14:31:44\",\"seller\":\"1.2.475168\",\"for_sale\":44187474,\"sell_price\":{\"base\":{\"amount\":44187474,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":758636,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39819539\",\"expiration\":\"2022-11-29T03:54:38\",\"seller\":\"1.2.456209\",\"for_sale\":8799002,\"sell_price\":{\"base\":{\"amount\":8799002,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":151078,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39817429\",\"expiration\":\"2022-11-29T03:40:58\",\"seller\":\"1.2.384257\",\"for_sale\":146100000,\"sell_price\":{\"base\":{\"amount\":146100000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":2512890,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39817124\",\"expiration\":\"2022-11-29T03:41:13\",\"seller\":\"1.2.456209\",\"for_sale\":8799002,\"sell_price\":{\"base\":{\"amount\":8799002,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":151342,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39827040\",\"expiration\":\"2017-11-29T05:31:31\",\"seller\":\"1.2.359723\",\"for_sale\":59168823,\"sell_price\":{\"base\":{\"amount\":59168823,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1021695,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826066\",\"expiration\":\"1963-11-25T22:31:44\",\"seller\":\"1.2.475521\",\"for_sale\":262398871,\"sell_price\":{\"base\":{\"amount\":262398871,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":4531618,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39814186\",\"expiration\":\"2022-11-29T03:30:39\",\"seller\":\"1.2.384257\",\"for_sale\":28800000,\"sell_price\":{\"base\":{\"amount\":28800000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":498237,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826021\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.403430\",\"for_sale\":1768527,\"sell_price\":{\"base\":{\"amount\":1768527,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":30602,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39825992\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.395549\",\"for_sale\":884263,\"sell_price\":{\"base\":{\"amount\":884263,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":15301,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826008\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.368699\",\"for_sale\":884263,\"sell_price\":{\"base\":{\"amount\":884263,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":15301,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826013\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.354462\",\"for_sale\":884263,\"sell_price\":{\"base\":{\"amount\":884263,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":15301,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39825997\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.443891\",\"for_sale\":8842636,\"sell_price\":{\"base\":{\"amount\":8842636,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":153014,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826005\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.423992\",\"for_sale\":8842636,\"sell_price\":{\"base\":{\"amount\":8842636,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":153014,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826034\",\"expiration\":\"1963-11-25T22:31:44\",\"seller\":\"1.2.95758\",\"for_sale\":88426363,\"sell_price\":{\"base\":{\"amount\":88426363,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1530149,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826012\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.465862\",\"for_sale\":104343108,\"sell_price\":{\"base\":{\"amount\":104343108,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1805576,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39813053\",\"expiration\":\"2022-11-29T03:26:57\",\"seller\":\"1.2.440027\",\"for_sale\":793249585,\"sell_price\":{\"base\":{\"amount\":793249585,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":13739082,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826041\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.265788\",\"for_sale\":1716847,\"sell_price\":{\"base\":{\"amount\":1716847,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":29855,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39812537\",\"expiration\":\"2022-11-29T03:23:59\",\"seller\":\"1.2.456209\",\"for_sale\":4580116,\"sell_price\":{\"base\":{\"amount\":4580116,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":79694,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39808094\",\"expiration\":\"2022-11-29T02:58:27\",\"seller\":\"1.2.384257\",\"for_sale\":65885582,\"sell_price\":{\"base\":{\"amount\":237000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":4130886,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":0},{\"id\":\"1.7.39825788\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.398049\",\"for_sale\":29415141,\"sell_price\":{\"base\":{\"amount\":29415141,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":512760,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39825974\",\"expiration\":\"1963-11-26T01:31:44\",\"seller\":\"1.2.284457\",\"for_sale\":176852726,\"sell_price\":{\"base\":{\"amount\":176852726,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":3090599,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826017\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.410471\",\"for_sale\":265279089,\"sell_price\":{\"base\":{\"amount\":265279089,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":4635899,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826241\",\"expiration\":\"2017-12-06T04:27:13\",\"seller\":\"1.2.171023\",\"for_sale\":881150,\"sell_price\":{\"base\":{\"amount\":881150,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":15429,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39815120\",\"expiration\":\"2022-11-29T03:34:31\",\"seller\":\"1.2.96660\",\"for_sale\":\"57100000000\",\"sell_price\":{\"base\":{\"amount\":\"57100000000\",\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1000000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39824425\",\"expiration\":\"2017-12-06T04:19:15\",\"seller\":\"1.2.287187\",\"for_sale\":15907571,\"sell_price\":{\"base\":{\"amount\":15907571,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":279521,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826399\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.399496\",\"for_sale\":448610,\"sell_price\":{\"base\":{\"amount\":448610,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":7908,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39825790\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.396680\",\"for_sale\":8833375,\"sell_price\":{\"base\":{\"amount\":8833375,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":156044,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826308\",\"expiration\":\"1963-11-29T12:38:45\",\"seller\":\"1.2.36449\",\"for_sale\":\"4421486581\",\"sell_price\":{\"base\":{\"amount\":\"4421486581\",\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":78781360,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826064\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.399578\",\"for_sale\":2652790,\"sell_price\":{\"base\":{\"amount\":2652790,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":47267,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826003\",\"expiration\":\"1963-11-25T15:31:44\",\"seller\":\"1.2.453726\",\"for_sale\":2521441,\"sell_price\":{\"base\":{\"amount\":2521441,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":44927,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826816\",\"expiration\":\"1963-11-29T12:38:45\",\"seller\":\"1.2.33015\",\"for_sale\":7356955,\"sell_price\":{\"base\":{\"amount\":7356955,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":131374,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38751649\",\"expiration\":\"2022-11-23T17:29:56\",\"seller\":\"1.2.203202\",\"for_sale\":112000000,\"sell_price\":{\"base\":{\"amount\":112000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":2000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39783095\",\"expiration\":\"2022-11-29T00:21:53\",\"seller\":\"1.2.437844\",\"for_sale\":161968793,\"sell_price\":{\"base\":{\"amount\":161968793,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":2899241,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826049\",\"expiration\":\"1963-11-25T14:31:44\",\"seller\":\"1.2.381972\",\"for_sale\":26527908,\"sell_price\":{\"base\":{\"amount\":26527908,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":474952,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39718235\",\"expiration\":\"2022-11-28T16:13:19\",\"seller\":\"1.2.99949\",\"for_sale\":\"6584400000\",\"sell_price\":{\"base\":{\"amount\":\"6584400000\",\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":118024711,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826039\",\"expiration\":\"1963-11-25T14:31:44\",\"seller\":\"1.2.414841\",\"for_sale\":44213181,\"sell_price\":{\"base\":{\"amount\":44213181,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":794617,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39825977\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.4890\",\"for_sale\":858029,\"sell_price\":{\"base\":{\"amount\":858029,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":15435,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.25560191\",\"expiration\":\"2022-09-01T16:47:07\",\"seller\":\"1.2.338201\",\"for_sale\":3494185,\"sell_price\":{\"base\":{\"amount\":3494185,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":62895,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38522042\",\"expiration\":\"2022-11-22T14:49:29\",\"seller\":\"1.2.183905\",\"for_sale\":2222223,\"sell_price\":{\"base\":{\"amount\":2222223,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":40000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.23679244\",\"expiration\":\"2022-08-18T14:23:42\",\"seller\":\"1.2.32432\",\"for_sale\":55555556,\"sell_price\":{\"base\":{\"amount\":55555556,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38835207\",\"expiration\":\"2022-11-24T06:11:33\",\"seller\":\"1.2.26041\",\"for_sale\":555555556,\"sell_price\":{\"base\":{\"amount\":555555556,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":10000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.36775910\",\"expiration\":\"2022-11-14T06:54:06\",\"seller\":\"1.2.461373\",\"for_sale\":14000000,\"sell_price\":{\"base\":{\"amount\":14000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":252000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38343747\",\"expiration\":\"2022-11-21T23:43:04\",\"seller\":\"1.2.114583\",\"for_sale\":500000000,\"sell_price\":{\"base\":{\"amount\":500000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":9000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826000\",\"expiration\":\"1963-11-25T14:31:44\",\"seller\":\"1.2.379967\",\"for_sale\":8381645,\"sell_price\":{\"base\":{\"amount\":8381645,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":151499,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38446613\",\"expiration\":\"2022-11-22T08:19:40\",\"seller\":\"1.2.444127\",\"for_sale\":77580077,\"sell_price\":{\"base\":{\"amount\":77580077,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1406451,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39826878\",\"expiration\":\"1963-11-25T22:31:44\",\"seller\":\"1.2.450176\",\"for_sale\":4013160,\"sell_price\":{\"base\":{\"amount\":4013160,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":72924,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39813365\",\"expiration\":\"2022-11-29T03:28:19\",\"seller\":\"1.2.470558\",\"for_sale\":27500000,\"sell_price\":{\"base\":{\"amount\":27500000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":500000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39822798\",\"expiration\":\"1963-11-25T09:31:44\",\"seller\":\"1.2.165710\",\"for_sale\":4248765,\"sell_price\":{\"base\":{\"amount\":4248765,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":77287,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38303494\",\"expiration\":\"2022-11-21T18:26:05\",\"seller\":\"1.2.457225\",\"for_sale\":64196743,\"sell_price\":{\"base\":{\"amount\":64196743,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1179750,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38242275\",\"expiration\":\"2022-11-21T11:26:50\",\"seller\":\"1.2.430159\",\"for_sale\":4000000,\"sell_price\":{\"base\":{\"amount\":4000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":73600,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38550329\",\"expiration\":\"2022-11-22T17:20:51\",\"seller\":\"1.2.422975\",\"for_sale\":51173959,\"sell_price\":{\"base\":{\"amount\":51173959,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":946718,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.25546186\",\"expiration\":\"2022-09-01T14:53:32\",\"seller\":\"1.2.158537\",\"for_sale\":212001462,\"sell_price\":{\"base\":{\"amount\":212001462,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":3962986,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39617047\",\"expiration\":\"2022-11-28T01:53:19\",\"seller\":\"1.2.159614\",\"for_sale\":159489634,\"sell_price\":{\"base\":{\"amount\":159489634,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":3000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.15353005\",\"expiration\":\"2022-07-09T12:07:25\",\"seller\":\"1.2.267\",\"for_sale\":265789474,\"sell_price\":{\"base\":{\"amount\":265789474,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":5050000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.21991367\",\"expiration\":\"2022-08-07T07:17:36\",\"seller\":\"1.2.32432\",\"for_sale\":52631579,\"sell_price\":{\"base\":{\"amount\":52631579,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38839709\",\"expiration\":\"2022-11-24T06:37:46\",\"seller\":\"1.2.26041\",\"for_sale\":526315790,\"sell_price\":{\"base\":{\"amount\":526315790,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":10000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39771147\",\"expiration\":\"2022-11-28T23:28:53\",\"seller\":\"1.2.375610\",\"for_sale\":100000000,\"sell_price\":{\"base\":{\"amount\":100000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1900000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38446699\",\"expiration\":\"2022-11-22T08:19:48\",\"seller\":\"1.2.444127\",\"for_sale\":76266740,\"sell_price\":{\"base\":{\"amount\":76266740,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1451774,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.18636813\",\"expiration\":\"2022-07-21T04:14:18\",\"seller\":\"1.2.116476\",\"for_sale\":525000000,\"sell_price\":{\"base\":{\"amount\":525000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":10000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.37077687\",\"expiration\":\"2022-11-16T01:37:47\",\"seller\":\"1.2.203594\",\"for_sale\":300000000,\"sell_price\":{\"base\":{\"amount\":300000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":5752293,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38303501\",\"expiration\":\"2022-11-21T18:26:13\",\"seller\":\"1.2.457225\",\"for_sale\":64196743,\"sell_price\":{\"base\":{\"amount\":64196743,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1243947,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.14883703\",\"expiration\":\"2022-07-07T22:48:58\",\"seller\":\"1.2.267\",\"for_sale\":258974359,\"sell_price\":{\"base\":{\"amount\":258974359,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":5050000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38333659\",\"expiration\":\"2022-11-21T22:24:06\",\"seller\":\"1.2.443514\",\"for_sale\":500000000,\"sell_price\":{\"base\":{\"amount\":500000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":9750000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.23484383\",\"expiration\":\"2022-08-17T06:57:34\",\"seller\":\"1.2.266278\",\"for_sale\":51000000,\"sell_price\":{\"base\":{\"amount\":51000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38258389\",\"expiration\":\"2022-11-21T12:48:52\",\"seller\":\"1.2.388463\",\"for_sale\":199000000,\"sell_price\":{\"base\":{\"amount\":199000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":3940200,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39534012\",\"expiration\":\"2022-11-27T15:32:14\",\"seller\":\"1.2.203202\",\"for_sale\":199900000,\"sell_price\":{\"base\":{\"amount\":199900000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":3958020,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39535581\",\"expiration\":\"2022-11-27T15:44:53\",\"seller\":\"1.2.203202\",\"for_sale\":199900000,\"sell_price\":{\"base\":{\"amount\":199900000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":3958020,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39617049\",\"expiration\":\"2022-11-28T01:53:26\",\"seller\":\"1.2.159614\",\"for_sale\":151438668,\"sell_price\":{\"base\":{\"amount\":151438668,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":3000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38333697\",\"expiration\":\"2022-11-21T22:24:19\",\"seller\":\"1.2.443514\",\"for_sale\":500000000,\"sell_price\":{\"base\":{\"amount\":500000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":9950000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39516285\",\"expiration\":\"2022-11-27T13:27:48\",\"seller\":\"1.2.36352\",\"for_sale\":753012049,\"sell_price\":{\"base\":{\"amount\":753012049,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":15000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39799318\",\"expiration\":\"2022-11-29T01:58:14\",\"seller\":\"1.2.398578\",\"for_sale\":44016437,\"sell_price\":{\"base\":{\"amount\":44016437,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":879448,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38446740\",\"expiration\":\"2022-11-22T08:19:58\",\"seller\":\"1.2.444127\",\"for_sale\":75015943,\"sell_price\":{\"base\":{\"amount\":75015943,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1499362,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39563988\",\"expiration\":\"2022-11-27T19:11:12\",\"seller\":\"1.2.155012\",\"for_sale\":\"10000000000\",\"sell_price\":{\"base\":{\"amount\":\"10000000000\",\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":199990000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38502824\",\"expiration\":\"2022-11-22T13:39:08\",\"seller\":\"1.2.422975\",\"for_sale\":33949422,\"sell_price\":{\"base\":{\"amount\":33949422,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":678988,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.26162941\",\"expiration\":\"2022-09-05T04:26:53\",\"seller\":\"1.2.114303\",\"for_sale\":87304970,\"sell_price\":{\"base\":{\"amount\":87304970,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1746099,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.30738611\",\"expiration\":\"2022-10-04T20:20:55\",\"seller\":\"1.2.394462\",\"for_sale\":648063095,\"sell_price\":{\"base\":{\"amount\":648063095,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":12961261,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39489300\",\"expiration\":\"2022-11-27T10:12:44\",\"seller\":\"1.2.437837\",\"for_sale\":548553862,\"sell_price\":{\"base\":{\"amount\":548553862,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":10971077,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.14756774\",\"expiration\":\"2022-07-07T12:10:46\",\"seller\":\"1.2.267\",\"for_sale\":252500000,\"sell_price\":{\"base\":{\"amount\":252500000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":5050000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.18636812\",\"expiration\":\"2022-07-21T04:14:07\",\"seller\":\"1.2.116476\",\"for_sale\":500000000,\"sell_price\":{\"base\":{\"amount\":500000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":10000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.21991369\",\"expiration\":\"2022-08-07T07:17:44\",\"seller\":\"1.2.32432\",\"for_sale\":50000000,\"sell_price\":{\"base\":{\"amount\":50000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.23216503\",\"expiration\":\"2022-08-15T08:57:18\",\"seller\":\"1.2.266278\",\"for_sale\":50000000,\"sell_price\":{\"base\":{\"amount\":50000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":1000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.23818382\",\"expiration\":\"2022-08-19T14:09:22\",\"seller\":\"1.2.266278\",\"for_sale\":25000000,\"sell_price\":{\"base\":{\"amount\":25000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":500000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.33199477\",\"expiration\":\"2022-10-23T08:11:42\",\"seller\":\"1.2.367064\",\"for_sale\":5000000,\"sell_price\":{\"base\":{\"amount\":5000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":100000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.37868756\",\"expiration\":\"2022-11-19T23:13:33\",\"seller\":\"1.2.104650\",\"for_sale\":\"4500000000\",\"sell_price\":{\"base\":{\"amount\":\"4500000000\",\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":90000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38050853\",\"expiration\":\"2022-11-20T17:59:01\",\"seller\":\"1.2.32653\",\"for_sale\":185000000,\"sell_price\":{\"base\":{\"amount\":185000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":3700000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38270285\",\"expiration\":\"2022-11-21T14:08:27\",\"seller\":\"1.2.404345\",\"for_sale\":2500000,\"sell_price\":{\"base\":{\"amount\":2500000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":50000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.39051789\",\"expiration\":\"2022-11-25T05:52:17\",\"seller\":\"1.2.165313\",\"for_sale\":250000000,\"sell_price\":{\"base\":{\"amount\":250000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":5000000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38038751\",\"expiration\":\"2022-11-20T17:09:43\",\"seller\":\"1.2.99949\",\"for_sale\":\"10628496871\",\"sell_price\":{\"base\":{\"amount\":\"10628496871\",\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":214729924,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38333708\",\"expiration\":\"2022-11-21T22:24:36\",\"seller\":\"1.2.443514\",\"for_sale\":500000000,\"sell_price\":{\"base\":{\"amount\":500000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":10150000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.37016152\",\"expiration\":\"2022-11-15T17:10:45\",\"seller\":\"1.2.99896\",\"for_sale\":1000000000,\"sell_price\":{\"base\":{\"amount\":1000000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":20300010,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38294306\",\"expiration\":\"2022-11-21T17:09:33\",\"seller\":\"1.2.99949\",\"for_sale\":\"9593198903\",\"sell_price\":{\"base\":{\"amount\":\"9593198903\",\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":195599090,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38038797\",\"expiration\":\"2022-11-20T17:09:56\",\"seller\":\"1.2.99949\",\"for_sale\":\"10628496871\",\"sell_price\":{\"base\":{\"amount\":\"10628496871\",\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":216855623,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.14673195\",\"expiration\":\"2022-07-07T03:21:11\",\"seller\":\"1.2.267\",\"for_sale\":183076053,\"sell_price\":{\"base\":{\"amount\":246341464,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":5050000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":0},{\"id\":\"1.7.39707664\",\"expiration\":\"2022-11-28T14:20:03\",\"seller\":\"1.2.443284\",\"for_sale\":3096209579,\"sell_price\":{\"base\":{\"amount\":3096209579,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":63695223,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213},{\"id\":\"1.7.38333740\",\"expiration\":\"2022-11-21T22:24:48\",\"seller\":\"1.2.443514\",\"for_sale\":500000000,\"sell_price\":{\"base\":{\"amount\":500000000,\"asset_id\":\"1.3.0\"},\"quote\":{\"amount\":10300000,\"asset_id\":\"1.3.121\"}},\"deferred_fee\":1213}]}"; + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer()); + builder.registerTypeAdapter(UserAccount.class, new UserAccount.UserAccountSimpleDeserializer()); + builder.registerTypeAdapter(LimitOrder.class, new LimitOrder.LimitOrderDeserializer()); + Type GetLimitOrdersResponse = new TypeToken>>() {}.getType(); + WitnessResponse> witnessResponse = builder.create().fromJson(serializedOrderBook, GetLimitOrdersResponse); + List orders = witnessResponse.result; + OrderBook orderBook = new OrderBook(orders); + + // Testing obtained quote calculation + long receivedValue = 56111; + long agoriseCut = 280; + UnsignedLong merchantsQuote = orderBook.calculateObtainedQuote(new AssetAmount(UnsignedLong.valueOf(receivedValue - agoriseCut), new Asset("1.3.0"))); + Assert.assertEquals(941, merchantsQuote.longValue()); + + // Testing required base calculation + UnsignedLong baseAmount = orderBook.calculateRequiredBase(new AssetAmount(UnsignedLong.valueOf(10000), new Asset("1.3.121"))); + Assert.assertEquals(593000, baseAmount.longValue()); + } +} diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/PublicKeyTest.java b/graphenej/src/test/java/cy/agorise/graphenej/PublicKeyTest.java similarity index 93% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/PublicKeyTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/PublicKeyTest.java index fe6307a..756b776 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/PublicKeyTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/PublicKeyTest.java @@ -1,6 +1,5 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; -import org.bitcoinj.core.*; import org.junit.*; import static org.junit.Assert.*; diff --git a/graphenej/src/test/java/cy/agorise/graphenej/TestAccounts.java b/graphenej/src/test/java/cy/agorise/graphenej/TestAccounts.java new file mode 100644 index 0000000..5eebf78 --- /dev/null +++ b/graphenej/src/test/java/cy/agorise/graphenej/TestAccounts.java @@ -0,0 +1,23 @@ +package cy.agorise.graphenej; + +/** + * Created by nelson on 11/2/17. + */ + +public class TestAccounts { + + public class Bilthon5 { + public static final String BRAINKEY = "TIGROID BUTLER GALLOWS PAKEHA MOONJAH ACARI LUPUS BAE ACRISIA ABBACY BASSOON AKUND"; + public static final String WIF = "5Jr84yteNbomGgLq5nvH2Y6WYJCBTsjugPouCtggfS3RguqxDo8"; + } + + public class Bilthon7 { + public static final String BRAINKEY = "PUMPER ISOTOME SERE STAINER CLINGER MOONLIT CHAETA UPBRIM AEDILIC BERTHER NIT SHAP SAID SHADING JUNCOUS CHOUGH"; + public static final String WIF = "5J96pne45qWM1WpektoeazN6k9Mt93jQ7LyueRxFfEMTiy6yxjM"; + } + + public class Bilthon16 { + public static final String BRAINKEY = "BARIC BICKERN LITZ TIPFUL JINGLED POOL TUMBAK PURIST APOPYLE DURAIN SATLIJK FAUCAL"; + public static final String WIF = "5JNxigtdkjkjM1dVGBBLk2axnUZmHrNLK4CqnUjWDzeX18HnyoD"; + } +} diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/TransactionTest.java b/graphenej/src/test/java/cy/agorise/graphenej/TransactionTest.java similarity index 80% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/TransactionTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/TransactionTest.java index f82cd2b..d4dd064 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/TransactionTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/TransactionTest.java @@ -1,53 +1,69 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.google.common.primitives.UnsignedLong; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketException; import com.neovisionaries.ws.client.WebSocketFactory; -import de.bitsharesmunich.graphenej.api.GetLimitOrders; -import de.bitsharesmunich.graphenej.api.TransactionBroadcastSequence; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; -import de.bitsharesmunich.graphenej.objects.Memo; -import de.bitsharesmunich.graphenej.operations.*; -import de.bitsharesmunich.graphenej.test.NaiveSSLContext; + import org.bitcoinj.core.ECKey; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import javax.net.ssl.SSLContext; import java.io.IOException; +import java.math.BigInteger; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; -import java.util.Date; +import java.util.Collections; import java.util.List; +import javax.net.ssl.SSLContext; + +import cy.agorise.graphenej.api.GetLimitOrders; +import cy.agorise.graphenej.api.TransactionBroadcastSequence; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.objects.Memo; +import cy.agorise.graphenej.operations.CustomOperation; +import cy.agorise.graphenej.operations.LimitOrderCancelOperation; +import cy.agorise.graphenej.operations.LimitOrderCreateOperation; +import cy.agorise.graphenej.operations.TransferOperation; +import cy.agorise.graphenej.operations.TransferOperationBuilder; +import cy.agorise.graphenej.test.NaiveSSLContext; + /** * Created by nelson on 3/6/17. */ public class TransactionTest { - private final String BILTHON_15_BRAIN_KEY = System.getenv("BILTHON_15_BRAINKEY"); - private final String BILTHON_5_BRAIN_KEY = System.getenv("BILTHON_5_BRAINKEY"); - private final String BILTHON_16_BRAIN_KEY = System.getenv("BILTHON_16_BRAINKEY"); + private final String BILTHON_7_BRAIN_KEY = TestAccounts.Bilthon7.BRAINKEY; + private final String BILTHON_5_BRAIN_KEY = TestAccounts.Bilthon5.BRAINKEY; + private final String BILTHON_16_BRAIN_KEY = TestAccounts.Bilthon16.BRAINKEY; - private final String BLOCK_PAY_DE = System.getenv("BLOCKPAY_DE"); - private final String BLOCK_PAY_FR = System.getenv("BLOCKPAY_FR"); + private final String NODE_URL = "wss://eu.openledger.info/ws"; // Transfer operation transaction private final Asset CORE_ASSET = new Asset("1.3.0"); - private final UserAccount bilthon_15 = new UserAccount("1.2.143563"); + private final UserAccount bilthon_7 = new UserAccount("1.2.140994"); private final UserAccount bilthon_5 = new UserAccount("1.2.139313"); private final UserAccount bilthon_16 = new UserAccount("1.2.143569"); // Limit order create transaction private final Asset BIT_USD = new Asset("1.3.121"); - private UserAccount seller = bilthon_15; + private UserAccount seller = bilthon_7; private AssetAmount amountToSell = new AssetAmount(UnsignedLong.valueOf(100000), CORE_ASSET); private AssetAmount minToReceive = new AssetAmount(UnsignedLong.valueOf(520), BIT_USD); private long expiration; + // Custom operation transaction + private final AssetAmount fee = new AssetAmount(UnsignedLong.valueOf(100000), CORE_ASSET); + private final UserAccount payer = bilthon_7; + private final Integer operationId = 61166; + private final List requiredAuths = Collections.singletonList(payer); + private final String data = "some data"; + + private final long FEE_AMOUNT = 21851; + // Lock object private static final class Lock { } private final Object lockObject = new Lock(); @@ -101,7 +117,7 @@ public class TransactionTest { // Set the custom SSL context. factory.setSSLContext(context); - WebSocket mWebSocket = factory.createSocket(BLOCK_PAY_DE); + WebSocket mWebSocket = factory.createSocket(NODE_URL); mWebSocket.addListener(new TransactionBroadcastSequence(transaction, CORE_ASSET, responseListener)); mWebSocket.connect(); @@ -132,29 +148,31 @@ public class TransactionTest { @Test public void testTransferTransaction(){ - ECKey sourcePrivateKey = new BrainKey(BILTHON_15_BRAIN_KEY, 0).getPrivateKey(); + ECKey sourcePrivateKey = new BrainKey(BILTHON_7_BRAIN_KEY, 0).getPrivateKey(); PublicKey to1 = new PublicKey(ECKey.fromPublicOnly(new BrainKey(BILTHON_5_BRAIN_KEY, 0).getPublicKey())); PublicKey to2 = new PublicKey(ECKey.fromPublicOnly(new BrainKey(BILTHON_16_BRAIN_KEY, 0).getPublicKey())); // Creating memo - long nonce = 1; + BigInteger nonce = BigInteger.ONE; byte[] encryptedMessage = Memo.encryptMessage(sourcePrivateKey, to1, nonce, "another message"); Memo memo = new Memo(new Address(ECKey.fromPublicOnly(sourcePrivateKey.getPubKey())), new Address(to1.getKey()), nonce, encryptedMessage); // Creating operation 1 TransferOperation transferOperation1 = new TransferOperationBuilder() .setTransferAmount(new AssetAmount(UnsignedLong.valueOf(1), CORE_ASSET)) - .setSource(bilthon_15) + .setSource(bilthon_7) .setDestination(bilthon_5) // bilthon-5 - .setFee(new AssetAmount(UnsignedLong.valueOf(264174), CORE_ASSET)) + .setFee(new AssetAmount(UnsignedLong.valueOf(FEE_AMOUNT), CORE_ASSET)) + .setMemo(memo) .build(); // Creating operation 2 TransferOperation transferOperation2 = new TransferOperationBuilder() .setTransferAmount(new AssetAmount(UnsignedLong.valueOf(1), CORE_ASSET)) - .setSource(bilthon_15) // bilthon-15 + .setSource(bilthon_7) // bilthon-15 .setDestination(bilthon_16) // bilthon-16 - .setFee(new AssetAmount(UnsignedLong.valueOf(264174), CORE_ASSET)) + .setFee(new AssetAmount(UnsignedLong.valueOf(FEE_AMOUNT), CORE_ASSET)) + .setMemo(memo) .build(); @@ -169,7 +187,7 @@ public class TransactionTest { @Test public void testLimitOrderCreateTransaction(){ - ECKey privateKey = new BrainKey(BILTHON_15_BRAIN_KEY, 0).getPrivateKey(); + ECKey privateKey = new BrainKey(BILTHON_7_BRAIN_KEY, 0).getPrivateKey(); expiration = (System.currentTimeMillis() / 1000) + 60 * 60; // Creating limit order creation operation @@ -205,7 +223,7 @@ public class TransactionTest { public void testLimitOrderCancelTransaction() throws NoSuchAlgorithmException, IOException, WebSocketException { // We first must create a limit order for this test - ECKey privateKey = new BrainKey(BILTHON_15_BRAIN_KEY, 0).getPrivateKey(); + ECKey privateKey = new BrainKey(BILTHON_7_BRAIN_KEY, 0).getPrivateKey(); expiration = (System.currentTimeMillis() / 1000) + 60 * 5; // Creating limit order creation operation @@ -232,7 +250,7 @@ public class TransactionTest { // Set the custom SSL context. factory.setSSLContext(context); - WebSocket mWebSocket = factory.createSocket(BLOCK_PAY_DE); + WebSocket mWebSocket = factory.createSocket(NODE_URL); // Requesting limit order to cancel (Task 2) mWebSocket.addListener(new GetLimitOrders(base.getObjectId(), quote.getObjectId(), 100, new WitnessResponseListener() { @@ -242,13 +260,13 @@ public class TransactionTest { System.out.println("onSuccess.1"); List orders = (List) response.result; for(LimitOrder order : orders){ - if(order.getSeller().getObjectId().equals(bilthon_15.getObjectId())){ + if(order.getSeller().getObjectId().equals(bilthon_7.getObjectId())){ // Instantiating a private key for bilthon-15 - ECKey privateKey = new BrainKey(BILTHON_15_BRAIN_KEY, 0).getPrivateKey(); + ECKey privateKey = new BrainKey(BILTHON_7_BRAIN_KEY, 0).getPrivateKey(); // Creating limit order cancellation operation - LimitOrderCancelOperation operation = new LimitOrderCancelOperation(order, bilthon_15); + LimitOrderCancelOperation operation = new LimitOrderCancelOperation(order, bilthon_7); ArrayList operationList = new ArrayList<>(); operationList.add(operation); @@ -313,4 +331,19 @@ public class TransactionTest { } }, lockObject); } + + @Test + public void testCustomOperationTransaction(){ + ECKey sourcePrivateKey = new BrainKey(BILTHON_7_BRAIN_KEY, 0).getPrivateKey(); + + // Creating custom operation + CustomOperation customOperation = new CustomOperation(fee, payer, operationId, requiredAuths, data); + + // Adding operation to the operation list + ArrayList operationList = new ArrayList<>(); + operationList.add(customOperation); + + // Broadcasting transaction + broadcastTransaction(sourcePrivateKey, operationList, listener, null); + } } \ No newline at end of file diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/UserAccountTest.java b/graphenej/src/test/java/cy/agorise/graphenej/UserAccountTest.java similarity index 84% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/UserAccountTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/UserAccountTest.java index 644c6f6..69e15c0 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/UserAccountTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/UserAccountTest.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej; +package cy.agorise.graphenej; import com.neovisionaries.ws.client.WebSocketException; @@ -7,11 +7,11 @@ import org.junit.Test; import java.util.ArrayList; import java.util.List; -import de.bitsharesmunich.graphenej.api.BaseApiTest; -import de.bitsharesmunich.graphenej.api.GetObjects; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.api.BaseApiTest; +import cy.agorise.graphenej.api.GetObjects; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.WitnessResponse; /** * Created by nelson on 5/20/17. diff --git a/graphenej/src/test/java/cy/agorise/graphenej/UtilTest.java b/graphenej/src/test/java/cy/agorise/graphenej/UtilTest.java new file mode 100644 index 0000000..9ba1d90 --- /dev/null +++ b/graphenej/src/test/java/cy/agorise/graphenej/UtilTest.java @@ -0,0 +1,21 @@ +package cy.agorise.graphenej; + +import com.google.common.primitives.UnsignedLong; + +import junit.framework.Assert; + +import org.junit.Test; + +/** + * Class used to test Util methods + */ + +public class UtilTest { + + @Test + public void testRevertUnsignedLong(){ + UnsignedLong unsignedLong = UnsignedLong.valueOf("12179241258665439971"); + byte[] reversed = Util.revertUnsignedLong(unsignedLong); + Assert.assertEquals("e3f28878655b05a9", Util.bytesToHex(reversed)); + } +} diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/BaseApiTest.java b/graphenej/src/test/java/cy/agorise/graphenej/api/BaseApiTest.java similarity index 65% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/api/BaseApiTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/api/BaseApiTest.java index 0a2f24f..7a3e76a 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/BaseApiTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/api/BaseApiTest.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketFactory; @@ -7,14 +7,14 @@ import org.junit.Before; import javax.net.ssl.SSLContext; -import de.bitsharesmunich.graphenej.test.NaiveSSLContext; +import cy.agorise.graphenej.test.NaiveSSLContext; /** - * Created by nelson on 4/14/17. + * Base class that every test that involves any communication with the API must extend */ public class BaseApiTest { - protected String BLOCK_PAY_DE = System.getenv("OPENLEDGER_EU"); + protected String NODE_URL = System.getenv("NODE_URL"); protected SSLContext context; protected WebSocket mWebSocket; @@ -27,7 +27,7 @@ public class BaseApiTest { // Set the custom SSL context. factory.setSSLContext(context); - mWebSocket = factory.createSocket(BLOCK_PAY_DE); + mWebSocket = factory.createSocket(NODE_URL); } } diff --git a/graphenej/src/test/java/cy/agorise/graphenej/api/GetBlockTest.java b/graphenej/src/test/java/cy/agorise/graphenej/api/GetBlockTest.java new file mode 100644 index 0000000..f6637a5 --- /dev/null +++ b/graphenej/src/test/java/cy/agorise/graphenej/api/GetBlockTest.java @@ -0,0 +1,181 @@ +package cy.agorise.graphenej.api; + +import com.google.common.primitives.UnsignedLong; +import com.neovisionaries.ws.client.WebSocketException; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.BaseOperation; +import cy.agorise.graphenej.Transaction; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.Block; +import cy.agorise.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.operations.CustomOperation; +import cy.agorise.graphenej.operations.TransferOperation; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; +import java.util.concurrent.Exchanger; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static org.hamcrest.CoreMatchers.instanceOf; + +public class GetBlockTest extends BaseApiTest { + // data for the test with transfer operation + private final static long TRANSFER_BLOCK_NUMBER = 15776988L; + + private final static String TRANSFER_EXPECTED_PREVIOUS = "00f0bcdbe3d9dc66d8597e7b013a16d8dea5f778"; + private final static String TRANSFER_EXPECTED_TIMESTAMP = "2017-04-18T04:14:51"; + private final static String TRANSFER_EXPECTED_WITNESS = "1.6.17"; + private final static String TRANSFER_EXPECTED_TRANSACTION_MERKLE_ROOT = "fb87a3f8af907a2450c327d181b2833b8270a504"; + private final static int TRANSFER_EXPECTED_EXTENSIONS_SIZE = 0; + private final static String TRANSFER_EXPECTED_WITNESS_SIGNATURE = "20160921c8ba0d312dee14bdc780c3d05b27e406e2d014b8a2415e9843bf7075cb7abbc45f5173ffefac69cecf4dd2afa5dce6076bdf24cc577ff49427babe75e1"; + private final static int TRANSFER_EXPECTED_TRANSACTIONS_SIZE = 1; + private final static int TRANSFER_EXPECTED_OPERATIONS_SIZE = 1; + + private final static UnsignedLong TRANSFER_EXPECTED_FEE_AMOUNT = UnsignedLong.valueOf(2048); + private final static String TRANSFER_EXPECTED_FEE_ASSET_ID = "1.3.113"; + private final static String TRANSFER_EXPECTED_FROM = "1.2.151069"; + private final static String TRANSFER_EXPECTED_TO = "1.2.116354"; + private final static UnsignedLong TRANSFER_EXPECTED_AMOUNT = UnsignedLong.valueOf(13700); + private final static String TRANSFER_EXPECTED_ASSET_ID = "1.3.113"; + + // data for the test with custom operation + private final static long CUSTOM_BLOCK_NUMBER = 22754473L; + private final static int CUSTOM_TRANSACTION_INDEX = 8; + + private final static UnsignedLong CUSTOM_EXPECTED_FEE_AMOUNT = UnsignedLong.valueOf(13798); + private final static String CUSTOM_EXPECTED_FEE_ASSET_ID = "1.3.0"; + private final static String CUSTOM_EXPECTED_PAYER = "1.2.140994"; + private final static int CUSTOM_EXPECTED_REQUIRED_AUTHS_SIZE = 1; + private final static String CUSTOM_EXPECTED_REQUIRED_AUTH = "1.2.140994"; + private final static int CUSTOM_EXPECTED_ID = 61166; + private final static String CUSTOM_EXPECTED_DATA = "some data"; + + @Test + public void testGetBlockWithTransferOperation() { + try { + final Exchanger responseExchanger = new Exchanger<>(); + mWebSocket.addListener(new GetBlock(TRANSFER_BLOCK_NUMBER, new WitnessResponseListener() { + @Override + public void onSuccess(WitnessResponse response) { + System.out.println("onSuccess"); + try { + responseExchanger.exchange(response.result); + } catch (InterruptedException e) { + System.out.println("InterruptedException in success handler. Msg: " + e.getMessage()); + } + } + + @Override + public void onError(BaseResponse.Error error) { + System.out.println("onError"); + try { + responseExchanger.exchange(null); + } catch (InterruptedException e) { + System.out.println("InterruptedException in error handler. Msg: " + e.getMessage()); + } + } + })); + + mWebSocket.connect(); + + Object responseResult = responseExchanger.exchange(null, 5, TimeUnit.SECONDS); + + Block block = (Block) responseResult; + Assert.assertNotNull(block); + Assert.assertEquals(TRANSFER_EXPECTED_PREVIOUS, block.getPrevious()); + Assert.assertEquals(TRANSFER_EXPECTED_TIMESTAMP, block.getTimestamp()); + Assert.assertEquals(TRANSFER_EXPECTED_WITNESS, block.getWitness()); + Assert.assertEquals(TRANSFER_EXPECTED_TRANSACTION_MERKLE_ROOT, block.getTransaction_merkle_root()); + Assert.assertEquals(TRANSFER_EXPECTED_EXTENSIONS_SIZE, block.getExtensions().length); + Assert.assertEquals(TRANSFER_EXPECTED_WITNESS_SIGNATURE, block.getWitness_signature()); + + List transactions = block.getTransactions(); + Assert.assertEquals(TRANSFER_EXPECTED_TRANSACTIONS_SIZE, transactions.size()); + + List operations = transactions.get(0).getOperations(); + Assert.assertEquals(TRANSFER_EXPECTED_OPERATIONS_SIZE, operations.size()); + + BaseOperation operation = operations.get(0); + Assert.assertThat(operation, instanceOf(TransferOperation.class)); + + TransferOperation transferOperation = (TransferOperation) operation; + AssetAmount fee = transferOperation.getFee(); + Assert.assertEquals(TRANSFER_EXPECTED_FEE_AMOUNT, fee.getAmount()); + Assert.assertEquals(TRANSFER_EXPECTED_FEE_ASSET_ID, fee.getAsset().getObjectId()); + Assert.assertEquals(TRANSFER_EXPECTED_FROM, transferOperation.getFrom().getObjectId()); + Assert.assertEquals(TRANSFER_EXPECTED_TO, transferOperation.getTo().getObjectId()); + AssetAmount assetAmount = transferOperation.getAssetAmount(); + Assert.assertEquals(TRANSFER_EXPECTED_AMOUNT, assetAmount.getAmount()); + Assert.assertEquals(TRANSFER_EXPECTED_ASSET_ID, assetAmount.getAsset().getObjectId()); + } catch (WebSocketException e) { + System.out.println("WebSocketException. Msg: " + e.getMessage()); + Assert.fail("Fail because of WebSocketException"); + } catch (InterruptedException e) { + System.out.println("InterruptedException. Msg: " + e.getMessage()); + Assert.fail("Fail because of InterruptedException"); + } catch (TimeoutException e) { + System.out.println("TimeoutException. Msg: " + e.getMessage()); + Assert.fail("Fail because of TimeoutException"); + } + } + + @Test + public void testGetBlockWithCustomOperation() { + try { + final Exchanger responseExchanger = new Exchanger<>(); + mWebSocket.addListener(new GetBlock(CUSTOM_BLOCK_NUMBER, new WitnessResponseListener() { + @Override + public void onSuccess(WitnessResponse response) { + System.out.println("onSuccess"); + try { + responseExchanger.exchange(response.result); + } catch (InterruptedException e) { + System.out.println("InterruptedException in success handler. Msg: " + e.getMessage()); + } + } + + @Override + public void onError(BaseResponse.Error error) { + System.out.println("onError"); + try { + responseExchanger.exchange(null); + } catch (InterruptedException e) { + System.out.println("InterruptedException in error handler. Msg: " + e.getMessage()); + } + } + })); + + mWebSocket.connect(); + + Object responseResult = responseExchanger.exchange(null, 5, TimeUnit.SECONDS); + + Block block = (Block) responseResult; + List transactions = block.getTransactions(); + List operations = transactions.get(CUSTOM_TRANSACTION_INDEX).getOperations(); + BaseOperation operation = operations.get(0); + Assert.assertThat(operation, instanceOf(CustomOperation.class)); + + CustomOperation customOperation = (CustomOperation) operation; + AssetAmount fee = customOperation.getFee(); + Assert.assertEquals(CUSTOM_EXPECTED_FEE_AMOUNT, fee.getAmount()); + Assert.assertEquals(CUSTOM_EXPECTED_FEE_ASSET_ID, fee.getAsset().getObjectId()); + Assert.assertEquals(CUSTOM_EXPECTED_PAYER, customOperation.getPayer().getObjectId()); + Assert.assertEquals(CUSTOM_EXPECTED_REQUIRED_AUTHS_SIZE, customOperation.getRequiredAuths().size()); + Assert.assertEquals(CUSTOM_EXPECTED_REQUIRED_AUTH, customOperation.getRequiredAuths().get(0).getObjectId()); + Assert.assertEquals(CUSTOM_EXPECTED_ID, customOperation.getOperationId()); + Assert.assertEquals(CUSTOM_EXPECTED_DATA, customOperation.getData()); + } catch (WebSocketException e) { + System.out.println("WebSocketException. Msg: " + e.getMessage()); + Assert.fail("Fail because of WebSocketException"); + } catch (InterruptedException e) { + System.out.println("InterruptedException. Msg: " + e.getMessage()); + Assert.fail("Fail because of InterruptedException"); + } catch (TimeoutException e) { + System.out.println("TimeoutException. Msg: " + e.getMessage()); + Assert.fail("Fail because of TimeoutException"); + } + } +} diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetKeyReferencesTest.java b/graphenej/src/test/java/cy/agorise/graphenej/api/GetKeyReferencesTest.java similarity index 87% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetKeyReferencesTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/api/GetKeyReferencesTest.java index c774973..5be267d 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetKeyReferencesTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/api/GetKeyReferencesTest.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.neovisionaries.ws.client.WebSocketException; @@ -7,12 +7,12 @@ import org.junit.Test; import java.util.ArrayList; import java.util.List; -import de.bitsharesmunich.graphenej.Address; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.errors.MalformedAddressException; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.Address; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.errors.MalformedAddressException; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.WitnessResponse; /** * Created by nelson on 4/14/17. diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetLimitOrdersTest.java b/graphenej/src/test/java/cy/agorise/graphenej/api/GetLimitOrdersTest.java similarity index 87% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetLimitOrdersTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/api/GetLimitOrdersTest.java index 74b9764..fecbeb0 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetLimitOrdersTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/api/GetLimitOrdersTest.java @@ -1,35 +1,43 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.google.common.primitives.UnsignedLong; import com.neovisionaries.ws.client.WebSocketException; import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import java.util.List; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.Converter; -import de.bitsharesmunich.graphenej.LimitOrder; -import de.bitsharesmunich.graphenej.OrderBook; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; -import de.bitsharesmunich.graphenej.operations.LimitOrderCreateOperation; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.Converter; +import cy.agorise.graphenej.LimitOrder; +import cy.agorise.graphenej.OrderBook; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.operations.LimitOrderCreateOperation; import static org.hamcrest.CoreMatchers.is; /** - * Created by nelson on 3/24/17. + * Class used to test the 'get_limit_order' API wrapper */ public class GetLimitOrdersTest extends BaseApiTest { private UserAccount seller = new UserAccount("1.2.143563"); private final Asset base = new Asset("1.3.121", "USD", 4); private final Asset quote = new Asset("1.3.0", "BTS", 5); + @Before + public void setup(){ + if(NODE_URL != null){ + System.out.println("Connecting to node: "+NODE_URL); + } + } + @Test public void testGetLimitOrders(){ try { @@ -104,7 +112,7 @@ public class GetLimitOrdersTest extends BaseApiTest { int expiration = (int) ((System.currentTimeMillis() + 60000) / 1000); LimitOrderCreateOperation operation = orderBook.exchange(seller, base, toBuy, expiration); - // Testing the successfull creation of a limit order create operation + // Testing the successful creation of a limit order create operation Assert.assertTrue(operation != null); double price = (double) Math.pow(10, base.getPrecision() - quote.getPrecision()) * operation.getMinToReceive().getAmount().longValue() / operation.getAmountToSell().getAmount().longValue(); System.out.println("price: "+price); diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetObjectsTest.java b/graphenej/src/test/java/cy/agorise/graphenej/api/GetObjectsTest.java similarity index 92% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetObjectsTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/api/GetObjectsTest.java index 2e36a17..5b76e68 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetObjectsTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/api/GetObjectsTest.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.neovisionaries.ws.client.WebSocketException; @@ -9,13 +9,13 @@ import org.junit.Test; import java.util.ArrayList; import java.util.List; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.GrapheneObject; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.BitAssetData; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.GrapheneObject; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.BitAssetData; +import cy.agorise.graphenej.models.WitnessResponse; /** * Testing the {@link GetObjects} API wrapper and its deserialization diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetRelativeAccountHistoryTest.java b/graphenej/src/test/java/cy/agorise/graphenej/api/GetRelativeAccountHistoryTest.java similarity index 85% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetRelativeAccountHistoryTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/api/GetRelativeAccountHistoryTest.java index c3ab49e..220a523 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/GetRelativeAccountHistoryTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/api/GetRelativeAccountHistoryTest.java @@ -1,16 +1,16 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.neovisionaries.ws.client.WebSocketException; import org.junit.Test; import java.util.List; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.HistoricalTransfer; -import de.bitsharesmunich.graphenej.models.WitnessResponse; -import de.bitsharesmunich.graphenej.operations.TransferOperation; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.HistoricalTransfer; +import cy.agorise.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.operations.TransferOperation; /** * Created by nelson on 9/25/17. diff --git a/graphenej/src/test/java/cy/agorise/graphenej/api/LookupAssetSymbolsTest.java b/graphenej/src/test/java/cy/agorise/graphenej/api/LookupAssetSymbolsTest.java new file mode 100644 index 0000000..de0d13c --- /dev/null +++ b/graphenej/src/test/java/cy/agorise/graphenej/api/LookupAssetSymbolsTest.java @@ -0,0 +1,60 @@ +package cy.agorise.graphenej.api; + +import junit.framework.Assert; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.WitnessResponse; + +/** + * Testing the standalone usage of the {@link LookupAssetSymbols} API handler. + */ + +public class LookupAssetSymbolsTest extends BaseApiTest { + + @Test + public void testLookupAssetSymbolsWithString(){ + ArrayList assetSymbols = new ArrayList<>(); + assetSymbols.add("USD"); + mWebSocket.addListener(new LookupAssetSymbols(assetSymbols, true, new WitnessResponseListener() { + @Override + public void onSuccess(WitnessResponse response) { + System.out.println("onSuccess"); + List assets = (List) response.result; + Assert.assertEquals(1, assets.size()); + Assert.assertEquals("1.3.121", assets.get(0).getObjectId()); + } + + @Override + public void onError(BaseResponse.Error error) { + System.out.println("onError"); + } + })); + } + + @Test + public void testLookupAssetSymbolsWithAsset(){ + ArrayList assetSymbols = new ArrayList<>(); + assetSymbols.add(new Asset("1.3.121")); + mWebSocket.addListener(new LookupAssetSymbols(assetSymbols, true, new WitnessResponseListener() { + @Override + public void onSuccess(WitnessResponse response) { + System.out.println("onSuccess"); + List assets = (List) response.result; + Assert.assertEquals(1, assets.size()); + Assert.assertEquals("1.3.121", assets.get(0).getObjectId()); + } + + @Override + public void onError(BaseResponse.Error error) { + System.out.println("onError"); + } + })); + } +} diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/SubscriptionMessagesHubTest.java b/graphenej/src/test/java/cy/agorise/graphenej/api/SubscriptionMessagesHubTest.java similarity index 92% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/api/SubscriptionMessagesHubTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/api/SubscriptionMessagesHubTest.java index 9d4e4b5..b6f8fda 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/SubscriptionMessagesHubTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/api/SubscriptionMessagesHubTest.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.api; +package cy.agorise.graphenej.api; import com.neovisionaries.ws.client.WebSocketException; @@ -9,19 +9,18 @@ import java.util.List; import java.util.Timer; import java.util.TimerTask; -import de.bitsharesmunich.graphenej.ObjectType; -import de.bitsharesmunich.graphenej.Transaction; -import de.bitsharesmunich.graphenej.interfaces.NodeErrorListener; -import de.bitsharesmunich.graphenej.interfaces.SubscriptionListener; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.BroadcastedTransaction; -import de.bitsharesmunich.graphenej.models.DynamicGlobalProperties; -import de.bitsharesmunich.graphenej.models.SubscriptionResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.ObjectType; +import cy.agorise.graphenej.Transaction; +import cy.agorise.graphenej.interfaces.NodeErrorListener; +import cy.agorise.graphenej.interfaces.SubscriptionListener; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.BroadcastedTransaction; +import cy.agorise.graphenej.models.DynamicGlobalProperties; +import cy.agorise.graphenej.models.SubscriptionResponse; /** * Class used to encapsulate all tests that relate to the {@see SubscriptionMessagesHub} class. + * This test requires setting up the NODE_URL environment variable */ public class SubscriptionMessagesHubTest extends BaseApiTest { diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/android/NodeConnectionTest.java b/graphenej/src/test/java/cy/agorise/graphenej/api/android/NodeConnectionTest.java similarity index 89% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/api/android/NodeConnectionTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/api/android/NodeConnectionTest.java index 226c92d..f95c6c0 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/android/NodeConnectionTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/api/android/NodeConnectionTest.java @@ -1,10 +1,12 @@ -package de.bitsharesmunich.graphenej.api.android; +package cy.agorise.graphenej.api.android; import com.google.common.primitives.UnsignedLong; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketException; import com.neovisionaries.ws.client.WebSocketFactory; +import junit.framework.Assert; + import org.bitcoinj.core.ECKey; import org.junit.Test; @@ -17,37 +19,38 @@ import java.util.TimerTask; import javax.net.ssl.SSLContext; -import de.bitsharesmunich.graphenej.Address; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.BaseOperation; -import de.bitsharesmunich.graphenej.BrainKey; -import de.bitsharesmunich.graphenej.Transaction; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.api.GetAccountBalances; -import de.bitsharesmunich.graphenej.api.GetAccountByName; -import de.bitsharesmunich.graphenej.api.GetAccounts; -import de.bitsharesmunich.graphenej.api.GetAllAssetHolders; -import de.bitsharesmunich.graphenej.api.GetBlockHeader; -import de.bitsharesmunich.graphenej.api.GetKeyReferences; -import de.bitsharesmunich.graphenej.api.GetLimitOrders; -import de.bitsharesmunich.graphenej.api.GetMarketHistory; -import de.bitsharesmunich.graphenej.api.GetObjects; -import de.bitsharesmunich.graphenej.api.GetRelativeAccountHistory; -import de.bitsharesmunich.graphenej.api.GetRequiredFees; -import de.bitsharesmunich.graphenej.api.GetTradeHistory; -import de.bitsharesmunich.graphenej.api.ListAssets; -import de.bitsharesmunich.graphenej.api.LookupAccounts; -import de.bitsharesmunich.graphenej.api.LookupAssetSymbols; -import de.bitsharesmunich.graphenej.api.TransactionBroadcastSequence; -import de.bitsharesmunich.graphenej.errors.MalformedAddressException; -import de.bitsharesmunich.graphenej.errors.RepeatedRequestIdException; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; -import de.bitsharesmunich.graphenej.operations.TransferOperation; -import de.bitsharesmunich.graphenej.operations.TransferOperationBuilder; -import de.bitsharesmunich.graphenej.test.NaiveSSLContext; +import cy.agorise.graphenej.Address; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.BaseOperation; +import cy.agorise.graphenej.BrainKey; +import cy.agorise.graphenej.Transaction; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.api.GetAccountBalances; +import cy.agorise.graphenej.api.GetAccountByName; +import cy.agorise.graphenej.api.GetAccounts; +import cy.agorise.graphenej.api.GetAllAssetHolders; +import cy.agorise.graphenej.api.GetBlockHeader; +import cy.agorise.graphenej.api.GetKeyReferences; +import cy.agorise.graphenej.api.GetLimitOrders; +import cy.agorise.graphenej.api.GetMarketHistory; +import cy.agorise.graphenej.api.GetObjects; +import cy.agorise.graphenej.api.GetRelativeAccountHistory; +import cy.agorise.graphenej.api.GetRequiredFees; +import cy.agorise.graphenej.api.GetTradeHistory; +import cy.agorise.graphenej.api.ListAssets; +import cy.agorise.graphenej.api.LookupAccounts; +import cy.agorise.graphenej.api.LookupAssetSymbols; +import cy.agorise.graphenej.api.TransactionBroadcastSequence; +import cy.agorise.graphenej.errors.MalformedAddressException; +import cy.agorise.graphenej.errors.RepeatedRequestIdException; +import cy.agorise.graphenej.interfaces.NodeErrorListener; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.WitnessResponse; +import cy.agorise.graphenej.operations.TransferOperation; +import cy.agorise.graphenej.operations.TransferOperationBuilder; +import cy.agorise.graphenej.test.NaiveSSLContext; /** * Created by nelson on 6/26/17. @@ -58,17 +61,20 @@ public class NodeConnectionTest { private String NODE_URL_3 = System.getenv("NODE_URL_3"); private String NODE_URL_4 = System.getenv("NODE_URL_4"); private String TEST_ACCOUNT_BRAIN_KEY = System.getenv("TEST_ACCOUNT_BRAIN_KEY"); - private String ACCOUNT_ID_1 = System.getenv("ACCOUNT_ID_1"); - private String ACCOUNT_ID_2 = System.getenv("ACCOUNT_ID_2"); - private String ACCOUNT_NAME = System.getenv("ACCOUNT_NAME"); - private long BlOCK_TEST_NUMBER = Long.parseLong(System.getenv("BlOCK_TEST_NUMBER")); + private String ACCOUNT_ID_1 = "1.2.140994"; + private String ACCOUNT_ID_2 = "1.2.138632"; + private String ACCOUNT_NAME = "bilthon-7"; + private long BlOCK_TEST_NUMBER = 11000000; private Asset BTS = new Asset("1.3.0"); private Asset BLOCKPAY = new Asset("1.3.1072"); - private Asset BITDOLAR = new Asset("1.3.121"); //USD Smartcoin - private Asset BITEURO = new Asset("1.3.120"); //EUR Smartcoin + private Asset BITUSD = new Asset("1.3.121"); //USD Smartcoin + private Asset BITEUR = new Asset("1.3.120"); //EUR Smartcoin private NodeConnection nodeConnection; - private TimerTask scheduleTask = new TimerTask() { + /** + * Sample task to be scheduled + */ + private TimerTask getAccountsTask = new TimerTask() { @Override public void run() { System.out.println("Adding request here"); @@ -91,6 +97,9 @@ public class NodeConnectionTest { } }; + /** + * Task that will release the worker thread, effectively terminating this test + */ private TimerTask releaseTask = new TimerTask() { @Override public void run() { @@ -103,12 +112,13 @@ public class NodeConnectionTest { @Test public void testNodeConnection(){ + System.out.println("** Testing simple node connection **"); nodeConnection = NodeConnection.getInstance(); nodeConnection.addNodeUrl(NODE_URL_1); nodeConnection.connect("", "", true, mErrorListener); Timer timer = new Timer(); - timer.schedule(scheduleTask, 5000); + timer.schedule(getAccountsTask, 5000); timer.schedule(releaseTask, 30000); try{ @@ -122,29 +132,53 @@ public class NodeConnectionTest { } @Test + public void testWrongUrl(){ + System.out.println("** Testing simple node connection with wrong URL **"); + nodeConnection = NodeConnection.getInstance(); + nodeConnection.addNodeUrl("wss://non-existing-host"); + nodeConnection.connect("", "", true, new NodeErrorListener() { + @Override + public void onError(BaseResponse.Error error) { + Assert.assertEquals("Can't connect, ran out of URLs!", error.message); + } + }); + + Timer timer = new Timer(); + timer.schedule(releaseTask, 5000); + + try{ + // Holding this thread while we get update notifications + synchronized (this){ + wait(); + } + }catch(InterruptedException e){ + System.out.println("InterruptedException. Msg: "+e.getMessage()); + } + } + /** * Test for NodeConnection's addNodeUrl and addNodeUrls working together. * - * Need to setup the NODE_URL_(1 to 4) env to work. Some of the nodes may have invalid nodes - * websockets URL just to test the hop. + * Need to setup the NODE_URL_2 env to work. The first hard-coded URL is wrong and will + * fail. The NodeConnection instance should recover and try the next one in the list. * */ + @Test public void testNodeHopFeature(){ + System.out.println("** Testing node hopping **"); nodeConnection = NodeConnection.getInstance(); - //nodeConnection.addNodeUrl(NODE_URL_4); + //Test adding a "sublist" ArrayList urlList = new ArrayList(){{ - add(NODE_URL_3); - add(NODE_URL_3); + add("wss://eu.openledger.info/wrong"); + add(NODE_URL_2); }}; - //nodeConnection.addNodeUrls(urlList); - nodeConnection.addNodeUrl(NODE_URL_1); + nodeConnection.addNodeUrls(urlList); nodeConnection.connect("", "", true, mErrorListener); Timer timer = new Timer(); - timer.schedule(scheduleTask, 5000); - timer.schedule(releaseTask, 30000); + timer.schedule(releaseTask, 15000); try{ // Holding this thread while we get update notifications @@ -164,17 +198,20 @@ public class NodeConnectionTest { */ @Test public void testGetAccountBalancesRequest(){ + System.out.println("** Testing GetAccountBalances request **"); + int callbackCount = 0; nodeConnection = NodeConnection.getInstance(); nodeConnection.addNodeUrl(NODE_URL_1); nodeConnection.connect("", "", false, mErrorListener); System.out.println("Adding GetAccountBalances here"); + // Trying to get the balances of ACCOUNT_ID_1 for BTS, bitUSD & bitEUR try{ UserAccount userAccount = new UserAccount(ACCOUNT_ID_1); ArrayList assetList = new ArrayList<>(); assetList.add(BTS); - assetList.add(BITDOLAR); - assetList.add(BITEURO); + assetList.add(BITUSD); + assetList.add(BITEUR); System.out.println("Test: Request to discrete asset list"); nodeConnection.addRequestHandler(new GetAccountBalances(userAccount, assetList, false, new WitnessResponseListener(){ @Override @@ -191,6 +228,7 @@ public class NodeConnectionTest { System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage()); } + // Trying to get the balances of ACCOUNT_ID_1 for all assets try{ UserAccount userAccount = new UserAccount(ACCOUNT_ID_1); System.out.println("Test: Request to all account' assets balance"); @@ -209,6 +247,8 @@ public class NodeConnectionTest { System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage()); } + Timer timer = new Timer(); + timer.schedule(releaseTask, 10000); try{ // Holding this thread while we get update notifications synchronized (this){ @@ -584,7 +624,7 @@ public class NodeConnectionTest { ArrayList objectList = new ArrayList(){{ add(BLOCKPAY.getBitassetId()); add(BTS.getBitassetId()); - add(BITEURO.getBitassetId()); + add(BITEUR.getBitassetId()); }}; System.out.println("Adding GetObjects request"); @@ -882,7 +922,7 @@ public class NodeConnectionTest { ArrayList assetList = new ArrayList(){{ add(BLOCKPAY); add(BTS); - add(BITEURO); + add(BITEUR); }}; System.out.println("Adding LookupAssetSymbols request"); @@ -926,7 +966,7 @@ public class NodeConnectionTest { ArrayList assetList = new ArrayList(){{ add(BLOCKPAY); add(BTS); - add(BITEURO); + add(BITEUR); }}; ECKey privateKey = new BrainKey(TEST_ACCOUNT_BRAIN_KEY, 0).getPrivateKey(); @@ -989,13 +1029,7 @@ public class NodeConnectionTest { } - private WitnessResponseListener mErrorListener = new WitnessResponseListener() { - - @Override - public void onSuccess(WitnessResponse response) { - System.out.println("onSuccess"); - } - + private NodeErrorListener mErrorListener = new NodeErrorListener() { @Override public void onError(BaseResponse.Error error) { System.out.println("onError"); diff --git a/graphenej/src/test/java/cy/agorise/graphenej/objects/MemoTest.java b/graphenej/src/test/java/cy/agorise/graphenej/objects/MemoTest.java new file mode 100644 index 0000000..303b140 --- /dev/null +++ b/graphenej/src/test/java/cy/agorise/graphenej/objects/MemoTest.java @@ -0,0 +1,164 @@ +package cy.agorise.graphenej.objects; + +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import org.bitcoinj.core.DumpedPrivateKey; +import org.bitcoinj.core.ECKey; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.math.BigInteger; + +import cy.agorise.graphenej.Address; +import cy.agorise.graphenej.PublicKey; +import cy.agorise.graphenej.TestAccounts; +import cy.agorise.graphenej.Util; +import cy.agorise.graphenej.errors.ChecksumException; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +/** + * Unit Tests for Memo Related Classes. + */ +public class MemoTest { + + private ECKey sourcePrivate; + private Address sourceAddress; + + private ECKey destinationPrivate; + private Address destinationAddress; + + private String sourceWIF = TestAccounts.Bilthon16.WIF; + private String destinationWIF = TestAccounts.Bilthon7.WIF; + private String shortMessage = "test"; + private String longerMessage = "testing now longer string with some special charaters é ç o ú á í Í mMno!!"; + + private byte[] shortEncryptedMessage = Util.hexToBytes("93c398e05f2a36a535f82880032a062d"); + private BigInteger shortEncryptedMessageNonce = new BigInteger("386471255144360"); + + private byte[] longerEncryptedMessage = Util.hexToBytes("8ba8f5ed85ad9f7675bd30408a28d6f6ba138476d1e995dd61c01f0041ab25911e04d93fe4ce30e4f6c9a5134cceb67d653e140aa542da19ce2fc646bcde46e088da06a9327eaac79ffe8bc9d71d586195c04bb023995f18e66c9f9e5c6b0d7c"); + private BigInteger longEncryptedMessageNonce = new BigInteger("386469162162343"); + + @Before + public void setUp() throws Exception { + //Source + sourcePrivate = DumpedPrivateKey.fromBase58(null, sourceWIF).getKey(); + PublicKey publicKey = new PublicKey(ECKey.fromPublicOnly(sourcePrivate.getPubKey())); + sourceAddress = new Address(publicKey.getKey()); + + //Destination + destinationPrivate = DumpedPrivateKey.fromBase58(null, destinationWIF).getKey(); + publicKey = new PublicKey(ECKey.fromPublicOnly(destinationPrivate.getPubKey())); + destinationAddress = new Address(publicKey.getKey()); + } + + @Test + public void shouldMatchPredefinedCiphertext(){ + byte[] encrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, shortEncryptedMessageNonce, shortMessage); + assertArrayEquals("Testing with short message and nonce 1", encrypted, shortEncryptedMessage); + + byte[] encryptedLong = Memo.encryptMessage(sourcePrivate, destinationAddress, longEncryptedMessageNonce, longerMessage); + assertArrayEquals("Testing with longer message and nonce 1", encryptedLong, longerEncryptedMessage); + } + + @Test + public void shouldDecryptShortMessage(){ + try { + String decrypted = Memo.decryptMessage(destinationPrivate, sourceAddress, shortEncryptedMessageNonce, shortEncryptedMessage); + System.out.println("Short Decrypted Message: " + decrypted); + assertEquals("Decrypted message must be equal to original", decrypted, shortMessage); + } catch (ChecksumException e) { + e.printStackTrace(); + } + } + + @Test + public void shouldDecryptLongerMessage(){ + try{ + System.out.println("Source address: "+sourceAddress.toString()); + System.out.println("Dest address..: "+new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(destinationPrivate.getPrivKeyBytes()).getPubKey())).toString()); + System.out.println("Nonce.........: "+longEncryptedMessageNonce); + System.out.println("Encrypted msg.: "+Util.bytesToHex(longerEncryptedMessage)); + String longDecrypted = Memo.decryptMessage(destinationPrivate, sourceAddress, longEncryptedMessageNonce, longerEncryptedMessage); + System.out.println("Long Decrypted Message: " + longDecrypted); + assertEquals("The longer message must be equal to the original", longerMessage, longDecrypted); + } catch (ChecksumException e) { + e.printStackTrace(); + } + } + + @Test + public void shouldEncryptAndDecryptShortMessage(){ + try { + BigInteger nonce = BigInteger.ONE; + byte[] encrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, nonce, shortMessage); + String decrypted = Memo.decryptMessage(destinationPrivate, sourceAddress, nonce, encrypted); + System.out.println("Short Decrypted Message: " + decrypted); + assertEquals("Decrypted message must be equal to original", decrypted, shortMessage); + } catch (ChecksumException e) { + e.printStackTrace(); + } + } + + @Test + public void shouldEncryptAndDecryptLongerMessage(){ + try{ + BigInteger nonce = BigInteger.ONE; + byte[] longEncrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, nonce, longerMessage); + String longDecrypted = Memo.decryptMessage(destinationPrivate, sourceAddress, nonce, longEncrypted); + System.out.println("Long Decrypted Message: " + longDecrypted); + assertEquals("The longer message must be equal to the original", longerMessage, longDecrypted); + } catch (ChecksumException e) { + e.printStackTrace(); + } + } + + @Test(expected = ChecksumException.class) + public void shouldThrowException() throws ChecksumException { + byte[] corrupted = Memo.encryptMessage(sourcePrivate, destinationAddress, longEncryptedMessageNonce, longerMessage); + corrupted[0] = 0; + String longDecrypted = Memo.decryptMessage(destinationPrivate, sourceAddress, longEncryptedMessageNonce, corrupted); + } + + @Test + public void shouldBeJsonObjectSerializable(){ + byte[] encrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, shortEncryptedMessageNonce, shortMessage); + Memo memo = new Memo(sourceAddress, destinationAddress, shortEncryptedMessageNonce, encrypted); + JsonElement jsonObject = memo.toJsonObject(); + JsonObject expected = new JsonObject(); + expected.addProperty("from", new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, TestAccounts.Bilthon16.WIF).getKey().getPrivKeyBytes()).getPubKey())).toString()); + expected.addProperty("to", new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, TestAccounts.Bilthon7.WIF).getKey().getPrivKeyBytes()).getPubKey())).toString()); + expected.addProperty("nonce", String.format("%x", shortEncryptedMessageNonce)); + expected.addProperty("message", "93c398e05f2a36a535f82880032a062d"); + assertEquals("Memo instance should generate a valid JsonObject",expected, jsonObject); + } + + @Test + public void shouldBeByteSerializable(){ + String byteReference = "01029392096400eafe5f5ce7e2ab74134c3422fc49e5853bdeb298fb096258e26f6303d1fb8c7421db64d46fba7e36f428854ca06eff65698b293f37c7ffaa54e2c2b20100000000000000104ccbca3750fd2e531441de02b23fe6c7"; + byte[] encrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, BigInteger.ONE, shortMessage); + Memo memo = new Memo(sourceAddress, destinationAddress, BigInteger.ONE, encrypted); + byte[] memoBytes = memo.toBytes(); + assertEquals("Memo instance should generate a valid byte array", byteReference, Util.bytesToHex(memoBytes)); + } + + @Test + public void shouldDeserializeFromString(){ + String jsonMemo = "{\"from\":\"BTS6nB7gw1EawYXRofLvuivLsboVmh2inXroQgSQqYfAc5Bamk4Vq\",\"to\":\"BTS4xAQGg2ePLeDGZvQFpsh9CjMhQvRnVkPp6jPoE6neVPotRfZX9\",\"nonce\":\"8000000000000000\",\"message\":\"b9aeb7632f1f4281eedcf28a684828a42d02de71254fb88e13ddcb9a79adf51d9770c58d7e7efcdbb1515f1136c3be3e\"}"; + GsonBuilder gsonBuilder = new GsonBuilder() + .registerTypeAdapter(Memo.class, new Memo.MemoSerializer()) + .registerTypeAdapter(Memo.class, new Memo.MemoDeserializer()); + Memo memo = gsonBuilder.create().fromJson(jsonMemo, Memo.class); + Assert.assertEquals("Source address should match the serialized one", "BTS6nB7gw1EawYXRofLvuivLsboVmh2inXroQgSQqYfAc5Bamk4Vq", memo.getSource().toString()); + Assert.assertEquals("Destination address should match the serialized one", "BTS4xAQGg2ePLeDGZvQFpsh9CjMhQvRnVkPp6jPoE6neVPotRfZX9", memo.getDestination().toString()); + Assert.assertEquals("Nonce should match serialized one", new BigInteger("8000000000000000", 10), memo.getNonce()); + Assert.assertArrayEquals(Util.hexToBytes("b9aeb7632f1f4281eedcf28a684828a42d02de71254fb88e13ddcb9a79adf51d9770c58d7e7efcdbb1515f1136c3be3e"), memo.getByteMessage()); + + String json = gsonBuilder.create().toJson(memo); + Assert.assertEquals("Serialized memo matches the original one", jsonMemo, json); + } +} \ No newline at end of file diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/operations/AccountUpdateOperationTest.java b/graphenej/src/test/java/cy/agorise/graphenej/operations/AccountUpdateOperationTest.java similarity index 76% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/operations/AccountUpdateOperationTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/operations/AccountUpdateOperationTest.java index 61ff0d1..59f4192 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/operations/AccountUpdateOperationTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/operations/AccountUpdateOperationTest.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.operations; +package cy.agorise.graphenej.operations; import com.google.common.primitives.UnsignedLong; @@ -9,19 +9,19 @@ import org.junit.Test; import java.util.ArrayList; import java.util.HashMap; -import de.bitsharesmunich.graphenej.AccountOptions; -import de.bitsharesmunich.graphenej.Address; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.Authority; -import de.bitsharesmunich.graphenej.BaseOperation; -import de.bitsharesmunich.graphenej.BlockData; -import de.bitsharesmunich.graphenej.BrainKey; -import de.bitsharesmunich.graphenej.PublicKey; -import de.bitsharesmunich.graphenej.Transaction; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.Util; -import de.bitsharesmunich.graphenej.errors.MalformedAddressException; +import cy.agorise.graphenej.AccountOptions; +import cy.agorise.graphenej.Address; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.Authority; +import cy.agorise.graphenej.BaseOperation; +import cy.agorise.graphenej.BlockData; +import cy.agorise.graphenej.BrainKey; +import cy.agorise.graphenej.PublicKey; +import cy.agorise.graphenej.Transaction; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.Util; +import cy.agorise.graphenej.errors.MalformedAddressException; /** * Created by nelson on 4/18/17. diff --git a/graphenej/src/test/java/cy/agorise/graphenej/operations/CustomOperationTest.java b/graphenej/src/test/java/cy/agorise/graphenej/operations/CustomOperationTest.java new file mode 100644 index 0000000..6196378 --- /dev/null +++ b/graphenej/src/test/java/cy/agorise/graphenej/operations/CustomOperationTest.java @@ -0,0 +1,39 @@ +package cy.agorise.graphenej.operations; + +import com.google.common.primitives.UnsignedLong; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.Util; +import org.junit.Test; + +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertArrayEquals; + +public class CustomOperationTest { + private final Asset CORE_ASSET = new Asset("1.3.0"); + private final AssetAmount fee = new AssetAmount(UnsignedLong.valueOf(100000L), CORE_ASSET); + private final UserAccount payer = new UserAccount("1.2.20"); + private final Integer operationId = 61166; + private final List requiredAuths = Collections.singletonList(payer); + private final String shortData = "some data"; + private final String longData = "very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data, very long data..."; + + private static final byte[] EXPECTED_SERIALIZED_BYTES_1 = Util.hexToBytes("a08601000000000000140114eeee09736f6d652064617461"); + private static final byte[] EXPECTED_SERIALIZED_BYTES_2 = Util.hexToBytes("a08601000000000000140114eeeee50176657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c202076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c202076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c202076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612c202076657279206c6f6e6720646174612c2076657279206c6f6e6720646174612e2e2e"); + + @Test + public void testToBytes() throws Exception { + CustomOperation customOperation1 = new CustomOperation(fee, payer, operationId, requiredAuths, shortData); + byte[] serialized1 = customOperation1.toBytes(); + assertArrayEquals(EXPECTED_SERIALIZED_BYTES_1, serialized1); + + // test with some long data string to check if data length is serialized correctly + CustomOperation customOperation2 = new CustomOperation(fee, payer, operationId, requiredAuths, longData); + byte[] serialized2 = customOperation2.toBytes(); + assertArrayEquals(EXPECTED_SERIALIZED_BYTES_2, serialized2); + } +} + diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/operations/LimitOrderCancelOperationTest.java b/graphenej/src/test/java/cy/agorise/graphenej/operations/LimitOrderCancelOperationTest.java similarity index 89% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/operations/LimitOrderCancelOperationTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/operations/LimitOrderCancelOperationTest.java index a065d45..dbe252f 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/operations/LimitOrderCancelOperationTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/operations/LimitOrderCancelOperationTest.java @@ -1,8 +1,8 @@ -package de.bitsharesmunich.graphenej.operations; +package cy.agorise.graphenej.operations; import com.google.common.primitives.UnsignedLong; -import de.bitsharesmunich.graphenej.*; -import org.junit.Assert; +import cy.agorise.graphenej.*; + import org.junit.Before; import org.junit.Test; diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/operations/LimitOrderCreateOperationTest.java b/graphenej/src/test/java/cy/agorise/graphenej/operations/LimitOrderCreateOperationTest.java similarity index 91% rename from graphenej/src/test/java/de/bitsharesmunich/graphenej/operations/LimitOrderCreateOperationTest.java rename to graphenej/src/test/java/cy/agorise/graphenej/operations/LimitOrderCreateOperationTest.java index b070d00..ae6dafe 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/operations/LimitOrderCreateOperationTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/operations/LimitOrderCreateOperationTest.java @@ -1,4 +1,4 @@ -package de.bitsharesmunich.graphenej.operations; +package cy.agorise.graphenej.operations; import com.google.common.primitives.UnsignedLong; @@ -8,10 +8,10 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.Util; +import cy.agorise.graphenej.Asset; +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.Util; /** * Created by nelson on 3/6/17. diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/AssetAmountTest.java b/graphenej/src/test/java/de/bitsharesmunich/graphenej/AssetAmountTest.java deleted file mode 100644 index db6fa3f..0000000 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/AssetAmountTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.bitsharesmunich.graphenej; - -import com.google.common.primitives.UnsignedLong; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Created by nelson on 2/23/17. - */ -public class AssetAmountTest { - private final int LARGE_VALUE = 1000; - private final int SMALL_VALUE = 500; - private AssetAmount large; - private AssetAmount small; - private Asset testAsset = new Asset("1.3.0"); - - @Before - public void setUp(){ - large = new AssetAmount(UnsignedLong.valueOf(LARGE_VALUE), testAsset); - small = new AssetAmount(UnsignedLong.valueOf(SMALL_VALUE), testAsset); - } - - @Test - public void testSubtraction(){ - assertEquals(large.subtract(small).getAmount(), new AssetAmount(UnsignedLong.valueOf(LARGE_VALUE - SMALL_VALUE), testAsset).getAmount()); - assertEquals(small.subtract(large).getAmount(), new AssetAmount(UnsignedLong.valueOf(Math.abs(SMALL_VALUE - LARGE_VALUE)), testAsset).getAmount()); - } -} \ No newline at end of file diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/objects/MemoTest.java b/graphenej/src/test/java/de/bitsharesmunich/graphenej/objects/MemoTest.java deleted file mode 100644 index cdc7101..0000000 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/objects/MemoTest.java +++ /dev/null @@ -1,151 +0,0 @@ -package de.bitsharesmunich.graphenej.objects; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import de.bitsharesmunich.graphenej.Address; -import de.bitsharesmunich.graphenej.PublicKey; -import de.bitsharesmunich.graphenej.Util; -import de.bitsharesmunich.graphenej.errors.ChecksumException; -import org.bitcoinj.core.DumpedPrivateKey; -import org.bitcoinj.core.ECKey; -import org.junit.*; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; - -/** - * Unit Tests for Memo Related Classes. - */ -public class MemoTest { - - private ECKey sourcePrivate; - private Address sourceAddress; - - private ECKey destinationPrivate; - private Address destinationAddress; - - private long nonce; - private String sourceWIF = System.getenv("SOURCE_WIF"); - private String destinationWIF = System.getenv("DESTINATION_WIF"); - private byte[] memoEncryptedEnvMessage = Util.hexToBytes(System.getenv("MEMO_MESSAGE")); - //private String sourceWIF = "5J96pne45qWM1WpektoeazN6k9Mt93jQ7LyueRxFfEMTiy6yxjM"; - //private String destinationWIF = "5HuGQT8qwHScBgD4XsGbQUmXQF18MrbzxaQDiGGXFNRrCtqgT5Q"; - private String shortMessage = "test"; - private String longerMessage = "testing now longer string with some special charaters é ç o ú á í Í mMno!!"; - - private byte[] shortEncryptedMessage = Util.hexToBytes("4c81c2db6ebc61e3f9e0ead65c0559dd"); - private byte[] longerEncryptedMessage = Util.hexToBytes("1f8a08f1ff53dcefd48eeb052d26fba425f2a917f508ce61fc3d5696b10efa17"); - - private String decodedMessage; - - @Before - public void setUp() throws Exception { - //Source - sourcePrivate = DumpedPrivateKey.fromBase58(null, sourceWIF).getKey(); - PublicKey publicKey = new PublicKey(ECKey.fromPublicOnly(sourcePrivate.getPubKey())); - sourceAddress = new Address(publicKey.getKey()); - - //Destination - destinationPrivate = DumpedPrivateKey.fromBase58(null, destinationWIF).getKey(); - publicKey = new PublicKey(ECKey.fromPublicOnly(destinationPrivate.getPubKey())); - destinationAddress = new Address(publicKey.getKey()); - - //memo.getNonce() - nonce = 5; - } - - @Test - public void shouldMatchPredefinedChiphertext(){ - byte[] encrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, 1, shortMessage); - assertArrayEquals("Testing with short message and nonce 1", encrypted, shortEncryptedMessage); - - byte[] encryptedLong = Memo.encryptMessage(sourcePrivate, destinationAddress, 1, longerMessage); - assertArrayEquals("Testing with longer message and nonce 1", encryptedLong, longerEncryptedMessage); - } - - @Test - public void shouldDecryptEnvMessage(){ - try { - String decrypted = Memo.decryptMessage(destinationPrivate, sourceAddress, nonce, memoEncryptedEnvMessage); - System.out.println("Short Decrypted Message: " + decrypted); - assertEquals("Decrypted message must be equal to original", decrypted, shortMessage); - } catch (ChecksumException e) { - e.printStackTrace(); - } - } - - @Test - public void shouldDecryptShortMessage(){ - try { - String decrypted = Memo.decryptMessage(destinationPrivate, sourceAddress, nonce, shortEncryptedMessage); - System.out.println("Short Decrypted Message: " + decrypted); - assertEquals("Decrypted message must be equal to original", decrypted, shortMessage); - } catch (ChecksumException e) { - e.printStackTrace(); - } - } - - @Test - public void shouldDecryptLongerMessage(){ - try{ - String longDecrypted = Memo.decryptMessage(destinationPrivate, sourceAddress, nonce, longerEncryptedMessage); - System.out.println("Long Decrypted Message: " + longDecrypted); - assertEquals("The longer message must be equal to the original", longerMessage, longDecrypted); - } catch (ChecksumException e) { - e.printStackTrace(); - } - } - - @Test - public void shouldEncryptAndDecryptShortMessage(){ - try { - byte[] encrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, nonce, shortMessage); - String decrypted = Memo.decryptMessage(destinationPrivate, sourceAddress, nonce, encrypted); - System.out.println("Short Decrypted Message: " + decrypted); - assertEquals("Decrypted message must be equal to original", decrypted, shortMessage); - } catch (ChecksumException e) { - e.printStackTrace(); - } - } - - @Test - public void shouldEncryptAndDecryptLongerMessage(){ - try{ - byte[] longEncrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, nonce, longerMessage); - String longDecrypted = Memo.decryptMessage(destinationPrivate, sourceAddress, nonce, longEncrypted); - System.out.println("Long Decrypted Message: " + longDecrypted); - assertEquals("The longer message must be equal to the original", longerMessage, longDecrypted); - } catch (ChecksumException e) { - e.printStackTrace(); - } - } - - @Test(expected = ChecksumException.class) - public void shouldThrowException() throws ChecksumException { - byte[] corrupted = Memo.encryptMessage(sourcePrivate, destinationAddress, nonce, longerMessage); - corrupted[0] = 0; - String longDecrypted = Memo.decryptMessage(destinationPrivate, sourceAddress, nonce, corrupted); - } - - @Test - public void shouldBeJsonObjectSerializable(){ - byte[] encrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, 1, shortMessage); - Memo memo = new Memo(sourceAddress, destinationAddress, 1, encrypted); - JsonElement jsonObject = memo.toJsonObject(); - JsonObject reference = new JsonObject(); - reference.addProperty("from", "BTS8RiFgs8HkcVPVobHLKEv6yL3iXcC9SWjbPVS15dDAXLG9GYhnY"); - reference.addProperty("to", "BTS8ADjGaswhfFoxMGxqCdBtzhTBJsrGadCLoc9Ey5AGc8eoVZ5bV"); - reference.addProperty("nonce", "1"); - reference.addProperty("message", "4c81c2db6ebc61e3f9e0ead65c0559dd"); - assertEquals("Memo instance should generate a valid JsonObject",jsonObject, reference); - } - - @Test - public void shouldBeByteSerializable(){ - String byteReference = "0103d1fb8c7421db64d46fba7e36f428854ca06eff65698b293f37c7ffaa54e2c2b203aece7c31616c02fcc96b50d3397c0e8d33d6384655d477c300d9196c728a5ee20100000000000000104c81c2db6ebc61e3f9e0ead65c0559dd"; - byte[] encrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, 1, shortMessage); - Memo memo = new Memo(sourceAddress, destinationAddress, 1, encrypted); - byte[] memoBytes = memo.toBytes(); - assertEquals("Memo instance should generate a valid byte array", byteReference, Util.bytesToHex(memoBytes)); - } -} \ No newline at end of file