Introducing the AccountBalanceObject and expanding the GrapheneObject class

This commit is contained in:
Nelson R. Perez 2017-01-13 16:21:51 -05:00
parent af653d376a
commit 7db116a894
3 changed files with 139 additions and 2 deletions

View file

@ -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);
}
}

View file

@ -1,7 +1,5 @@
package de.bitsharesmunich.graphenej; package de.bitsharesmunich.graphenej;
/** /**
* <p> * <p>
* Generic class used to represent a graphene object as defined in * 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. * Created by nelson on 11/8/16.
*/ */
public class GrapheneObject { 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 space;
protected int type; protected int type;
protected long instance; protected long instance;
public GrapheneObject(String id){ public GrapheneObject(String id){
this.id = id;
String[] parts = id.split("\\."); String[] parts = id.split("\\.");
if(parts.length == 3){ if(parts.length == 3){
this.space = Integer.parseInt(parts[0]); this.space = Integer.parseInt(parts[0]);
@ -30,4 +33,78 @@ public class GrapheneObject {
public String getObjectId(){ public String getObjectId(){
return String.format("%d.%d.%d", space, type, instance); 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;
}
} }

View file

@ -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
}