Skip to content

Commit

Permalink
Merge pull request #41 from aivve/feature/send_no_relay
Browse files Browse the repository at this point in the history
Save raw tx without relay
  • Loading branch information
aivve authored Jan 12, 2021
2 parents a7f5c52 + 9062a67 commit 96a2b86
Show file tree
Hide file tree
Showing 23 changed files with 1,670 additions and 667 deletions.
3 changes: 3 additions & 0 deletions src/Languages.pro
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ gui/SendGlassFrame.cpp \
gui/SignMessageDialog.cpp \
gui/OptimizationSettings.cpp \
gui/GetBalanceProofDialog.cpp \
gui/ExportRawTxDialog.cpp \


HEADERS = CommandLineParser.h \
Expand Down Expand Up @@ -139,6 +140,7 @@ gui/SendGlassFrame.h \
gui/SignMessageDialog.h \
gui/OptimizationSettings.h \
gui/GetBalanceProofDialog.h \
gui/ExportRawTxDialog.h \

FORMS = gui/ui/aboutdialog.ui \
Expand Down Expand Up @@ -180,6 +182,7 @@ gui/ui/nowalletframe.ui \
gui/ui/signmessagedialog.ui \
gui/ui/optimizationsettingsdialog.ui \
gui/ui/getbalanceproofdialog.ui \
gui/ui/exportrawtxdialog.ui \

TRANSLATIONS = languages/uk.ts \
Expand Down
17 changes: 15 additions & 2 deletions src/WalletAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,30 @@ Crypto::SecretKey WalletAdapter::getTxKey(Crypto::Hash& txid) {
return CryptoNote::NULL_SECRET_KEY;
}

