Search in sources :

Example 61 with JsonArray

use of com.eclipsesource.json.JsonArray in project zencash-swing-wallet-ui by ZencashOfficial.

the class ZCashClientCaller method getSuccessfulOperationTXID.

public synchronized String getSuccessfulOperationTXID(String opID) throws WalletCallException, IOException, InterruptedException {
    String TXID = null;
    JsonArray response = this.executeCommandAndGetJsonArray("z_getoperationstatus", wrapStringParameter("[\"" + opID + "\"]"));
    JsonObject jsonStatus = response.get(0).asObject();
    JsonValue opResultValue = jsonStatus.get("result");
    if (opResultValue != null) {
        JsonObject opResult = opResultValue.asObject();
        if (opResult.get("txid") != null) {
            TXID = opResult.get("txid").asString();
        }
    }
    return TXID;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject)

Example 62 with JsonArray

use of com.eclipsesource.json.JsonArray in project zencash-swing-wallet-ui by ZencashOfficial.

the class ZCashClientCaller method getWalletZReceivedTransactions.

public synchronized String[][] getWalletZReceivedTransactions() throws WalletCallException, IOException, InterruptedException {
    String[] zAddresses = this.getWalletZAddresses();
    List<String[]> zReceivedTransactions = new ArrayList<String[]>();
    for (String zAddress : zAddresses) {
        JsonArray jsonTransactions = executeCommandAndGetJsonArray("z_listreceivedbyaddress", wrapStringParameter(zAddress), "0");
        for (int i = 0; i < jsonTransactions.size(); i++) {
            String[] currentTransaction = new String[7];
            JsonObject trans = jsonTransactions.get(i).asObject();
            String txID = trans.getString("txid", "ERROR!");
            // Needs to be the same as in getWalletPublicTransactions()
            // TODO: some day refactor to use object containers
            currentTransaction[0] = "\u2605Z (Private)";
            currentTransaction[1] = "receive";
            // Transaction confirmations cached - cleared every 10 min
            if ((System.currentTimeMillis() - this.lastTransactionConfirmationsAccess) > (10 * 60 * 1000)) {
                this.lastTransactionConfirmationsAccess = System.currentTimeMillis();
                this.transactionConfirmations.clear();
            }
            String confirmations = this.transactionConfirmations.get(txID);
            if ((confirmations == null) || confirmations.equals("0")) {
                currentTransaction[2] = this.getWalletTransactionConfirmations(txID);
                this.transactionConfirmations.put(txID, currentTransaction[2]);
            } else {
                currentTransaction[2] = confirmations;
            }
            currentTransaction[3] = trans.get("amount").toString();
            // Transaction time is cached - cleared every 10 min
            if ((System.currentTimeMillis() - this.lastTransactionTimesAccess) > (10 * 60 * 1000)) {
                this.lastTransactionTimesAccess = System.currentTimeMillis();
                this.transactionTimes.clear();
            }
            String time = this.transactionTimes.get(txID);
            if ((time == null) || (time.equals("-1"))) {
                currentTransaction[4] = this.getWalletTransactionTime(txID);
                this.transactionTimes.put(txID, currentTransaction[4]);
            } else {
                currentTransaction[4] = time;
            }
            currentTransaction[5] = zAddress;
            currentTransaction[6] = trans.get("txid").toString();
            zReceivedTransactions.add(currentTransaction);
        }
    }
    return zReceivedTransactions.toArray(new String[0][]);
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) ArrayList(java.util.ArrayList) JsonObject(com.eclipsesource.json.JsonObject)

Example 63 with JsonArray

use of com.eclipsesource.json.JsonArray in project zencash-swing-wallet-ui by ZencashOfficial.

the class ZCashClientCaller method getWalletZAddresses.

public synchronized String[] getWalletZAddresses() throws WalletCallException, IOException, InterruptedException {
    JsonArray jsonAddresses = executeCommandAndGetJsonArray("z_listaddresses", null);
    String[] strAddresses = new String[jsonAddresses.size()];
    for (int i = 0; i < jsonAddresses.size(); i++) {
        strAddresses[i] = jsonAddresses.get(i).asString();
    }
    return strAddresses;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray)

Example 64 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-android-sdk by box.

the class BoxRequestCollectionUpdate method setCollectionId.

/**
 * Sets the id of the collection to update.
 *
 * @param id    id of the collection to update.
 * @return  request with the updated collection id.
 */
protected R setCollectionId(String id) {
    JsonArray jsonArray = new JsonArray();
    if (!TextUtils.isEmpty(id)) {
        BoxCollection col = BoxCollection.createFromId(id);
        jsonArray.add(col.toJsonObject());
    }
    mBodyMap.put(FIELD_COLLECTIONS, jsonArray);
    return (R) this;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) BoxCollection(com.box.androidsdk.content.models.BoxCollection)

Example 65 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-android-sdk by box.

the class BoxRequestItemUpdate method setTags.

/**
 * Sets the new tags for the item.
 *
 * @param tags  new tags for the item.
 * @return  request with the updated tags.
 */
public R setTags(List<String> tags) {
    JsonArray jsonArray = new JsonArray();
    for (String s : tags) {
        jsonArray.add(s);
    }
    mBodyMap.put(BoxItem.FIELD_TAGS, jsonArray);
    return (R) this;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray)

Aggregations

JsonArray (com.eclipsesource.json.JsonArray)111 JsonObject (com.eclipsesource.json.JsonObject)96 JsonValue (com.eclipsesource.json.JsonValue)32 Test (org.junit.Test)30 URL (java.net.URL)28 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)11 Matchers.containsString (org.hamcrest.Matchers.containsString)6 JsonUtil.getString (com.hazelcast.util.JsonUtil.getString)5 Map (java.util.Map)5 Link (org.eclipse.leshan.Link)4 Date (java.util.Date)3 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)3 ClientEndPointDTO (com.hazelcast.internal.management.dto.ClientEndPointDTO)2 MalformedURLException (java.net.MalformedURLException)2 DecimalFormat (java.text.DecimalFormat)2 DecimalFormatSymbols (java.text.DecimalFormatSymbols)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)2