Skip to content

Commit

Permalink
Merge pull request #26 from ConcealNetwork/dust
Browse files Browse the repository at this point in the history
Dust
  • Loading branch information
cryptokatz authored Jan 14, 2019
2 parents 44b8301 + 3a1030f commit 7a4938c
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/IWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class IWallet {
virtual std::string createAddress(const Crypto::PublicKey& spendPublicKey) = 0;
virtual void deleteAddress(const std::string& address) = 0;


virtual uint64_t getActualBalance() const = 0;
virtual uint64_t getActualBalance(const std::string& address) const = 0;
virtual uint64_t getPendingBalance() const = 0;
Expand Down
1 change: 1 addition & 0 deletions include/IWalletLegacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class IWalletLegacy {
virtual std::string getAddress() = 0;

virtual uint64_t actualBalance() = 0;
virtual uint64_t dustBalance() = 0;

virtual uint64_t pendingBalance() = 0;
virtual uint64_t actualDepositBalance() = 0;
Expand Down
9 changes: 9 additions & 0 deletions src/CryptoNoteCore/CryptoNoteFormatUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "CryptoNoteSerialization.h"
#include "TransactionExtra.h"
#include "CryptoNoteTools.h"
#include "Currency.h"

#include "CryptoNoteConfig.h"

Expand Down Expand Up @@ -530,4 +531,12 @@ Hash get_tx_tree_hash(const Block& b) {
return get_tx_tree_hash(txs_ids);
}

bool is_valid_decomposed_amount(uint64_t amount) {
auto it = std::lower_bound(Currency::PRETTY_AMOUNTS.begin(), Currency::PRETTY_AMOUNTS.end(), amount);
if (it == Currency::PRETTY_AMOUNTS.end() || amount != *it) {
return false;
}
return true;
}

}
2 changes: 2 additions & 0 deletions src/CryptoNoteCore/CryptoNoteFormatUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,7 @@ void decompose_amount_into_digits(uint64_t amount, uint64_t dust_threshold, cons
void get_tx_tree_hash(const std::vector<Crypto::Hash>& tx_hashes, Crypto::Hash& h);
Crypto::Hash get_tx_tree_hash(const std::vector<Crypto::Hash>& tx_hashes);
Crypto::Hash get_tx_tree_hash(const Block& b);
bool is_valid_decomposed_amount(uint64_t amount);


}
3 changes: 2 additions & 1 deletion src/CryptoNoteCore/Currency.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class AccountBase;

class Currency {
public:
static const std::vector<uint64_t> PRETTY_AMOUNTS;

uint64_t maxBlockHeight() const { return m_maxBlockHeight; }
size_t maxBlockBlobSize() const { return m_maxBlockBlobSize; }
size_t maxTxSize() const { return m_maxTxSize; }
Expand Down Expand Up @@ -251,7 +253,6 @@ class Currency {
std::string m_txPoolFileName;
std::string m_blockchinIndicesFileName;

static const std::vector<uint64_t> PRETTY_AMOUNTS;
static const std::vector<uint64_t> REWARD_INCREASING_FACTOR;

bool m_testnet;
Expand Down
16 changes: 12 additions & 4 deletions src/SimpleWallet/SimpleWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,15 +647,15 @@ simple_wallet::simple_wallet(System::Dispatcher& dispatcher, const CryptoNote::C
m_refresh_progress_reporter(*this),
m_initResultPromise(nullptr),
m_walletSynchronized(false) {
// m_consoleHandler.setHandler("start_mining", boost::bind(&simple_wallet::start_mining, this, _1), "start_mining [<number_of_threads>] - Start mining in daemon");
// m_consoleHandler.setHandler("stop_mining", boost::bind(&simple_wallet::stop_mining, this, _1), "Stop mining in daemon");
m_consoleHandler.setHandler("create_integrated", boost::bind(&simple_wallet::create_integrated, this, _1), "create_integrated <payment_id> - Create an integrated address with a payment ID");
m_consoleHandler.setHandler("export_keys", boost::bind(&simple_wallet::export_keys, this, _1), "Show the secret keys of the current wallet");
m_consoleHandler.setHandler("balance", boost::bind(&simple_wallet::show_balance, this, _1), "Show current wallet balance");
m_consoleHandler.setHandler("incoming_transfers", boost::bind(&simple_wallet::show_incoming_transfers, this, _1), "Show incoming transfers");
m_consoleHandler.setHandler("list_transfers", boost::bind(&simple_wallet::listTransfers, this, _1), "list_transfers <height> - Show all known transfers from a certain (optional) block height");
m_consoleHandler.setHandler("payments", boost::bind(&simple_wallet::show_payments, this, _1), "payments <payment_id_1> [<payment_id_2> ... <payment_id_N>] - Show payments <payment_id_1>, ... <payment_id_N>");
m_consoleHandler.setHandler("bc_height", boost::bind(&simple_wallet::show_blockchain_height, this, _1), "Show blockchain height");
m_consoleHandler.setHandler("show_dust", boost::bind(&simple_wallet::show_dust, this, _1), "Show the number of unmixable dust outputs");
m_consoleHandler.setHandler("sweep_dust", boost::bind(&simple_wallet::sweep_dust, this, _1), "Sweep unmixable dust");
m_consoleHandler.setHandler("outputs", boost::bind(&simple_wallet::show_num_unlocked_outputs, this, _1), "Show the number of unlocked outputs available for a transaction");
m_consoleHandler.setHandler("optimize", boost::bind(&simple_wallet::optimize_outputs, this, _1), "Combine many available outputs into a few by sending a transaction to self");
m_consoleHandler.setHandler("optimize_all", boost::bind(&simple_wallet::optimize_all_outputs, this, _1), "Optimize your wallet several times so you can send large transactions");
Expand All @@ -670,6 +670,14 @@ simple_wallet::simple_wallet(System::Dispatcher& dispatcher, const CryptoNote::C
m_consoleHandler.setHandler("help", boost::bind(&simple_wallet::help, this, _1), "Show this help");
m_consoleHandler.setHandler("exit", boost::bind(&simple_wallet::exit, this, _1), "Close wallet");
}

/* This function shows the number of outputs in the wallet
that are below the dust threshold */
bool simple_wallet::show_dust(const std::vector<std::string>& args) {
logger(INFO, BRIGHT_WHITE) << "Dust outputs: " << m_wallet->dustBalance() << std::endl;
return true;
}

//----------------------------------------------------------------------------------------------------
bool simple_wallet::set_log(const std::vector<std::string> &args) {
if (args.size() != 1) {
Expand Down Expand Up @@ -1491,7 +1499,7 @@ bool simple_wallet::optimize_outputs(const std::vector<std::string>& args) {
std::vector<CryptoNote::WalletLegacyTransfer> transfers;
std::vector<CryptoNote::TransactionMessage> messages;
std::string extraString;
uint64_t fee = CryptoNote::parameters::MINIMUM_FEE_V1;
uint64_t fee = CryptoNote::parameters::MINIMUM_FEE;
uint64_t mixIn = 0;
uint64_t unlockTimestamp = 0;
uint64_t ttl = 0;
Expand Down Expand Up @@ -1559,7 +1567,7 @@ bool simple_wallet::optimize_all_outputs(const std::vector<std::string>& args) {
std::vector<CryptoNote::WalletLegacyTransfer> transfers;
std::vector<CryptoNote::TransactionMessage> messages;
std::string extraString;
uint64_t fee = CryptoNote::parameters::MINIMUM_FEE_V1;
uint64_t fee = CryptoNote::parameters::MINIMUM_FEE;
uint64_t mixIn = 0;
uint64_t unlockTimestamp = 0;
uint64_t ttl = 0;
Expand Down
1 change: 1 addition & 0 deletions src/SimpleWallet/SimpleWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace CryptoNote
bool help(const std::vector<std::string> &args = std::vector<std::string>());
bool exit(const std::vector<std::string> &args);
bool start_mining(const std::vector<std::string> &args);
bool show_dust(const std::vector<std::string> &args);
bool stop_mining(const std::vector<std::string> &args);
bool show_balance(const std::vector<std::string> &args = std::vector<std::string>());
bool export_keys(const std::vector<std::string> &args = std::vector<std::string>());
Expand Down
20 changes: 20 additions & 0 deletions src/WalletLegacy/WalletLegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,26 @@ TransactionId WalletLegacy::withdrawDeposits(const std::vector<DepositId>& depos
return txId;
}

/* go through all unlocked outputs and return a total of
everything below the dust threshold */
uint64_t WalletLegacy::dustBalance() {
std::unique_lock<std::mutex> lock(m_cacheMutex);
throwIfNotInitialised();
std::vector<TransactionOutputInformation> outputs;
m_transferDetails->getOutputs(outputs, ITransfersContainer::IncludeKeyUnlocked);
uint64_t money = 0;
for (size_t i = 0; i < outputs.size(); ++i) {
const auto& out = outputs[i];
if (!m_transactionsCache.isUsed(out)) {
if (out.amount < m_currency.defaultDustThreshold()) {
money += out.amount;
}
}
}
return money;
}


void WalletLegacy::sendTransactionCallback(WalletRequest::Callback callback, std::error_code ec) {
ContextCounterHolder counterHolder(m_asyncContextCounter);
std::deque<std::unique_ptr<WalletLegacyEvent> > events;
Expand Down
1 change: 1 addition & 0 deletions src/WalletLegacy/WalletLegacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class WalletLegacy :
uint64_t calculateActualInvestmentBalance();
uint64_t calculatePendingDepositBalance();
uint64_t calculatePendingInvestmentBalance();
uint64_t dustBalance();

uint64_t calculateActualBalance();
uint64_t calculatePendingBalance();
Expand Down

0 comments on commit 7a4938c

Please sign in to comment.