Skip to content

Commit

Permalink
Clean up, remove:
Browse files Browse the repository at this point in the history
(Method name: reason)
signTxToStr: gets added in monero-project#9492 as `signAsString()`
loadTx: not needed, all it does is `loadFromFile()` and `parseTxFromStr()`
estimateBacklog(min_tx_weight, max_tx_weight, fees): not needed, calls `estimateBacklog(fee_levels)`
  • Loading branch information
SNeedlewoods committed Oct 30, 2024
1 parent 8c553f6 commit 4f393f8
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 109 deletions.
2 changes: 1 addition & 1 deletion src/wallet/api/enote_details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ bool EnoteDetailsImpl::isKeyImageKnown() const
{ return m_key_image_known; }
bool EnoteDetailsImpl::isKeyImageRequest() const
{ return m_key_image_request; }
uint64_t EnoteDetailsImpl::pkIndex() const
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; }
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/api/enote_details.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class EnoteDetailsImpl : public EnoteDetails
TxProtocol protocolVersion() const override;
bool isKeyImageKnown() const override;
bool isKeyImageRequest() const override;
uint64_t pkIndex() const override;
std::uint64_t pkIndex() const override;
std::vector<std::pair<std::uint64_t, std::string>> uses() const override;

// Multisig
Expand Down Expand Up @@ -93,7 +93,7 @@ class EnoteDetailsImpl : public EnoteDetails
// view wallets: we want to request it; cold wallets: it was requested
bool m_key_image_request;
// public key index in tx_extra
uint64_t m_pk_index;
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;

Expand Down
2 changes: 1 addition & 1 deletion src/wallet/api/transaction_history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void TransactionHistoryImpl::refresh()
ti->m_confirmations = 0;
ti->m_unlock_time = pd.m_tx.unlock_time;
ti->m_change = pd.m_change;
ti->m_tx_state = pd.m_state;
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)
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/api/transaction_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ std::uint64_t TransactionInfoImpl::receivedChangeAmount() const
return m_change;
}

int TransactionInfoImpl::txState() const
TransactionInfo::TxState TransactionInfoImpl::txState() const
{
return m_tx_state;
}
Expand Down
6 changes: 3 additions & 3 deletions src/wallet/api/transaction_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TransactionInfoImpl : public TransactionInfo
virtual uint64_t unlockTime() const override;

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

private:
Expand All @@ -87,8 +87,8 @@ class TransactionInfoImpl : public TransactionInfo
uint64_t m_unlock_time;
// received change amount from outgoing transaction
std::uint64_t m_change;
// enum TxState
int m_tx_state;
// tx state : pending / pending_in_pool / failed / confirmed
TxState m_tx_state;
// is double spend seen
bool m_double_spend_seen;

Expand Down
98 changes: 22 additions & 76 deletions src/wallet/api/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ bool WalletImpl::create(const std::string &path, const std::string &password, co
return false;
}
setSeedLanguage(language);
if (!statusOk())
return false;
crypto::secret_key recovery_val, secret_key;
try {
recovery_val = m_wallet->generate(path, password, secret_key, false, false);
Expand Down Expand Up @@ -681,6 +683,8 @@ bool WalletImpl::recoverFromKeysWithPassword(const std::string &path,
if(has_spendkey && !has_viewkey) {
m_wallet->generate(path, password, spendkey, true, false);
setSeedLanguage(language);
if (!statusOk())
return false;
LOG_PRINT_L1("Generated deterministic wallet from spend key with seed language: " + language);
}

Expand Down Expand Up @@ -737,7 +741,7 @@ bool WalletImpl::open(const std::string &path, const std::string &password)
LOG_ERROR("Error opening wallet: " << e.what());
setStatusCritical(e.what());
}
return status() == Status_Ok;
return statusOk();
}

