List of usage examples for javax.json JsonObject getString
String getString(String name, String defaultValue);
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 av a2 s .c o m*/ 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 BtcLastBlock jsonLastBlock(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }/*from w ww.j a v a2 s . c om*/ BtcLastBlock lastBlock = new BtcLastBlock(); lastBlock.setLastBlock(object.getString(BTCOBJ_LAST_BLOCK_LAST_BLOCK, "")); List<BtcTransaction> transactions = new ArrayList<BtcTransaction>(); JsonValue txs = object.get(BTCOBJ_LAST_BLOCK_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(jsonTransaction(tx)); } } lastBlock.setTransactions(transactions); return lastBlock; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcAddedNode jsonAddedNode(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }/*from w w w.j a va2s. c om*/ BtcAddedNode addedNode = new BtcAddedNode(); addedNode.setAddedNode(object.getString(BTCOBJ_NODE_ADDED_NODE, "")); addedNode.setConnected(object.getBoolean(BTCOBJ_NODE_CONNECTED, false)); List<BtcNode> nodes = new ArrayList<BtcNode>(); JsonValue addresses = object.get(BTCOBJ_NODE_ADDRESSES); if ((addresses != null) && (addresses.getValueType() == JsonValue.ValueType.ARRAY) && (addresses instanceof JsonArray)) { JsonArray addressesArray = (JsonArray) addresses; for (JsonValue address : addressesArray.getValuesAs(JsonValue.class)) { nodes.add(jsonNode(address)); } } addedNode.setAddresses(nodes); return addedNode; }
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 va 2 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; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcTransactionDetail jsonTransactionDetail(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }//from w ww . ja va2 s. co m BtcTransactionDetail detail = new BtcTransactionDetail(); detail.setAccount(object.getString(BTCOBJ_TX_DETAIL_ACCOUNT, "")); detail.setAddress(object.getString(BTCOBJ_TX_DETAIL_ADDRESS, "")); detail.setCategory(BtcTransaction.Category.getValue(object.getString(BTCOBJ_TX_DETAIL_CATEGORY, ""))); detail.setAmount(jsonDouble(object, BTCOBJ_TX_DETAIL_AMOUNT)); detail.setFee(jsonDouble(object, BTCOBJ_TX_DETAIL_FEE)); return detail; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcMultiSignatureAddress jsonMultiSignatureAddress(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }/* w ww . jav a2s .c om*/ BtcMultiSignatureAddress address = new BtcMultiSignatureAddress(); address.setAddress(object.getString(BTCOBJ_ADDRESS_ADDRESS, "")); address.setRedeemScript(object.getString(BTCOBJ_ADDRESS_REDEEM_SCRIPT, "")); return address; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcTransaction jsonTransaction(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }//from w ww . j a v a 2 s . c o m BtcTransaction transaction = new BtcTransaction(); transaction.setTransaction(object.getString(BTCOBJ_TX_TRANSACTION, "")); transaction.setAmount(jsonDouble(object, BTCOBJ_TX_AMOUNT)); transaction.setFee(jsonDouble(object, BTCOBJ_TX_FEE)); transaction.setConfirmations(jsonLong(object, BTCOBJ_TX_CONFIRMATIONS)); transaction.setTime(jsonLong(object, BTCOBJ_TX_TIME)); transaction.setTimeReceived(jsonLong(object, BTCOBJ_TX_TIME_RECEIVED)); transaction.setBlockHash(object.getString(BTCOBJ_TX_BLOCK_HASH, "")); transaction.setBlockIndex(jsonLong(object, BTCOBJ_TX_BLOCK_INDEX)); transaction.setBlockTime(jsonLong(object, BTCOBJ_TX_BLOCK_TIME)); List<BtcTransactionDetail> details = new ArrayList<BtcTransactionDetail>(); JsonValue txDetails = object.get(BTCOBJ_TX_DETAILS); if ((txDetails != null) && (txDetails.getValueType() == JsonValue.ValueType.ARRAY) && (txDetails instanceof JsonArray)) { JsonArray txDetailsArray = (JsonArray) txDetails; for (JsonValue txDetail : txDetailsArray.getValuesAs(JsonValue.class)) { details.add(jsonTransactionDetail(txDetail)); } } else { details.add(jsonTransactionDetail(value)); } transaction.setDetails(details); return transaction; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcRawTransaction jsonRawTransaction(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }/*from w ww . ja va 2s . co m*/ BtcRawTransaction transaction = new BtcRawTransaction(); transaction.setHex(object.getString(BTCOBJ_TX_HEX, "")); transaction.setTransaction(object.getString(BTCOBJ_TX_TRANSACTION, "")); transaction.setVersion(jsonLong(object, BTCOBJ_TX_VERSION)); transaction.setLockTime(jsonLong(object, BTCOBJ_TX_LOCK_TIME)); List<BtcInput> inputTransactions = new ArrayList<BtcInput>(); JsonValue inputs = object.get(BTCOBJ_TX_INPUTS); if ((inputs != null) && (inputs.getValueType() == JsonValue.ValueType.ARRAY) && (inputs instanceof JsonArray)) { JsonArray inputsArray = (JsonArray) inputs; for (JsonValue input : inputsArray.getValuesAs(JsonValue.class)) { inputTransactions.add(jsonInput(input)); } } transaction.setInputs(inputTransactions); List<BtcOutput> outputTransactions = new ArrayList<BtcOutput>(); JsonValue outputs = object.get(BTCOBJ_TX_OUTPUTS); if ((outputs != null) && (outputs.getValueType() == JsonValue.ValueType.ARRAY) && (outputs instanceof JsonArray)) { JsonArray outputsArray = (JsonArray) outputs; for (JsonValue output : outputsArray.getValuesAs(JsonValue.class)) { outputTransactions.add(jsonOutput(output)); } } transaction.setOutputs(outputTransactions); transaction.setBlockHash(object.getString(BTCOBJ_TX_BLOCK_HASH, "")); transaction.setConfirmations(jsonLong(object, BTCOBJ_TX_CONFIRMATIONS)); transaction.setTime(jsonLong(object, BTCOBJ_TX_TIME)); transaction.setBlockTime(jsonLong(object, BTCOBJ_TX_BLOCK_TIME)); transaction.setComplete(object.getBoolean(BTCOBJ_TX_COMPLETE, true)); return transaction; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcOutputSet jsonOutputSet(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }//w ww .j a va2 s. c o m BtcOutputSet output = new BtcOutputSet(); output.setHeight(jsonLong(object, BTCOBJ_TX_OUTPUT_SET_HEIGHT)); output.setBestBlock(object.getString(BTCOBJ_TX_OUTPUT_SET_BEST_BLOCK, "")); output.setTransactions(jsonLong(object, BTCOBJ_TX_OUTPUT_SET_TRANSACTIONS)); output.setOutputs(jsonLong(object, BTCOBJ_TX_OUTPUT_SET_OUTPUT_TRANSACTIONS)); output.setBytesSerialized(jsonLong(object, BTCOBJ_TX_OUTPUT_SET_BYTES_SERIALIZED)); output.setHashSerialized(object.getString(BTCOBJ_TX_OUTPUT_SET_HASH_SERIALIZED, "")); output.setTotalAmount(jsonDouble(object, BTCOBJ_TX_OUTPUT_SET_TOTAL_AMOUNT)); return output; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcAddress jsonAddress(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }/*from ww w . j a v a2 s . co m*/ BtcAddress address = new BtcAddress(); address.setValid(object.getBoolean(BTCOBJ_ADDRESS_VALID, false)); address.setAddress(object.getString(BTCOBJ_ADDRESS_ADDRESS, "")); address.setMine(object.getBoolean(BTCOBJ_ADDRESS_MINE, false)); address.setScript(object.getBoolean(BTCOBJ_ADDRESS_SCRIPT, false)); address.setPublicKey(object.getString(BTCOBJ_ADDRESS_PUBLIC_KEY, "")); address.setCompressed(object.getBoolean(BTCOBJ_ADDRESS_COMPRESSED, false)); BtcAccount account = new BtcAccount(); account.setAccount(object.getString(BTCOBJ_ADDRESS_ACCOUNT, "")); address.setAccount(account); address.setAmount(jsonDouble(object, BTCOBJ_ADDRESS_AMOUNT)); address.setConfirmations(jsonLong(object, BTCOBJ_ADDRESS_CONFIRMATIONS)); return address; }