Browse Source

Merge pull request #83 from MyHush/dev

add random Sietch, update lib,
pull/98/head
Denio 4 years ago
committed by GitHub
parent
commit
e4d798509b
  1. 1780
      lib/Cargo.lock
  2. 2
      lib/Cargo.toml
  3. 2258
      res/SilentDragonLite.xpm
  4. 4
      silentdragon-lite.pro
  5. 484
      src/controller.cpp
  6. 13
      src/controller.h
  7. 8
      src/liteinterface.cpp
  8. 3
      src/liteinterface.h
  9. 8
      src/mainwindow.ui
  10. 1
      src/recurring.cpp
  11. 10702
      src/sietch.h
  12. 111
      src/websockets.cpp
  13. 1
      src/websockets.h

1780
lib/Cargo.lock

File diff suppressed because it is too large

2
lib/Cargo.toml

@ -11,4 +11,4 @@ crate-type = ["staticlib"]
[dependencies]
libc = "0.2.58"
lazy_static = "1.4.0"
silentdragonlitelib = { git = "https://github.com/MyHush/silentdragonlite-cli", rev = "b5534d6f830b9af2e6a2992d67c99fea2ef5f21a" }
silentdragonlitelib = { git = "https://github.com/MyHush/silentdragonlite-cli", rev = "cdf2c834a4eaea633274030dce98c61b9e2cc927" }

2258
res/SilentDragonLite.xpm

File diff suppressed because it is too large

4
silentdragon-lite.pro

@ -27,6 +27,10 @@ DEFINES += \
INCLUDEPATH += src/3rdparty/
INCLUDEPATH += src/
mac: LIBS+= -Wl,-dead_strip
mac: LIBS+= -Wl,-dead_strip_dylibs
mac: LIBS+= -Wl,-bind_at_load
RESOURCES = application.qrc
MOC_DIR = bin

484
src/controller.cpp

@ -1,11 +1,11 @@
#include "controller.h"
#include "mainwindow.h"
#include "addressbook.h"
#include "settings.h"
#include "version.h"
#include "camount.h"
#include "websockets.h"
#include "sietch.h"
using json = nlohmann::json;
@ -59,7 +59,8 @@ Controller::~Controller() {
delete model;
delete zrpc;
}
// Called when a connection to hushd is available.
void Controller::setConnection(Connection* c) {
if (c == nullptr) return;
@ -79,60 +80,470 @@ void Controller::setConnection(Connection* c) {
// Force update, because this might be coming from a settings update
// where we need to immediately refresh
refresh(true);
// Create Sietch zdust addr at startup.
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch1.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch2.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch3.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch4.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch5.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch6.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch7.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch8.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch9.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
}
// Build the RPC JSON Parameters for this tx
void Controller::fillTxJsonParams(json& allRecepients, Tx tx) {
Q_ASSERT(allRecepients.is_array());
// For each addr/amt/memo, construct the JSON and also build the confirm dialog box
for (int i=0; i < tx.toAddrs.size(); i++) {
auto toAddr = tx.toAddrs[i];
// Construct the JSON params
json rec = json::object();
json dust = json::object();
json dust1 = json::object();
json dust2 = json::object();
json dust3 = json::object();
json dust4 = json::object();
json dust5 = json::object();
json dust6 = json::object();
json dust7 = json::object();
json dust8 = json::object();
json dust9 = json::object();
// Create Sietch zdust addr again to not use it twice.
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch1.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch2.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch3.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch4.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch5.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch6.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch7.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch8.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
zrpc->createNewSietchZaddr( [=] (json reply) {
QString path= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch9.txt");
QFile file(path);
QString zdust = QString::fromStdString(reply.get<json::array_t>()[0]);
if(!file.open(QIODevice::WriteOnly)){
file.close();
} else {
QTextStream out(&file); out << zdust.toUtf8();
file.close();
}
} );
// Set sietch zdust addr to json.
QString path= (QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)) + QString("/Sietch.txt");
QFile inputFile(path);
if (inputFile.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile);
while (!in.atEnd())
{
QString line = in.readLine();
dust["address"] = line.toStdString();
}
inputFile.close();
}
QString path1= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch1.txt");
QFile inputFile1(path1);
if (inputFile1.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile1);
while (!in.atEnd())
{
QString line = in.readLine();
QString zdust = line;
dust1["address"] = zdust.toStdString();
}
inputFile1.close();
}
QString path2= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch2.txt");
QFile inputFile2(path2);
if (inputFile2.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile2);
while (!in.atEnd())
{
QString line = in.readLine();
dust2["address"] = line.toStdString();
}
inputFile2.close();
}
QString path3= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch3.txt");
QFile inputFile3(path3);
if (inputFile3.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile3);
while (!in.atEnd())
{
QString line = in.readLine();
dust3["address"] = line.toStdString();
}
inputFile3.close();
}
QString path4= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch4.txt");
QFile inputFile4(path4);
if (inputFile4.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile4);
while (!in.atEnd())
{
QString line = in.readLine();
dust4["address"] = line.toStdString();
}
inputFile4.close();
}
QString path5= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch5.txt");
QFile inputFile5(path5);
if (inputFile5.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile5);
while (!in.atEnd())
{
QString line = in.readLine();
dust5["address"] = line.toStdString();
}
inputFile5.close();
}
QString path6= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch6.txt");
QFile inputFile6(path6);
if (inputFile6.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile6);
while (!in.atEnd())
{
QString line = in.readLine();
dust6["address"] = line.toStdString();
}
inputFile6.close();
}
QString path7= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch7.txt");
QFile inputFile7(path7);
if (inputFile7.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile7);
while (!in.atEnd())
{
QString line = in.readLine();
dust7["address"] = line.toStdString();
}
inputFile7.close();
}
QString path8= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch8.txt");
QFile inputFile8(path8);
if (inputFile8.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile8);
while (!in.atEnd())
{
QString line = in.readLine();
dust8["address"] = line.toStdString();
}
inputFile.close();
}
QString path9= QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QString("/Sietch9.txt");
QFile inputFile9(path9);
if (inputFile9.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile9);
while (!in.atEnd())
{
QString line = in.readLine();
dust9["address"] = line.toStdString();
}
inputFile9.close();
}
// Dust amt/memo, construct the JSON
dust["amount"] = 0;
dust["memo"] = "";
dust1["amount"] = 0;
dust1["memo"] = "";
dust2["amount"] = 0;
dust2["memo"] = "";
dust3["amount"] = 0;
dust3["memo"] = "";
dust4["amount"] = 0;
dust4["memo"] = "";
dust5["amount"] = 0;
dust5["memo"] = "";
dust6["amount"] = 0;
dust6["memo"] = "";
dust7["amount"] = 0;
dust7["memo"] = "";
dust8["amount"] = 0;
dust8["memo"] = "";
dust9["amount"] = 0;
dust9["memo"] = "";
// For each addr/amt/memo, construct the JSON and also build the confirm dialog box
for (int i=0; i < tx.toAddrs.size(); i++) {
auto toAddr = tx.toAddrs[i];
rec["address"] = toAddr.addr.toStdString();
rec["amount"] = toAddr.amount.toqint64();
if (Settings::isZAddress(toAddr.addr) && !toAddr.memo.trimmed().isEmpty())
rec["memo"] = toAddr.memo.toStdString();
unsigned int MIN_ZOUTS=8;
while (allRecepients.size() < MIN_ZOUTS) {
int decider = qrand() % ((100 + 1) - 1) + 1;// random int between 1 and 100
QString zdust1;
zdust1 = randomSietchZaddr();
QString zdust2;
zdust2 = randomSietchZaddr();
dust["address"] = zdust1.toStdString();
dust["amount"] = 0;
// dust["memo"] = "";
dust1["address"] = zdust2.toStdString();
dust1["amount"] = 0;
// dust1["memo"] = "";
}
int decider = qrand() % ((100 + 1)-1)+ 1;// random int between 1 and 100
//50% chance of adding another zdust, shuffle.
if (decider % 2) {
if(decider % 4 == 3) {
allRecepients.insert(std::begin(allRecepients),{dust,dust1}) ;
std::shuffle(allRecepients.begin(),allRecepients.end(),std::random_device());
allRecepients.insert(std::begin(allRecepients),{dust,dust1,dust2,dust3,dust4,dust5,dust6,dust7,dust8}) ;
// std::shuffle(allRecepients.begin(),allRecepients.end(),std::random_device());
}else {
allRecepients.insert(std::begin(allRecepients),{dust}) ;
std::shuffle(allRecepients.begin(),allRecepients.end(),std::random_device());
}}
}
allRecepients.insert(std::begin(allRecepients),{dust,dust1,dust2,dust3,dust4,dust5,dust6,dust7,dust8,dust9}) ;
// std::shuffle(allRecepients.begin(),allRecepients.end(),std::random_device());
}
allRecepients.push_back(rec) ;
}
}
void Controller::noConnection() {
QIcon i = QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical);
@ -393,6 +804,7 @@ void Controller::refreshAddresses() {
auto newzaddresses = new QList<QString>();
auto newtaddresses = new QList<QString>();
zrpc->fetchAddresses([=] (json reply) {
auto zaddrs = reply["z_addresses"].get<json::array_t>();
for (auto& it : zaddrs) {
@ -1277,3 +1689,7 @@ QString Controller::getDefaultTAddress() {
else
return QString();
}

13
src/controller.h

@ -101,12 +101,18 @@ public:
zrpc->createNewZaddr(sapling, cb);
}, [=](){});
}
void createNewTaddr(const std::function<void(json)>& cb) {
unlockIfEncrypted([=] () {
zrpc->createNewTaddr(cb);
}, [=](){});
}
void createNewSietchZaddr(const std::function<void(json)>& cb) {
unlockIfEncrypted([=] () {
zrpc->createNewSietchZaddr(cb);
}, [=](){});
}
void fetchPrivKey(QString addr, const std::function<void(json)>& cb) {
unlockIfEncrypted([=] () {
zrpc->fetchPrivKey(addr, cb);
@ -134,12 +140,14 @@ public:
});
}
// void importZPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb) { zrpc->importZPrivKey(addr, rescan, cb); }
// void importTPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb) { zrpc->importTPrivKey(addr, rescan, cb); }
QString getDefaultSaplingAddress();
QString getDefaultTAddress();
private:
void processInfo(const json&);
void refreshBalances();
@ -154,6 +162,7 @@ private:
void unlockIfEncrypted (std::function<void(void)> cb, std::function<void(void)> error);
QProcess* ehushd = nullptr;
TxTableModel* transactionsTableModel = nullptr;
@ -172,6 +181,8 @@ private:
// Current balance in the UI. If this number updates, then refresh the UI
QString currentBalance;
QString sietch;
};
#endif // RPCCLIENT_H