bool WalletImpl::recover(const std::string &path, const std::string &seed)
Expand Down Expand Up @@ -773,12 +777,14 @@ bool WalletImpl::recover(const std::string &path, const std::string &password, c

try {
setSeedLanguage(old_language);
if (!statusOk())
return false;
m_wallet->generate(path, password, recovery_key, true, false);

} catch (const std::exception &e) {
setStatusCritical(e.what());
}
return status() == Status_Ok;
return statusOk();
}

bool WalletImpl::close(bool do_store)
Expand Down Expand Up @@ -864,7 +870,7 @@ bool WalletImpl::setPassword(const std::string &password)
} catch (const std::exception &e) {
setStatusError(e.what());
}
return status() == Status_Ok;
return statusOk();
}

const std::string& WalletImpl::getPassword() const
Expand All @@ -880,7 +886,7 @@ bool WalletImpl::setDevicePin(const std::string &pin)
} catch (const std::exception &e) {
setStatusError(e.what());
}
return status() == Status_Ok;
return statusOk();
}

bool WalletImpl::setDevicePassphrase(const std::string &passphrase)
Expand All @@ -891,7 +897,7 @@ bool WalletImpl::setDevicePassphrase(const std::string &passphrase)
} catch (const std::exception &e) {
setStatusError(e.what());
}
return status() == Status_Ok;
return statusOk();
}

std::string WalletImpl::address(uint32_t accountIndex, uint32_t addressIndex) const
Expand Down Expand Up @@ -1084,7 +1090,7 @@ bool WalletImpl::refresh()
//TODO: make doRefresh return bool to know whether the error occured during refresh or not
//otherwise one may try, say, to send transaction, transfer fails and this method returns false
doRefresh();
return status() == Status_Ok;
return statusOk();
}

void WalletImpl::refreshAsync()
Expand All @@ -1101,7 +1107,7 @@ bool WalletImpl::rescanBlockchain()
clearStatus();
m_refreshShouldRescan = true;
doRefresh();
return status() == Status_Ok;
return statusOk();
}

void WalletImpl::rescanBlockchainAsync()
Expand Down Expand Up @@ -1276,7 +1282,7 @@ bool WalletImpl::importOutputs(const string &filename)
try
{
size_t n_outputs = importEnotesFromStr(data);
if (status() != Status_Ok)
if (!statusOk())
throw runtime_error(errorString());
LOG_PRINT_L2(std::to_string(n_outputs) << " outputs imported");
}
Expand Down Expand Up @@ -1644,10 +1650,8 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
PendingTransactionImpl * transaction = new PendingTransactionImpl(*this);

uint32_t adjusted_priority = adjustPriority(static_cast<uint32_t>(priority));
if (status() != Status_Ok)
{
if (!statusOk())
return transaction;
}

