Changeset View
Changeset View
Standalone View
Standalone View
src/rest.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "chain.h" | #include "chain.h" | ||||
#include "chainparams.h" | #include "chainparams.h" | ||||
#include "config.h" | #include "config.h" | ||||
#include "core_io.h" | |||||
#include "httpserver.h" | #include "httpserver.h" | ||||
#include "primitives/block.h" | #include "primitives/block.h" | ||||
#include "primitives/transaction.h" | #include "primitives/transaction.h" | ||||
#include "rpc/blockchain.h" | #include "rpc/blockchain.h" | ||||
#include "rpc/server.h" | #include "rpc/server.h" | ||||
#include "rpc/tojson.h" | #include "rpc/tojson.h" | ||||
#include "streams.h" | #include "streams.h" | ||||
#include "sync.h" | #include "sync.h" | ||||
▲ Show 20 Lines • Show All 408 Lines • ▼ Show 20 Lines | switch (rf) { | ||||
std::string strHex = HexStr(ssTx.begin(), ssTx.end()) + "\n"; | std::string strHex = HexStr(ssTx.begin(), ssTx.end()) + "\n"; | ||||
req->WriteHeader("Content-Type", "text/plain"); | req->WriteHeader("Content-Type", "text/plain"); | ||||
req->WriteReply(HTTP_OK, strHex); | req->WriteReply(HTTP_OK, strHex); | ||||
return true; | return true; | ||||
} | } | ||||
case RF_JSON: { | case RF_JSON: { | ||||
UniValue objTx(UniValue::VOBJ); | UniValue objTx(UniValue::VOBJ); | ||||
TxToJSON(config, *tx, hashBlock, objTx); | TxToUniv(*tx, hashBlock, objTx); | ||||
std::string strJSON = objTx.write() + "\n"; | std::string strJSON = objTx.write() + "\n"; | ||||
req->WriteHeader("Content-Type", "application/json"); | req->WriteHeader("Content-Type", "application/json"); | ||||
req->WriteReply(HTTP_OK, strJSON); | req->WriteReply(HTTP_OK, strJSON); | ||||
return true; | return true; | ||||
} | } | ||||
default: { | default: { | ||||
return RESTERR(req, HTTP_NOT_FOUND, | return RESTERR(req, HTTP_NOT_FOUND, | ||||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | switch (rf) { | ||||
UniValue utxos(UniValue::VARR); | UniValue utxos(UniValue::VARR); | ||||
for (const CCoin &coin : outs) { | for (const CCoin &coin : outs) { | ||||
UniValue utxo(UniValue::VOBJ); | UniValue utxo(UniValue::VOBJ); | ||||
utxo.pushKV("height", int32_t(coin.nHeight)); | utxo.pushKV("height", int32_t(coin.nHeight)); | ||||
utxo.pushKV("value", ValueFromAmount(coin.out.nValue)); | utxo.pushKV("value", ValueFromAmount(coin.out.nValue)); | ||||
// include the script in a json output | // include the script in a json output | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
ScriptPubKeyToJSON(config, coin.out.scriptPubKey, o, true); | ScriptPubKeyToUniv(coin.out.scriptPubKey, o, true); | ||||
utxo.pushKV("scriptPubKey", o); | utxo.pushKV("scriptPubKey", o); | ||||
utxos.push_back(utxo); | utxos.push_back(utxo); | ||||
} | } | ||||
objGetUTXOResponse.pushKV("utxos", utxos); | objGetUTXOResponse.pushKV("utxos", utxos); | ||||
// return json string | // return json string | ||||
std::string strJSON = objGetUTXOResponse.write() + "\n"; | std::string strJSON = objGetUTXOResponse.write() + "\n"; | ||||
req->WriteHeader("Content-Type", "application/json"); | req->WriteHeader("Content-Type", "application/json"); | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |