Skip to content
Permalink
Browse files

get_tx_key fixes for Trezor

  • Loading branch information...
ph4r05 committed Jun 17, 2019
1 parent d1e8b6f commit e6e53fa4db3f037bc7890470454a2e6977f7b287
Showing with 50 additions and 4 deletions.
  1. +21 −1 pages/History.qml
  2. +22 −2 src/libwalletqt/Wallet.cpp
  3. +7 −1 src/libwalletqt/Wallet.h
@@ -1095,11 +1095,20 @@ Rectangle {
color: "transparent"
Layout.fillWidth: true
Layout.preferredHeight: 20
state: "ready"

MoneroComponents.TextPlain {
font.family: MoneroComponents.Style.fontRegular.name
font.pixelSize: 15
text: {
if (currentWallet.isTrezorBacked()){
var txKey = currentWallet.getCachedTxKey(hash);
if (txKey) return txKey;

parent.state = "hw";
return qsTr("Click to recover");
}

var txKey = currentWallet.getTxKey(hash)
if(txKey) return txKey;
else return "-"
@@ -1109,7 +1118,7 @@ Rectangle {
anchors.verticalCenter: parent.verticalCenter

MouseArea {
state: "copyable"
state: "copyable_txkey"
anchors.fill: parent
hoverEnabled: true
onEntered: parent.color = MoneroComponents.Style.orange
@@ -1200,6 +1209,7 @@ Rectangle {
if(res[i].containsMouse === true){
if(res[i].state === 'copyable' && res[i].parent.hasOwnProperty('text')) toClipboard(res[i].parent.text);
if(res[i].state === 'copyable_address') root.toClipboard(address);
if(res[i].state === 'copyable_txkey') root.getTxKey(hash, res[i]);
if(res[i].state === 'set_tx_note') root.editDescription(hash);
if(res[i].state === 'details') root.showTxDetails(hash, paymentId, destinations, subaddrAccount, subaddrIndex);
if(res[i].state === 'proof') root.showTxProof(hash, paymentId, destinations, subaddrAccount, subaddrIndex);
@@ -1577,6 +1587,16 @@ Rectangle {
}
}

function getTxKey(hash, elem){
if (elem.parent.parent.state == 'hw'){
var txKey = currentWallet.getTxKey(hash)
elem.parent.text = txKey ? txKey : '-';
elem.parent.parent.state = 'ready';
}

toClipboard(elem.parent.text);
}

function showTxDetails(hash, paymentId, destinations, subaddrAccount, subaddrIndex){
var tx_key = currentWallet.getTxKey(hash)
var tx_note = currentWallet.getUserNote(hash)
@@ -265,6 +265,11 @@ void Wallet::initAsync(const QString &daemonAddress, quint64 upperTransactionLim
watcher->setFuture(future);
}

bool Wallet::isTrezorBacked() const
{
return m_walletImpl->getDeviceType() == Monero::Wallet::Device_Trezor;
}

//! create a view only wallet
bool Wallet::createViewOnly(const QString &path, const QString &password) const
{
@@ -657,9 +662,24 @@ QString Wallet::getUserNote(const QString &txid) const
return QString::fromStdString(m_walletImpl->getUserNote(txid.toStdString()));
}

QString Wallet::getTxKey(const QString &txid) const
QString Wallet::getCachedTxKey(const QString &txid) const
{
return m_txKeyCache.value(txid);
}

QString Wallet::getTxKey(const QString &txid)
{
return QString::fromStdString(m_walletImpl->getTxKey(txid.toStdString()));
if (m_txKeyCache.contains(txid))
{
return m_txKeyCache[txid];
}

QString res = QString::fromStdString(m_walletImpl->getTxKey(txid.toStdString()));
if (!res.isEmpty())
{
m_txKeyCache[txid] = res;
}
return res;
}

QString Wallet::checkTxKey(const QString &txid, const QString &tx_key, const QString &address)
@@ -33,6 +33,7 @@
#include <QTime>
#include <QMutex>
#include <QList>
#include <QMap>
#include <QtConcurrent/QtConcurrent>

#include "wallet/api/wallet2_api.h" // we need to have an access to the Monero::Wallet::Status enum here;
@@ -178,6 +179,9 @@ class Wallet : public QObject
Q_INVOKABLE QString getSubaddressLabel(quint32 accountIndex, quint32 addressIndex) const;
Q_INVOKABLE void setSubaddressLabel(quint32 accountIndex, quint32 addressIndex, const QString &label);

//! hw-device backed wallets
Q_INVOKABLE bool isTrezorBacked() const;

//! returns if view only wallet
Q_INVOKABLE bool viewOnly() const;

@@ -288,7 +292,8 @@ class Wallet : public QObject

Q_INVOKABLE bool setUserNote(const QString &txid, const QString &note);
Q_INVOKABLE QString getUserNote(const QString &txid) const;
Q_INVOKABLE QString getTxKey(const QString &txid) const;
Q_INVOKABLE QString getCachedTxKey(const QString &txid) const;
Q_INVOKABLE QString getTxKey(const QString &txid);
Q_INVOKABLE QString checkTxKey(const QString &txid, const QString &tx_key, const QString &address);
Q_INVOKABLE QString getTxProof(const QString &txid, const QString &address, const QString &message) const;
Q_INVOKABLE QString checkTxProof(const QString &txid, const QString &address, const QString &message, const QString &signature);
@@ -374,6 +379,7 @@ class Wallet : public QObject
friend class WalletListenerImpl;
//! libwallet's
Monero::Wallet * m_walletImpl;
QMap<QString, QString> m_txKeyCache;
// history lifetime managed by wallet;
TransactionHistory * m_history;
// Used for UI history view

0 comments on commit e6e53fa

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