|
|
@ -62,7 +62,9 @@ UniValue TxJoinSplitToJSON(const CTransaction& tx) { |
|
|
|
UniValue joinsplit(UniValue::VOBJ); |
|
|
|
|
|
|
|
joinsplit.push_back(Pair("vpub_old", ValueFromAmount(jsdescription.vpub_old))); |
|
|
|
joinsplit.push_back(Pair("vpub_oldZat", jsdescription.vpub_old)); |
|
|
|
joinsplit.push_back(Pair("vpub_new", ValueFromAmount(jsdescription.vpub_new))); |
|
|
|
joinsplit.push_back(Pair("vpub_newZat", jsdescription.vpub_new)); |
|
|
|
|
|
|
|
joinsplit.push_back(Pair("anchor", jsdescription.anchor.GetHex())); |
|
|
|
|
|
|
@ -110,9 +112,11 @@ UniValue TxJoinSplitToJSON(const CTransaction& tx) { |
|
|
|
return vjoinsplit; |
|
|
|
} |
|
|
|
|
|
|
|
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) |
|
|
|
void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, Object& entry, |
|
|
|
int nHeight = 0, int nConfirmations = 0, int nBlockTime = 0) |
|
|
|
{ |
|
|
|
entry.push_back(Pair("txid", tx.GetHash().GetHex())); |
|
|
|
uint256 txid = tx.GetTxid(); |
|
|
|
entry.push_back(Pair("txid", txid.GetHex())); |
|
|
|
entry.push_back(Pair("version", tx.nVersion)); |
|
|
|
entry.push_back(Pair("locktime", (int64_t)tx.nLockTime)); |
|
|
|
UniValue vin(UniValue::VARR); |
|
|
@ -127,6 +131,20 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) |
|
|
|
o.push_back(Pair("asm", txin.scriptSig.ToString())); |
|
|
|
o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); |
|
|
|
in.push_back(Pair("scriptSig", o)); |
|
|
|
|
|
|
|
// Add address and value info if spentindex enabled
|
|
|
|
CSpentIndexValue spentInfo; |
|
|
|
CSpentIndexKey spentKey(txin.prevout.hash, txin.prevout.n); |
|
|
|
if (GetSpentIndex(spentKey, spentInfo)) { |
|
|
|
in.push_back(Pair("value", ValueFromAmount(spentInfo.satoshis))); |
|
|
|
in.push_back(Pair("valueSat", spentInfo.satoshis)); |
|
|
|
if (spentInfo.addressType == 1) { |
|
|
|
in.push_back(Pair("address", CBitcoinAddress(CKeyID(spentInfo.addressHash)).ToString())); |
|
|
|
} else if (spentInfo.addressType == 2) { |
|
|
|
in.push_back(Pair("address", CBitcoinAddress(CScriptID(spentInfo.addressHash)).ToString())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
in.push_back(Pair("sequence", (int64_t)txin.nSequence)); |
|
|
|
vin.push_back(in); |
|
|
@ -137,11 +155,22 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) |
|
|
|
const CTxOut& txout = tx.vout[i]; |
|
|
|
UniValue out(UniValue::VOBJ); |
|
|
|
out.push_back(Pair("value", ValueFromAmount(txout.nValue))); |
|
|
|
out.push_back(Pair("valueSat", txout.nValue)); |
|
|
|
out.push_back(Pair("valueZat", txout.nValue)); |
|
|
|
out.push_back(Pair("n", (int64_t)i)); |
|
|
|
UniValue o(UniValue::VOBJ); |
|
|
|
ScriptPubKeyToJSON(txout.scriptPubKey, o, true); |
|
|
|
out.push_back(Pair("scriptPubKey", o)); |
|
|
|
|
|
|
|
// Add spent information if spentindex is enabled
|
|
|
|
CSpentIndexValue spentInfo; |
|
|
|
CSpentIndexKey spentKey(txid, i); |
|
|
|
if (GetSpentIndex(spentKey, spentInfo)) { |
|
|
|
out.push_back(Pair("spentTxId", spentInfo.txid.GetHex())); |
|
|
|
out.push_back(Pair("spentIndex", (int)spentInfo.inputIndex)); |
|
|
|
out.push_back(Pair("spentHeight", spentInfo.blockHeight)); |
|
|
|
} |
|
|
|
|
|
|
|
vout.push_back(out); |
|
|
|
} |
|
|
|
entry.push_back(Pair("vout", vout)); |
|
|
@ -149,17 +178,76 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) |
|
|
|
UniValue vjoinsplit = TxJoinSplitToJSON(tx); |
|
|
|
entry.push_back(Pair("vjoinsplit", vjoinsplit)); |
|
|
|
|
|
|
|
if (!hashBlock.IsNull()) { |
|
|
|
entry.push_back(Pair("blockhash", hashBlock.GetHex())); |
|
|
|
|
|
|
|
if (nConfirmations > 0) { |
|
|
|
entry.push_back(Pair("height", nHeight)); |
|
|
|
entry.push_back(Pair("confirmations", nConfirmations)); |
|
|
|
entry.push_back(Pair("time", nBlockTime)); |
|
|
|
entry.push_back(Pair("blocktime", nBlockTime)); |
|
|
|
} else { |
|
|
|
entry.push_back(Pair("height", -1)); |
|
|
|
entry.push_back(Pair("confirmations", 0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) |
|
|
|
{ |
|
|
|
|
|
|
|
uint256 txid = tx.GetTxid(); |
|
|
|
entry.push_back(Pair("txid", txid.GetHex())); |
|
|
|
entry.push_back(Pair("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION))); |
|
|
|
entry.push_back(Pair("version", tx.nVersion)); |
|
|
|
entry.push_back(Pair("locktime", (int64_t)tx.nLockTime)); |
|
|
|
|
|
|
|
Array vin; |
|
|
|
BOOST_FOREACH(const CTxIn& txin, tx.vin) { |
|
|
|
Object in; |
|
|
|
if (tx.IsCoinBase()) |
|
|
|
in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); |
|
|
|
else { |
|
|
|
in.push_back(Pair("txid", txin.prevout.hash.GetHex())); |
|
|
|
in.push_back(Pair("vout", (int64_t)txin.prevout.n)); |
|
|
|
Object o; |
|
|
|
o.push_back(Pair("asm", txin.scriptSig.ToString())); |
|
|
|
o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); |
|
|
|
in.push_back(Pair("scriptSig", o)); |
|
|
|
} |
|
|
|
in.push_back(Pair("sequence", (int64_t)txin.nSequence)); |
|
|
|
vin.push_back(in); |
|
|
|
} |
|
|
|
entry.push_back(Pair("vin", vin)); |
|
|
|
|
|
|
|
Array vout; |
|
|
|
for (unsigned int i = 0; i < tx.vout.size(); i++) { |
|
|
|
const CTxOut& txout = tx.vout[i]; |
|
|
|
Object out; |
|
|
|
out.push_back(Pair("value", ValueFromAmount(txout.nValue))); |
|
|
|
out.push_back(Pair("valueSat", txout.nValue)); |
|
|
|
out.push_back(Pair("n", (int64_t)i)); |
|
|
|
Object o; |
|
|
|
ScriptPubKeyToJSON(txout.scriptPubKey, o, true); |
|
|
|
out.push_back(Pair("scriptPubKey", o)); |
|
|
|
vout.push_back(out); |
|
|
|
} |
|
|
|
entry.push_back(Pair("vout", vout)); |
|
|
|
|
|
|
|
if (!hashBlock.IsNull()) { |
|
|
|
entry.push_back(Pair("blockhash", hashBlock.GetHex())); |
|
|
|
BlockMap::iterator mi = mapBlockIndex.find(hashBlock); |
|
|
|
if (mi != mapBlockIndex.end() && (*mi).second) { |
|
|
|
CBlockIndex* pindex = (*mi).second; |
|
|
|
if (chainActive.Contains(pindex)) { |
|
|
|
entry.push_back(Pair("height", pindex->nHeight)); |
|
|
|
entry.push_back(Pair("confirmations", 1 + chainActive.Height() - pindex->nHeight)); |
|
|
|
entry.push_back(Pair("time", pindex->GetBlockTime())); |
|
|
|
entry.push_back(Pair("blocktime", pindex->GetBlockTime())); |
|
|
|
} |
|
|
|
else |
|
|
|
entry.push_back(Pair("height", -1)); |
|
|
|
entry.push_back(Pair("confirmations", 0)); |
|
|
|
} |
|
|
|
} |
|
|
@ -258,8 +346,6 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp) |
|
|
|
+ HelpExampleRpc("getrawtransaction", "\"mytxid\", 1") |
|
|
|
); |
|
|
|
|
|
|
|
LOCK(cs_main); |
|
|
|
|
|
|
|
uint256 hash = ParseHashV(params[0], "parameter 1"); |
|
|
|
|
|
|
|
bool fVerbose = false; |
|
|
@ -267,9 +353,32 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp) |
|
|
|
fVerbose = (params[1].get_int() != 0); |
|
|
|
|
|
|
|
CTransaction tx; |
|
|
|
|
|
|
|
uint256 hashBlock; |
|
|
|
if (!GetTransaction(hash, tx, hashBlock, true)) |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction"); |
|
|
|
int nHeight = 0; |
|
|
|
int nConfirmations = 0; |
|
|
|
|
|
|
|
int nBlockTime = 0; |
|
|
|
|
|
|
|
{ |
|
|
|
LOCK(cs_main); |
|
|
|
if (!GetTransaction(hash, tx, hashBlock, true)) |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction"); |
|
|
|
|
|
|
|
BlockMap::iterator mi = mapBlockIndex.find(hashBlock); |
|
|
|
if (mi != mapBlockIndex.end() && (*mi).second) { |
|
|
|
CBlockIndex* pindex = (*mi).second; |
|
|
|
if (chainActive.Contains(pindex)) { |
|
|
|
nHeight = pindex->nHeight; |
|
|
|
nConfirmations = 1 + chainActive.Height() - pindex->nHeight; |
|
|
|
nBlockTime = pindex->GetBlockTime(); |
|
|
|
} else { |
|
|
|
nHeight = -1; |
|
|
|
nConfirmations = 0; |
|
|
|
nBlockTime = pindex->GetBlockTime(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
string strHex = EncodeHexTx(tx); |
|
|
|
|
|
|
@ -278,7 +387,7 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp) |
|
|
|
|
|
|
|
UniValue result(UniValue::VOBJ); |
|
|
|
result.push_back(Pair("hex", strHex)); |
|
|
|
TxToJSON(tx, hashBlock, result); |
|
|
|
TxToJSONExpanded(tx, hashBlock, result, nHeight, nConfirmations, nBlockTime); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|