From 6d994454d56426bf3eb27a3738caa509a9f72ad5 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 13 Nov 2014 15:45:55 -0800 Subject: [PATCH] always include hex in wallet transactions. convert to regular transactions. --- lib/bitcoind.js | 12 ++++++++---- src/bitcoindjs.cc | 13 +++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/bitcoind.js b/lib/bitcoind.js index 82a4b0bc..9836fb1d 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -809,12 +809,14 @@ Wallet.prototype.getUnconfirmedBalance = function(options) { }; // XXX Wallet Transactions +// Convert to regular TX Wallet.prototype.listTransactions = Wallet.prototype.getTransactions = function(options) { - return bitcoindjs.walletListTransactions(options || {}); + return bitcoindjs.walletListTransactions(options || {}).map(function(tx) { + return Transaction.fromHex(tx.hex); + }); }; -// XXX Wallet Transactions Wallet.prototype.listReceivedByAddress = Wallet.prototype.getReceivedByAddress = function(options) { return bitcoindjs.walletReceivedByAddress(options || {}); @@ -825,9 +827,11 @@ Wallet.prototype.getAccounts = function(options) { return bitcoindjs.walletListAccounts(options || {}); }; -// XXX Wallet Transactions +// XXX Wallet Transaction +// Convert to regular TX Wallet.prototype.getTransaction = function(options) { - return bitcoindjs.walletGetTransaction(options || {}); + var tx = bitcoindjs.walletGetTransaction(options || {}); + return tx ? Transaction.fromHex(tx.hex) : tx; }; Wallet.prototype.backup = function(options) { diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index ad043c82..b72812f0 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -4136,6 +4136,9 @@ WalletTxToJSON_V8(const CWalletTx& wtx, Local& entry) { BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue) { entry->Set(NanNew(item.first), NanNew(item.second)); } + + std::string strHex = EncodeHexTx(static_cast(wtx)); + entry->Set(NanNew("hex"), NanNew(strHex)); } static void @@ -4176,6 +4179,9 @@ ListTransactions_V8(const CWalletTx& wtx, const string& strAccount, entry->Set(NanNew("fee"), NanNew(-nFee)); if (fLong) { WalletTxToJSON_V8(wtx, entry); + } else { + std::string strHex = EncodeHexTx(static_cast(wtx)); + entry->Set(NanNew("hex"), NanNew(strHex)); } ret->Set(i, entry); i++; @@ -4212,6 +4218,9 @@ ListTransactions_V8(const CWalletTx& wtx, const string& strAccount, // entry->Set(NanNew("vout"), NanNew(r.vout)); if (fLong) { WalletTxToJSON_V8(wtx, entry); + } else { + std::string strHex = EncodeHexTx(static_cast(wtx)); + entry->Set(NanNew("hex"), NanNew(strHex)); } ret->Set(i, entry); i++; @@ -4449,8 +4458,8 @@ NAN_METHOD(WalletGetTransaction) { ListTransactions_V8(wtx, "*", 0, false, details, filter, &a_count); entry->Set(NanNew("details"), details); - std::string strHex = EncodeHexTx(static_cast(wtx)); - entry->Set(NanNew("hex"), NanNew(strHex)); + //std::string strHex = EncodeHexTx(static_cast(wtx)); + //entry->Set(NanNew("hex"), NanNew(strHex)); NanReturnValue(entry); }