Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show All 38 Lines | |||||
void ScriptPubKeyToJSON(const Config &config, const CScript &scriptPubKey, | void ScriptPubKeyToJSON(const Config &config, const CScript &scriptPubKey, | ||||
UniValue &out, bool fIncludeHex) { | UniValue &out, bool fIncludeHex) { | ||||
txnouttype type; | txnouttype type; | ||||
std::vector<CTxDestination> addresses; | std::vector<CTxDestination> addresses; | ||||
int nRequired; | int nRequired; | ||||
out.pushKV("asm", ScriptToAsmStr(scriptPubKey)); | out.pushKV("asm", ScriptToAsmStr(scriptPubKey)); | ||||
if (fIncludeHex) { | if (fIncludeHex) { | ||||
out.push_back( | out.pushKV("hex", HexStr(scriptPubKey.begin(), scriptPubKey.end())); | ||||
Pair("hex", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); | |||||
} | } | ||||
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) { | if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) { | ||||
out.pushKV("type", GetTxnOutputType(type)); | out.pushKV("type", GetTxnOutputType(type)); | ||||
return; | return; | ||||
} | } | ||||
out.pushKV("reqSigs", nRequired); | out.pushKV("reqSigs", nRequired); | ||||
out.pushKV("type", GetTxnOutputType(type)); | out.pushKV("type", GetTxnOutputType(type)); | ||||
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.pushKV("addresses", a); | out.pushKV("addresses", a); | ||||
} | } | ||||
void TxToJSON(const Config &config, const CTransaction &tx, | void TxToJSON(const Config &config, const CTransaction &tx, | ||||
const uint256 hashBlock, UniValue &entry) { | const uint256 hashBlock, UniValue &entry) { | ||||
entry.pushKV("txid", tx.GetId().GetHex()); | entry.pushKV("txid", tx.GetId().GetHex()); | ||||
entry.pushKV("hash", tx.GetHash().GetHex()); | entry.pushKV("hash", tx.GetHash().GetHex()); | ||||
entry.push_back(Pair( | entry.pushKV("size", | ||||
"size", int(::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION)))); | int(::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION))); | ||||
entry.pushKV("version", tx.nVersion); | entry.pushKV("version", tx.nVersion); | ||||
entry.pushKV("locktime", int64_t(tx.nLockTime)); | entry.pushKV("locktime", int64_t(tx.nLockTime)); | ||||
UniValue vin(UniValue::VARR); | UniValue vin(UniValue::VARR); | ||||
for (unsigned int i = 0; i < tx.vin.size(); i++) { | for (unsigned int i = 0; i < tx.vin.size(); i++) { | ||||
const CTxIn &txin = tx.vin[i]; | const CTxIn &txin = tx.vin[i]; | ||||
UniValue in(UniValue::VOBJ); | UniValue in(UniValue::VOBJ); | ||||
if (tx.IsCoinBase()) { | if (tx.IsCoinBase()) { | ||||
in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), | in.pushKV("coinbase", | ||||
txin.scriptSig.end()))); | HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); | ||||
} else { | } else { | ||||
in.pushKV("txid", txin.prevout.GetTxId().GetHex()); | in.pushKV("txid", txin.prevout.GetTxId().GetHex()); | ||||
in.pushKV("vout", int64_t(txin.prevout.GetN())); | in.pushKV("vout", int64_t(txin.prevout.GetN())); | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true)); | o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true)); | ||||
o.push_back(Pair( | o.pushKV("hex", | ||||
"hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); | HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); | ||||
in.pushKV("scriptSig", o); | in.pushKV("scriptSig", o); | ||||
} | } | ||||
in.pushKV("sequence", int64_t(txin.nSequence)); | in.pushKV("sequence", int64_t(txin.nSequence)); | ||||
vin.push_back(in); | vin.push_back(in); | ||||
} | } | ||||
entry.pushKV("vin", vin); | entry.pushKV("vin", vin); | ||||
Show All 12 Lines | void TxToJSON(const Config &config, const CTransaction &tx, | ||||
entry.pushKV("vout", vout); | entry.pushKV("vout", vout); | ||||
if (!hashBlock.IsNull()) { | if (!hashBlock.IsNull()) { | ||||
entry.pushKV("blockhash", hashBlock.GetHex()); | entry.pushKV("blockhash", hashBlock.GetHex()); | ||||
BlockMap::iterator mi = mapBlockIndex.find(hashBlock); | BlockMap::iterator mi = mapBlockIndex.find(hashBlock); | ||||
if (mi != mapBlockIndex.end() && (*mi).second) { | if (mi != mapBlockIndex.end() && (*mi).second) { | ||||
CBlockIndex *pindex = (*mi).second; | CBlockIndex *pindex = (*mi).second; | ||||
if (chainActive.Contains(pindex)) { | if (chainActive.Contains(pindex)) { | ||||
entry.push_back( | entry.pushKV("confirmations", | ||||
Pair("confirmations", | 1 + chainActive.Height() - pindex->nHeight); | ||||
1 + chainActive.Height() - pindex->nHeight)); | |||||
entry.pushKV("time", pindex->GetBlockTime()); | entry.pushKV("time", pindex->GetBlockTime()); | ||||
entry.pushKV("blocktime", pindex->GetBlockTime()); | entry.pushKV("blocktime", pindex->GetBlockTime()); | ||||
} else { | } else { | ||||
entry.pushKV("confirmations", 0); | entry.pushKV("confirmations", 0); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 583 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Pushes a JSON object for script verification or signing errors to vErrorsRet. | * Pushes a JSON object for script verification or signing errors to vErrorsRet. | ||||
*/ | */ | ||||
static void TxInErrorToJSON(const CTxIn &txin, UniValue &vErrorsRet, | static void TxInErrorToJSON(const CTxIn &txin, UniValue &vErrorsRet, | ||||
const std::string &strMessage) { | const std::string &strMessage) { | ||||
UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
entry.pushKV("txid", txin.prevout.GetTxId().ToString()); | entry.pushKV("txid", txin.prevout.GetTxId().ToString()); | ||||
entry.pushKV("vout", uint64_t(txin.prevout.GetN())); | entry.pushKV("vout", uint64_t(txin.prevout.GetN())); | ||||
entry.push_back(Pair("scriptSig", | entry.pushKV("scriptSig", | ||||
HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); | HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); | ||||
entry.pushKV("sequence", uint64_t(txin.nSequence)); | entry.pushKV("sequence", uint64_t(txin.nSequence)); | ||||
entry.pushKV("error", strMessage); | entry.pushKV("error", strMessage); | ||||
vErrorsRet.push_back(entry); | vErrorsRet.push_back(entry); | ||||
} | } | ||||
UniValue combinerawtransaction(const Config &config, | UniValue combinerawtransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
▲ Show 20 Lines • Show All 553 Lines • Show Last 20 Lines |