Skip to content

Commit

Permalink
Fix wallet update labels, disable heavy benchmark in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goatpig committed May 25, 2022
1 parent a7d4bc7 commit c12846e
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 59 deletions.
11 changes: 11 additions & 0 deletions armoryengine/CppBridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,17 @@ def setComment(self, wltId, key, val):

self.sendToBridgeProto(packet, False)

#############################################################################
def setWalletLabels(self, wltId, title, desc):
packet = ClientProto_pb2.ClientCommand()
packet.method = ClientProto_pb2.setWalletLabels

packet.stringArgs.append(wltId)
packet.stringArgs.append(title)
packet.stringArgs.append(desc)

self.sendToBridgeProto(packet, False)

#############################################################################
def estimateFee(self, blocks, strat):
packet = ClientProto_pb2.ClientCommand()
Expand Down
7 changes: 2 additions & 5 deletions armoryengine/PyBtcWallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,12 +1168,9 @@ def getCommentForLE(self, le):
def setWalletLabels(self, lshort, llong=''):
self.labelName = lshort
self.labelDescr = llong
toWriteS = lshort.ljust( 32, '\x00')
toWriteL = llong.ljust(256, '\x00')

updList = []
updList.append([WLT_UPDATE_MODIFY, self.offsetLabelName, toWriteS])
updList.append([WLT_UPDATE_MODIFY, self.offsetLabelDescr, toWriteL])
TheBridge.setWalletLabels(self.uniqueIDB58,
self.labelName, self.labelDescr)

#############################################################################
def deleteImportedAddress(self, addr160):
Expand Down
17 changes: 17 additions & 0 deletions cppForSwig/BridgeAPI/CppBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,23 @@ void CppBridge::setComment(const ClientCommand& msg)
wltContainer->setComment(hashKey, comment);
}

////////////////////////////////////////////////////////////////////////////////
void CppBridge::setWalletLabels(const ClientCommand& msg)
{
if (msg.stringargs_size() < 1 || msg.stringargs_size() > 3)
throw runtime_error("invalid command: setWalletLabels");

const auto& walletId = msg.stringargs(0);

auto wai = WalletAccountIdentifier::deserialize(walletId);
auto wltContainer = wltManager_->getWalletContainer(
wai.walletId, wai.accountId);

const auto& title = msg.stringargs(1);
const auto& desc = msg.stringargs(2);
wltContainer->setLabels(title, desc);
}

////////////////////////////////////////////////////////////////////////////////
void CppBridge::getUtxosForValue(const string& id,
uint64_t value, unsigned msgId)
Expand Down
1 change: 1 addition & 0 deletions cppForSwig/BridgeAPI/CppBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ namespace Armory
std::vector<std::string>, unsigned);
void createAddressBook(const std::string&, unsigned);
void setComment(const Codec_ClientProto::ClientCommand&);
void setWalletLabels(const Codec_ClientProto::ClientCommand&);

//txs & headers
void getTxByHash(const BinaryData&, unsigned);
Expand Down
6 changes: 6 additions & 0 deletions cppForSwig/BridgeAPI/ProtobufCommandParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@ bool ProtobufCommandParser::processData(
break;
}

case Methods::setWalletLabels:
{
bridge->setWalletLabels(msg);
break;
}

case Methods::getUtxosForValue:
{
if (msg.stringargs_size() != 1 || msg.longargs_size() != 1)
Expand Down
8 changes: 8 additions & 0 deletions cppForSwig/BridgeAPI/WalletManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,14 @@ void WalletContainer::setComment(const string& key, const string& val)
wallet_->setComment(keyBd, val);
}

////////////////////////////////////////////////////////////////////////////////
void WalletContainer::setLabels(const string& title, const string& desc)
{
wallet_->setLabel(title);
wallet_->setDescription(desc);
}


////////////////////////////////////////////////////////////////////////////////
////
//// Armory135Header
Expand Down
1 change: 1 addition & 0 deletions cppForSwig/BridgeAPI/WalletManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class WalletContainer
Armory::Backups::WalletBackup getBackupStrings(const PassphraseLambda&) const;

void setComment(const std::string&, const std::string&);
void setLabels(const std::string&, const std::string&);
};

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion cppForSwig/gtest/UtilsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ TEST_F(BinaryDataTest, Contains)
EXPECT_FALSE(bd4_.contains(d, 8));
}

