Added the get asset by name
Update equivalent value url. If we are going to use the testnet the equivalent value has to be retrieved from the main net. Update docs and code
This commit is contained in:
parent
a9ec777e5c
commit
000be8ab51
15 changed files with 334 additions and 60 deletions
|
@ -55,7 +55,7 @@ dependencies {
|
||||||
compile 'com.neovisionaries:nv-websocket-client:1.30'
|
compile 'com.neovisionaries:nv-websocket-client:1.30'
|
||||||
compile 'org.tukaani:xz:1.6'
|
compile 'org.tukaani:xz:1.6'
|
||||||
compile 'com.jakewharton:butterknife:8.8.1'
|
compile 'com.jakewharton:butterknife:8.8.1'
|
||||||
compile 'com.github.bilthon:graphenej:0.4.6-alpha0'
|
compile 'com.github.bilthon:graphenej:0.4.6-alpha1'
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
testCompile 'org.mockito:mockito-core:1.10.19'
|
testCompile 'org.mockito:mockito-core:1.10.19'
|
||||||
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0-alpha9-1'
|
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0-alpha9-1'
|
||||||
|
|
|
@ -1,15 +1,28 @@
|
||||||
package cy.agorise.crystalwallet.apigenerator;
|
package cy.agorise.crystalwallet.apigenerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This is a request to be passed to an api generator, when an answer is expected.
|
||||||
|
*
|
||||||
|
*
|
||||||
* Created by henry on 27/9/2017.
|
* Created by henry on 27/9/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ApiRequest {
|
public class ApiRequest {
|
||||||
|
/**
|
||||||
|
* The id of this api request
|
||||||
|
*/
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The listener of this apirequest, to be passed the answer
|
||||||
|
*/
|
||||||
ApiRequestListener listener;
|
ApiRequestListener listener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic constructor
|
||||||
|
* @param id The id of this request
|
||||||
|
* @param listener The listener for this request
|
||||||
|
*/
|
||||||
public ApiRequest(int id, ApiRequestListener listener) {
|
public ApiRequest(int id, ApiRequestListener listener) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
|
|
@ -1,12 +1,24 @@
|
||||||
package cy.agorise.crystalwallet.apigenerator;
|
package cy.agorise.crystalwallet.apigenerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This listener and apirquest answer
|
||||||
|
*
|
||||||
* Created by henry on 27/9/2017.
|
* Created by henry on 27/9/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface ApiRequestListener {
|
public interface ApiRequestListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call when the function returns successfully
|
||||||
|
* @param answer The answer, this object depends on the kind of request is made to the api
|
||||||
|
* @param idPetition the id of the ApiRequest petition
|
||||||
|
*/
|
||||||
public void success(Object answer, int idPetition);
|
public void success(Object answer, int idPetition);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call when the function fails
|
||||||
|
* @param idPetition the id of the ApiRequest petition
|
||||||
|
*/
|
||||||
public void fail(int idPetition);
|
public void fail(int idPetition);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package cy.agorise.crystalwallet.apigenerator;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This maanges the calls for the creation of accounts using the bitshares faucet
|
||||||
|
*
|
||||||
* Created by henry on 15/10/2017.
|
* Created by henry on 15/10/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -15,9 +17,11 @@ public abstract class BitsharesFaucetApiGenerator {
|
||||||
* @param ownerKey The owner key public address
|
* @param ownerKey The owner key public address
|
||||||
* @param activeKey The active key public address
|
* @param activeKey The active key public address
|
||||||
* @param memoKey the memo key public address
|
* @param memoKey the memo key public address
|
||||||
|
* @param url The url of the faucet
|
||||||
* @return The bitshares id of the registered account, or null
|
* @return The bitshares id of the registered account, or null
|
||||||
*/
|
*/
|
||||||
public static String registerBitsharesAccount(String accountName, String ownerKey, String activeKey, String memoKey){
|
public static String registerBitsharesAccount(String accountName, String ownerKey,
|
||||||
|
String activeKey, String memoKey, String url){
|
||||||
CreateAccountPetition petition = new CreateAccountPetition();
|
CreateAccountPetition petition = new CreateAccountPetition();
|
||||||
Account account = new Account();
|
Account account = new Account();
|
||||||
account.name=accountName;
|
account.name=accountName;
|
||||||
|
@ -33,15 +37,33 @@ public abstract class BitsharesFaucetApiGenerator {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class used for the json serializer. this represents a peitition
|
||||||
|
*/
|
||||||
private static class CreateAccountPetition{
|
private static class CreateAccountPetition{
|
||||||
|
// The account to be created
|
||||||
Account account;
|
Account account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class used for the json serializer. This represents the account on the petition
|
||||||
|
*/
|
||||||
private static class Account{
|
private static class Account{
|
||||||
|
/**
|
||||||
|
* The name of the account
|
||||||
|
*/
|
||||||
String name;
|
String name;
|
||||||
|
/**
|
||||||
|
* The owner key address
|
||||||
|
*/
|
||||||
String owner_key;
|
String owner_key;
|
||||||
|
/**
|
||||||
|
* The active key address
|
||||||
|
*/
|
||||||
String active_key;
|
String active_key;
|
||||||
|
/**
|
||||||
|
* The memo key address
|
||||||
|
*/
|
||||||
String memo_key;
|
String memo_key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,7 @@ import cy.agorise.graphenej.api.GetAccounts;
|
||||||
import cy.agorise.graphenej.api.GetBlockHeader;
|
import cy.agorise.graphenej.api.GetBlockHeader;
|
||||||
import cy.agorise.graphenej.api.GetKeyReferences;
|
import cy.agorise.graphenej.api.GetKeyReferences;
|
||||||
import cy.agorise.graphenej.api.GetLimitOrders;
|
import cy.agorise.graphenej.api.GetLimitOrders;
|
||||||
import cy.agorise.graphenej.api.GetMarketHistory;
|
|
||||||
import cy.agorise.graphenej.api.GetRelativeAccountHistory;
|
import cy.agorise.graphenej.api.GetRelativeAccountHistory;
|
||||||
import cy.agorise.graphenej.api.ListAssets;
|
|
||||||
import cy.agorise.graphenej.api.LookupAssetSymbols;
|
import cy.agorise.graphenej.api.LookupAssetSymbols;
|
||||||
import cy.agorise.graphenej.api.SubscriptionMessagesHub;
|
import cy.agorise.graphenej.api.SubscriptionMessagesHub;
|
||||||
import cy.agorise.graphenej.api.TransactionBroadcastSequence;
|
import cy.agorise.graphenej.api.TransactionBroadcastSequence;
|
||||||
|
@ -58,10 +56,11 @@ import cy.agorise.graphenej.models.WitnessResponse;
|
||||||
public abstract class GrapheneApiGenerator {
|
public abstract class GrapheneApiGenerator {
|
||||||
|
|
||||||
//TODO network connections
|
//TODO network connections
|
||||||
//TODO make to work with all Graphene stype, not only bitshares
|
//TODO make to work with all Graphene type, not only bitshares
|
||||||
private static String url = "http://128.0.69.157:8090";
|
public static String url = "http://128.0.69.157:8090";
|
||||||
|
private static String equivalentUrl = "http://128.0.69.157:8090";
|
||||||
|
|
||||||
// The meesage broker for bitshares
|
// The message broker for bitshares
|
||||||
private static SubscriptionMessagesHub bitsharesSubscriptionHub = new SubscriptionMessagesHub("", "", true, new NodeErrorListener() {
|
private static SubscriptionMessagesHub bitsharesSubscriptionHub = new SubscriptionMessagesHub("", "", true, new NodeErrorListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onError(BaseResponse.Error error) {
|
public void onError(BaseResponse.Error error) {
|
||||||
|
@ -69,7 +68,13 @@ public abstract class GrapheneApiGenerator {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The subscription thread for the real time updates
|
||||||
|
*/
|
||||||
private static WebSocketThread subscriptionThread = new WebSocketThread(bitsharesSubscriptionHub,url);
|
private static WebSocketThread subscriptionThread = new WebSocketThread(bitsharesSubscriptionHub,url);
|
||||||
|
/**
|
||||||
|
* This is used for manager each listener in the subscription thread
|
||||||
|
*/
|
||||||
private static HashMap<Long,SubscriptionListener> currentBitsharesListener = new HashMap<>();
|
private static HashMap<Long,SubscriptionListener> currentBitsharesListener = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,7 +84,8 @@ public abstract class GrapheneApiGenerator {
|
||||||
* @param request The Api request object, to answer this petition
|
* @param request The Api request object, to answer this petition
|
||||||
*/
|
*/
|
||||||
public static void getAccountById(String accountId, final ApiRequest request){
|
public static void getAccountById(String accountId, final ApiRequest request){
|
||||||
WebSocketThread thread = new WebSocketThread(new GetAccounts(accountId, new WitnessResponseListener() {
|
WebSocketThread thread = new WebSocketThread(new GetAccounts(accountId,
|
||||||
|
new WitnessResponseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WitnessResponse response) {
|
public void onSuccess(WitnessResponse response) {
|
||||||
if (response.result.getClass() == ArrayList.class) {
|
if (response.result.getClass() == ArrayList.class) {
|
||||||
|
@ -88,7 +94,6 @@ public abstract class GrapheneApiGenerator {
|
||||||
if (list.get(0).getClass() == AccountProperties.class) {
|
if (list.get(0).getClass() == AccountProperties.class) {
|
||||||
request.getListener().success(list.get(0),request.getId());
|
request.getListener().success(list.get(0),request.getId());
|
||||||
return;
|
return;
|
||||||
//TODO answer a crystal model
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +115,8 @@ public abstract class GrapheneApiGenerator {
|
||||||
* @param request The Api request object, to answer this petition
|
* @param request The Api request object, to answer this petition
|
||||||
*/
|
*/
|
||||||
public static void getAccountByOwnerOrActiveAddress(Address address, final ApiRequest request){
|
public static void getAccountByOwnerOrActiveAddress(Address address, final ApiRequest request){
|
||||||
WebSocketThread thread = new WebSocketThread(new GetKeyReferences(address, true, new WitnessResponseListener() {
|
WebSocketThread thread = new WebSocketThread(new GetKeyReferences(address, true,
|
||||||
|
new WitnessResponseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WitnessResponse response) {
|
public void onSuccess(WitnessResponse response) {
|
||||||
final List<List<UserAccount>> resp = (List<List<UserAccount>>) response.result;
|
final List<List<UserAccount>> resp = (List<List<UserAccount>>) response.result;
|
||||||
|
@ -140,12 +146,13 @@ public abstract class GrapheneApiGenerator {
|
||||||
* @param limit the maximun transactions to retrieve
|
* @param limit the maximun transactions to retrieve
|
||||||
* @param request The Api request object, to answer this petition
|
* @param request The Api request object, to answer this petition
|
||||||
*/
|
*/
|
||||||
public static void getAccountTransaction(String accountGrapheneId, int start, int stop, int limit, final ApiRequest request){
|
public static void getAccountTransaction(String accountGrapheneId, int start, int stop,
|
||||||
WebSocketThread thread = new WebSocketThread(new GetRelativeAccountHistory(new UserAccount(accountGrapheneId), start, limit, stop, new WitnessResponseListener() {
|
int limit, final ApiRequest request){
|
||||||
|
WebSocketThread thread = new WebSocketThread(new GetRelativeAccountHistory(new UserAccount(accountGrapheneId),
|
||||||
|
start, limit, stop, new WitnessResponseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WitnessResponse response) {
|
public void onSuccess(WitnessResponse response) {
|
||||||
WitnessResponse<List<HistoricalTransfer>> resp = response;
|
request.getListener().success(response.result,request.getId());
|
||||||
request.getListener().success(resp.result,request.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -163,10 +170,11 @@ public abstract class GrapheneApiGenerator {
|
||||||
* @param request The Api request object, to answer this petition
|
* @param request The Api request object, to answer this petition
|
||||||
*/
|
*/
|
||||||
public static void getAccountByName(String accountName, final ApiRequest request){
|
public static void getAccountByName(String accountName, final ApiRequest request){
|
||||||
WebSocketThread thread = new WebSocketThread(new GetAccountByName(accountName, new WitnessResponseListener() {
|
WebSocketThread thread = new WebSocketThread(new GetAccountByName(accountName,
|
||||||
|
new WitnessResponseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WitnessResponse response) {
|
public void onSuccess(WitnessResponse response) {
|
||||||
AccountProperties accountProperties = ((WitnessResponse<AccountProperties>) response).result;
|
AccountProperties accountProperties = (AccountProperties)response.result;
|
||||||
if(accountProperties == null){
|
if(accountProperties == null){
|
||||||
request.getListener().fail(request.getId());
|
request.getListener().fail(request.getId());
|
||||||
}else{
|
}else{
|
||||||
|
@ -189,10 +197,11 @@ public abstract class GrapheneApiGenerator {
|
||||||
* @param request The Api request object, to answer this petition
|
* @param request The Api request object, to answer this petition
|
||||||
*/
|
*/
|
||||||
public static void getAccountIdByName(String accountName, final ApiRequest request){
|
public static void getAccountIdByName(String accountName, final ApiRequest request){
|
||||||
WebSocketThread thread = new WebSocketThread(new GetAccountByName(accountName, new WitnessResponseListener() {
|
WebSocketThread thread = new WebSocketThread(new GetAccountByName(accountName,
|
||||||
|
new WitnessResponseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WitnessResponse response) {
|
public void onSuccess(WitnessResponse response) {
|
||||||
AccountProperties accountProperties = ((WitnessResponse<AccountProperties>) response).result;
|
AccountProperties accountProperties = (AccountProperties)response.result;
|
||||||
if(accountProperties == null){
|
if(accountProperties == null){
|
||||||
request.getListener().success(null,request.getId());
|
request.getListener().success(null,request.getId());
|
||||||
}else{
|
}else{
|
||||||
|
@ -208,8 +217,17 @@ public abstract class GrapheneApiGenerator {
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void broadcastTransaction(Transaction transaction, Asset feeAsset, final ApiRequest request){
|
/**
|
||||||
WebSocketThread thread = new WebSocketThread(new TransactionBroadcastSequence(transaction, feeAsset, new WitnessResponseListener() {
|
* Broadcast a transaction, this is use for sending funds
|
||||||
|
*
|
||||||
|
* @param transaction The graphene transaction
|
||||||
|
* @param feeAsset The feeAseet, this needs only the id of the asset
|
||||||
|
* @param request the api request object, to answer this petition
|
||||||
|
*/
|
||||||
|
public static void broadcastTransaction(Transaction transaction, Asset feeAsset,
|
||||||
|
final ApiRequest request){
|
||||||
|
WebSocketThread thread = new WebSocketThread(new TransactionBroadcastSequence(transaction,
|
||||||
|
feeAsset, new WitnessResponseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WitnessResponse response) {
|
public void onSuccess(WitnessResponse response) {
|
||||||
request.getListener().success(true,request.getId());
|
request.getListener().success(true,request.getId());
|
||||||
|
@ -223,16 +241,16 @@ public abstract class GrapheneApiGenerator {
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This gets the asset information using only the asset name
|
||||||
|
*
|
||||||
|
* @param assetNames The list of the names of the assets to be retrieve
|
||||||
|
* @param request the api request object, to answer this petition
|
||||||
|
*/
|
||||||
public static void getAssetByName(ArrayList<String> assetNames, final ApiRequest request){
|
public static void getAssetByName(ArrayList<String> assetNames, final ApiRequest request){
|
||||||
//TODO the graphenej library needs a way to creates the Asset object only with the symbol
|
|
||||||
ArrayList<Asset> assets = new ArrayList<>();
|
WebSocketThread thread = new WebSocketThread(new LookupAssetSymbols(assetNames,true,
|
||||||
for(String assetName : assetNames){
|
new WitnessResponseListener() {
|
||||||
Asset asset = new Asset("",assetName,-1);
|
|
||||||
assets.add(asset);
|
|
||||||
}
|
|
||||||
//TODO the graphenj library needs to add the lookupAssetSymbols to be able to search the asset by symbol
|
|
||||||
// this can be done with the same lookupassetsymbol, but passing only the symbol not the objetcid
|
|
||||||
WebSocketThread thread = new WebSocketThread(new LookupAssetSymbols(assets, new WitnessResponseListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WitnessResponse response) {
|
public void onSuccess(WitnessResponse response) {
|
||||||
List<Asset> assets = (List<Asset>) response.result;
|
List<Asset> assets = (List<Asset>) response.result;
|
||||||
|
@ -241,6 +259,7 @@ public abstract class GrapheneApiGenerator {
|
||||||
}else{
|
}else{
|
||||||
ArrayList<BitsharesAsset> responseAssets = new ArrayList<>();
|
ArrayList<BitsharesAsset> responseAssets = new ArrayList<>();
|
||||||
for(Asset asset: assets){
|
for(Asset asset: assets){
|
||||||
|
//TODO asset type
|
||||||
BitsharesAsset.Type assetType = BitsharesAsset.Type.UIA;
|
BitsharesAsset.Type assetType = BitsharesAsset.Type.UIA;
|
||||||
/*if(asset.getAssetType().equals(Asset.AssetType.CORE_ASSET)){
|
/*if(asset.getAssetType().equals(Asset.AssetType.CORE_ASSET)){
|
||||||
assetType = BitsharesAsset.Type.CORE;
|
assetType = BitsharesAsset.Type.CORE;
|
||||||
|
@ -251,7 +270,8 @@ public abstract class GrapheneApiGenerator {
|
||||||
}else if(asset.getAssetType().equals(Asset.AssetType.PREDICTION_MARKET)){
|
}else if(asset.getAssetType().equals(Asset.AssetType.PREDICTION_MARKET)){
|
||||||
assetType = BitsharesAsset.Type.PREDICTION_MARKET;
|
assetType = BitsharesAsset.Type.PREDICTION_MARKET;
|
||||||
}*/
|
}*/
|
||||||
BitsharesAsset responseAsset = new BitsharesAsset(asset.getSymbol(),asset.getPrecision(),asset.getObjectId(),assetType);
|
BitsharesAsset responseAsset = new BitsharesAsset(asset.getSymbol(),
|
||||||
|
asset.getPrecision(),asset.getObjectId(),assetType);
|
||||||
responseAssets.add(responseAsset);
|
responseAssets.add(responseAsset);
|
||||||
}
|
}
|
||||||
request.getListener().success(responseAssets,request.getId());
|
request.getListener().success(responseAssets,request.getId());
|
||||||
|
@ -266,6 +286,11 @@ public abstract class GrapheneApiGenerator {
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the asset ifnormation using the id of the net
|
||||||
|
* @param assetIds The list of the ids to retrieve
|
||||||
|
* @param request the api request object, to answer this petition
|
||||||
|
*/
|
||||||
public static void getAssetById(ArrayList<String> assetIds, final ApiRequest request){
|
public static void getAssetById(ArrayList<String> assetIds, final ApiRequest request){
|
||||||
ArrayList<Asset> assets = new ArrayList<>();
|
ArrayList<Asset> assets = new ArrayList<>();
|
||||||
for(String assetId : assetIds){
|
for(String assetId : assetIds){
|
||||||
|
@ -273,7 +298,7 @@ public abstract class GrapheneApiGenerator {
|
||||||
assets.add(asset);
|
assets.add(asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketThread thread = new WebSocketThread(new LookupAssetSymbols(assets, new WitnessResponseListener() {
|
WebSocketThread thread = new WebSocketThread(new LookupAssetSymbols(assets,true, new WitnessResponseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WitnessResponse response) {
|
public void onSuccess(WitnessResponse response) {
|
||||||
List<Asset> assets = (List<Asset>) response.result;
|
List<Asset> assets = (List<Asset>) response.result;
|
||||||
|
@ -282,6 +307,7 @@ public abstract class GrapheneApiGenerator {
|
||||||
}else{
|
}else{
|
||||||
ArrayList<BitsharesAsset> responseAssets = new ArrayList<>();
|
ArrayList<BitsharesAsset> responseAssets = new ArrayList<>();
|
||||||
for(Asset asset: assets){
|
for(Asset asset: assets){
|
||||||
|
//TODO asset type
|
||||||
BitsharesAsset.Type assetType = BitsharesAsset.Type.UIA;
|
BitsharesAsset.Type assetType = BitsharesAsset.Type.UIA;
|
||||||
/*if(asset.getAssetType().equals(Asset.AssetType.CORE_ASSET)){
|
/*if(asset.getAssetType().equals(Asset.AssetType.CORE_ASSET)){
|
||||||
assetType = BitsharesAsset.Type.CORE;
|
assetType = BitsharesAsset.Type.CORE;
|
||||||
|
@ -292,7 +318,8 @@ public abstract class GrapheneApiGenerator {
|
||||||
}else if(asset.getAssetType().equals(Asset.AssetType.PREDICTION_MARKET)){
|
}else if(asset.getAssetType().equals(Asset.AssetType.PREDICTION_MARKET)){
|
||||||
assetType = BitsharesAsset.Type.PREDICTION_MARKET;
|
assetType = BitsharesAsset.Type.PREDICTION_MARKET;
|
||||||
}*/
|
}*/
|
||||||
BitsharesAsset responseAsset = new BitsharesAsset(asset.getSymbol(),asset.getPrecision(),asset.getObjectId(),assetType);
|
BitsharesAsset responseAsset = new BitsharesAsset(asset.getSymbol(),
|
||||||
|
asset.getPrecision(),asset.getObjectId(),assetType);
|
||||||
responseAssets.add(responseAsset);
|
responseAssets.add(responseAsset);
|
||||||
}
|
}
|
||||||
request.getListener().success(responseAssets,request.getId());
|
request.getListener().success(responseAssets,request.getId());
|
||||||
|
@ -307,7 +334,15 @@ public abstract class GrapheneApiGenerator {
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void subscribeBitsharesAccount(final long accountId, final String accountBitsharesId, final Context context){
|
/**
|
||||||
|
* Subscribe a bitshares account to receive real time updates
|
||||||
|
*
|
||||||
|
* @param accountId The id opf the database of the account
|
||||||
|
* @param accountBitsharesId The bitshares id of the account
|
||||||
|
* @param context The android context of this application
|
||||||
|
*/
|
||||||
|
public static void subscribeBitsharesAccount(final long accountId, final String accountBitsharesId,
|
||||||
|
final Context context){
|
||||||
if(!currentBitsharesListener.containsKey(accountId)){
|
if(!currentBitsharesListener.containsKey(accountId)){
|
||||||
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
|
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
|
||||||
final CryptoCoinBalanceDao balanceDao = db.cryptoCoinBalanceDao();
|
final CryptoCoinBalanceDao balanceDao = db.cryptoCoinBalanceDao();
|
||||||
|
@ -380,17 +415,29 @@ public abstract class GrapheneApiGenerator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cancelBitsharesAccountSubcriptions(){
|
/**
|
||||||
|
* Cancels all bitshares account subscriptions
|
||||||
|
*/
|
||||||
|
public static void cancelBitsharesAccountSubscriptions(){
|
||||||
bitsharesSubscriptionHub.cancelSubscriptions();
|
bitsharesSubscriptionHub.cancelSubscriptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void getAccountBalance(final long accountId, final String accountGrapheneId, final Context context){
|
/**
|
||||||
|
* Retrieve the account balance of an account
|
||||||
|
*
|
||||||
|
* @param accountId The dataabase id of the account
|
||||||
|
* @param accountGrapheneId The bitshares id of the account
|
||||||
|
* @param context The android context of this application
|
||||||
|
*/
|
||||||
|
public static void getAccountBalance(final long accountId, final String accountGrapheneId,
|
||||||
|
final Context context){
|
||||||
|
|
||||||
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
|
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
|
||||||
final CryptoCoinBalanceDao balanceDao = db.cryptoCoinBalanceDao();
|
final CryptoCoinBalanceDao balanceDao = db.cryptoCoinBalanceDao();
|
||||||
final BitsharesAssetDao bitsharesAssetDao = db.bitsharesAssetDao();
|
final BitsharesAssetDao bitsharesAssetDao = db.bitsharesAssetDao();
|
||||||
final CryptoCurrencyDao cryptoCurrencyDao = db.cryptoCurrencyDao();
|
final CryptoCurrencyDao cryptoCurrencyDao = db.cryptoCurrencyDao();
|
||||||
WebSocketThread thread = new WebSocketThread(new GetAccountBalances(new UserAccount(accountGrapheneId), new ArrayList<Asset>(), new WitnessResponseListener() {
|
WebSocketThread thread = new WebSocketThread(new GetAccountBalances(new UserAccount(accountGrapheneId),
|
||||||
|
new ArrayList<Asset>(), new WitnessResponseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WitnessResponse response) {
|
public void onSuccess(WitnessResponse response) {
|
||||||
List<AssetAmount> balances = (List<AssetAmount>) response.result;
|
List<AssetAmount> balances = (List<AssetAmount>) response.result;
|
||||||
|
@ -440,6 +487,12 @@ public abstract class GrapheneApiGenerator {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the date time of a block header
|
||||||
|
*
|
||||||
|
* @param blockHeader The block header to retrieve the date time
|
||||||
|
* @param request the api request object, to answer this petition
|
||||||
|
*/
|
||||||
public static void getBlockHeaderTime(long blockHeader, final ApiRequest request){
|
public static void getBlockHeaderTime(long blockHeader, final ApiRequest request){
|
||||||
WebSocketThread thread = new WebSocketThread(new GetBlockHeader(blockHeader, new WitnessResponseListener() {
|
WebSocketThread thread = new WebSocketThread(new GetBlockHeader(blockHeader, new WitnessResponseListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -460,8 +513,16 @@ public abstract class GrapheneApiGenerator {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void getEquivalentValue(String baseId, String quoteId, final ApiRequest request){
|
/**
|
||||||
WebSocketThread thread = new WebSocketThread(new GetLimitOrders(baseId, quoteId, 100, new WitnessResponseListener() {
|
* Gets a single equivalent value
|
||||||
|
*
|
||||||
|
* @param baseId The base asset bistshares id
|
||||||
|
* @param quoteId the quote asset bitshares id
|
||||||
|
* @param request the api request object, to answer this petition
|
||||||
|
*/
|
||||||
|
public static void getEquivalentValue(final String baseId, String quoteId, final ApiRequest request){
|
||||||
|
WebSocketThread thread = new WebSocketThread(new GetLimitOrders(baseId, quoteId, 10,
|
||||||
|
new WitnessResponseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WitnessResponse response) {
|
public void onSuccess(WitnessResponse response) {
|
||||||
List<LimitOrder> orders = (List<LimitOrder>) response.result;
|
List<LimitOrder> orders = (List<LimitOrder>) response.result;
|
||||||
|
@ -469,10 +530,13 @@ public abstract class GrapheneApiGenerator {
|
||||||
//TODO indirect equivalent value
|
//TODO indirect equivalent value
|
||||||
}
|
}
|
||||||
for(LimitOrder order : orders){
|
for(LimitOrder order : orders){
|
||||||
Converter converter = new Converter();
|
if(order.getSellPrice().base.getAsset().getBitassetId().equals(baseId)) {
|
||||||
double equiValue = converter.getConversionRate(order.getSellPrice(),Converter.BASE_TO_QUOTE);
|
Converter converter = new Converter();
|
||||||
request.getListener().success(equiValue,request.getId());
|
double equiValue = converter.getConversionRate(order.getSellPrice(),
|
||||||
break;
|
Converter.BASE_TO_QUOTE);
|
||||||
|
request.getListener().success(equiValue, request.getId());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,20 +544,42 @@ public abstract class GrapheneApiGenerator {
|
||||||
public void onError(BaseResponse.Error error) {
|
public void onError(BaseResponse.Error error) {
|
||||||
request.getListener().fail(request.getId());
|
request.getListener().fail(request.getId());
|
||||||
}
|
}
|
||||||
}),url);
|
}),equivalentUrl);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void getEquivalentValue(BitsharesAsset baseAsset, List<BitsharesAsset> quoteAssets,Context context){
|
/**
|
||||||
|
* Gets equivalent value and store it on the database
|
||||||
|
*
|
||||||
|
* @param baseAsset The baset asset as a bitshares asset, it needs the CryptoCurrency and thge BitsharesInfo
|
||||||
|
* @param quoteAssets The list of the qutoe assets as a full bitshares asset object
|
||||||
|
* @param context The android context of this application
|
||||||
|
*/
|
||||||
|
public static void getEquivalentValue(BitsharesAsset baseAsset,
|
||||||
|
List<BitsharesAsset> quoteAssets,Context context){
|
||||||
for(BitsharesAsset quoteAsset : quoteAssets){
|
for(BitsharesAsset quoteAsset : quoteAssets){
|
||||||
WebSocketThread thread = new WebSocketThread(new GetLimitOrders(baseAsset.getBitsharesId(), quoteAsset.getBitsharesId(), 10, new EquivalentValueListener(baseAsset,quoteAsset,context)),url);
|
WebSocketThread thread = new WebSocketThread(new GetLimitOrders(baseAsset.getBitsharesId(),
|
||||||
|
quoteAsset.getBitsharesId(), 10, new EquivalentValueListener(baseAsset,
|
||||||
|
quoteAsset,context)),equivalentUrl);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener of the equivalent value the answer is stored in the database, for use in conjuntion with LiveData
|
||||||
|
*/
|
||||||
private static class EquivalentValueListener implements WitnessResponseListener{
|
private static class EquivalentValueListener implements WitnessResponseListener{
|
||||||
|
/**
|
||||||
|
* The base asset
|
||||||
|
*/
|
||||||
private BitsharesAsset baseAsset;
|
private BitsharesAsset baseAsset;
|
||||||
|
/**
|
||||||
|
* The quote asset
|
||||||
|
*/
|
||||||
private BitsharesAsset quoteAsset;
|
private BitsharesAsset quoteAsset;
|
||||||
|
/**
|
||||||
|
* The android context of this application
|
||||||
|
*/
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
public EquivalentValueListener(BitsharesAsset baseAsset, BitsharesAsset quoteAsset, Context context) {
|
public EquivalentValueListener(BitsharesAsset baseAsset, BitsharesAsset quoteAsset, Context context) {
|
||||||
|
@ -509,11 +595,13 @@ public abstract class GrapheneApiGenerator {
|
||||||
//TODO indirect equivalent value
|
//TODO indirect equivalent value
|
||||||
}
|
}
|
||||||
for(LimitOrder order : orders){
|
for(LimitOrder order : orders){
|
||||||
Converter converter = new Converter();
|
if(order.getSellPrice().base.getAsset().getBitassetId().equals(baseAsset.getBitsharesId())) {
|
||||||
double equiValue = converter.getConversionRate(order.getSellPrice(),Converter.BASE_TO_QUOTE);
|
Converter converter = new Converter();
|
||||||
CryptoCurrencyEquivalence equivalence = new CryptoCurrencyEquivalence(baseAsset.getId(),quoteAsset.getId(),(int)(Math.pow(10,baseAsset.getPrecision())*equiValue),new Date());
|
double equiValue = converter.getConversionRate(order.getSellPrice(), Converter.BASE_TO_QUOTE);
|
||||||
CrystalDatabase.getAppDatabase(context).cryptoCurrencyEquivalenceDao().insertCryptoCurrencyEquivalence(equivalence);
|
CryptoCurrencyEquivalence equivalence = new CryptoCurrencyEquivalence(baseAsset.getId(), quoteAsset.getId(), (int) (Math.pow(10, baseAsset.getPrecision()) * equiValue), new Date());
|
||||||
break;
|
CrystalDatabase.getAppDatabase(context).cryptoCurrencyEquivalenceDao().insertCryptoCurrencyEquivalence(equivalence);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
||||||
import cy.agorise.crystalwallet.service.CrystalWalletService;
|
import cy.agorise.crystalwallet.service.CrystalWalletService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The main application
|
||||||
|
*
|
||||||
* Created by Henry Varona on 6/9/2017.
|
* Created by Henry Varona on 6/9/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,32 @@ import cy.agorise.crystalwallet.enums.CryptoCoin;
|
||||||
import cy.agorise.crystalwallet.models.CryptoCurrency;
|
import cy.agorise.crystalwallet.models.CryptoCurrency;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This a request for a simple one on one asset equivalent value
|
||||||
|
*
|
||||||
* Created by henry on 6/11/2017.
|
* Created by henry on 6/11/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class CryptoNetEquivalentRequest extends CryptoNetInfoRequest {
|
public class CryptoNetEquivalentRequest extends CryptoNetInfoRequest {
|
||||||
|
/**
|
||||||
|
* The android context of this application
|
||||||
|
*/
|
||||||
private Context context;
|
private Context context;
|
||||||
|
/**
|
||||||
|
* The base currency
|
||||||
|
*/
|
||||||
private CryptoCurrency fromCurrency;
|
private CryptoCurrency fromCurrency;
|
||||||
|
/**
|
||||||
|
* The to currency
|
||||||
|
*/
|
||||||
private CryptoCurrency toCurrency;
|
private CryptoCurrency toCurrency;
|
||||||
|
/**
|
||||||
|
* The answer, less than 0 is an error, or no answer
|
||||||
|
*/
|
||||||
private long price = -1;
|
private long price = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic Constructor
|
||||||
|
*/
|
||||||
public CryptoNetEquivalentRequest(CryptoCoin coin, Context context, CryptoCurrency fromCurrency, CryptoCurrency toCurrency) {
|
public CryptoNetEquivalentRequest(CryptoCoin coin, Context context, CryptoCurrency fromCurrency, CryptoCurrency toCurrency) {
|
||||||
super(coin);
|
super(coin);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
@ -47,6 +63,10 @@ public class CryptoNetEquivalentRequest extends CryptoNetInfoRequest {
|
||||||
this.toCurrency = toCurrency;
|
this.toCurrency = toCurrency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Answer of the apigenerator
|
||||||
|
* @param price The fetched equivalent value
|
||||||
|
*/
|
||||||
public void setPrice(long price) {
|
public void setPrice(long price) {
|
||||||
this.price = price;
|
this.price = price;
|
||||||
this._fireOnCarryOutEvent();
|
this._fireOnCarryOutEvent();
|
||||||
|
|
|
@ -3,11 +3,20 @@ package cy.agorise.crystalwallet.cryptonetinforequests;
|
||||||
import cy.agorise.crystalwallet.enums.CryptoCoin;
|
import cy.agorise.crystalwallet.enums.CryptoCoin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* An request for the managers. Is used for the asyncrhonous petition of each manager
|
||||||
|
*
|
||||||
|
*
|
||||||
* Created by Henry Varona on 1/10/2017.
|
* Created by Henry Varona on 1/10/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class CryptoNetInfoRequest {
|
public abstract class CryptoNetInfoRequest {
|
||||||
|
/**
|
||||||
|
* The cryptocoin this request belongs
|
||||||
|
*/
|
||||||
protected CryptoCoin coin;
|
protected CryptoCoin coin;
|
||||||
|
/**
|
||||||
|
* The listener for the answer of this petition
|
||||||
|
*/
|
||||||
protected CryptoNetInfoRequestListener listener;
|
protected CryptoNetInfoRequestListener listener;
|
||||||
|
|
||||||
public CryptoNetInfoRequest(CryptoCoin coin){
|
public CryptoNetInfoRequest(CryptoCoin coin){
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package cy.agorise.crystalwallet.cryptonetinforequests;
|
package cy.agorise.crystalwallet.cryptonetinforequests;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Listener for manager request
|
||||||
* Created by Henry Varona on 1/10/2017.
|
* Created by Henry Varona on 1/10/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface CryptoNetInfoRequestListener {
|
public interface CryptoNetInfoRequestListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to exist the current petition
|
||||||
|
*/
|
||||||
public void onCarryOut();
|
public void onCarryOut();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,10 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The manager of each request.
|
||||||
|
*
|
||||||
|
* This helps connects the manager of each coin with the rest of application
|
||||||
|
*
|
||||||
* Created by Henry Varona on 1/10/2017.
|
* Created by Henry Varona on 1/10/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -12,15 +16,21 @@ public class CryptoNetInfoRequests {
|
||||||
private List<CryptoNetInfoRequestsListener> listeners;
|
private List<CryptoNetInfoRequestsListener> listeners;
|
||||||
private static CryptoNetInfoRequests instance;
|
private static CryptoNetInfoRequests instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private constructor for singleton pattern
|
||||||
|
*/
|
||||||
private void CryptoNetInfoRequests(){
|
private void CryptoNetInfoRequests(){
|
||||||
//Private constructor for singleton pattern
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an instance of this manager
|
||||||
|
* @return the instance to manage the cryptonetinforequest
|
||||||
|
*/
|
||||||
public static CryptoNetInfoRequests getInstance(){
|
public static CryptoNetInfoRequests getInstance(){
|
||||||
if (CryptoNetInfoRequests.instance == null){
|
if (CryptoNetInfoRequests.instance == null){
|
||||||
CryptoNetInfoRequests.instance = new CryptoNetInfoRequests();
|
CryptoNetInfoRequests.instance = new CryptoNetInfoRequests();
|
||||||
CryptoNetInfoRequests.instance.requests = new ArrayList<CryptoNetInfoRequest>();
|
CryptoNetInfoRequests.instance.requests = new ArrayList<>();
|
||||||
CryptoNetInfoRequests.instance.listeners = new ArrayList<CryptoNetInfoRequestsListener>();
|
CryptoNetInfoRequests.instance.listeners = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return CryptoNetInfoRequests.instance;
|
return CryptoNetInfoRequests.instance;
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package cy.agorise.crystalwallet.cryptonetinforequests;
|
package cy.agorise.crystalwallet.cryptonetinforequests;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Listener extends for the manager classes
|
||||||
* Created by Henry Varona on 1/10/2017.
|
* Created by Henry Varona on 1/10/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface CryptoNetInfoRequestsListener {
|
public interface CryptoNetInfoRequestsListener {
|
||||||
|
/**
|
||||||
|
* A new request for the manager
|
||||||
|
* @param request The request, we can query of the class of this object to know if the request is from a particular manager
|
||||||
|
*/
|
||||||
public void onNewRequest(CryptoNetInfoRequest request);
|
public void onNewRequest(CryptoNetInfoRequest request);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,31 @@ package cy.agorise.crystalwallet.cryptonetinforequests;
|
||||||
import cy.agorise.crystalwallet.enums.CryptoCoin;
|
import cy.agorise.crystalwallet.enums.CryptoCoin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Imports a bitsahres accounts,
|
||||||
|
*
|
||||||
|
* return true if the account exist, and the mnemonic (brainkey provide is for that account
|
||||||
* Created by Henry Varona on 1/10/2017.
|
* Created by Henry Varona on 1/10/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ValidateImportBitsharesAccountRequest extends CryptoNetInfoRequest {
|
public class ValidateImportBitsharesAccountRequest extends CryptoNetInfoRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the account
|
||||||
|
*/
|
||||||
private String accountName;
|
private String accountName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The mnemonic words
|
||||||
|
*/
|
||||||
private String mnemonic;
|
private String mnemonic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the account exist
|
||||||
|
*/
|
||||||
private Boolean accountExists;
|
private Boolean accountExists;
|
||||||
|
/**
|
||||||
|
* Indicates if the mnemonic provided belongs to that account
|
||||||
|
*/
|
||||||
private Boolean mnemonicIsCorrect;
|
private Boolean mnemonicIsCorrect;
|
||||||
|
|
||||||
public ValidateImportBitsharesAccountRequest(String accountName, String mnemonic){
|
public ValidateImportBitsharesAccountRequest(String accountName, String mnemonic){
|
||||||
|
|
|
@ -5,6 +5,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This represents each supported Crypto Coin
|
||||||
|
*
|
||||||
* Created by Henry Varona on 12/9/2017.
|
* Created by Henry Varona on 12/9/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -51,10 +51,12 @@ import cy.agorise.graphenej.objects.Memo;
|
||||||
import cy.agorise.graphenej.operations.TransferOperationBuilder;
|
import cy.agorise.graphenej.operations.TransferOperationBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The manager for the Bitshare CryptoCoin
|
||||||
|
*
|
||||||
* Created by henry on 26/9/2017.
|
* Created by henry on 26/9/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetInfoRequestsListener {
|
public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetInfoRequestsListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CryptoNetAccount createAccountFromSeed(CryptoNetAccount account, Context context) {
|
public CryptoNetAccount createAccountFromSeed(CryptoNetAccount account, Context context) {
|
||||||
if(account instanceof GrapheneAccount) {
|
if(account instanceof GrapheneAccount) {
|
||||||
|
@ -64,7 +66,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
String btsIdAccount = BitsharesFaucetApiGenerator.registerBitsharesAccount(grapheneAccount.getName(),
|
String btsIdAccount = BitsharesFaucetApiGenerator.registerBitsharesAccount(grapheneAccount.getName(),
|
||||||
new Address(grapheneAccount.getOwnerKey(),"BTS").toString(),
|
new Address(grapheneAccount.getOwnerKey(),"BTS").toString(),
|
||||||
new Address(grapheneAccount.getActiveKey(),"BTS").toString(),
|
new Address(grapheneAccount.getActiveKey(),"BTS").toString(),
|
||||||
new Address(grapheneAccount.getMemoKey(),"BTS").toString());
|
new Address(grapheneAccount.getMemoKey(),"BTS").toString(),GrapheneApiGenerator.url);
|
||||||
if(btsIdAccount !=null) {
|
if(btsIdAccount !=null) {
|
||||||
grapheneAccount.setAccountId(btsIdAccount);
|
grapheneAccount.setAccountId(btsIdAccount);
|
||||||
|
|
||||||
|
@ -159,6 +161,10 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the bitshares manager request
|
||||||
|
* @param request The request Object
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onNewRequest(CryptoNetInfoRequest request) {
|
public void onNewRequest(CryptoNetInfoRequest request) {
|
||||||
if (request instanceof ValidateImportBitsharesAccountRequest){
|
if (request instanceof ValidateImportBitsharesAccountRequest){
|
||||||
|
@ -174,6 +180,9 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the import account request
|
||||||
|
*/
|
||||||
private void validateImportAccount(final ValidateImportBitsharesAccountRequest importRequest){
|
private void validateImportAccount(final ValidateImportBitsharesAccountRequest importRequest){
|
||||||
ApiRequest checkAccountName = new ApiRequest(0, new ApiRequestListener() {
|
ApiRequest checkAccountName = new ApiRequest(0, new ApiRequestListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -215,6 +224,11 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
GrapheneApiGenerator.getAccountIdByName(importRequest.getAccountName(),checkAccountName);
|
GrapheneApiGenerator.getAccountIdByName(importRequest.getAccountName(),checkAccountName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the account exist request, it consults the bitshares api for the account name.
|
||||||
|
*
|
||||||
|
* This can be used to know if the name is avaible, or the account to be send fund exists
|
||||||
|
*/
|
||||||
private void validateExistAcccount(final ValidateExistBitsharesAccountRequest validateRequest){
|
private void validateExistAcccount(final ValidateExistBitsharesAccountRequest validateRequest){
|
||||||
ApiRequest checkAccountName = new ApiRequest(0, new ApiRequestListener() {
|
ApiRequest checkAccountName = new ApiRequest(0, new ApiRequestListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -231,6 +245,9 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
GrapheneApiGenerator.getAccountIdByName(validateRequest.getAccountName(),checkAccountName);
|
GrapheneApiGenerator.getAccountIdByName(validateRequest.getAccountName(),checkAccountName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Broadcast a transaction request
|
||||||
|
*/
|
||||||
private void validateSendRequest(final ValidateBitsharesSendRequest sendRequest){
|
private void validateSendRequest(final ValidateBitsharesSendRequest sendRequest){
|
||||||
Asset feeAsset = new Asset(sendRequest.getAsset());
|
Asset feeAsset = new Asset(sendRequest.getAsset());
|
||||||
UserAccount fromUserAccount =new UserAccount(sendRequest.getSourceAccount().getAccountId());
|
UserAccount fromUserAccount =new UserAccount(sendRequest.getSourceAccount().getAccountId());
|
||||||
|
@ -265,6 +282,10 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
GrapheneApiGenerator.broadcastTransaction(transaction,feeAsset, transactionRequest);
|
GrapheneApiGenerator.broadcastTransaction(transaction,feeAsset, transactionRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the account info from a graphene id
|
||||||
|
* @param grapheneId The graphene id of the account
|
||||||
|
*/
|
||||||
private GrapheneAccount getAccountInfoById(String grapheneId){
|
private GrapheneAccount getAccountInfoById(String grapheneId){
|
||||||
final Object SYNC = new Object();
|
final Object SYNC = new Object();
|
||||||
long timeout = 60000;
|
long timeout = 60000;
|
||||||
|
@ -309,6 +330,11 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
return listener.account;
|
return listener.account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh the transactions of an account, important to notice, it return nothing, to get the changes tuse the LiveData
|
||||||
|
* @param idAccount database id of the account
|
||||||
|
* @param context The android context of this application
|
||||||
|
*/
|
||||||
public static void refreshAccountTransactions(long idAccount, Context context){
|
public static void refreshAccountTransactions(long idAccount, Context context){
|
||||||
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
|
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
|
||||||
List<CryptoCoinTransaction> transactions = db.transactionDao().getByIdAccount(idAccount);
|
List<CryptoCoinTransaction> transactions = db.transactionDao().getByIdAccount(idAccount);
|
||||||
|
@ -327,15 +353,36 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that handles the transactions request
|
||||||
|
*/
|
||||||
private static class TransactionRequestListener implements ApiRequestListener{
|
private static class TransactionRequestListener implements ApiRequestListener{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start index
|
||||||
|
*/
|
||||||
int start;
|
int start;
|
||||||
|
/**
|
||||||
|
* End index
|
||||||
|
*/
|
||||||
int stop;
|
int stop;
|
||||||
|
/**
|
||||||
|
* Limit of transasction to fetch
|
||||||
|
*/
|
||||||
int limit;
|
int limit;
|
||||||
|
/**
|
||||||
|
* The grapheneaccount with all data CryptoCurrnecy + info
|
||||||
|
*/
|
||||||
GrapheneAccount account;
|
GrapheneAccount account;
|
||||||
|
/**
|
||||||
|
* The database
|
||||||
|
*/
|
||||||
CrystalDatabase db;
|
CrystalDatabase db;
|
||||||
|
|
||||||
public TransactionRequestListener(int start, int stop, int limit, GrapheneAccount account, CrystalDatabase db) {
|
/**
|
||||||
|
* Basic consturctor
|
||||||
|
*/
|
||||||
|
TransactionRequestListener(int start, int stop, int limit, GrapheneAccount account, CrystalDatabase db) {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.stop = stop;
|
this.stop = stop;
|
||||||
this.limit = limit;
|
this.limit = limit;
|
||||||
|
@ -343,6 +390,11 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the succes request of the transaction, if the amount of transaction is equal to the limit, ask for more transaction
|
||||||
|
* @param answer The answer, this object depends on the kind of request is made to the api
|
||||||
|
* @param idPetition the id of the ApiRequest petition
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void success(Object answer, int idPetition) {
|
public void success(Object answer, int idPetition) {
|
||||||
List<HistoricalTransfer> transfers = (List<HistoricalTransfer>) answer ;
|
List<HistoricalTransfer> transfers = (List<HistoricalTransfer>) answer ;
|
||||||
|
@ -354,8 +406,9 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
BitsharesAssetInfo info = db.bitsharesAssetDao().getBitsharesAssetInfoById(transfer.getOperation().getAssetAmount().getAsset().getObjectId());
|
BitsharesAssetInfo info = db.bitsharesAssetDao().getBitsharesAssetInfoById(transfer.getOperation().getAssetAmount().getAsset().getObjectId());
|
||||||
|
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
|
//The cryptoCurrency is not in the database, queringfor its data
|
||||||
System.out.println("CryptoCurrency not in database");
|
System.out.println("CryptoCurrency not in database");
|
||||||
final Object SYNC = new Object();
|
final Object SYNC = new Object(); //Object to syn the answer
|
||||||
ApiRequest assetRequest = new ApiRequest(0, new ApiRequestListener() {
|
ApiRequest assetRequest = new ApiRequest(0, new ApiRequestListener() {
|
||||||
@Override
|
@Override
|
||||||
public void success(Object answer, int idPetition) {
|
public void success(Object answer, int idPetition) {
|
||||||
|
@ -389,6 +442,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
info = db.bitsharesAssetDao().getBitsharesAssetInfoById(transfer.getOperation().getAssetAmount().getAsset().getObjectId());
|
info = db.bitsharesAssetDao().getBitsharesAssetInfoById(transfer.getOperation().getAssetAmount().getAsset().getObjectId());
|
||||||
}
|
}
|
||||||
if( info == null){
|
if( info == null){
|
||||||
|
//We couldn't retrieve the cryptocurrency
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
transaction.setIdCurrency((int)info.getCryptoCurrencyId());
|
transaction.setIdCurrency((int)info.getCryptoCurrencyId());
|
||||||
|
@ -401,6 +455,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(transfers.size()>= limit){
|
if(transfers.size()>= limit){
|
||||||
|
// The amount of transaction in the answer is equal to the limit, we need to query to see if there is more transactions
|
||||||
int newStart= start + limit;
|
int newStart= start + limit;
|
||||||
int newStop= stop + limit;
|
int newStop= stop + limit;
|
||||||
ApiRequest transactionRequest = new ApiRequest(newStart/limit, new TransactionRequestListener(newStart,newStop,limit,account,db));
|
ApiRequest transactionRequest = new ApiRequest(newStart/limit, new TransactionRequestListener(newStart,newStop,limit,account,db));
|
||||||
|
@ -414,6 +469,9 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current change from two assets
|
||||||
|
*/
|
||||||
private static void getEquivalentValue(final CryptoNetEquivalentRequest request){
|
private static void getEquivalentValue(final CryptoNetEquivalentRequest request){
|
||||||
if(request.getFromCurrency() instanceof BitsharesAsset && request.getToCurrency() instanceof BitsharesAsset) {
|
if(request.getFromCurrency() instanceof BitsharesAsset && request.getToCurrency() instanceof BitsharesAsset) {
|
||||||
BitsharesAsset fromAsset = (BitsharesAsset) request.getFromCurrency();
|
BitsharesAsset fromAsset = (BitsharesAsset) request.getFromCurrency();
|
||||||
|
@ -435,6 +493,9 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to retrieve the account id or the account name, if one of those is missing
|
||||||
|
*/
|
||||||
private class AccountIdOrNameListener implements ApiRequestListener{
|
private class AccountIdOrNameListener implements ApiRequestListener{
|
||||||
Object SYNC;
|
Object SYNC;
|
||||||
boolean ready = false;
|
boolean ready = false;
|
||||||
|
@ -469,8 +530,17 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to retrieve the transaction date
|
||||||
|
*/
|
||||||
private static class GetTransactionDate implements ApiRequestListener{
|
private static class GetTransactionDate implements ApiRequestListener{
|
||||||
|
/**
|
||||||
|
* The transaction to retrieve
|
||||||
|
*/
|
||||||
private CryptoCoinTransaction transaction;
|
private CryptoCoinTransaction transaction;
|
||||||
|
/**
|
||||||
|
* The DAO to insert or update the transaction
|
||||||
|
*/
|
||||||
TransactionDao transactionDao;
|
TransactionDao transactionDao;
|
||||||
|
|
||||||
public GetTransactionDate(CryptoCoinTransaction transaction, TransactionDao transactionDao) {
|
public GetTransactionDate(CryptoCoinTransaction transaction, TransactionDao transactionDao) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package cy.agorise.crystalwallet.models;
|
||||||
import cy.agorise.crystalwallet.enums.CryptoNet;
|
import cy.agorise.crystalwallet.enums.CryptoNet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Represents an Bitshares Assets, the assets extends the CryptoCurrency
|
||||||
* Created by henry on 8/10/2017.
|
* Created by henry on 8/10/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue