Merge branch 'master' of https://github.com/Agorise/crystal-wallet-android
This commit is contained in:
commit
a21b0a8752
5 changed files with 202 additions and 20 deletions
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2017 Agorise
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -0,0 +1,33 @@
|
||||||
|
package cy.agorise.crystalwallet.apigenerator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by henry on 27/9/2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ApiRequest {
|
||||||
|
|
||||||
|
int id;
|
||||||
|
|
||||||
|
ApiRequestListener listener;
|
||||||
|
|
||||||
|
public ApiRequest(int id, ApiRequestListener listener) {
|
||||||
|
this.id = id;
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiRequestListener getListener() {
|
||||||
|
return listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListener(ApiRequestListener listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package cy.agorise.crystalwallet.apigenerator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by henry on 27/9/2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface ApiRequestListener {
|
||||||
|
|
||||||
|
public void success(Object answer, int idPetition);
|
||||||
|
public void fail(int idPetition);
|
||||||
|
|
||||||
|
}
|
|
@ -1,9 +1,24 @@
|
||||||
package cy.agorise.crystalwallet.apigenerator;
|
package cy.agorise.crystalwallet.apigenerator;
|
||||||
|
|
||||||
|
import com.neovisionaries.ws.client.WebSocket;
|
||||||
|
import com.neovisionaries.ws.client.WebSocketException;
|
||||||
|
import com.neovisionaries.ws.client.WebSocketFactory;
|
||||||
|
|
||||||
|
import cy.agorise.graphenej.Address;
|
||||||
|
import cy.agorise.graphenej.UserAccount;
|
||||||
|
import cy.agorise.graphenej.api.GetAccounts;
|
||||||
|
import cy.agorise.graphenej.api.GetKeyReferences;
|
||||||
|
import cy.agorise.graphenej.api.GetRelativeAccountHistory;
|
||||||
|
import cy.agorise.graphenej.interfaces.WitnessResponseListener;
|
||||||
|
import cy.agorise.graphenej.models.AccountProperties;
|
||||||
|
import cy.agorise.graphenej.models.BaseResponse;
|
||||||
|
import cy.agorise.graphenej.models.HistoricalTransfer;
|
||||||
|
import cy.agorise.graphenej.models.WitnessResponse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import cy.agorise.crystalwallet.models.GrapheneAccount;
|
|
||||||
import cy.agorise.graphenej.models.HistoricalTransfer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by henry on 26/9/2017.
|
* Created by henry on 26/9/2017.
|
||||||
|
@ -11,50 +26,151 @@ import cy.agorise.graphenej.models.HistoricalTransfer;
|
||||||
|
|
||||||
public class GrapheneApiGenerator {
|
public class GrapheneApiGenerator {
|
||||||
|
|
||||||
|
//TODO network connections
|
||||||
|
private static int connectionTimeout = 5000;
|
||||||
|
private static String url = "http://128.0.69.157:8090"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the data of an account searching by it's id
|
* Retrieves the data of an account searching by it's id
|
||||||
*
|
*
|
||||||
* @param accountId The accountId to retrieve
|
* @param accountId The accountId to retrieve
|
||||||
* @return The Account properties retrieved from the net, or null if fails
|
* @param request The Api request object, to answer this petition
|
||||||
*/
|
*/
|
||||||
public GrapheneAccount getAccountById(String accountId){
|
public static void getAccountById(String accountId, final ApiRequest request){
|
||||||
//TODO implement
|
WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(connectionTimeout);
|
||||||
return null;
|
try {
|
||||||
|
final WebSocket webSocket = factory.createSocket(url);
|
||||||
|
webSocket.addListener(new GetAccounts(accountId, new WitnessResponseListener() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(WitnessResponse response) {
|
||||||
|
if (response.result.getClass() == ArrayList.class) {
|
||||||
|
List list = (List) response.result;
|
||||||
|
if (list.size() > 0) {
|
||||||
|
if (list.get(0).getClass() == AccountProperties.class) {
|
||||||
|
request.getListener().success(list.get(0),request.getId());
|
||||||
|
//TODO answer a crystal model
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
request.getListener().fail(request.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(BaseResponse.Error error) {
|
||||||
|
request.getListener().fail(request.getId());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
Thread thread = new Thread(){
|
||||||
|
public void run(){
|
||||||
|
try {
|
||||||
|
webSocket.connect();
|
||||||
|
} catch (WebSocketException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
request.getListener().fail(request.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
thread.start();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
request.getListener().fail(request.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the account ID from an owner or active key
|
* Gets the account ID from an owner or active key
|
||||||
*
|
*
|
||||||
* @param address The address to retrieve
|
* @param address The address to retrieve
|
||||||
* @return The id of the account, of null
|
* @param request The Api request object, to answer this petition
|
||||||
*/
|
*/
|
||||||
public String getAccountByOwnerOrActiveAddress(String address){
|
public static void getAccountByOwnerOrActiveAddress(Address address, final ApiRequest request){
|
||||||
//TODO implement
|
//TODO change address
|
||||||
return null;
|
WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(connectionTimeout);
|
||||||
|
try {
|
||||||
|
final WebSocket webSocket = factory.createSocket(url);
|
||||||
|
webSocket.addListener(new GetKeyReferences(address, true, new WitnessResponseListener() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(WitnessResponse response) {
|
||||||
|
final List<List<UserAccount>> resp = (List<List<UserAccount>>) response.result;
|
||||||
|
if(resp.size() > 0){
|
||||||
|
List<UserAccount> accounts = resp.get(0);
|
||||||
|
if(accounts.size() > 0){
|
||||||
|
for(UserAccount account : accounts) {
|
||||||
|
request.getListener().success(account,request.getId());}}}
|
||||||
|
request.getListener().fail(request.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(BaseResponse.Error error) {
|
||||||
|
request.getListener().fail(request.getId());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
Thread thread = new Thread(){
|
||||||
|
public void run(){
|
||||||
|
try {
|
||||||
|
webSocket.connect();
|
||||||
|
} catch (WebSocketException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
request.getListener().fail(request.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
thread.start();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
request.getListener().fail(request.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the Transaction for an Account
|
* Gets the Transaction for an Account
|
||||||
*
|
*
|
||||||
* @param accountId The account id to search
|
* @param accountId The account id to search
|
||||||
* @param start The start index of the transaction list
|
* @param start The start index of the transaction list
|
||||||
* @param stop The stop index of the transaction list
|
* @param stop The stop index of the transaction list
|
||||||
* @param limit the maximun transactions to retrieve
|
* @param limit the maximun transactions to retrieve
|
||||||
* @return The list of trnsaction of the account, or null if the call fail
|
* @param request The Api request object, to answer this petition
|
||||||
*/
|
*/
|
||||||
public List<HistoricalTransfer> getAccountTransaction(String accountId, int start, int stop, int limit){
|
public static void getAccountTransaction(String accountId, int start, int stop, int limit, final ApiRequest request){
|
||||||
//TODO implement
|
WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(connectionTimeout);
|
||||||
return null;
|
try {
|
||||||
|
final WebSocket webSocket = factory.createSocket(url);
|
||||||
|
webSocket.addListener(new GetRelativeAccountHistory(new UserAccount(accountId), stop, limit, start, new WitnessResponseListener() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(WitnessResponse response) {
|
||||||
|
WitnessResponse<List<HistoricalTransfer>> resp = response;
|
||||||
|
request.getListener().success(resp,request.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(BaseResponse.Error error) {
|
||||||
|
request.getListener().fail(request.getId());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
Thread thread = new Thread(){
|
||||||
|
public void run(){
|
||||||
|
try {
|
||||||
|
webSocket.connect();
|
||||||
|
} catch (WebSocketException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
request.getListener().fail(request.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
thread.start();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
request.getListener().fail(request.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if an Account Name is avaible to be used for a new account
|
* Gets if an Account Name is avaible to be used for a new account
|
||||||
*
|
*
|
||||||
* @param accountName The account Name to find
|
* @param accountName The account Name to find
|
||||||
* @return If the account name isn't used in any bitshares account
|
* @param request The Api request object, to answer this petition
|
||||||
*/
|
*/
|
||||||
public boolean isAccountNameAvaible(String accountName){
|
public static void isAccountNameAvaible(String accountName, ApiRequest request){
|
||||||
//TODO implement
|
//TODO implement
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ public enum CryptoCoin implements Serializable {
|
||||||
LITECOIN(CryptoNet.LITECOIN,"LTC",8),
|
LITECOIN(CryptoNet.LITECOIN,"LTC",8),
|
||||||
DASH(CryptoNet.DASH,"DASH",8),
|
DASH(CryptoNet.DASH,"DASH",8),
|
||||||
DOGECOIN(CryptoNet.DOGECOIN,"DOGE",8),
|
DOGECOIN(CryptoNet.DOGECOIN,"DOGE",8),
|
||||||
BITSHARES(CryptoNet.BITSHARES,"BTS",8);
|
BITSHARES(CryptoNet.BITSHARES,"BTS",5);
|
||||||
|
|
||||||
protected CryptoNet cryptoNet;
|
protected CryptoNet cryptoNet;
|
||||||
protected String label;
|
protected String label;
|
||||||
|
|
Loading…
Reference in a new issue