From 7db116a89496572f5e0862309592effda508d582 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Fri, 13 Jan 2017 16:21:51 -0500 Subject: [PATCH] Introducing the AccountBalanceObject and expanding the GrapheneObject class --- .../graphenej/AccountBalanceObject.java | 23 ++++++ .../graphenej/GrapheneObject.java | 81 ++++++++++++++++++- .../bitsharesmunich/graphenej/ObjectType.java | 37 +++++++++ 3 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/bitsharesmunich/graphenej/AccountBalanceObject.java create mode 100644 src/main/java/de/bitsharesmunich/graphenej/ObjectType.java diff --git a/src/main/java/de/bitsharesmunich/graphenej/AccountBalanceObject.java b/src/main/java/de/bitsharesmunich/graphenej/AccountBalanceObject.java new file mode 100644 index 0000000..0443a29 --- /dev/null +++ b/src/main/java/de/bitsharesmunich/graphenej/AccountBalanceObject.java @@ -0,0 +1,23 @@ +package de.bitsharesmunich.graphenej.models; + +import java.io.Serializable; + +import de.bitsharesmunich.graphenej.GrapheneObject; + +/** + * Created by nelson on 1/12/17. + */ + +public class AccountBalanceObject extends GrapheneObject implements Serializable { + public static final String KEY_OWNER = "owner"; + public static final String KEY_ASSET_TYPE = "asset_type"; + public static final String KEY_BALANCE = "balance"; + + public String owner; + public String asset_type; + public long balance; + + public AccountBalanceObject(String id) { + super(id); + } +} diff --git a/src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java b/src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java index a30355b..9bfcd9c 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java +++ b/src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java @@ -1,7 +1,5 @@ package de.bitsharesmunich.graphenej; - - /** *

* Generic class used to represent a graphene object as defined in @@ -10,11 +8,16 @@ package de.bitsharesmunich.graphenej; * Created by nelson on 11/8/16. */ public class GrapheneObject { + public static final int PROTOCOL_SPACE = 1; + public static final int IMPLEMENTATION_SPACE = 2; + + protected String id; protected int space; protected int type; protected long instance; public GrapheneObject(String id){ + this.id = id; String[] parts = id.split("\\."); if(parts.length == 3){ this.space = Integer.parseInt(parts[0]); @@ -30,4 +33,78 @@ public class GrapheneObject { public String getObjectId(){ return String.format("%d.%d.%d", space, type, instance); } + + /** + * Returns the type of this object. + * @return: Instance of the ObjectType enum. + */ + public ObjectType getObjectType(){ + switch(space){ + case PROTOCOL_SPACE: + switch(type){ + case 1: + return ObjectType.BASE_OBJECT; + case 2: + return ObjectType.ACCOUNT_OBJECT; + case 3: + return ObjectType.ASSET_OBJECT; + case 4: + return ObjectType.FORCE_SETTLEMENT_OBJECT; + case 5: + return ObjectType.COMMITTEE_MEMBER_OBJECT; + case 6: + return ObjectType.WITNESS_OBJECT; + case 7: + return ObjectType.LIMIT_ORDER_OBJECT; + case 8: + return ObjectType.CALL_ORDER_OBJECT; + case 9: + return ObjectType.CUSTOM_OBJECT; + case 10: + return ObjectType.PROPOSAL_OBJECT; + case 11: + return ObjectType.OPERATION_HISTORY_OBJECT; + case 12: + return ObjectType.WITHDRAW_PERMISSION_OBJECT; + case 13: + return ObjectType.VESTING_BALANCE_OBJECT; + case 14: + return ObjectType.WORKER_OBJECT; + case 15: + return ObjectType.BALANCE_OBJECT; + } + case IMPLEMENTATION_SPACE: + switch(type){ + case 1: + return ObjectType.GLOBAL_PROPERTY_OBJECT; + case 2: + return ObjectType.DYNAMIC_GLOBAL_PROPERTY_OBJECT; + case 3: + return ObjectType.ASSET_DYNAMIC_DATA; + case 4: + return ObjectType.ASSET_BITASSET_DATA; + case 5: + return ObjectType.ACCOUNT_BALANCE_OBJECT; + case 6: + return ObjectType.ACCOUNT_STATISTICS_OBJECT; + case 7: + return ObjectType.TRANSACTION_OBJECT; + case 8: + return ObjectType.BLOCK_SUMMARY_OBJECT; + case 9: + return ObjectType.ACCOUNT_TRANSACTION_HISTORY_OBJECT; + case 10: + return ObjectType.BLINDED_BALANCE_OBJECT; + case 11: + return ObjectType.CHAIN_PROPERTY_OBJECT; + case 12: + return ObjectType.WITNESS_SCHEDULE_OBJECT; + case 13: + return ObjectType.BUDGET_RECORD_OBJECT; + case 14: + return ObjectType.SPECIAL_AUTHORITY_OBJECT; + } + } + return null; + } } diff --git a/src/main/java/de/bitsharesmunich/graphenej/ObjectType.java b/src/main/java/de/bitsharesmunich/graphenej/ObjectType.java new file mode 100644 index 0000000..d39c32a --- /dev/null +++ b/src/main/java/de/bitsharesmunich/graphenej/ObjectType.java @@ -0,0 +1,37 @@ +package de.bitsharesmunich.graphenej; + +/** + * Created by nelson on 1/12/17. + */ + +public enum ObjectType { + BASE_OBJECT, + ACCOUNT_OBJECT, + ASSET_OBJECT, + FORCE_SETTLEMENT_OBJECT, + COMMITTEE_MEMBER_OBJECT, + WITNESS_OBJECT, + LIMIT_ORDER_OBJECT, + CALL_ORDER_OBJECT, + CUSTOM_OBJECT, + PROPOSAL_OBJECT, + OPERATION_HISTORY_OBJECT, + WITHDRAW_PERMISSION_OBJECT, + VESTING_BALANCE_OBJECT, + WORKER_OBJECT, + BALANCE_OBJECT, + GLOBAL_PROPERTY_OBJECT, + DYNAMIC_GLOBAL_PROPERTY_OBJECT, + ASSET_DYNAMIC_DATA, + ASSET_BITASSET_DATA, + ACCOUNT_BALANCE_OBJECT, + ACCOUNT_STATISTICS_OBJECT, + TRANSACTION_OBJECT, + BLOCK_SUMMARY_OBJECT, + ACCOUNT_TRANSACTION_HISTORY_OBJECT, + BLINDED_BALANCE_OBJECT, + CHAIN_PROPERTY_OBJECT, + WITNESS_SCHEDULE_OBJECT, + BUDGET_RECORD_OBJECT, + SPECIAL_AUTHORITY_OBJECT +}