Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show All 11 Lines | |||||
#include "dstencode.h" | #include "dstencode.h" | ||||
#include "init.h" | #include "init.h" | ||||
#include "keystore.h" | #include "keystore.h" | ||||
#include "merkleblock.h" | #include "merkleblock.h" | ||||
#include "net.h" | #include "net.h" | ||||
#include "policy/policy.h" | #include "policy/policy.h" | ||||
#include "primitives/transaction.h" | #include "primitives/transaction.h" | ||||
#include "rpc/server.h" | #include "rpc/server.h" | ||||
#include "rpc/tojson.h" | |||||
#include "script/script.h" | #include "script/script.h" | ||||
#include "script/script_error.h" | #include "script/script_error.h" | ||||
#include "script/sign.h" | #include "script/sign.h" | ||||
#include "script/standard.h" | #include "script/standard.h" | ||||
#include "txmempool.h" | #include "txmempool.h" | ||||
#include "uint256.h" | #include "uint256.h" | ||||
#include "utilstrencodings.h" | #include "utilstrencodings.h" | ||||
#include "validation.h" | #include "validation.h" | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
#include "wallet/wallet.h" | #include "wallet/wallet.h" | ||||
#endif | #endif | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <univalue.h> | #include <univalue.h> | ||||
void ScriptPubKeyToJSON(const CScript &scriptPubKey, UniValue &out, | void ScriptPubKeyToJSON(const Config &config, const CScript &scriptPubKey, | ||||
bool fIncludeHex) { | UniValue &out, bool fIncludeHex) { | ||||
txnouttype type; | txnouttype type; | ||||
std::vector<CTxDestination> addresses; | std::vector<CTxDestination> addresses; | ||||
int nRequired; | int nRequired; | ||||
out.push_back(Pair("asm", ScriptToAsmStr(scriptPubKey))); | out.push_back(Pair("asm", ScriptToAsmStr(scriptPubKey))); | ||||
if (fIncludeHex) { | if (fIncludeHex) { | ||||
out.push_back( | out.push_back( | ||||
Pair("hex", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); | Pair("hex", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); | ||||
Show All 10 Lines | void ScriptPubKeyToJSON(const Config &config, const CScript &scriptPubKey, | ||||
UniValue a(UniValue::VARR); | UniValue a(UniValue::VARR); | ||||
for (const CTxDestination &addr : addresses) { | for (const CTxDestination &addr : addresses) { | ||||
a.push_back(EncodeDestination(addr)); | a.push_back(EncodeDestination(addr)); | ||||
} | } | ||||
out.push_back(Pair("addresses", a)); | out.push_back(Pair("addresses", a)); | ||||
} | } | ||||
void TxToJSON(const CTransaction &tx, const uint256 hashBlock, | void TxToJSON(const Config &config, const CTransaction &tx, | ||||
UniValue &entry) { | const uint256 hashBlock, UniValue &entry) { | ||||
entry.push_back(Pair("txid", tx.GetId().GetHex())); | entry.push_back(Pair("txid", tx.GetId().GetHex())); | ||||
entry.push_back(Pair("hash", tx.GetHash().GetHex())); | entry.push_back(Pair("hash", tx.GetHash().GetHex())); | ||||
entry.push_back(Pair( | entry.push_back(Pair( | ||||
"size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION))); | "size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION))); | ||||
entry.push_back(Pair("version", tx.nVersion)); | entry.push_back(Pair("version", tx.nVersion)); | ||||
entry.push_back(Pair("locktime", (int64_t)tx.nLockTime)); | entry.push_back(Pair("locktime", (int64_t)tx.nLockTime)); | ||||
UniValue vin(UniValue::VARR); | UniValue vin(UniValue::VARR); | ||||
Show All 20 Lines | void TxToJSON(const Config &config, const CTransaction &tx, | ||||
entry.push_back(Pair("vin", vin)); | entry.push_back(Pair("vin", vin)); | ||||
UniValue vout(UniValue::VARR); | UniValue vout(UniValue::VARR); | ||||
for (unsigned int i = 0; i < tx.vout.size(); i++) { | for (unsigned int i = 0; i < tx.vout.size(); i++) { | ||||
const CTxOut &txout = tx.vout[i]; | const CTxOut &txout = tx.vout[i]; | ||||
UniValue out(UniValue::VOBJ); | UniValue out(UniValue::VOBJ); | ||||
out.push_back(Pair("value", ValueFromAmount(txout.nValue))); | out.push_back(Pair("value", ValueFromAmount(txout.nValue))); | ||||
out.push_back(Pair("n", (int64_t)i)); | out.push_back(Pair("n", (int64_t)i)); | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
ScriptPubKeyToJSON(txout.scriptPubKey, o, true); | ScriptPubKeyToJSON(config, txout.scriptPubKey, o, true); | ||||
out.push_back(Pair("scriptPubKey", o)); | out.push_back(Pair("scriptPubKey", o)); | ||||
vout.push_back(out); | vout.push_back(out); | ||||
} | } | ||||
entry.push_back(Pair("vout", vout)); | entry.push_back(Pair("vout", vout)); | ||||
if (!hashBlock.IsNull()) { | if (!hashBlock.IsNull()) { | ||||
entry.push_back(Pair("blockhash", hashBlock.GetHex())); | entry.push_back(Pair("blockhash", hashBlock.GetHex())); | ||||
▲ Show 20 Lines • Show All 134 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.push_back(Pair("hex", strHex)); | result.push_back(Pair("hex", strHex)); | ||||
TxToJSON(*tx, hashBlock, result); | TxToJSON(config, *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 369 Lines • ▼ Show 20 Lines | static UniValue decoderawtransaction(const Config &config, | ||||
CMutableTransaction mtx; | CMutableTransaction mtx; | ||||
if (!DecodeHexTx(mtx, request.params[0].get_str())) { | if (!DecodeHexTx(mtx, request.params[0].get_str())) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | ||||
} | } | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
TxToJSON(CTransaction(std::move(mtx)), uint256(), result); | TxToJSON(config, CTransaction(std::move(mtx)), uint256(), result); | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue decodescript(const Config &config, | static UniValue decodescript(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
Show All 27 Lines | static UniValue decodescript(const Config &config, | ||||
if (request.params[0].get_str().size() > 0) { | if (request.params[0].get_str().size() > 0) { | ||||
std::vector<uint8_t> scriptData( | std::vector<uint8_t> scriptData( | ||||
ParseHexV(request.params[0], "argument")); | ParseHexV(request.params[0], "argument")); | ||||
script = CScript(scriptData.begin(), scriptData.end()); | script = CScript(scriptData.begin(), scriptData.end()); | ||||
} else { | } else { | ||||
// Empty scripts are valid. | // Empty scripts are valid. | ||||
} | } | ||||
ScriptPubKeyToJSON(script, r, false); | ScriptPubKeyToJSON(config, script, r, false); | ||||
UniValue type; | UniValue type; | ||||
type = find_value(r, "type"); | type = find_value(r, "type"); | ||||
if (type.isStr() && type.get_str() != "scripthash") { | if (type.isStr() && type.get_str() != "scripthash") { | ||||
// P2SH cannot be wrapped in a P2SH. If this script is already a P2SH, | // P2SH cannot be wrapped in a P2SH. If this script is already a P2SH, | ||||
// don't return the address for a P2SH of the P2SH. | // don't return the address for a P2SH of the P2SH. | ||||
r.push_back(Pair("p2sh", EncodeDestination(CScriptID(script)))); | r.push_back(Pair("p2sh", EncodeDestination(CScriptID(script)))); | ||||
▲ Show 20 Lines • Show All 494 Lines • Show Last 20 Lines |