Skip to content
Permalink
Browse files

Add Export/Import Wallet to GUI

  • Loading branch information
iamunick committed Jun 6, 2014
1 parent b6a1343 commit 377b1d8d09e6025f39b2c5da7f1ef2ba70a40dbb
@@ -41,6 +41,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>
@@ -258,6 +258,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);
@@ -282,6 +286,8 @@ void BitcoinGUI::createActions()
connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));
connect(dumpWalletAction, SIGNAL(triggered()), this, SLOT(dumpWallet()));
connect(importWalletAction, SIGNAL(triggered()), this, SLOT(importWallet()));
}

void BitcoinGUI::createMenuBar()
@@ -297,6 +303,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);
@@ -886,6 +896,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);
@@ -87,6 +87,8 @@ class BitcoinGUI : public QMainWindow
QAction *exportAction;
QAction *encryptWalletAction;
QAction *backupWalletAction;
QAction *dumpWalletAction;
QAction *importWalletAction;
QAction *changePassphraseAction;
QAction *aboutQtAction;
QAction *openRPCConsoleAction;
@@ -171,6 +173,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 */
Binary file not shown.
BIN +1006 Bytes src/qt/res/icons/import.png
Binary file not shown.
@@ -313,6 +313,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);
@@ -95,6 +95,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);

0 comments on commit 377b1d8

Please sign in to comment.
You can’t perform that action at this time.