Skip to content

Commit

Permalink
#345 added ability to rescan utxo
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolse committed Jan 19, 2019
1 parent 4971eef commit 025e9e6
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 10 deletions.
3 changes: 3 additions & 0 deletions android/jni.cpp
Expand Up @@ -339,6 +339,8 @@ namespace
}

void getNetworkStatus() override {}

void refresh() override {}
};

static JavaVM* JVM = NULL;
Expand Down Expand Up @@ -621,6 +623,7 @@ namespace
void setNodeAddress(const std::string& addr) override {}
void changeWalletPassword(const beam::SecString& password) override {}
void getNetworkStatus() override {}
void refresh() override {}

///////////////////////////////////////////////
// callbacks
Expand Down
25 changes: 25 additions & 0 deletions ui/model/wallet_model.cpp
Expand Up @@ -208,6 +208,14 @@ struct WalletModelBridge : public Bridge<IWalletModelAsync>
receiver_.getNetworkStatus();
});
}

void refresh() override
{
tx.send([](BridgeInterface& receiver_) mutable
{
receiver_.refresh();
});
}
};

WalletModel::WalletModel(IWalletDB::Ptr walletDB, const std::string& nodeAddr)
Expand Down Expand Up @@ -677,6 +685,23 @@ void WalletModel::getNetworkStatus()
emit nodeConnectionChanged(_isConnected);
}

void WalletModel::refresh()
{
try
{
assert(!_wallet.expired());
auto s = _wallet.lock();
if (s)
{
s->Refresh();
}
}
catch (...)
{

}
}

bool WalletModel::check_receiver_address(const std::string& addr)
{
WalletID walletID;
Expand Down
1 change: 1 addition & 0 deletions ui/model/wallet_model.h
Expand Up @@ -99,6 +99,7 @@ class WalletModel
void setNodeAddress(const std::string& addr) override;
void changeWalletPassword(const beam::SecString& password) override;
void getNetworkStatus() override;
void refresh() override;

void onNodeConnectedStatusChanged(bool isNodeConnected);
void onNodeConnectionFailed(const beam::proto::NodeConnection::DisconnectReason&);
Expand Down
40 changes: 34 additions & 6 deletions ui/view/settings.qml
Expand Up @@ -356,6 +356,20 @@ Rectangle {
}
}

ConfirmationDialog {
id: confirmRefreshDialog
property bool canRefresh: true
okButtonText: qsTr("yes")
okButtonIconSource: "qrc:/assets/icon-done.svg"
cancelVisible: false
width: 460
text: qsTr("Rescan will update transaction and UTXO data in your wallet and get latest information from the blockchain. Are you sure?")
onAccepted: {
canRefresh = false;
viewModel.refreshWallet();
}
}

ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
Expand Down Expand Up @@ -489,12 +503,26 @@ Rectangle {
wrapMode: Text.WordWrap
}
}

