Skip to content
This repository has been archived by the owner on Dec 20, 2017. It is now read-only.

Commit

Permalink
Return back some of graphenej lib hardcoded models
Browse files Browse the repository at this point in the history
  • Loading branch information
computationalcore committed Jul 3, 2017
1 parent 5593847 commit 0685cc1
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@
import de.bitsharesmunich.graphenej.models.BlockHeader;
import de.bitsharesmunich.graphenej.models.BucketObject;
import de.bitsharesmunich.graphenej.models.HistoricalTransfer;
import de.bitsharesmunich.graphenej.models.Market;
import de.bitsharesmunich.graphenej.models.WitnessResponse;
import de.bitsharesmunich.graphenej.models.api.GetLimitOrders;
import de.bitsharesmunich.graphenej.objects.Memo;
import de.bitsharesmunich.graphenej.operations.TransferOperation;
import de.codecrafters.tableview.SortableTableView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import de.bitsharesmunich.graphenej.Address;
import de.bitsharesmunich.graphenej.Asset;
import de.bitsharesmunich.graphenej.PublicKey;
import de.bitsharesmunich.graphenej.models.api.GetLimitOrders;
import de.bitsharesmunich.graphenej.api.LookupAssetSymbols;
import de.bitsharesmunich.graphenej.errors.MalformedAddressException;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.BaseResponse;
import de.bitsharesmunich.graphenej.models.Market;
import de.bitsharesmunich.graphenej.models.WitnessResponse;


Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/de/bitsharesmunich/graphenej/models/Market.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.bitsharesmunich.graphenej.models;

/**
*
* @author hvarona 12/12/16
*/
public class Market {

public String id;
public String expiration;
public String seller;
public long for_sale;
public long deferred_fee;
public Price sell_price;

public class Price {

public AmountPrice base;
public AmountPrice quote;
}

public class AmountPrice {

public String asset_id;
public long amount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package de.bitsharesmunich.graphenej.models.api;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketAdapter;
import com.neovisionaries.ws.client.WebSocketException;
import com.neovisionaries.ws.client.WebSocketFrame;

import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.BaseResponse;
import de.bitsharesmunich.graphenej.models.Market;
import de.bitsharesmunich.graphenej.models.WitnessResponse;

/**
* Created by hvarona on 12/12/16.
*/
public class GetLimitOrders extends WebSocketAdapter {

private String a;
private String b;
private int limit;
private WitnessResponseListener mListener;

public GetLimitOrders(String a, String b, int limit, WitnessResponseListener mListener) {
this.a = a;
this.b = b;
this.limit = limit;
this.mListener = mListener;
}

@Override
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
ArrayList<Serializable> accountParams = new ArrayList<>();
accountParams.add(this.a);
accountParams.add(this.b);
accountParams.add(this.limit);
ApiCall getAccountByName = new ApiCall(0, RPC.CALL_GET_LIMIT_ORDERS, accountParams, "2.0", 1);
websocket.sendText(getAccountByName.toJsonString());
}

@Override
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
try {
String response = frame.getPayloadText();
Gson gson = new Gson();

Type GetLimitiOrdersResponse = new TypeToken<WitnessResponse<ArrayList<Market>>>() {
}.getType();
WitnessResponse<ArrayList<Market>> witnessResponse = gson.fromJson(response, GetLimitiOrdersResponse);
if (witnessResponse.error != null) {
this.mListener.onError(witnessResponse.error);
} else {
this.mListener.onSuccess(witnessResponse);
}
} catch (Exception e) {
e.printStackTrace();
}
websocket.disconnect();
}

@Override
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}

@Override
public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception {
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
}

0 comments on commit 0685cc1

Please sign in to comment.