8
src/liteinterface.cpp

@ -42,6 +42,14 @@ void LiteInterface::createNewZaddr(bool, const std::function<void(json)>& cb) {
conn->doRPCWithDefaultErrorHandling("new", "zs", cb);
}
void LiteInterface::createNewSietchZaddr(const std::function<void(json)>& cb) {
if (conn == nullptr)
return;
conn->doRPCWithDefaultErrorHandling("sietch", "zs", cb);
}
void LiteInterface::createNewTaddr(const std::function<void(json)>& cb) {
if (conn == nullptr)
return;

3
src/liteinterface.h

@ -55,6 +55,7 @@ public:
void createNewZaddr(bool sapling, const std::function<void(json)>& cb);
void createNewTaddr(const std::function<void(json)>& cb);
void createNewSietchZaddr(const std::function<void(json)>& cb);
void fetchPrivKey(QString addr, const std::function<void(json)>& cb);
void fetchAllPrivKeys(const std::function<void(json)>);
@ -71,11 +72,13 @@ public:
//void importZPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb);
//void importTPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb);
void sendTransaction(QString params, const std::function<void(json)>& cb, const std::function<void(QString)>& err);
private:
Connection* conn = nullptr;
};
#endif // hushDRPC_H

8
src/mainwindow.ui

@ -22,7 +22,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>4</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -85,12 +85,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
<kerning>true</kerning>
</font>
</property>
<property name="text">
<string>Notarized</string>
</property>

1
src/recurring.cpp