do {
if (checkBackgroundSync("cannot create transactions"))
Expand Down Expand Up @@ -3188,44 +3192,6 @@ bool WalletImpl::parseUnsignedTxFromStr(const std::string &unsigned_tx_str, Unsi
return true;
}
//-------------------------------------------------------------------------------------------------------------------
std::string WalletImpl::signTxToStr(UnsignedTransaction &exported_txs, PendingTransaction &ptx) const
{
clearStatus();

tools::wallet2::unsigned_tx_set &utx_set = dynamic_cast<UnsignedTransactionImpl*>(&exported_txs)->m_unsigned_tx_set;
PendingTransactionImpl *ptx_impl = dynamic_cast<PendingTransactionImpl*>(&ptx);

std::string signed_tx_data;
tools::wallet2::signed_tx_set signed_txs;

try
{
signed_tx_data = m_wallet->sign_tx_dump_to_str(utx_set, ptx_impl->m_pending_tx, signed_txs);
}
catch (const exception &e)
{
setStatusError(string(tr("Failed to sign tx: ")) + e.what());
return "";
}

ptx_impl->m_key_images = signed_txs.key_images;
return signed_tx_data;
}
//-------------------------------------------------------------------------------------------------------------------
bool WalletImpl::loadTx(const std::string &signed_filename, PendingTransaction &ptx) const
{
clearStatus();

PendingTransactionImpl *ptx_impl = dynamic_cast<PendingTransactionImpl*>(&ptx);

if (!m_wallet->load_tx(signed_filename, ptx_impl->m_pending_tx))
{
setStatusError((boost::format(tr("Failed to load tx from file with filename `%s`. For more info see log file")) % signed_filename).str());
return false;
}
return true;
}
//-------------------------------------------------------------------------------------------------------------------
bool WalletImpl::parseMultisigTxFromStr(const std::string &multisig_tx_str, PendingTransaction &exported_txs) const
{
clearStatus();
Expand Down Expand Up @@ -3504,33 +3470,6 @@ std::vector<std::pair<std::uint64_t, std::uint64_t>> WalletImpl::estimateBacklog
return { std::make_pair(0, 0) };
}
//-------------------------------------------------------------------------------------------------------------------
std::vector<std::pair<std::uint64_t, std::uint64_t>> WalletImpl::estimateBacklog(std::uint64_t min_tx_weight, std::uint64_t max_tx_weight, const std::vector<std::uint64_t> &fees) const
{
clearStatus();

if (min_tx_weight == 0 || max_tx_weight == 0)
{
setStatusError("Invalid 0 weight");
return { std::make_pair(0, 0) };
}
for (std::uint64_t fee: fees)
{
if (fee == 0)
{
setStatusError("Invalid 0 fee");
return { std::make_pair(0, 0) };
}
}

std::vector<std::pair<double, double>> fee_levels;
for (uint64_t fee: fees)
{
double our_fee_byte_min = fee / (double)min_tx_weight, our_fee_byte_max = fee / (double)max_tx_weight;
fee_levels.emplace_back(our_fee_byte_min, our_fee_byte_max);
}
return estimateBacklog(fee_levels);
}
//-------------------------------------------------------------------------------------------------------------------
bool WalletImpl::saveToFile(const std::string &path_to_file, const std::string &binary, bool is_printable /* = false */) const
{
return m_wallet->save_to_file(path_to_file, binary, is_printable);
Expand Down Expand Up @@ -3710,5 +3649,12 @@ std::size_t WalletImpl::getEnoteIndex(const std::string &key_image) const
return 0;
}
//-------------------------------------------------------------------------------------------------------------------
bool WalletImpl::statusOk() const
{
boost::lock_guard<boost::mutex> l(m_statusMutex);
return m_status == Status_Ok;
}
//-------------------------------------------------------------------------------------------------------------------


} // namespace
8 changes: 5 additions & 3 deletions src/wallet/api/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ class WalletImpl : public Wallet
bool saveMultisigTx(const PendingTransaction &multisig_ptx, const std::string &filename) const override;
std::string convertTxToStr(const PendingTransaction &ptxs) const override;
bool parseUnsignedTxFromStr(const std::string &unsigned_tx_str, UnsignedTransaction &exported_txs) const override;
std::string signTxToStr(UnsignedTransaction &exported_txs, PendingTransaction &ptx) const override;
bool loadTx(const std::string &signed_filename, PendingTransaction &ptx) const override;
bool parseMultisigTxFromStr(const std::string &multisig_tx_str, PendingTransaction &exported_txs) const override;
std::uint64_t getFeeMultiplier(std::uint32_t priority, int fee_algorithm) const override;
std::uint64_t getBaseFee() const override;
Expand All @@ -271,7 +269,6 @@ class WalletImpl : public Wallet
std::size_t importEnotesFromStr(const std::string &enotes_str) override;
std::uint64_t getBlockchainHeightByDate(std::uint16_t year, std::uint8_t month, std::uint8_t day) const override;
std::vector<std::pair<std::uint64_t, std::uint64_t>> estimateBacklog(const std::vector<std::pair<double, double>> &fee_levels) const override;
std::vector<std::pair<std::uint64_t, std::uint64_t>> estimateBacklog(std::uint64_t min_tx_weight, std::uint64_t max_tx_weight, const std::vector<std::uint64_t> &fees) const override;
bool saveToFile(const std::string &path_to_file, const std::string &binary, bool is_printable = false) const override;
bool loadFromFile(const std::string &path_to_file, std::string &target_str, std::size_t max_size = 1000000000) const override;
std::uint64_t hashEnotes(std::uint64_t enote_idx, std::string &hash) const override;
Expand Down Expand Up @@ -301,6 +298,11 @@ class WalletImpl : public Wallet
* return: enote index
*/
std::size_t getEnoteIndex(const std::string &key_image) const;
/**
* brief: statusOk -
* return: true if status is ok, else false
*/
bool statusOk() const;

