Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add functions to wallet API #9464

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
113dcf6
rebase
Aug 30, 2024
12c35d1
use API functions instead of wallet2 where possible
Sep 1, 2024
9ab5694
rbrunner7 review
Sep 2, 2024
8fb9913
remove blackball & ringdb
Sep 6, 2024
8d630d3
WIP rbrunner7 review round 2
Sep 7, 2024
49371c6
TransactionInfo, EnoteDetails, some clean-up
Sep 16, 2024
55c8463
still WIP rbrunner7 review round 2
Sep 16, 2024
42d61a7
resolve some TODOs, QUESTIONs and clean up
Sep 22, 2024
d39fc1f
rbrunner7 review round 3
Sep 22, 2024
7cddeb2
clean up, work on TODOs
Sep 23, 2024
e92942f
remove accept function from loadTx()
Sep 23, 2024
50d5711
clean-up, work on TODOs and QUESTIONs
Sep 27, 2024
14d35de
rbrunner7 review round 4: rename outputs to enotes
Sep 27, 2024
11f698d
rbrunner7 review round 4: writeWatchOnlyWallet; remove QUESTIONs
Sep 27, 2024
6fafd26
work on TODOs & QUESTIONs
Sep 30, 2024
1ad0c55
improve error messages and handling
Sep 30, 2024
9c63017
some bugs fixed
Sep 30, 2024
2e842ea
fix bugs
Oct 1, 2024
9cb69d8
replace term transfer
Oct 2, 2024
8c553f6
add enote_details .h/.cpp
Oct 7, 2024
4f393f8
Clean up, remove:
Oct 21, 2024
19ad41f
accept_func almost complete
Oct 21, 2024
9ab6da3
mini clean up
Oct 25, 2024
450bdcc
split up parse_tx_from_str() so accept_func() can be applied outside …
Oct 28, 2024
6704d55
jeffro256 review
Oct 31, 2024
d8e0ce1
remove cryptonote::address_parse_info
Nov 4, 2024
a47a07a
underscore
Nov 8, 2024
8738c59
add getter/setter for allow_mismatched_daemon_version
Nov 8, 2024
85d3200
callback functions interface
Nov 18, 2024
087b925
add setDaemon()
Nov 25, 2024
e077fd3
clean-up
Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/wallet/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(wallet_api_sources
wallet.cpp
wallet_manager.cpp
enote_details.cpp
transaction_info.cpp
transaction_history.cpp
pending_transaction.cpp
Expand All @@ -48,6 +49,7 @@ set(wallet_api_headers
set(wallet_api_private_headers
wallet.h
wallet_manager.h
enote_details.h
transaction_info.h
transaction_history.h
pending_transaction.h
Expand Down
96 changes: 96 additions & 0 deletions src/wallet/api/enote_details.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) 2014-2024, The Monero Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers

#include "enote_details.h"


namespace Monero {

EnoteDetails::~EnoteDetails() {}


EnoteDetailsImpl::EnoteDetailsImpl():
m_block_height(0),
m_internal_enote_index(0),
m_global_enote_index(0),
m_spent(false),
m_frozen(false),
m_spent_height(0),
m_amount(0),
m_protocol_version(Tx_Protocol_CryptoNote),
m_key_image_known(false),
m_key_image_request(false),
m_pk_index(0),
m_key_image_partial(false)
{
}

EnoteDetailsImpl::~EnoteDetailsImpl() {}

std::string EnoteDetailsImpl::onetimeAddress() const
{ return m_onetime_address; }
std::string EnoteDetailsImpl::viewTag() const
{ return m_view_tag; }
std::uint64_t EnoteDetailsImpl::blockHeight() const
{ return m_block_height; }
std::string EnoteDetailsImpl::txId() const
{ return m_tx_id; }
std::uint64_t EnoteDetailsImpl::internalEnoteIndex() const
{ return m_internal_enote_index; }
std::uint64_t EnoteDetailsImpl::globalEnoteIndex() const
{ return m_global_enote_index; }
bool EnoteDetailsImpl::isSpent() const
{ return m_spent; }
bool EnoteDetailsImpl::isFrozen() const
{ return m_frozen; }
std::uint64_t EnoteDetailsImpl::spentHeight() const
{ return m_spent_height; }
std::string EnoteDetailsImpl::keyImage() const
{ return m_key_image; }
std::string EnoteDetailsImpl::mask() const
{ return m_mask; }
std::uint64_t EnoteDetailsImpl::amount() const
{ return m_amount; }
EnoteDetails::TxProtocol EnoteDetailsImpl::protocolVersion() const
{ return m_protocol_version; }
bool EnoteDetailsImpl::isKeyImageKnown() const
{ return m_key_image_known; }
bool EnoteDetailsImpl::isKeyImageRequest() const
{ return m_key_image_request; }
std::uint64_t EnoteDetailsImpl::pkIndex() const
{ return m_pk_index; }
std::vector<std::pair<std::uint64_t, std::string>> EnoteDetailsImpl::uses() const
{ return m_uses; }

// Multisig
bool EnoteDetailsImpl::isKeyImagePartial() const
{ return m_key_image_partial; }

} // namespace
109 changes: 109 additions & 0 deletions src/wallet/api/enote_details.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright (c) 2014-2024, The Monero Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers

#include "wallet/api/wallet2_api.h"


namespace Monero {

class EnoteDetailsImpl : public EnoteDetails
{
public:
EnoteDetailsImpl();
~EnoteDetailsImpl() override;
std::string onetimeAddress() const override;
std::string viewTag() const override;
std::uint64_t blockHeight() const override;
std::string txId() const override;
std::uint64_t internalEnoteIndex() const override;
std::uint64_t globalEnoteIndex() const override;
bool isSpent() const override;
bool isFrozen() const override;
std::uint64_t spentHeight() const override;
std::string keyImage() const override;
std::string mask() const override;
std::uint64_t amount() const override;
TxProtocol protocolVersion() const override;
bool isKeyImageKnown() const override;
bool isKeyImageRequest() const override;
std::uint64_t pkIndex() const override;
std::vector<std::pair<std::uint64_t, std::string>> uses() const override;

// Multisig
bool isKeyImagePartial() const override;

private:
friend class WalletImpl;

// Ko
std::string m_onetime_address;
// view_tag
std::string m_view_tag;
// this enote was received at block height
std::uint64_t m_block_height;
// tx id in which tx enote was received
std::string m_tx_id;
// relative index in tx
std::uint64_t m_internal_enote_index;
// absolute index from `cryptonote::COMMAND_RPC_GET_TRANSACTIONS::entry.output_indices`
std::uint64_t m_global_enote_index;
// is spent
bool m_spent;
// is frozen
bool m_frozen;
// blockchain height, set if spent
std::uint64_t m_spent_height;
// key image
std::string m_key_image;
// x, blinding factor in amount commitment C = x G + a H
std::string m_mask;
// a
std::uint64_t m_amount;
// protocol version : Tx_Protocol_CryptoNote / Tx_Protocol_RingCT
TxProtocol m_protocol_version;
// is key image known
bool m_key_image_known;
// view wallets: we want to request it; cold wallets: it was requested
bool m_key_image_request;
// public key index in tx_extra
std::uint64_t m_pk_index;
// track uses of this enote in the blockchain in the format [ [block_height, tx_id], ... ] if `wallet2::m_track_uses` is true (default is false)
std::vector<std::pair<std::uint64_t, std::string>> m_uses;

// Multisig
bool m_key_image_partial;
// NOTE : These multisig members are part of wallet2 transfer_details and may need to get added here.
/*
std::vector<rct::key> m_multisig_k;
std::vector<multisig_info> m_multisig_info; // one per other participant
*/
};

} // namespace
2 changes: 2 additions & 0 deletions src/wallet/api/pending_transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class PendingTransactionImpl : public PendingTransaction
std::unordered_set<crypto::public_key> m_signers;
std::vector<std::string> m_tx_device_aux;
std::vector<crypto::key_image> m_key_images;
// wallet2 m_cold_key_images
std::unordered_map<crypto::public_key, crypto::key_image> m_tx_key_images;
};


Expand Down
20 changes: 20 additions & 0 deletions src/wallet/api/transaction_history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ void TransactionHistoryImpl::refresh()
ti->m_timestamp = pd.m_timestamp;
ti->m_confirmations = (wallet_height > pd.m_block_height) ? wallet_height - pd.m_block_height : 0;
ti->m_unlock_time = pd.m_unlock_time;
// not used for payment_details
ti->m_change = 0;
ti->m_tx_state = TransactionInfo::confirmed;
// not used for payment_details
ti->m_double_spend_seen = false;
m_history.push_back(ti);

}
Expand Down Expand Up @@ -193,6 +198,11 @@ void TransactionHistoryImpl::refresh()
ti->m_label = pd.m_subaddr_indices.size() == 1 ? m_wallet->m_wallet->get_subaddress_label({pd.m_subaddr_account, *pd.m_subaddr_indices.begin()}) : "";
ti->m_timestamp = pd.m_timestamp;
ti->m_confirmations = (wallet_height > pd.m_block_height) ? wallet_height - pd.m_block_height : 0;
ti->m_unlock_time = pd.m_unlock_time;
ti->m_change = pd.m_change;
ti->m_tx_state = TransactionInfo::confirmed;
// not used for confirmed_transfer_details
ti->m_double_spend_seen = false;

