Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show All 38 Lines | |||||
void TxToJSON(const CTransaction &tx, const uint256 hashBlock, | void TxToJSON(const CTransaction &tx, const uint256 hashBlock, | ||||
UniValue &entry) { | UniValue &entry) { | ||||
// Call into TxToUniv() in bitcoin-common to decode the transaction hex. | // Call into TxToUniv() in bitcoin-common to decode the transaction hex. | ||||
// | // | ||||
// Blockchain contextual information (confirmations and blocktime) is not | // Blockchain contextual information (confirmations and blocktime) is not | ||||
// available to code in bitcoin-common, so we query them here and push the | // available to code in bitcoin-common, so we query them here and push the | ||||
// data into the returned UniValue. | // data into the returned UniValue. | ||||
TxToUniv(tx, uint256(), entry); | TxToUniv(tx, uint256(), entry); | ||||
if (!hashBlock.IsNull()) { | |||||
entry.pushKV("blockhash", hashBlock.GetHex()); | |||||
BlockMap::iterator mi = mapBlockIndex.find(hashBlock); | |||||
if (mi != mapBlockIndex.end() && (*mi).second) { | |||||
CBlockIndex *pindex = (*mi).second; | |||||
if (chainActive.Contains(pindex)) { | |||||
entry.pushKV("confirmations", | |||||
1 + chainActive.Height() - pindex->nHeight); | |||||
entry.pushKV("time", pindex->GetBlockTime()); | |||||
entry.pushKV("blocktime", pindex->GetBlockTime()); | |||||
} else { | |||||
entry.pushKV("confirmations", 0); | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
static UniValue getrawtransaction(const Config &config, | static UniValue getrawtransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getrawtransaction \"txid\" ( verbose )\n" | "getrawtransaction \"txid\" ( verbose )\n" | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | static UniValue getrawtransaction(const Config &config, | ||||
std::string strHex = EncodeHexTx(*tx, RPCSerializationFlags()); | std::string strHex = EncodeHexTx(*tx, RPCSerializationFlags()); | ||||
if (!fVerbose) { | if (!fVerbose) { | ||||
return strHex; | return strHex; | ||||
} | } | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
result.pushKV("hex", strHex); | result.pushKV("hex", strHex); | ||||
TxToUniv(*tx, hashBlock, result); | TxToJSON(*tx, hashBlock, result); | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue gettxoutproof(const Config &config, | static UniValue gettxoutproof(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || | if (request.fHelp || | ||||
(request.params.size() != 1 && request.params.size() != 2)) { | (request.params.size() != 1 && request.params.size() != 2)) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
▲ Show 20 Lines • Show All 1,025 Lines • Show Last 20 Lines |