Example usage for javax.json JsonValue getValueType

List of usage examples for javax.json JsonValue getValueType

Introduction

In this page you can find the example usage for javax.json JsonValue getValueType.

Prototype

ValueType getValueType();

Source Link

Document

Returns the value type of this JSON value.

Usage

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcBlock jsonBlock(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }//from w w w  . j  a va2  s.  com
    BtcBlock block = new BtcBlock();
    block.setHash(object.getString(BTCOBJ_BLOCK_HASH, ""));
    block.setConfirmations(jsonLong(object, BTCOBJ_BLOCK_CONFIRMATIONS));
    block.setSize(jsonLong(object, BTCOBJ_BLOCK_SIZE));
    block.setHeight(jsonLong(object, BTCOBJ_BLOCK_HEIGHT));
    block.setVersion(jsonLong(object, BTCOBJ_BLOCK_VERSION));
    block.setMerkleRoot(object.getString(BTCOBJ_BLOCK_MERKLE_ROOT, ""));
    List<BtcTransaction> transactions = new ArrayList<BtcTransaction>();
    JsonValue txIds = object.get(BTCOBJ_BLOCK_TRANSACTIONS);
    if ((txIds != null) && (txIds.getValueType() == JsonValue.ValueType.ARRAY)
            && (txIds instanceof JsonArray)) {
        JsonArray txIdsArray = (JsonArray) txIds;
        for (JsonValue transactionId : txIdsArray.getValuesAs(JsonValue.class)) {
            BtcTransaction transaction = new BtcTransaction();
            transaction.setTransaction(jsonString(transactionId));
            transactions.add(transaction);
        }
    }
    block.setTransactions(transactions);
    block.setTime(jsonLong(object, BTCOBJ_BLOCK_TIME));
    block.setNonce(jsonLong(object, BTCOBJ_BLOCK_NONCE));
    block.setBits(object.getString(BTCOBJ_BLOCK_BITS, ""));
    block.setDifficulty(jsonDouble(object, BTCOBJ_BLOCK_DIFFICULTY));
    block.setPreviousBlockHash(object.getString(BTCOBJ_BLOCK_PREVIOUS_BLOCK_HASH, ""));
    block.setNextBlockHash(object.getString(BTCOBJ_BLOCK_NEXT_BLOCK_HASH, ""));
    return block;
}

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcBlockTemplate jsonBlockTemplate(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }/*www .  j  a v a2s  . com*/
    BtcBlockTemplate block = new BtcBlockTemplate();
    block.setVersion(jsonLong(object, BTCOBJ_BLOCK_VERSION));
    block.setPreviousBlockHash(object.getString(BTCOBJ_BLOCK_PREVIOUS_BLOCK_HASH, ""));
    List<BtcTransactionTemplate> transactions = new ArrayList<BtcTransactionTemplate>();
    JsonValue txs = object.get(BTCOBJ_BLOCK_TEMPLATE_TRANSACTIONS);
    if ((txs != null) && (txs.getValueType() == JsonValue.ValueType.ARRAY) && (txs instanceof JsonArray)) {
        JsonArray txsArray = (JsonArray) txs;
        for (JsonValue tx : txsArray.getValuesAs(JsonValue.class)) {
            transactions.add(jsonTransactionTemplate(tx));
        }
    }
    block.setTransactions(transactions);
    block.setCoinbase(jsonCoinbase(value));
    block.setTarget(object.getString(BTCOBJ_BLOCK_TEMPLATE_TARGET, ""));
    block.setMinimumTime(jsonLong(object, BTCOBJ_BLOCK_TEMPLATE_MIN_TIME));
    List<String> mutable = new ArrayList<String>();
    JsonValue mutableIds = object.get(BTCOBJ_BLOCK_TEMPLATE_MUTABLE);
    if ((mutableIds != null) && (mutableIds.getValueType() == JsonValue.ValueType.ARRAY)
            && (mutableIds instanceof JsonArray)) {
        JsonArray mutableIdsArray = (JsonArray) mutableIds;
        for (JsonValue mutableId : mutableIdsArray.getValuesAs(JsonValue.class)) {
            mutable.add(jsonString(mutableId));
        }
    }
    block.setMutable(mutable);
    block.setNonceRange(object.getString(BTCOBJ_BLOCK_TEMPLATE_NONCE_RANGE, ""));
    block.setSignatureOperations(jsonLong(object, BTCOBJ_BLOCK_TEMPLATE_SIGNATURE_OPERATIONS));
    block.setSize(jsonLong(object, BTCOBJ_BLOCK_TEMPLATE_SIZE));
    block.setTime(jsonLong(object, BTCOBJ_BLOCK_TEMPLATE_TIME));
    block.setBits(object.getString(BTCOBJ_BLOCK_BITS, ""));
    block.setHeight(jsonLong(object, BTCOBJ_BLOCK_HEIGHT));
    return block;
}

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcOutput jsonOutput(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }/*from   w w  w.j a  va2 s .c  o m*/
    BtcOutput output = new BtcOutput();
    output.setTransaction(object.getString(BTCOBJ_TX_OUTPUT_TRANSACTION, ""));
    output.setBestBlock(object.getString(BTCOBJ_TX_OUTPUT_BEST_BLOCK, ""));
    output.setConfirmations(jsonLong(object, BTCOBJ_TX_OUTPUT_CONFIRMATIONS));
    output.setValue(jsonDouble(object, BTCOBJ_TX_OUTPUT_VALUE));
    output.setIndex(jsonLong(object, BTCOBJ_TX_OUTPUT_INDEX));
    output.setOutput(jsonLong(object, BTCOBJ_TX_OUTPUT_OUTPUT));
    JsonValue scriptPubKey = object.get(BTCOBJ_TX_OUTPUT_SCRIPT_PUBLIC_KEY);
    if (scriptPubKey != null) {
        if ((scriptPubKey.getValueType() == JsonValue.ValueType.OBJECT)
                && (scriptPubKey instanceof JsonObject)) {
            output.setScript(jsonScript(scriptPubKey));
        }
        if ((scriptPubKey.getValueType() == JsonValue.ValueType.STRING)
                && (scriptPubKey instanceof JsonString)) {
            BtcScript script = new BtcScript();
            script.setPublicKey(jsonString(scriptPubKey));
            output.setScript(script);
        }
    }
    output.setVersion(jsonLong(object, BTCOBJ_TX_OUTPUT_VERSION));
    output.setCoinbase(object.getBoolean(BTCOBJ_TX_OUTPUT_COINBASE, false));
    output.setDetail(jsonTransactionDetail(object));
    return output;
}