// single output transaction might contain multiple transfers
for (const auto &d: pd.m_dests) {
Expand Down Expand Up @@ -229,6 +239,11 @@ void TransactionHistoryImpl::refresh()
ti->m_label = pd.m_subaddr_indices.size() == 1 ? m_wallet->m_wallet->get_subaddress_label({pd.m_subaddr_account, *pd.m_subaddr_indices.begin()}) : "";
ti->m_timestamp = pd.m_timestamp;
ti->m_confirmations = 0;
ti->m_unlock_time = pd.m_tx.unlock_time;
ti->m_change = pd.m_change;
ti->m_tx_state = (TransactionInfo::TxState) pd.m_state;
// not used for unconfirmed_transfer_details
ti->m_double_spend_seen = false;
for (const auto &d : pd.m_dests)
{
ti->m_transfers.push_back({d.amount, d.address(m_wallet->m_wallet->nettype(), pd.m_payment_id)});
Expand Down Expand Up @@ -258,6 +273,11 @@ void TransactionHistoryImpl::refresh()
ti->m_label = m_wallet->m_wallet->get_subaddress_label(pd.m_subaddr_index);
ti->m_timestamp = pd.m_timestamp;
ti->m_confirmations = 0;
ti->m_unlock_time = pd.m_unlock_time;
// not used for pool_payment_details
ti->m_change = 0;
ti->m_tx_state = TransactionInfo::pending_in_pool;
ti->m_double_spend_seen = i->second.m_double_spend_seen;
m_history.push_back(ti);

LOG_PRINT_L1(__FUNCTION__ << ": Unconfirmed payment found " << pd.m_amount);
Expand Down
15 changes: 15 additions & 0 deletions src/wallet/api/transaction_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,19 @@ uint64_t TransactionInfoImpl::unlockTime() const
return m_unlock_time;
}

std::uint64_t TransactionInfoImpl::receivedChangeAmount() const
{
return m_change;
}

TransactionInfo::TxState TransactionInfoImpl::txState() const
{
return m_tx_state;
}

bool TransactionInfoImpl::isDoubleSpendSeen() const
{
return m_double_spend_seen;
}

} // namespace
10 changes: 10 additions & 0 deletions src/wallet/api/transaction_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class TransactionInfoImpl : public TransactionInfo
virtual uint64_t confirmations() const override;
virtual uint64_t unlockTime() const override;

std::uint64_t receivedChangeAmount() const override;
TxState txState() const override;
bool isDoubleSpendSeen() const override;

private:
int m_direction;
bool m_pending;
Expand All @@ -81,6 +85,12 @@ class TransactionInfoImpl : public TransactionInfo
std::vector<Transfer> m_transfers;
uint64_t m_confirmations;
uint64_t m_unlock_time;
// received change amount from outgoing transaction
std::uint64_t m_change;
// tx state : pending / pending_in_pool / failed / confirmed
TxState m_tx_state;
// is double spend seen
bool m_double_spend_seen;

friend class TransactionHistoryImpl;

Expand Down
Loading
Loading