Skip to content

Commit

Permalink
Merge pull request #476 from blocknetdx/feature-xbridge-showallorders
Browse files Browse the repository at this point in the history
[xbridge] ShowAllOrders=true in xbridge.conf
  • Loading branch information
magic53 authored May 8, 2020
2 parents f111584 + a7b1bc5 commit 2acc40b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/xbridge/rpcxbridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include <rpc/server.h>

#include <xbridge/util/settings.h>
#include <xbridge/util/logger.h>
#include <xbridge/util/settings.h>
#include <xbridge/util/xbridgeerror.h>
#include <xbridge/util/xseries.h>
#include <xbridge/util/xutil.h>
Expand Down Expand Up @@ -207,6 +207,8 @@ UniValue dxLoadXBridgeConf(const JSONRPCRequest& request)
auto success = app.loadSettings();
app.clearBadWallets(); // clear any bad wallet designations b/c user is explicitly requesting a wallet update
app.updateActiveWallets();
if (!settings().showAllOrders())
app.clearNonLocalOrders();
return uret(success);
}

Expand Down Expand Up @@ -307,7 +309,7 @@ UniValue dxGetOrders(const JSONRPCRequest& request)
auto &xapp = xbridge::App::instance();
TransactionMap trlist = xapp.transactions();
auto currentTime = boost::posix_time::second_clock::universal_time();
bool nowalletswitch = gArgs.GetBoolArg("-dxnowallets", false);
bool nowalletswitch = gArgs.GetBoolArg("-dxnowallets", settings().showAllOrders());
Array result;
for (const auto& trEntry : trlist) {

Expand Down
1 change: 1 addition & 0 deletions src/xbridge/util/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Settings
public:
bool isFullLog()
{ return get<bool>("Main.FullLog", false); }
bool showAllOrders() { return get<bool>("Main.ShowAllOrders", false); }

bool isExchangeEnabled() const { return m_isExchangeEnabled; }
std::string appPath() const { return m_appPath; }
Expand Down
20 changes: 19 additions & 1 deletion src/xbridge/xbridgeapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ bool App::createConf()
"[Main]" + eol +
"ExchangeWallets=" + eol +
"FullLog=true" + eol +
"# Show all orders across the network regardless of whether wallets are " + eol +
"# installed locally, set to \"true\". -dxnowallets in blocknet.conf " + eol +
"# overrides this setting" + eol +
"ShowAllOrders=false" + eol +
"" + eol +
"# Sample configuration:" + eol +
"# [BLOCK]" + eol +
Expand Down Expand Up @@ -355,7 +359,7 @@ bool App::createConf()
//*****************************************************************************
bool App::isEnabled()
{
return connectors().size() > 0 || xbridge::Exchange::instance().isEnabled();
return connectors().size() > 0 || xbridge::Exchange::instance().isEnabled() || gArgs.GetBoolArg("-dxnowallets", settings().showAllOrders());
}

//*****************************************************************************
Expand Down Expand Up @@ -3078,6 +3082,20 @@ void App::clearMempool() {
m_p->m_processedMessages.clear();
}

void App::clearNonLocalOrders() {
LOCK(m_p->m_txLocker);
for (auto it = m_p->m_transactions.begin(); it != m_p->m_transactions.end(); ) {
const TransactionDescrPtr & ptr = it->second;
if (ptr->isLocal())
continue; // do not remove any orders that belong to us
LOCK(m_p->m_connectorsLock);
if (!m_p->m_connectorCurrencyMap.count(ptr->fromCurrency) || !m_p->m_connectorCurrencyMap.count(ptr->toCurrency)) {
m_p->m_transactions.erase(it++);
} else {
++it;
}
}
}

std::ostream & operator << (std::ostream& out, const TransactionDescrPtr& tx)
{
Expand Down
5 changes: 5 additions & 0 deletions src/xbridge/xbridgeapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ class App
m_badWallets.clear();
}

/**
* @brief Clears the non-local orders.
*/
void clearNonLocalOrders();

/**
* @brief Returns true if wallet update checks are already in progress, otherwise returns false.
* @return
Expand Down
3 changes: 2 additions & 1 deletion src/xbridge/xbridgesession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <xbridge/util/posixtimeconversion.h>
#include <xbridge/util/xutil.h>
#include <xbridge/util/logger.h>
#include <xbridge/util/settings.h>
#include <xbridge/util/txlog.h>
#include <xbridge/util/xassert.h>
#include <xbridge/xbitcointransaction.h>
Expand Down Expand Up @@ -723,7 +724,7 @@ bool Session::Impl::processPendingTransaction(XBridgePacketPtr packet) const

WalletConnectorPtr sconn = xapp.connectorByCurrency(scurrency);
WalletConnectorPtr dconn = xapp.connectorByCurrency(dcurrency);
bool nowalletswitch = gArgs.GetBoolArg("-dxnowallets", false);
bool nowalletswitch = gArgs.GetBoolArg("-dxnowallets", settings().showAllOrders());
if ((!sconn || !dconn) && !nowalletswitch)
{
xbridge::LogOrderMsg(txid.GetHex(), "no connector for <" + (!sconn ? scurrency : dcurrency) + ">", __FUNCTION__);
Expand Down

0 comments on commit 2acc40b

Please sign in to comment.