Expanding Asset and AssetOptions classes
This commit is contained in:
parent
7cd0a76e2e
commit
1929e18e06
5 changed files with 77 additions and 15 deletions
|
@ -1,7 +1,11 @@
|
||||||
package de.bitsharesmunich.graphenej;
|
package de.bitsharesmunich.graphenej;
|
||||||
|
|
||||||
import com.google.common.primitives.UnsignedLong;
|
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;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
@ -9,6 +13,8 @@ import java.lang.reflect.Type;
|
||||||
* Created by nelson on 11/9/16.
|
* Created by nelson on 11/9/16.
|
||||||
*/
|
*/
|
||||||
public class Asset extends GrapheneObject {
|
public class Asset extends GrapheneObject {
|
||||||
|
public final static String TAG = "Asset";
|
||||||
|
|
||||||
public static final String KEY_ID = "id";
|
public static final String KEY_ID = "id";
|
||||||
public static final String KEY_SYMBOL = "symbol";
|
public static final String KEY_SYMBOL = "symbol";
|
||||||
public static final String KEY_PRECISION = "precision";
|
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_CORE_EXCHANGE_RATE = "core_exchange_rate";
|
||||||
public static final String KEY_DESCRIPTION = "description";
|
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_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 String symbol;
|
||||||
private int precision = -1;
|
private int precision = -1;
|
||||||
|
@ -29,6 +46,8 @@ public class Asset extends GrapheneObject {
|
||||||
private String description;
|
private String description;
|
||||||
private String dynamic_asset_data_id;
|
private String dynamic_asset_data_id;
|
||||||
private AssetOptions options;
|
private AssetOptions options;
|
||||||
|
private String bitasset_data_id;
|
||||||
|
private AssetType mAssetType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple constructor
|
* Simple constructor
|
||||||
|
@ -100,6 +119,22 @@ public class Asset extends GrapheneObject {
|
||||||
return this.options;
|
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
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return super.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
|
* Custom deserializer used to instantiate a simple version of the Asset class from the response of the
|
||||||
* 'lookup_asset_symbols' API call.
|
* 'lookup_asset_symbols' API call.
|
||||||
|
@ -136,6 +163,7 @@ public class Asset extends GrapheneObject {
|
||||||
int precision = object.get(KEY_PRECISION).getAsInt();
|
int precision = object.get(KEY_PRECISION).getAsInt();
|
||||||
String issuer = object.get(KEY_ISSUER).getAsString();
|
String issuer = object.get(KEY_ISSUER).getAsString();
|
||||||
JsonObject optionsJson = object.get(KEY_OPTIONS).getAsJsonObject();
|
JsonObject optionsJson = object.get(KEY_OPTIONS).getAsJsonObject();
|
||||||
|
JsonElement bitassetDataId = object.get(KEY_BITASSET_DATA_ID);
|
||||||
|
|
||||||
// Deserializing asset options
|
// Deserializing asset options
|
||||||
AssetOptions options = new AssetOptions();
|
AssetOptions options = new AssetOptions();
|
||||||
|
@ -144,11 +172,13 @@ public class Asset extends GrapheneObject {
|
||||||
options.setMaxMarketFee(UnsignedLong.valueOf(optionsJson.get(KEY_MARKET_FEE).getAsString()));
|
options.setMaxMarketFee(UnsignedLong.valueOf(optionsJson.get(KEY_MARKET_FEE).getAsString()));
|
||||||
options.setIssuerPermissions(optionsJson.get(KEY_ISSUER_PERMISSIONS).getAsLong());
|
options.setIssuerPermissions(optionsJson.get(KEY_ISSUER_PERMISSIONS).getAsLong());
|
||||||
options.setFlags(optionsJson.get(KEY_FLAGS).getAsInt());
|
options.setFlags(optionsJson.get(KEY_FLAGS).getAsInt());
|
||||||
|
|
||||||
//TODO: Deserialize core_exchange_rate field
|
//TODO: Deserialize core_exchange_rate field
|
||||||
|
|
||||||
Asset asset = new Asset(id, symbol, precision, issuer);
|
Asset asset = new Asset(id, symbol, precision, issuer);
|
||||||
asset.setAssetOptions(options);
|
asset.setAssetOptions(options);
|
||||||
|
if(bitassetDataId != null){
|
||||||
|
asset.setBitassetDataId(bitassetDataId.getAsString());
|
||||||
|
}
|
||||||
return asset;
|
return asset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,19 @@ import com.google.common.primitives.UnsignedLong;
|
||||||
* Created by nelson on 12/13/16.
|
* Created by nelson on 12/13/16.
|
||||||
*/
|
*/
|
||||||
public class AssetOptions {
|
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 UnsignedLong max_supply;
|
||||||
private long market_fee_percent;
|
private float market_fee_percent;
|
||||||
private UnsignedLong max_market_fee;
|
private UnsignedLong max_market_fee;
|
||||||
private long issuer_permissions;
|
private long issuer_permissions;
|
||||||
private int flags;
|
private int flags;
|
||||||
|
@ -23,15 +34,15 @@ public class AssetOptions {
|
||||||
this.max_supply = max_supply;
|
this.max_supply = max_supply;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getMarketFeePercent() {
|
public float getMarketFeePercent() {
|
||||||
return market_fee_percent;
|
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;
|
this.market_fee_percent = market_fee_percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnsignedLong getMax_market_fee() {
|
public UnsignedLong getMaxMarketFee() {
|
||||||
return max_market_fee;
|
return max_market_fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package de.bitsharesmunich.graphenej.api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nelson on 1/8/17.
|
||||||
|
*/
|
||||||
|
public class GetObjects {
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package de.bitsharesmunich.graphenej.models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nelson on 1/9/17.
|
||||||
|
*/
|
||||||
|
public class AssetFeed {
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package de.bitsharesmunich.graphenej.models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by nelson on 1/8/17.
|
||||||
|
*/
|
||||||
|
public class BitAssetData {
|
||||||
|
}
|
Loading…
Reference in a new issue