return uBits.nBits;
}
+void TxToJSON(const CTransaction &tx, Object& entry)
+{
+ entry.push_back(Pair("version", tx.nVersion));
+ entry.push_back(Pair("locktime", (boost::int64_t)tx.nLockTime));
+ entry.push_back(Pair("size", (boost::int64_t)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION)));
+ 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
+ {
+ Object prevout;
+ prevout.push_back(Pair("hash", txin.prevout.hash.GetHex()));
+ prevout.push_back(Pair("n", (boost::int64_t)txin.prevout.n));
+ in.push_back(Pair("prevout", prevout));
+ in.push_back(Pair("scriptSig", txin.scriptSig.ToString()));
+ }
+ in.push_back(Pair("sequence", (boost::int64_t)txin.nSequence));
+ vin.push_back(in);
+ }
+ entry.push_back(Pair("vin", vin));
+ Array vout;
+ BOOST_FOREACH(const CTxOut& txout, tx.vout)
+ {
+ Object out;
+ out.push_back(Pair("value", ValueFromAmount(txout.nValue)));
+ out.push_back(Pair("scriptPubKey", txout.scriptPubKey.ToString()));
+ vout.push_back(out);
+ }
+ entry.push_back(Pair("vout", vout));
+}
+
void WalletTxToJSON(const CWalletTx& wtx, Object& entry)
{
int confirms = wtx.GetDepthInMainChain();
{
if (fPrintTransactionDetail)
{
- txinfo.push_back(tx.ToStringShort());
- txinfo.push_back(DateTimeStrFormat(tx.nTime));
- BOOST_FOREACH(const CTxIn& txin, tx.vin)
- txinfo.push_back(txin.ToStringShort());
- BOOST_FOREACH(const CTxOut& txout, tx.vout)
- txinfo.push_back(txout.ToStringShort());
+ Object entry;
+
+ entry.push_back(Pair("txid", tx.GetHash().GetHex()));
+ TxToJSON(tx, entry);
+ entry.push_back(Pair("time", DateTimeStrFormat(tx.nTime)));
+
+ txinfo.push_back(entry);
}
else
txinfo.push_back(tx.GetHash().GetHex());
}
- result.push_back(Pair("tx", txinfo));
+ result.push_back(Pair("tx", txinfo));
+
return result;
}
Object entry;
- if (!pwalletMain->mapWallet.count(hash))
- throw JSONRPCError(-5, "Invalid or non-wallet transaction id");
- const CWalletTx& wtx = pwalletMain->mapWallet[hash];
+ if (pwalletMain->mapWallet.count(hash))
+ {
+ const CWalletTx& wtx = pwalletMain->mapWallet[hash];
+
+ TxToJSON(wtx, entry);
- int64 nCredit = wtx.GetCredit();
- int64 nDebit = wtx.GetDebit();
- int64 nNet = nCredit - nDebit;
- int64 nFee = (wtx.IsFromMe() ? wtx.GetValueOut() - nDebit : 0);
+ int64 nCredit = wtx.GetCredit();
+ int64 nDebit = wtx.GetDebit();
+ int64 nNet = nCredit - nDebit;
+ int64 nFee = (wtx.IsFromMe() ? wtx.GetValueOut() - nDebit : 0);
- entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
- if (wtx.IsFromMe())
- entry.push_back(Pair("fee", ValueFromAmount(nFee)));
+ entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
+ if (wtx.IsFromMe())
+ entry.push_back(Pair("fee", ValueFromAmount(nFee)));
- WalletTxToJSON(pwalletMain->mapWallet[hash], entry);
+ WalletTxToJSON(wtx, entry);
- Array details;
- ListTransactions(pwalletMain->mapWallet[hash], "*", 0, false, details);
- entry.push_back(Pair("details", details));
+ Array details;
+ ListTransactions(pwalletMain->mapWallet[hash], "*", 0, false, details);
+ entry.push_back(Pair("details", details));
+ }
+ else
+ {
+ CTransaction tx;
+ uint256 hashBlock = 0;
+ if (GetTransaction(hash, tx, hashBlock))
+ {
+ entry.push_back(Pair("txid", hash.GetHex()));
+ TxToJSON(tx, entry);
+ if (hashBlock == 0)
+ entry.push_back(Pair("confirmations", 0));
+ else
+ {
+ entry.push_back(Pair("blockhash", hashBlock.GetHex()));
+ map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock);
+ if (mi != mapBlockIndex.end() && (*mi).second)
+ {
+ CBlockIndex* pindex = (*mi).second;
+ if (pindex->IsInMainChain())
+ {
+ entry.push_back(Pair("confirmations", 1 + nBestHeight - pindex->nHeight));
+ entry.push_back(Pair("txntime", (boost::int64_t)tx.nTime));
+ entry.push_back(Pair("time", (boost::int64_t)pindex->nTime));
+ }
+ else
+ entry.push_back(Pair("confirmations", 0));
+ }
+ }
+ }
+ else
+ throw JSONRPCError(-5, "No information available about transaction");
+ }
return entry;
}
pwalletMain->TopUpKeyPool();
// Generate a new key that is added to wallet
- std::vector<unsigned char> newKey = pwalletMain->GenerateNewKey(false);
+ std::vector<unsigned char> newKey = pwalletMain->GenerateNewKey(true);
if(!newKey.size())
throw JSONRPCError(-12, "Error: Unable to create key");