@ -106,6 +106,7 @@ QString RecurringPaymentInfo::getAmountPretty() const {
} else if (Settings::getInstance()->get_currency_name() == "AUD") {
return currency == "AUD" ? amount.toDecimalAUDString() : amount.toDecimalhushString();
}
else return currency == "USD" ? amount.toDecimalUSDString() : amount.toDecimalhushString();
}
QString RecurringPaymentInfo::getScheduleDescription() const {

10702
src/sietch.h

File diff suppressed because it is too large

111
src/websockets.cpp

@ -432,9 +432,12 @@ void AppDataServer::saveNonceHex(NonceType nt, QString noncehex) {
// Encrypt an outgoing message with the stored secret key.
QString AppDataServer::encryptOutgoing(QString msg) {
if (msg.length() % 256 > 0) {
msg = msg + QString(" ").repeated(256 - (msg.length() % 256));
int padding = 16*1024;
qDebug() << "Encrypt msg(pad="<<padding<<") prepad len=" << msg.length();
if (msg.length() % padding > 0) {
msg = msg + QString(" ").repeated(padding - (msg.length() % padding));
}
qDebug() << "Encrypt msg postpad len=" << msg.length();
QString localNonceHex = getNonceHex(NonceType::LOCAL);
@ -661,6 +664,9 @@ void AppDataServer::processDecryptedMessage(QString message, MainWindow* mainWin
}
else if (msg.object()["command"] == "sendTx") {
processSendTx(msg.object()["tx"].toObject(), mainWindow, pClient);
}
else if (msg.object()["command"] == "sendmanyTx") {
processSendManyTx(msg.object()["tx"].toObject(), mainWindow, pClient);
}
else {
auto r = QJsonDocument(QJsonObject{
@ -762,6 +768,107 @@ void AppDataServer::processSendTx(QJsonObject sendTx, MainWindow* mainwindow, st
pClient->sendTextMessage(encryptOutgoing(r));
}
// "sendmanyTx" command. This method will actually send money, so be careful with everything
void AppDataServer::processSendManyTx(QJsonObject sendmanyTx, MainWindow* mainwindow, std::shared_ptr<ClientWebSocket> pClient) {
qDebug() << "processSendManyTx with to=" << sendmanyTx["to"].toString();
auto error = [=](QString reason) {
auto r = QJsonDocument(QJsonObject{
{"errorCode", -1},
{"errorMessage", "Couldn't send Tx:" + reason}
}).toJson();
pClient->sendTextMessage(encryptOutgoing(r));
return;
};
// Refuse to send if the node is still syncing
if (Settings::getInstance()->isSyncing()) {
error(QObject::tr("Node is still syncing."));
return;
}
// Create a Tx Object
Tx tx;
tx.fee = Settings::getMinerFee();
// Find a from address that has at least the sending amout
CAmount amt = CAmount::fromDecimalString(sendmanyTx["amount"].toString());
auto allBalances = mainwindow->getRPC()->getModel()->getAllBalances();
QList<QPair<QString, CAmount>> bals;
for (auto i : allBalances.keys()) {
// Filter out sprout addresses
if (Settings::getInstance()->isSproutAddress(i))
continue;
// Filter out balances that don't have the requisite amount
if (allBalances.value(i) < amt)
continue;
bals.append(QPair<QString, CAmount>(i, allBalances.value(i)));
}
if (bals.isEmpty()) {
error(QObject::tr("No sapling or transparent addresses with enough balance to spend."));
return;
}
std::sort(bals.begin(), bals.end(), [=](const QPair<QString, CAmount>a, const QPair<QString, CAmount> b) -> bool {
// Sort z addresses first
return a.first > b.first;
});
//send to more then one Receipent
int totalSendManyItems = sendmanyTx.size();
for (int i=0; i < totalSendManyItems; i++) {
amt = CAmount::fromDecimalString(sendmanyTx["amount"].toString() % QString::number(i+1));
QString addr = sendmanyTx["to"].toString() % QString::number(i+1);
QString memo = sendmanyTx["memo"].toString() % QString::number(i+1);
tx.fromAddr = bals[0].first;
tx.toAddrs = { ToFields{ addr, amt, memo} };
}
// TODO: Respect the autoshield change setting
QString validation = mainwindow->doSendTxValidations(tx);
if (!validation.isEmpty()) {
error(validation);
return;
}
json params = json::array();
mainwindow->getRPC()->fillTxJsonParams(params, tx);
std::cout << std::setw(2) << params << std::endl;
// And send the Tx
mainwindow->getRPC()->executeTransaction(tx,
[=] (QString txid) {
auto r = QJsonDocument(QJsonObject{
{"version", 1.0},
{"command", "sendTxSubmitted"},
{"txid", txid}
}).toJson();
pClient->sendTextMessage(encryptOutgoing(r));
},
// Errored while submitting Tx
[=] (QString, QString errStr) {
auto r = QJsonDocument(QJsonObject{
{"version", 1.0},
{"command", "sendTxFailed"},
{"err", errStr}
}).toJson();
pClient->sendTextMessage(encryptOutgoing(r));
}
);
auto r = QJsonDocument(QJsonObject{
{"version", 1.0},
{"command", "sendTx"},
{"result", "success"}
}).toJson();
pClient->sendTextMessage(encryptOutgoing(r));
}
// "getInfo" command
void AppDataServer::processGetInfo(QJsonObject jobj, MainWindow* mainWindow, std::shared_ptr<ClientWebSocket> pClient) {
auto connectedName = jobj["name"].toString();

1
src/websockets.h

@ -101,6 +101,7 @@ public:
void updateUIWithNewQRCode(MainWindow* mainwindow);
void processSendTx(QJsonObject sendTx, MainWindow* mainwindow, std::shared_ptr<ClientWebSocket> pClient);
void processSendManyTx(QJsonObject sendmanyTx, MainWindow* mainwindow, std::shared_ptr<ClientWebSocket> pClient);
void processMessage(QString message, MainWindow* mainWindow, std::shared_ptr<ClientWebSocket> pClient, AppConnectionType connType);
void processGetInfo(QJsonObject jobj, MainWindow* mainWindow, std::shared_ptr<ClientWebSocket> pClient);
void processDecryptedMessage(QString message, MainWindow* mainWindow, std::shared_ptr<ClientWebSocket> pClient);

Loading…
Cancel
Save