Changeset View
Changeset View
Standalone View
Standalone View
src/core_write.cpp
| Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | |||||
| std::string EncodeHexTx(const CTransaction &tx, const int serialFlags) { | std::string EncodeHexTx(const CTransaction &tx, const int serialFlags) { | ||||
| CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | serialFlags); | CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | serialFlags); | ||||
| ssTx << tx; | ssTx << tx; | ||||
| return HexStr(ssTx.begin(), ssTx.end()); | return HexStr(ssTx.begin(), ssTx.end()); | ||||
| } | } | ||||
| void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, | void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, | ||||
| bool fIncludeHex) { | bool fIncludeHex, const Config &config) { | ||||
| 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.pushKV("hex", HexStr(scriptPubKey.begin(), scriptPubKey.end())); | out.pushKV("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, config)); | ||||
| } | } | ||||
| out.pushKV("addresses", a); | out.pushKV("addresses", a); | ||||
| } | } | ||||
| void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, | void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, UniValue &entry, | ||||
| UniValue &entry) { | const Config &config) { | ||||
deadalnix: This looks like you only need the chainparams in there. | |||||
| 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.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]; | ||||
| Show All 23 Lines | for (unsigned int i = 0; i < tx.vout.size(); i++) { | ||||
| UniValue out(UniValue::VOBJ); | UniValue out(UniValue::VOBJ); | ||||
| UniValue outValue(UniValue::VNUM, FormatMoney(txout.nValue)); | UniValue outValue(UniValue::VNUM, FormatMoney(txout.nValue)); | ||||
| out.pushKV("value", outValue); | out.pushKV("value", outValue); | ||||
| out.pushKV("n", (int64_t)i); | out.pushKV("n", (int64_t)i); | ||||
| UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
| ScriptPubKeyToUniv(txout.scriptPubKey, o, true); | ScriptPubKeyToUniv(txout.scriptPubKey, o, true, config); | ||||
| out.pushKV("scriptPubKey", o); | out.pushKV("scriptPubKey", o); | ||||
| vout.push_back(out); | vout.push_back(out); | ||||
| } | } | ||||
| entry.pushKV("vout", vout); | entry.pushKV("vout", vout); | ||||
| if (!hashBlock.IsNull()) { | if (!hashBlock.IsNull()) { | ||||
| entry.pushKV("blockhash", hashBlock.GetHex()); | entry.pushKV("blockhash", hashBlock.GetHex()); | ||||
| } | } | ||||
| // the hex-encoded transaction. used the name "hex" to be consistent with | // the hex-encoded transaction. used the name "hex" to be consistent with | ||||
| // the verbose output of "getrawtransaction". | // the verbose output of "getrawtransaction". | ||||
| entry.pushKV("hex", EncodeHexTx(tx)); | entry.pushKV("hex", EncodeHexTx(tx)); | ||||
| } | } | ||||
This looks like you only need the chainparams in there.