diff --git a/app/build.gradle b/app/build.gradle index b2d7697..0186326 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -55,7 +55,7 @@ dependencies { compile 'com.neovisionaries:nv-websocket-client:1.30' compile 'org.tukaani:xz:1.6' 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 'org.mockito:mockito-core:1.10.19' annotationProcessor 'android.arch.lifecycle:compiler:1.0.0-alpha9-1' diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequest.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequest.java index 1843f70..9c71c3b 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequest.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequest.java @@ -1,15 +1,28 @@ 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. */ public class ApiRequest { - + /** + * The id of this api request + */ int id; + /** + * The listener of this apirequest, to be passed the answer + */ ApiRequestListener listener; + /** + * Basic constructor + * @param id The id of this request + * @param listener The listener for this request + */ public ApiRequest(int id, ApiRequestListener listener) { this.id = id; this.listener = listener; diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequestListener.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequestListener.java index bd3d76e..e0af357 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequestListener.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequestListener.java @@ -1,12 +1,24 @@ package cy.agorise.crystalwallet.apigenerator; /** + * This listener and apirquest answer + * * Created by henry on 27/9/2017. */ 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); + + /** + * Call when the function fails + * @param idPetition the id of the ApiRequest petition + */ public void fail(int idPetition); } diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/BitsharesFaucetApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/BitsharesFaucetApiGenerator.java index 7e73bbc..cdc77f7 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/BitsharesFaucetApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/BitsharesFaucetApiGenerator.java @@ -3,6 +3,8 @@ package cy.agorise.crystalwallet.apigenerator; 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. */ @@ -15,9 +17,11 @@ public abstract class BitsharesFaucetApiGenerator { * @param ownerKey The owner key public address * @param activeKey The active 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 */ - 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(); Account account = new Account(); account.name=accountName; @@ -33,15 +37,33 @@ public abstract class BitsharesFaucetApiGenerator { return null; } - + /** + * Class used for the json serializer. this represents a peitition + */ private static class CreateAccountPetition{ + // The account to be created Account account; } + /** + * Class used for the json serializer. This represents the account on the petition + */ private static class Account{ + /** + * The name of the account + */ String name; + /** + * The owner key address + */ String owner_key; + /** + * The active key address + */ String active_key; + /** + * The memo key address + */ String memo_key; } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java index 138c060..ac66720 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -33,9 +33,7 @@ import cy.agorise.graphenej.api.GetAccounts; import cy.agorise.graphenej.api.GetBlockHeader; import cy.agorise.graphenej.api.GetKeyReferences; import cy.agorise.graphenej.api.GetLimitOrders; -import cy.agorise.graphenej.api.GetMarketHistory; import cy.agorise.graphenej.api.GetRelativeAccountHistory; -import cy.agorise.graphenej.api.ListAssets; import cy.agorise.graphenej.api.LookupAssetSymbols; import cy.agorise.graphenej.api.SubscriptionMessagesHub; import cy.agorise.graphenej.api.TransactionBroadcastSequence; @@ -58,10 +56,11 @@ import cy.agorise.graphenej.models.WitnessResponse; public abstract class GrapheneApiGenerator { //TODO network connections - //TODO make to work with all Graphene stype, not only bitshares - private static String url = "http://128.0.69.157:8090"; + //TODO make to work with all Graphene type, not only bitshares + 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() { @Override 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); + /** + * This is used for manager each listener in the subscription thread + */ private static HashMap currentBitsharesListener = new HashMap<>(); /** @@ -79,7 +84,8 @@ public abstract class GrapheneApiGenerator { * @param request The Api request object, to answer this petition */ 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 public void onSuccess(WitnessResponse response) { if (response.result.getClass() == ArrayList.class) { @@ -88,7 +94,6 @@ public abstract class GrapheneApiGenerator { if (list.get(0).getClass() == AccountProperties.class) { request.getListener().success(list.get(0),request.getId()); return; - //TODO answer a crystal model } } } @@ -110,7 +115,8 @@ public abstract class GrapheneApiGenerator { * @param request The Api request object, to answer this petition */ 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 public void onSuccess(WitnessResponse response) { final List> resp = (List>) response.result; @@ -140,12 +146,13 @@ public abstract class GrapheneApiGenerator { * @param limit the maximun transactions to retrieve * @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){ - WebSocketThread thread = new WebSocketThread(new GetRelativeAccountHistory(new UserAccount(accountGrapheneId), start, limit, stop, new WitnessResponseListener() { + public static void getAccountTransaction(String accountGrapheneId, int start, int stop, + int limit, final ApiRequest request){ + WebSocketThread thread = new WebSocketThread(new GetRelativeAccountHistory(new UserAccount(accountGrapheneId), + start, limit, stop, new WitnessResponseListener() { @Override public void onSuccess(WitnessResponse response) { - WitnessResponse> resp = response; - request.getListener().success(resp.result,request.getId()); + request.getListener().success(response.result,request.getId()); } @Override @@ -163,10 +170,11 @@ public abstract class GrapheneApiGenerator { * @param request The Api request object, to answer this petition */ 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 public void onSuccess(WitnessResponse response) { - AccountProperties accountProperties = ((WitnessResponse) response).result; + AccountProperties accountProperties = (AccountProperties)response.result; if(accountProperties == null){ request.getListener().fail(request.getId()); }else{ @@ -189,10 +197,11 @@ public abstract class GrapheneApiGenerator { * @param request The Api request object, to answer this petition */ 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 public void onSuccess(WitnessResponse response) { - AccountProperties accountProperties = ((WitnessResponse) response).result; + AccountProperties accountProperties = (AccountProperties)response.result; if(accountProperties == null){ request.getListener().success(null,request.getId()); }else{ @@ -208,8 +217,17 @@ public abstract class GrapheneApiGenerator { 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 public void onSuccess(WitnessResponse response) { request.getListener().success(true,request.getId()); @@ -223,16 +241,16 @@ public abstract class GrapheneApiGenerator { 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 assetNames, final ApiRequest request){ - //TODO the graphenej library needs a way to creates the Asset object only with the symbol - ArrayList assets = new ArrayList<>(); - for(String assetName : assetNames){ - 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() { + + WebSocketThread thread = new WebSocketThread(new LookupAssetSymbols(assetNames,true, + new WitnessResponseListener() { @Override public void onSuccess(WitnessResponse response) { List assets = (List) response.result; @@ -241,6 +259,7 @@ public abstract class GrapheneApiGenerator { }else{ ArrayList responseAssets = new ArrayList<>(); for(Asset asset: assets){ + //TODO asset type BitsharesAsset.Type assetType = BitsharesAsset.Type.UIA; /*if(asset.getAssetType().equals(Asset.AssetType.CORE_ASSET)){ assetType = BitsharesAsset.Type.CORE; @@ -251,7 +270,8 @@ public abstract class GrapheneApiGenerator { }else if(asset.getAssetType().equals(Asset.AssetType.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); } request.getListener().success(responseAssets,request.getId()); @@ -266,6 +286,11 @@ public abstract class GrapheneApiGenerator { 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 assetIds, final ApiRequest request){ ArrayList assets = new ArrayList<>(); for(String assetId : assetIds){ @@ -273,7 +298,7 @@ public abstract class GrapheneApiGenerator { assets.add(asset); } - WebSocketThread thread = new WebSocketThread(new LookupAssetSymbols(assets, new WitnessResponseListener() { + WebSocketThread thread = new WebSocketThread(new LookupAssetSymbols(assets,true, new WitnessResponseListener() { @Override public void onSuccess(WitnessResponse response) { List assets = (List) response.result; @@ -282,6 +307,7 @@ public abstract class GrapheneApiGenerator { }else{ ArrayList responseAssets = new ArrayList<>(); for(Asset asset: assets){ + //TODO asset type BitsharesAsset.Type assetType = BitsharesAsset.Type.UIA; /*if(asset.getAssetType().equals(Asset.AssetType.CORE_ASSET)){ assetType = BitsharesAsset.Type.CORE; @@ -292,7 +318,8 @@ public abstract class GrapheneApiGenerator { }else if(asset.getAssetType().equals(Asset.AssetType.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); } request.getListener().success(responseAssets,request.getId()); @@ -307,7 +334,15 @@ public abstract class GrapheneApiGenerator { 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)){ CrystalDatabase db = CrystalDatabase.getAppDatabase(context); 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(); } - 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); final CryptoCoinBalanceDao balanceDao = db.cryptoCoinBalanceDao(); final BitsharesAssetDao bitsharesAssetDao = db.bitsharesAssetDao(); final CryptoCurrencyDao cryptoCurrencyDao = db.cryptoCurrencyDao(); - WebSocketThread thread = new WebSocketThread(new GetAccountBalances(new UserAccount(accountGrapheneId), new ArrayList(), new WitnessResponseListener() { + WebSocketThread thread = new WebSocketThread(new GetAccountBalances(new UserAccount(accountGrapheneId), + new ArrayList(), new WitnessResponseListener() { @Override public void onSuccess(WitnessResponse response) { List balances = (List) 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){ WebSocketThread thread = new WebSocketThread(new GetBlockHeader(blockHeader, new WitnessResponseListener() { @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 public void onSuccess(WitnessResponse response) { List orders = (List) response.result; @@ -469,10 +530,13 @@ public abstract class GrapheneApiGenerator { //TODO indirect equivalent value } for(LimitOrder order : orders){ - Converter converter = new Converter(); - double equiValue = converter.getConversionRate(order.getSellPrice(),Converter.BASE_TO_QUOTE); - request.getListener().success(equiValue,request.getId()); - break; + if(order.getSellPrice().base.getAsset().getBitassetId().equals(baseId)) { + Converter converter = new Converter(); + double equiValue = converter.getConversionRate(order.getSellPrice(), + 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) { request.getListener().fail(request.getId()); } - }),url); + }),equivalentUrl); thread.start(); } - public static void getEquivalentValue(BitsharesAsset baseAsset, List 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 quoteAssets,Context context){ 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(); } } + /** + * Listener of the equivalent value the answer is stored in the database, for use in conjuntion with LiveData + */ private static class EquivalentValueListener implements WitnessResponseListener{ + /** + * The base asset + */ private BitsharesAsset baseAsset; + /** + * The quote asset + */ private BitsharesAsset quoteAsset; + /** + * The android context of this application + */ private Context context; public EquivalentValueListener(BitsharesAsset baseAsset, BitsharesAsset quoteAsset, Context context) { @@ -509,11 +595,13 @@ public abstract class GrapheneApiGenerator { //TODO indirect equivalent value } for(LimitOrder order : orders){ - Converter converter = new Converter(); - double equiValue = converter.getConversionRate(order.getSellPrice(),Converter.BASE_TO_QUOTE); - CryptoCurrencyEquivalence equivalence = new CryptoCurrencyEquivalence(baseAsset.getId(),quoteAsset.getId(),(int)(Math.pow(10,baseAsset.getPrecision())*equiValue),new Date()); - CrystalDatabase.getAppDatabase(context).cryptoCurrencyEquivalenceDao().insertCryptoCurrencyEquivalence(equivalence); - break; + if(order.getSellPrice().base.getAsset().getBitassetId().equals(baseAsset.getBitsharesId())) { + Converter converter = new Converter(); + double equiValue = converter.getConversionRate(order.getSellPrice(), Converter.BASE_TO_QUOTE); + CryptoCurrencyEquivalence equivalence = new CryptoCurrencyEquivalence(baseAsset.getId(), quoteAsset.getId(), (int) (Math.pow(10, baseAsset.getPrecision()) * equiValue), new Date()); + CrystalDatabase.getAppDatabase(context).cryptoCurrencyEquivalenceDao().insertCryptoCurrencyEquivalence(equivalence); + break; + } } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java b/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java index 2bea06c..fc5f6c7 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java +++ b/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java @@ -9,6 +9,8 @@ import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.service.CrystalWalletService; /** + * The main application + * * Created by Henry Varona on 6/9/2017. */ diff --git a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetEquivalentRequest.java b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetEquivalentRequest.java index 4fc9b14..e24f573 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetEquivalentRequest.java +++ b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetEquivalentRequest.java @@ -6,16 +6,32 @@ import cy.agorise.crystalwallet.enums.CryptoCoin; 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. */ public class CryptoNetEquivalentRequest extends CryptoNetInfoRequest { - + /** + * The android context of this application + */ private Context context; + /** + * The base currency + */ private CryptoCurrency fromCurrency; + /** + * The to currency + */ private CryptoCurrency toCurrency; + /** + * The answer, less than 0 is an error, or no answer + */ private long price = -1; + /** + * Basic Constructor + */ public CryptoNetEquivalentRequest(CryptoCoin coin, Context context, CryptoCurrency fromCurrency, CryptoCurrency toCurrency) { super(coin); this.context = context; @@ -47,6 +63,10 @@ public class CryptoNetEquivalentRequest extends CryptoNetInfoRequest { this.toCurrency = toCurrency; } + /** + * Answer of the apigenerator + * @param price The fetched equivalent value + */ public void setPrice(long price) { this.price = price; this._fireOnCarryOutEvent(); diff --git a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequest.java b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequest.java index a9e7f83..33c9815 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequest.java +++ b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequest.java @@ -3,11 +3,20 @@ package cy.agorise.crystalwallet.cryptonetinforequests; 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. */ public abstract class CryptoNetInfoRequest { + /** + * The cryptocoin this request belongs + */ protected CryptoCoin coin; + /** + * The listener for the answer of this petition + */ protected CryptoNetInfoRequestListener listener; public CryptoNetInfoRequest(CryptoCoin coin){ diff --git a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestListener.java b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestListener.java index e53c05d..72f5a65 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestListener.java +++ b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestListener.java @@ -1,10 +1,14 @@ package cy.agorise.crystalwallet.cryptonetinforequests; /** + * Listener for manager request * Created by Henry Varona on 1/10/2017. */ public interface CryptoNetInfoRequestListener { + /** + * Used to exist the current petition + */ public void onCarryOut(); } diff --git a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequests.java b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequests.java index 01b27f8..92e34a1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequests.java +++ b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequests.java @@ -4,6 +4,10 @@ import java.util.ArrayList; 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. */ @@ -12,15 +16,21 @@ public class CryptoNetInfoRequests { private List listeners; private static CryptoNetInfoRequests instance; + /** + * Private constructor for singleton pattern + */ 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(){ if (CryptoNetInfoRequests.instance == null){ CryptoNetInfoRequests.instance = new CryptoNetInfoRequests(); - CryptoNetInfoRequests.instance.requests = new ArrayList(); - CryptoNetInfoRequests.instance.listeners = new ArrayList(); + CryptoNetInfoRequests.instance.requests = new ArrayList<>(); + CryptoNetInfoRequests.instance.listeners = new ArrayList<>(); } return CryptoNetInfoRequests.instance; diff --git a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestsListener.java b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestsListener.java index 05efb5f..82c234c 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestsListener.java +++ b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestsListener.java @@ -1,9 +1,14 @@ package cy.agorise.crystalwallet.cryptonetinforequests; /** + * Listener extends for the manager classes * Created by Henry Varona on 1/10/2017. */ 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); } diff --git a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/ValidateImportBitsharesAccountRequest.java b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/ValidateImportBitsharesAccountRequest.java index 54bc93c..8dcdda2 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/ValidateImportBitsharesAccountRequest.java +++ b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/ValidateImportBitsharesAccountRequest.java @@ -3,15 +3,31 @@ package cy.agorise.crystalwallet.cryptonetinforequests; 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. */ public class ValidateImportBitsharesAccountRequest extends CryptoNetInfoRequest { + /** + * The name of the account + */ private String accountName; + + /** + * The mnemonic words + */ private String mnemonic; + /** + * Indicates if the account exist + */ private Boolean accountExists; + /** + * Indicates if the mnemonic provided belongs to that account + */ private Boolean mnemonicIsCorrect; public ValidateImportBitsharesAccountRequest(String accountName, String mnemonic){ diff --git a/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java b/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java index 3bf8ff7..6d06e9a 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java +++ b/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java @@ -5,6 +5,8 @@ import java.util.ArrayList; import java.util.List; /** + * This represents each supported Crypto Coin + * * Created by Henry Varona on 12/9/2017. */ diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java index 6e9a553..6470540 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -51,10 +51,12 @@ import cy.agorise.graphenej.objects.Memo; import cy.agorise.graphenej.operations.TransferOperationBuilder; /** + * The manager for the Bitshare CryptoCoin + * * Created by henry on 26/9/2017. */ - public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetInfoRequestsListener { + @Override public CryptoNetAccount createAccountFromSeed(CryptoNetAccount account, Context context) { if(account instanceof GrapheneAccount) { @@ -64,7 +66,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI String btsIdAccount = BitsharesFaucetApiGenerator.registerBitsharesAccount(grapheneAccount.getName(), new Address(grapheneAccount.getOwnerKey(),"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) { grapheneAccount.setAccountId(btsIdAccount); @@ -159,6 +161,10 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI } } + /** + * Process the bitshares manager request + * @param request The request Object + */ @Override public void onNewRequest(CryptoNetInfoRequest request) { 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){ ApiRequest checkAccountName = new ApiRequest(0, new ApiRequestListener() { @Override @@ -215,6 +224,11 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI 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){ ApiRequest checkAccountName = new ApiRequest(0, new ApiRequestListener() { @Override @@ -231,6 +245,9 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI GrapheneApiGenerator.getAccountIdByName(validateRequest.getAccountName(),checkAccountName); } + /** + * Broadcast a transaction request + */ private void validateSendRequest(final ValidateBitsharesSendRequest sendRequest){ Asset feeAsset = new Asset(sendRequest.getAsset()); UserAccount fromUserAccount =new UserAccount(sendRequest.getSourceAccount().getAccountId()); @@ -265,6 +282,10 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI 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){ final Object SYNC = new Object(); long timeout = 60000; @@ -309,6 +330,11 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI 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){ CrystalDatabase db = CrystalDatabase.getAppDatabase(context); List 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{ + /** + * Start index + */ int start; + /** + * End index + */ int stop; + /** + * Limit of transasction to fetch + */ int limit; + /** + * The grapheneaccount with all data CryptoCurrnecy + info + */ GrapheneAccount account; + /** + * The database + */ 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.stop = stop; this.limit = limit; @@ -343,6 +390,11 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI 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 public void success(Object answer, int idPetition) { List transfers = (List) answer ; @@ -354,8 +406,9 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI BitsharesAssetInfo info = db.bitsharesAssetDao().getBitsharesAssetInfoById(transfer.getOperation().getAssetAmount().getAsset().getObjectId()); if (info == null) { + //The cryptoCurrency is not in the database, queringfor its data 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() { @Override 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()); } if( info == null){ + //We couldn't retrieve the cryptocurrency return; } transaction.setIdCurrency((int)info.getCryptoCurrencyId()); @@ -401,6 +455,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI } } 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 newStop= stop + limit; 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){ if(request.getFromCurrency() instanceof BitsharesAsset && request.getToCurrency() instanceof BitsharesAsset) { 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{ Object SYNC; 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{ + /** + * The transaction to retrieve + */ private CryptoCoinTransaction transaction; + /** + * The DAO to insert or update the transaction + */ TransactionDao transactionDao; public GetTransactionDate(CryptoCoinTransaction transaction, TransactionDao transactionDao) { diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/BitsharesAsset.java b/app/src/main/java/cy/agorise/crystalwallet/models/BitsharesAsset.java index 974d615..cbcbde5 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/BitsharesAsset.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/BitsharesAsset.java @@ -3,6 +3,7 @@ package cy.agorise.crystalwallet.models; import cy.agorise.crystalwallet.enums.CryptoNet; /** + * Represents an Bitshares Assets, the assets extends the CryptoCurrency * Created by henry on 8/10/2017. */