Changeset View
Changeset View
Standalone View
Standalone View
src/core_write.cpp
Show All 11 Lines | |||||
#include <script/standard.h> | #include <script/standard.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <univalue.h> | #include <univalue.h> | ||||
UniValue ValueFromAmount(const Amount &amount) { | |||||
bool sign = amount < Amount::zero(); | |||||
Amount n_abs(sign ? -amount : amount); | |||||
int64_t quotient = n_abs / COIN; | |||||
int64_t remainder = (n_abs % COIN) / SATOSHI; | |||||
return UniValue(UniValue::VNUM, strprintf("%s%d.%08d", sign ? "-" : "", | |||||
quotient, remainder)); | |||||
} | |||||
std::string FormatScript(const CScript &script) { | std::string FormatScript(const CScript &script) { | ||||
std::string ret; | std::string ret; | ||||
CScript::const_iterator it = script.begin(); | CScript::const_iterator it = script.begin(); | ||||
opcodetype op; | opcodetype op; | ||||
while (it != script.end()) { | while (it != script.end()) { | ||||
CScript::const_iterator it2 = it; | CScript::const_iterator it2 = it; | ||||
std::vector<uint8_t> vch; | std::vector<uint8_t> vch; | ||||
if (script.GetOp(it, op, vch)) { | if (script.GetOp(it, op, vch)) { | ||||
▲ Show 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, UniValue &entry, | ||||
entry.pushKV("vin", vin); | entry.pushKV("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.pushKV("value", ValueFromAmount(txout.nValue)); | out.pushKV("value", txout.nValue); | ||||
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); | ||||
out.pushKV("scriptPubKey", o); | out.pushKV("scriptPubKey", o); | ||||
vout.push_back(out); | vout.push_back(out); | ||||
} | } | ||||
Show All 12 Lines |