Skip to content

Commit

Permalink
Add Export/Import Wallet to GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Tranz5 committed May 21, 2014
1 parent 4b49049 commit 3747989
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/qt/bitcoin.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<file alias="filesave">res/icons/filesave.png</file>
<file alias="qrcode">res/icons/qrcode.png</file>
<file alias="debugwindow">res/icons/debugwindow.png</file>
<file alias="import">res/icons/import.png</file>
<file alias="export2">res/icons/export2.png</file>
</qresource>
<qresource prefix="/images">
<file alias="about">res/images/about.png</file>
Expand Down
77 changes: 77 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ void BitcoinGUI::createActions()
encryptWalletAction->setCheckable(true);
backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
dumpWalletAction = new QAction(QIcon(":/icons/export2"), tr("&Export Wallet..."), this);
dumpWalletAction->setStatusTip(tr("Export wallet's keys to a text file"));
importWalletAction = new QAction(QIcon(":/icons/import"), tr("&Import Wallet..."), this);
importWalletAction->setStatusTip(tr("Import a file's keys into a wallet"));
changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
changePassphraseAction->setStatusTip(tr("Change the passphrase used for wallet encryption"));
signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this);
Expand All @@ -282,6 +286,8 @@ void BitcoinGUI::createActions()
connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
Expand All @@ -300,6 +306,10 @@ void BitcoinGUI::createMenuBar()
// Configure the menus
QMenu *file = appMenuBar->addMenu(tr("&File"));
file->addAction(backupWalletAction);
file->addSeparator();
file->addAction(dumpWalletAction);
file->addAction(importWalletAction);
file->addSeparator();
file->addAction(exportAction);
file->addAction(signMessageAction);
file->addAction(verifyMessageAction);
Expand Down Expand Up @@ -892,6 +902,73 @@ void BitcoinGUI::backupWallet()
}
}

void BitcoinGUI::dumpWallet()
{
if(!walletModel)
return;

WalletModel::UnlockContext ctx(walletModel->requestUnlock());
if(!ctx.isValid())
{
// Unlock wallet failed or was cancelled
return;
}

#if QT_VERSION < 0x050000
QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
#else
QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#endif
QString filename = QFileDialog::getSaveFileName(this, tr("Export Wallet"), saveDir, tr("Wallet Text (*.txt)"));
if(!filename.isEmpty()) {
if(!walletModel->dumpWallet(filename)) {
message(tr("Export Failed"),
tr("There was an error trying to save the wallet's keys to your location.\n"
"Keys were not saved")
,CClientUIInterface::MSG_ERROR);
}
else
message(tr("Export Successful"),
tr("Keys were saved to:\n %1")
.arg(filename)
,CClientUIInterface::MSG_INFORMATION);
}
}

void BitcoinGUI::importWallet()
{
if(!walletModel)
return;

WalletModel::UnlockContext ctx(walletModel->requestUnlock());
if(!ctx.isValid())
{
// Unlock wallet failed or was cancelled
return;
}

#if QT_VERSION < 0x050000
QString openDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
#else
QString openDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#endif
QString filename = QFileDialog::getOpenFileName(this, tr("Import Wallet"), openDir, tr("Wallet Text (*.txt)"));
if(!filename.isEmpty()) {
if(!walletModel->importWallet(filename)) {
message(tr("Import Failed"),
tr("There was an error trying to import the file's keys into your wallet.\n"
"Some or all keys were not imported from walletfile: %1")
.arg(filename)
,CClientUIInterface::MSG_ERROR);
}
else
message(tr("Import Successful"),
tr("Keys %1, were imported into wallet.")
.arg(filename)
,CClientUIInterface::MSG_INFORMATION);
}
}

void BitcoinGUI::changePassphrase()
{
AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);
Expand Down
5 changes: 5 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class BitcoinGUI : public QMainWindow
QAction *exportAction;
QAction *encryptWalletAction;
QAction *backupWalletAction;
QAction *dumpWalletAction;
QAction *importWalletAction;
QAction *changePassphraseAction;
QAction *aboutQtAction;
QAction *openRPCConsoleAction;
Expand Down Expand Up @@ -172,6 +174,9 @@ private slots:
void incomingTransaction(const QModelIndex & parent, int start, int end);
/** Encrypt the wallet */
void encryptWallet(bool status);
/** Import/Export the wallet's keys */
void dumpWallet();
void importWallet();
/** Backup the wallet */
void backupWallet();
/** Change encrypted wallet passphrase */
Expand Down
Binary file added src/qt/res/icons/export2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/qt/res/icons/import.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ bool WalletModel::backupWallet(const QString &filename)
return BackupWallet(*wallet, filename.toLocal8Bit().data());
}

bool WalletModel::dumpWallet(const QString &filename)
{
return DumpWallet(wallet, filename.toLocal8Bit().data());
}

bool WalletModel::importWallet(const QString &filename)
{
return ImportWallet(wallet, filename.toLocal8Bit().data());
}

void WalletModel::getStakeWeightFromValue(const int64& nTime, const int64& nValue, uint64& nWeight)
{
wallet->GetStakeWeightFromValue(nTime, nValue, nWeight);
Expand Down
4 changes: 3 additions & 1 deletion src/qt/walletmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ class WalletModel : public QObject
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
// Wallet backup
bool backupWallet(const QString &filename);

//Wallet Inport/Export
bool dumpWallet(const QString &filename);
bool importWallet(const QString &filename);
//PoS Information about value and time
void getStakeWeightFromValue(const qint64& nTime, const qint64& nValue, quint64& nWeight);

Expand Down

0 comments on commit 3747989

Please sign in to comment.