From a8eed01cc6e22568dd302b8fb1a46a88ed7721aa Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 31 Jul 2019 21:07:40 -0400 Subject: [PATCH] shared_ptr cnTxToTx(const cryptonote::transaction& cnTx, bool initAsTxWallet = false); --- src/utils/MoneroUtils.cpp | 6 +++--- src/utils/MoneroUtils.h | 10 ++++++---- src/wallet/MoneroWallet.cpp | 5 ++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/utils/MoneroUtils.cpp b/src/utils/MoneroUtils.cpp index c8d871f..c7e87ee 100644 --- a/src/utils/MoneroUtils.cpp +++ b/src/utils/MoneroUtils.cpp @@ -479,15 +479,15 @@ shared_ptr MoneroUtils::cnBlockToBlock(const cryptonote::block& cnB block->timestamp = cnBlock.timestamp; block->prevId = epee::string_tools::pod_to_hex(cnBlock.prev_id); block->nonce = cnBlock.nonce; - block->coinbaseTx = MoneroUtils::cnTransactionToTx(cnBlock.miner_tx); + block->coinbaseTx = MoneroUtils::cnTxToTx(cnBlock.miner_tx); for (const crypto::hash& txHash : cnBlock.tx_hashes) { block->txIds.push_back(epee::string_tools::pod_to_hex(txHash)); } return block; } -shared_ptr MoneroUtils::cnTransactionToTx(const cryptonote::transaction& cnTx) { - shared_ptr tx = make_shared(); +shared_ptr MoneroUtils::cnTxToTx(const cryptonote::transaction& cnTx, bool initAsTxWallet) { + shared_ptr tx = initAsTxWallet ? make_shared() : make_shared(); //tx->version = cnTx.version; tx->unlockTime = cnTx.unlock_time; tx->id = epee::string_tools::pod_to_hex(cnTx.hash); diff --git a/src/utils/MoneroUtils.h b/src/utils/MoneroUtils.h index 009a850..c698795 100644 --- a/src/utils/MoneroUtils.h +++ b/src/utils/MoneroUtils.h @@ -92,13 +92,15 @@ namespace MoneroUtils */ shared_ptr cnBlockToBlock(const cryptonote::block& cnBlock); + /** - * Convert a Monero Core cryptonote::transaction to a transaction in this library's native model. + * Convert a Monero Core crpytonote::transaction to a transaction in this library's + * native model. * - * @param cnTransaction is the Core transaction to convert - * @return a transaction in this library's native model + * @param cnTx is the Core transaction to convert + * @param initAsTxWallet specifies if a MoneroTx xor MoneroTxWallet should be initialized */ - shared_ptr cnTransactionToTx(const cryptonote::transaction& cnTransaction); + shared_ptr cnTxToTx(const cryptonote::transaction& cnTx, bool initAsTxWallet = false); /** * Modified from core_rpc_server.cpp to return a string. diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index 4e5f31f..9b34800 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -719,14 +719,17 @@ namespace monero { // TODO **: fill this out shared_ptr block = make_shared(); block->height = height; - shared_ptr tx = make_shared(); + shared_ptr tx = static_pointer_cast(MoneroUtils::cnTxToTx(cnTx, true)); block->txs.push_back(tx); tx->block = block; tx->id = epee::string_tools::pod_to_hex(txid); + tx->unlockTime = unlock_time; shared_ptr transfer = make_shared(); tx->incomingTransfers.push_back(transfer); transfer->tx = tx; transfer->amount = amount; + transfer->accountIndex = subaddr_index.major; + transfer->subaddressIndex = subaddr_index.minor; // notify listener of transfer listener->onIncomingTransfer(*transfer);