void WalletAdapter::sendTransaction(const std::vector<CryptoNote::WalletLegacyTransfer>& _transfers, quint64 _fee, const QString& _paymentId, quint64 _mixin) {
void WalletAdapter::sendTransaction(const std::vector<CryptoNote::WalletLegacyTransfer>& _transfers, quint64 _fee, const QString& _payment_id, quint64 _mixin) {
Q_CHECK_PTR(m_wallet);
try {
lock();
Q_EMIT walletStateChangedSignal(tr("Sending transaction"));
m_wallet->sendTransaction(_transfers, _fee, NodeAdapter::instance().convertPaymentId(_paymentId), _mixin, 0);
m_wallet->sendTransaction(_transfers, _fee, NodeAdapter::instance().convertPaymentId(_payment_id), _mixin, 0);
} catch (std::system_error&) {
unlock();
}
}

QString WalletAdapter::prepareRawTransaction(const std::vector<CryptoNote::WalletLegacyTransfer>& _transfers, quint64 _fee, const QString& _payment_id, quint64 _mixin) {
Q_CHECK_PTR(m_wallet);
try {
lock();
Q_EMIT walletStateChangedSignal(tr("Preparing transaction"));
CryptoNote::TransactionId transactionId;
return QString::fromStdString(m_wallet->prepareRawTransaction(transactionId, _transfers, _fee, NodeAdapter::instance().convertPaymentId(_payment_id), _mixin, 0));
} catch (std::system_error&) {
unlock();
}
return QString();
}

quint64 WalletAdapter::estimateFusion(quint64 _threshold) {
Q_CHECK_PTR(m_wallet);
try {
Expand Down
13 changes: 9 additions & 4 deletions src/WalletAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,23 @@ class WalletAdapter : public QObject, public CryptoNote::IWalletLegacyObserver {
bool getAccountKeys(CryptoNote::AccountKeys& _keys);
QString getTxProof(Crypto::Hash& _txid, CryptoNote::AccountPublicAddress& _address, Crypto::SecretKey& _tx_key);
QString getReserveProof(const quint64 &_reserve, const QString &_message);
Crypto::SecretKey getTxKey(Crypto::Hash& txid);
size_t getUnlockedOutputsCount();
bool isOpen() const;

void sendTransaction(const std::vector<CryptoNote::WalletLegacyTransfer>& _transfers, quint64 _fee, const QString& _payment_id, quint64 _mixin);
bool changePassword(const QString& _old_pass, const QString& _new_pass);
void setWalletFile(const QString& _path);
Crypto::SecretKey getTxKey(Crypto::Hash& txid);

QString prepareRawTransaction(const std::vector<CryptoNote::WalletLegacyTransfer>& _transfers, quint64 _fee, const QString& _payment_id, quint64 _mixin);

quint64 estimateFusion(quint64 _threshold);
std::list<CryptoNote::TransactionOutputInformation> getFusionTransfersToSend(quint64 _threshold, size_t _min_input_count, size_t _max_input_count);
void sendFusionTransaction(const std::list<CryptoNote::TransactionOutputInformation>& _fusion_inputs, quint64 _fee, const QString& _extra, quint64 _mixin);
bool isFusionTransaction(const CryptoNote::WalletLegacyTransaction& walletTx) const;

bool isOpen() const;

bool changePassword(const QString& _old_pass, const QString& _new_pass);
void setWalletFile(const QString& _path);

QString signMessage(const QString &data);
bool verifyMessage(const QString &data, const CryptoNote::AccountPublicAddress &address, const QString &signature);

Expand Down
46 changes: 46 additions & 0 deletions src/gui/ExportRawTxDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2016 The Karbowanec developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "ExportRawTxDialog.h"
#include "ui_exportrawtxdialog.h"
#include <QClipboard>
#include <QFileDialog>
#include <QTextStream>
#include <Common/StringTools.h>
#include "CurrencyAdapter.h"
#include "WalletAdapter.h"
#include "MainWindow.h"
#include <boost/utility/value_init.hpp>

namespace WalletGui {

ExportRawTransactionDialog::ExportRawTransactionDialog(QWidget* _parent) : QDialog(_parent), m_ui(new Ui::ExportRawTransactionDialog) {
m_ui->setupUi(this);
}

ExportRawTransactionDialog::~ExportRawTransactionDialog() {
m_ui->m_txEdit->clear();
}

void ExportRawTransactionDialog::setTransaction(const QString& _transaction) {
m_ui->m_txEdit->setText(_transaction);
}

void ExportRawTransactionDialog::copyTx() {
QApplication::clipboard()->setText(m_ui->m_txEdit->toPlainText());
}

void ExportRawTransactionDialog::saveTxToFile() {
QString fileName = QFileDialog::getSaveFileName(&MainWindow::instance(), tr("Save transaction to..."), QDir::homePath(), tr("Raw hex transaction (*.txt)"));
if (!fileName.isEmpty()) {
QFile f(fileName);
if (f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
QTextStream outputStream(&f);
outputStream << m_ui->m_txEdit->toPlainText();
f.close();
}
}
}

}
30 changes: 30 additions & 0 deletions src/gui/ExportRawTxDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2016-2017 The Karbowanec developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <QDialog>

namespace Ui {
class ExportRawTransactionDialog;
}

namespace WalletGui {

class ExportRawTransactionDialog : public QDialog {
Q_OBJECT

public:
ExportRawTransactionDialog(QWidget * _parent);

~ExportRawTransactionDialog();

void setTransaction(const QString& _transaction);

private:
Q_SLOT void copyTx();
Q_SLOT void saveTxToFile();

QScopedPointer<Ui::ExportRawTransactionDialog> m_ui;
};

}
12 changes: 11 additions & 1 deletion src/gui/SendFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "ConfirmSendDialog.h"
#include "PasswordDialog.h"
#include <CryptoNoteConfig.h>
#include "ExportRawTxDialog.h"

#include "ui_sendframe.h"

Expand Down Expand Up @@ -393,7 +394,16 @@ void SendFrame::sendClicked() {
return;
}

WalletAdapter::instance().sendTransaction(walletTransfers, fee, m_ui->m_paymentIdEdit->text(), m_ui->m_mixinSlider->value());
if (!m_ui->dontRelayCheckBox->isChecked()) {
WalletAdapter::instance().sendTransaction(walletTransfers, fee, m_ui->m_paymentIdEdit->text(), m_ui->m_mixinSlider->value());
} else {
QString rawTx = WalletAdapter::instance().prepareRawTransaction(walletTransfers, fee, m_ui->m_paymentIdEdit->text(), m_ui->m_mixinSlider->value());
if (!rawTx.isEmpty()) {
ExportRawTransactionDialog dlg(&MainWindow::instance());
dlg.setTransaction(rawTx);
dlg.exec();
}
}
}
}
}
Expand Down
158 changes: 158 additions & 0 deletions src/gui/ui/exportrawtxdialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExportRawTransactionDialog</class>
<widget class="QDialog" name="ExportRawTransactionDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>626</width>
<height>460</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>600</width>
<height>150</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>Export raw transaction</string>
</property>
<property name="windowIcon">
<iconset resource="../../resources.qrc">
<normaloff>:/images/cryptonote</normaloff>:/images/cryptonote</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QTextEdit" name="m_txEdit">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="acceptRichText">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>You can broadcast this transaction to the network e.g. via block explorer or RPC request to any public node.</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="m_saveTxButton">
<property name="text">
<string>Save to file</string>
</property>
<property name="icon">
<iconset resource="../../resources.qrc">
<normaloff>:/icons/save</normaloff>:/icons/save</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_copyTxButton">
<property name="text">
<string>Copy</string>
</property>
<property name="icon">
<iconset resource="../../resources.qrc">
<normaloff>:/icons/copy_white</normaloff>:/icons/copy_white</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ClosePushButton">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>ClosePushButton</sender>
<signal>clicked()</signal>
<receiver>ExportRawTransactionDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>622</x>
<y>274</y>
</hint>
<hint type="destinationlabel">
<x>333</x>
<y>149</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_copyTxButton</sender>
<signal>clicked()</signal>
<receiver>ExportRawTransactionDialog</receiver>
<slot>copyTx()</slot>
<hints>
<hint type="sourcelabel">
<x>711</x>
<y>68</y>
</hint>
<hint type="destinationlabel">
<x>419</x>
<y>44</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_saveTxButton</sender>
<signal>clicked()</signal>
<receiver>ExportRawTransactionDialog</receiver>
<slot>saveTxToFile()</slot>
<hints>
<hint type="sourcelabel">
<x>412</x>
<y>127</y>
</hint>
<hint type="destinationlabel">
<x>312</x>
<y>74</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Loading

0 comments on commit 96a2b86

Please sign in to comment.