private:
friend class PendingTransactionImpl;
Expand Down
24 changes: 2 additions & 22 deletions src/wallet/api/wallet2_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct EnoteDetails
virtual TxProtocol protocolVersion() const = 0;
virtual bool isKeyImageKnown() const = 0;
virtual bool isKeyImageRequest() const = 0;
virtual uint64_t pkIndex() const = 0;
virtual std::uint64_t pkIndex() const = 0;
virtual std::vector<std::pair<std::uint64_t, std::string>> uses() const = 0;

// Multisig
Expand Down Expand Up @@ -246,7 +246,7 @@ struct TransactionInfo
virtual const std::vector<Transfer> & transfers() const = 0;

virtual std::uint64_t receivedChangeAmount() const = 0;
virtual int txState() const = 0;
virtual TxState txState() const = 0;
virtual bool isDoubleSpendSeen() const = 0;
};
/**
Expand Down Expand Up @@ -1333,22 +1333,7 @@ struct Wallet
* note: sets status error on fail
*/
virtual bool parseUnsignedTxFromStr(const std::string &unsigned_tx_str, UnsignedTransaction &exported_txs) const = 0;
/**
* brief: signTxToStr - get a signed pending transaction from an unsigned transaction
* param: exported_txs - unsigned transaction
* outparam: ptx - signed pending transaction
* return: signed tx data as encrypted hex string
* note: sets status error on fail
*/
virtual std::string signTxToStr(UnsignedTransaction &exported_txs, PendingTransaction &ptx) const = 0;
// TODO : if it's fine to drop the accept_func, do it for all the functions below (where possible, meaning accept_func is optional in wallet2 params)
/**
* brief: loadTx - load pending transactions from a file
* param: signed_filename -
* outparam: ptx -
* return: true if succeeded
*/
virtual bool loadTx(const std::string &signed_filename, PendingTransaction &ptx) const = 0;
// TODO : accept_func with wallet2::signed_tx_set
/**
* brief: parseTxFromStr - get transactions from encrypted signed transaction as hex string
Expand Down Expand Up @@ -1477,18 +1462,13 @@ struct Wallet
* note: sets status error on fail
*/
virtual std::uint64_t getBlockchainHeightByDate(std::uint16_t year, std::uint8_t month, std::uint8_t day) const = 0;
// QUESTION : Can anyone help with these comments?
/**
* brief: estimateBacklog -
* param: fee_levels - [ [fee per byte min, fee per byte max], ... ]
* param: min_tx_weight -
* param: max_tx_weight -
* param: fees -
* return: [ [number of blocks min, number of blocks max], ... ]
* note: sets status error on fail
*/
virtual std::vector<std::pair<std::uint64_t, std::uint64_t>> estimateBacklog(const std::vector<std::pair<double, double>> &fee_levels) const = 0;
virtual std::vector<std::pair<std::uint64_t, std::uint64_t>> estimateBacklog(std::uint64_t min_tx_weight, std::uint64_t max_tx_weight, const std::vector<std::uint64_t> &fees) const = 0;
// TODO : mms::multisig_wallet_state - from a quick search for get_multisig_wallet_state in simplewallet.cpp this will be complicated to replace
/**
* brief: getMultisigWalletState -
Expand Down

0 comments on commit 4f393f8

Please sign in to comment.