TEST_F(BinaryDataTest, CompareBench)
TEST_F(BinaryDataTest, DISABLED_CompareBench)
{
auto start = chrono::system_clock::now();

Expand Down
1 change: 1 addition & 0 deletions cppForSwig/protobuf/ClientProto.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum Methods
getHeaderByHeight = 71;
createAddressBook = 72;
setComment = 73;
setWalletLabels = 74;

getNewAddress = 80;
getChangeAddress = 81;
Expand Down
58 changes: 54 additions & 4 deletions qtdialogs/DlgWalletDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

from PySide2.QtCore import Qt, QByteArray
from PySide2.QtWidgets import QFrame, QVBoxLayout, QGridLayout, QPushButton, \
QTreeView, QLabel, QCheckBox, QLineEdit, QDialogButtonBox
QTreeView, QLabel, QCheckBox, QLineEdit, QDialogButtonBox, QTextEdit

from armoryengine.ArmoryUtils import getVersionString, coin2str
from armoryengine.ArmoryUtils import getVersionString, coin2str, isASCII
from armoryengine.BDM import TheBDM, BDM_UNINITIALIZED, BDM_OFFLINE, \
BDM_SCANNING
from armorycolors import htmlColor
Expand All @@ -23,7 +23,8 @@
from qtdialogs.qtdefines import USERMODE, determineWalletType, \
relaxedSizeNChar, relaxedSizeStr, QLabelButton, STYLE_SUNKEN, STYLE_NONE, \
QRichLabel, makeHorizFrame, restoreTableView, WLTTYPES, \
WLTFIELDS, tightSizeStr, saveTableView
WLTFIELDS, tightSizeStr, saveTableView, tightSizeNChar, \
UnicodeErrorBox

from qtdialogs.ArmoryDialog import ArmoryDialog
from qtdialogs.MsgBoxWithDNAA import MsgBoxWithDNAA
Expand Down Expand Up @@ -1003,4 +1004,53 @@ def __init__(self, wltID, parent=None, main=None):
bbox.rejected.connect(self.reject)
layout.addWidget(bbox, 4, 0)
self.setLayout(layout)
self.setWindowTitle(self.tr('Set Wallet Owner'))
self.setWindowTitle(self.tr('Set Wallet Owner'))

################################################################################
class DlgChangeLabels(ArmoryDialog):
def __init__(self, currName='', currDescr='', parent=None, main=None):
super(DlgChangeLabels, self).__init__(parent, main)

self.edtName = QLineEdit()
self.edtName.setMaxLength(32)
lblName = QLabel(self.tr("Wallet &name:"))
lblName.setBuddy(self.edtName)

self.edtDescr = QTextEdit()
tightHeight = tightSizeNChar(self.edtDescr, 1)[1]
self.edtDescr.setMaximumHeight(tightHeight * 4.2)
lblDescr = QLabel(self.tr("Wallet &description:"))
lblDescr.setAlignment(Qt.AlignVCenter)
lblDescr.setBuddy(self.edtDescr)

self.edtName.setText(currName)
self.edtDescr.setText(currDescr)

buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | \
QDialogButtonBox.Cancel)
buttonBox.accepted.connect(self.accept)
buttonBox.rejected.connect(self.reject)

layout = QGridLayout()
layout.addWidget(lblName, 1, 0, 1, 1)
layout.addWidget(self.edtName, 1, 1, 1, 1)
layout.addWidget(lblDescr, 2, 0, 1, 1)
layout.addWidget(self.edtDescr, 2, 1, 2, 1)
layout.addWidget(buttonBox, 4, 0, 1, 2)
self.setLayout(layout)

self.setWindowTitle(self.tr('Wallet Descriptions'))


def accept(self, *args):
try:
self.edtName.text().encode("ascii")
except UnicodeDecodeError:
UnicodeErrorBox(self)
return

if len(str(self.edtName.text()).strip()) == 0:
QMessageBox.critical(self, self.tr('Empty Name'), \
self.tr('All wallets must have a name. '), QMessageBox.Ok)
return
super(DlgChangeLabels, self).accept(*args)
49 changes: 0 additions & 49 deletions qtdialogs/qtdialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,55 +555,6 @@ def getImportWltPath(self):
if self.importFile:
self.accept()


################################################################################
class DlgChangeLabels(ArmoryDialog):
def __init__(self, currName='', currDescr='', parent=None, main=None):
super(DlgChangeLabels, self).__init__(parent, main)

self.edtName = QLineEdit()
self.edtName.setMaxLength(32)
lblName = QLabel(self.tr("Wallet &name:"))
lblName.setBuddy(self.edtName)

self.edtDescr = QTextEdit()
tightHeight = tightSizeNChar(self.edtDescr, 1)[1]
self.edtDescr.setMaximumHeight(tightHeight * 4.2)
lblDescr = QLabel(self.tr("Wallet &description:"))
lblDescr.setAlignment(Qt.AlignVCenter)
lblDescr.setBuddy(self.edtDescr)

self.edtName.setText(currName)
self.edtDescr.setText(currDescr)

buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | \
QDialogButtonBox.Cancel)
self.connect(buttonBox, SIGNAL('accepted()'), self.accept)
self.connect(buttonBox, SIGNAL('rejected()'), self.reject)

layout = QGridLayout()
layout.addWidget(lblName, 1, 0, 1, 1)
layout.addWidget(self.edtName, 1, 1, 1, 1)
layout.addWidget(lblDescr, 2, 0, 1, 1)
layout.addWidget(self.edtDescr, 2, 1, 2, 1)
layout.addWidget(buttonBox, 4, 0, 1, 2)
self.setLayout(layout)

self.setWindowTitle(self.tr('Wallet Descriptions'))


def accept(self, *args):
if not isASCII(unicode(self.edtName.text())) or \
not isASCII(unicode(self.edtDescr.toPlainText())):
UnicodeErrorBox(self)
return

if len(str(self.edtName.text()).strip()) == 0:
QMessageBox.critical(self, self.tr('Empty Name'), \
self.tr('All wallets must have a name. '), QMessageBox.Ok)
return
super(DlgChangeLabels, self).accept(*args)

################################################################################
class LoadingDisp(ArmoryDialog):
def __init__(self, parent, main):
Expand Down

0 comments on commit c12846e

Please sign in to comment.