From 1929e18e0671ba340e26b5b9c6ae44c8d26400d6 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Tue, 10 Jan 2017 14:20:39 -0500 Subject: [PATCH] Expanding Asset and AssetOptions classes --- .../de/bitsharesmunich/graphenej/Asset.java | 50 +++++++++++++++---- .../graphenej/AssetOptions.java | 21 ++++++-- .../graphenej/api/GetObjects.java | 7 +++ .../graphenej/models/AssetFeed.java | 7 +++ .../graphenej/models/BitAssetData.java | 7 +++ 5 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 src/main/java/de/bitsharesmunich/graphenej/api/GetObjects.java create mode 100644 src/main/java/de/bitsharesmunich/graphenej/models/AssetFeed.java create mode 100644 src/main/java/de/bitsharesmunich/graphenej/models/BitAssetData.java diff --git a/src/main/java/de/bitsharesmunich/graphenej/Asset.java b/src/main/java/de/bitsharesmunich/graphenej/Asset.java index a19ecd2..daf6e9b 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/Asset.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Asset.java @@ -1,7 +1,11 @@ package de.bitsharesmunich.graphenej; import com.google.common.primitives.UnsignedLong; -import com.google.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 java.lang.reflect.Type; @@ -9,6 +13,8 @@ import java.lang.reflect.Type; * Created by nelson on 11/9/16. */ public class Asset extends GrapheneObject { + public final static String TAG = "Asset"; + public static final String KEY_ID = "id"; public static final String KEY_SYMBOL = "symbol"; public static final String KEY_PRECISION = "precision"; @@ -22,6 +28,17 @@ public class Asset extends GrapheneObject { public static final String KEY_CORE_EXCHANGE_RATE = "core_exchange_rate"; public static final String KEY_DESCRIPTION = "description"; public static final String KEY_DYNAMIC_ASSET_DATA_ID = "dynamic_asset_data_id"; + public static final String KEY_BITASSET_DATA_ID = "bitasset_data_id"; + + /** + * Enum type used to represent the possible types an asset can be classified into. + */ + public enum AssetType { + CORE_ASSET, + UIA, + SMART_COIN, + PREDICTION_MARKET + } private String symbol; private int precision = -1; @@ -29,6 +46,8 @@ public class Asset extends GrapheneObject { private String description; private String dynamic_asset_data_id; private AssetOptions options; + private String bitasset_data_id; + private AssetType mAssetType; /** * Simple constructor @@ -100,6 +119,22 @@ public class Asset extends GrapheneObject { return this.options; } + public String getBitassetId(){ + return this.bitasset_data_id; + } + + public void setBitassetDataId(String id){ + this.bitasset_data_id = id; + } + + public AssetType getAssetType() { + return mAssetType; + } + + public void setAssetType(AssetType mAssetType) { + this.mAssetType = mAssetType; + } + @Override public int hashCode() { return super.hashCode(); @@ -114,14 +149,6 @@ public class Asset extends GrapheneObject { } } - /** - * Returns true if this is a witness-fed asset and all issuer permissions flags are set. - * @return: True if the asset is a smartcoin. - */ - public boolean isSmartcoin(){ - return this.options.getFlags() == 128 && options.getIssuerPermissions() == 511; - } - /** * Custom deserializer used to instantiate a simple version of the Asset class from the response of the * 'lookup_asset_symbols' API call. @@ -136,6 +163,7 @@ public class Asset extends GrapheneObject { int precision = object.get(KEY_PRECISION).getAsInt(); String issuer = object.get(KEY_ISSUER).getAsString(); JsonObject optionsJson = object.get(KEY_OPTIONS).getAsJsonObject(); + JsonElement bitassetDataId = object.get(KEY_BITASSET_DATA_ID); // Deserializing asset options AssetOptions options = new AssetOptions(); @@ -144,11 +172,13 @@ public class Asset extends GrapheneObject { options.setMaxMarketFee(UnsignedLong.valueOf(optionsJson.get(KEY_MARKET_FEE).getAsString())); options.setIssuerPermissions(optionsJson.get(KEY_ISSUER_PERMISSIONS).getAsLong()); options.setFlags(optionsJson.get(KEY_FLAGS).getAsInt()); - //TODO: Deserialize core_exchange_rate field Asset asset = new Asset(id, symbol, precision, issuer); asset.setAssetOptions(options); + if(bitassetDataId != null){ + asset.setBitassetDataId(bitassetDataId.getAsString()); + } return asset; } } diff --git a/src/main/java/de/bitsharesmunich/graphenej/AssetOptions.java b/src/main/java/de/bitsharesmunich/graphenej/AssetOptions.java index 16a281d..06fee0b 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/AssetOptions.java +++ b/src/main/java/de/bitsharesmunich/graphenej/AssetOptions.java @@ -6,8 +6,19 @@ import com.google.common.primitives.UnsignedLong; * Created by nelson on 12/13/16. */ public class AssetOptions { + // TODO: Use these constants instead of using cryptic constants like 128 and 511 + public static final int CHARGE_MARKET_FEE = 0x01; + public static final int WHITE_LIST = 0x02; + public static final int OVERRIDE_AUTHORITY = 0x04; + public static final int TRANSFER_RESTRICTED = 0x08; + public static final int DISABLE_FORCE_SETTLE = 0x10; + public static final int GLOBAL_SETTLE = 0x20; + public static final int DISABLE_CONFIDENTIAL = 0x40; + public static final int WITNESS_FED_ASSET = 0x80; + public static final int COMITEE_FED_ASSET = 0x100; + private UnsignedLong max_supply; - private long market_fee_percent; + private float market_fee_percent; private UnsignedLong max_market_fee; private long issuer_permissions; private int flags; @@ -23,15 +34,15 @@ public class AssetOptions { this.max_supply = max_supply; } - public long getMarketFeePercent() { + public float getMarketFeePercent() { return market_fee_percent; } - public void setMarketFeePercent(long market_fee_percent) { + public void setMarketFeePercent(float market_fee_percent) { this.market_fee_percent = market_fee_percent; } - public UnsignedLong getMax_market_fee() { + public UnsignedLong getMaxMarketFee() { return max_market_fee; } @@ -70,4 +81,4 @@ public class AssetOptions { public void setDescription(String description) { this.description = description; } -} +} \ No newline at end of file diff --git a/src/main/java/de/bitsharesmunich/graphenej/api/GetObjects.java b/src/main/java/de/bitsharesmunich/graphenej/api/GetObjects.java new file mode 100644 index 0000000..d57905e --- /dev/null +++ b/src/main/java/de/bitsharesmunich/graphenej/api/GetObjects.java @@ -0,0 +1,7 @@ +package de.bitsharesmunich.graphenej.api; + +/** + * Created by nelson on 1/8/17. + */ +public class GetObjects { +} diff --git a/src/main/java/de/bitsharesmunich/graphenej/models/AssetFeed.java b/src/main/java/de/bitsharesmunich/graphenej/models/AssetFeed.java new file mode 100644 index 0000000..2681e4c --- /dev/null +++ b/src/main/java/de/bitsharesmunich/graphenej/models/AssetFeed.java @@ -0,0 +1,7 @@ +package de.bitsharesmunich.graphenej.models; + +/** + * Created by nelson on 1/9/17. + */ +public class AssetFeed { +} diff --git a/src/main/java/de/bitsharesmunich/graphenej/models/BitAssetData.java b/src/main/java/de/bitsharesmunich/graphenej/models/BitAssetData.java new file mode 100644 index 0000000..eed3bbb --- /dev/null +++ b/src/main/java/de/bitsharesmunich/graphenej/models/BitAssetData.java @@ -0,0 +1,7 @@ +package de.bitsharesmunich.graphenej.models; + +/** + * Created by nelson on 1/8/17. + */ +public class BitAssetData { +}