CustomButton {
text: "save wallet logs"
palette.buttonText : "white"
palette.button: "#708090"
onClicked: viewModel.reportProblem()
RowLayout {
Layout.fillWidth: true
CustomButton {
text: "save wallet logs"
palette.buttonText : "white"
palette.button: "#708090"
onClicked: viewModel.reportProblem()
}
spacing: 30
CustomButton {
icon.source: "qrc:/assets/icon-restore.svg"
Layout.alignment: Qt.AlignRight
text: qsTr("rescan")
palette.button: "#708090"
palette.buttonText : localNodeRun.checked ? Style.white : Style.disable_text_color
enabled: localNodeRun.checked && confirmRefreshDialog.canRefresh
onClicked: {
confirmRefreshDialog.open();
}
}
}

SFText {
Expand Down
5 changes: 5 additions & 0 deletions ui/viewmodel/settings_view.cpp
Expand Up @@ -229,6 +229,11 @@ bool SettingsViewModel::hasSupportedGpu()
#endif
}

void SettingsViewModel::refreshWallet()
{
AppModel::getInstance()->getWallet()->getAsync()->refresh();
}

#ifdef BEAM_USE_GPU

vector<int32_t> SettingsViewModel::getSelectedDevice() const
Expand Down
1 change: 1 addition & 0 deletions ui/viewmodel/settings_view.h
Expand Up @@ -96,6 +96,7 @@ class SettingsViewModel : public QObject
Q_INVOKABLE void copyToClipboard(const QString& text);
Q_INVOKABLE bool showUseGpu() const;
Q_INVOKABLE bool hasSupportedGpu();
Q_INVOKABLE void refreshWallet();

private:
#ifdef BEAM_USE_GPU
Expand Down
3 changes: 2 additions & 1 deletion utility/options.cpp
Expand Up @@ -91,6 +91,7 @@ namespace beam
const char* WALLET_ADDR = "address";
const char* CHANGE_ADDRESS_EXPIRATION = "change_address_expiration";
const char* WALLET_ADDRESS_LIST = "address_list";
const char* WALLET_REFRESH = "refresh";
#if defined(BEAM_USE_GPU)
const char* MINER_TYPE = "miner_type";
#endif
Expand Down Expand Up @@ -185,7 +186,7 @@ namespace beam
(cli::WALLET_ADDR, po::value<string>()->default_value("*"), "wallet address")
(cli::PAYMENT_PROOF_DATA, po::value<string>(), "payment proof data to verify")
(cli::PAYMENT_PROOF_REQUIRED, po::value<bool>(), "Set to disallow outgoing payments if the receiver doesn't supports the payment proof (older wallets)")
(cli::COMMAND, po::value<string>(), "command to execute [new_addr|send|receive|listen|init|restore|info|export_miner_key|export_owner_key|generate_phrase|change_address_expiration|address_list]");
(cli::COMMAND, po::value<string>(), "command to execute [new_addr|send|receive|listen|init|restore|info|export_miner_key|export_owner_key|generate_phrase|change_address_expiration|address_list|refresh]");

po::options_description wallet_treasury_options("Wallet treasury options");
wallet_treasury_options.add_options()
Expand Down
1 change: 1 addition & 0 deletions utility/options.h
Expand Up @@ -90,6 +90,7 @@ namespace beam
extern const char* WALLET_ADDR;
extern const char* CHANGE_ADDRESS_EXPIRATION;
extern const char* WALLET_ADDRESS_LIST;
extern const char* WALLET_REFRESH;
#if defined(BEAM_USE_GPU)
extern const char* MINER_TYPE;
#endif
Expand Down
8 changes: 7 additions & 1 deletion wallet/cli.cpp
Expand Up @@ -603,7 +603,8 @@ int main_impl(int argc, char* argv[])
&& command != cli::PAYMENT_PROOF_EXPORT
&& command != cli::PAYMENT_PROOF_VERIFY
&& command != cli::GENERATE_PHRASE
&& command != cli::WALLET_ADDRESS_LIST)
&& command != cli::WALLET_ADDRESS_LIST
&& command != cli::WALLET_REFRESH)
{
LOG_ERROR() << "unknown command: \'" << command << "\'";
return -1;
Expand Down Expand Up @@ -981,6 +982,11 @@ int main_impl(int argc, char* argv[])
}
}

if (command == cli::WALLET_REFRESH)
{
wallet.Refresh();
}

io::Reactor::get_Current().run();

}
Expand Down
20 changes: 20 additions & 0 deletions wallet/wallet.cpp
Expand Up @@ -283,6 +283,26 @@ namespace beam
return txID;
}

void Wallet::Refresh()
{
SetUtxoEventsHeight(0);
RequestUtxoEvents();
}

void Wallet::RefreshTransactions()
{
/* auto txs = m_WalletDB->getTxHistory();
for (auto& tx : txs)
{
if (m_Transactions.find(tx.m_txId) == m_Transactions.end())
{
auto t = constructTransaction(tx.m_txId, TxType::Simple);
if (t->GetParameter())
m_Transactions.emplace(tx.m_txId, t);
}
}*/
}

void Wallet::ResumeTransaction(const TxDescription& tx)
{
if (tx.canResume() && m_Transactions.find(tx.m_txId) == m_Transactions.end())
Expand Down
6 changes: 4 additions & 2 deletions wallet/wallet.h
Expand Up @@ -66,8 +66,7 @@ namespace beam
boost::optional<TxID> transfer_money(const WalletID& from, const WalletID& to, const AmountList& amountList, Amount fee = 0, bool sender = true, Height lifetime = 120, ByteBuffer&& message = {});
boost::optional<TxID> split_coins(const WalletID& from, const AmountList& amountList, Amount fee = 0, bool sender = true, Height lifetime = 120, ByteBuffer&& message = {});
TxID swap_coins(const WalletID& from, const WalletID& to, Amount amount, Amount fee, wallet::AtomicSwapCoin swapCoin, Amount swapAmount);
void ResumeTransaction(const TxDescription& tx);
void ResumeAllTransactions();
void Refresh();

// IWallet
void subscribe(IWalletObserver* observer) override;
Expand All @@ -76,6 +75,9 @@ namespace beam
void delete_tx(const TxID& txId) override;

private:
void RefreshTransactions();
void ResumeTransaction(const TxDescription& tx);
void ResumeAllTransactions();
void on_tx_completed(const TxID& txID) override;

void confirm_outputs(const std::vector<Coin>&) override;
Expand Down
1 change: 1 addition & 0 deletions wallet/wallet_model_async.h
Expand Up @@ -42,6 +42,7 @@ struct IWalletModelAsync
virtual void changeWalletPassword(const beam::SecString& password) = 0;

virtual void getNetworkStatus() = 0;
virtual void refresh() = 0;

virtual ~IWalletModelAsync() {}
};

0 comments on commit 025e9e6

Please sign in to comment.