/* * This file is part of the Flowee project * Copyright (C) 2020-2024 Tom Zander * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TXINFOOBJECT_P_H #define TXINFOOBJECT_P_H #include #include #include #include class Wallet; class TxInfoObject; class TxInfoPrivate : public QObject { Q_OBJECT public: TxInfoPrivate(TxInfoObject *parent); struct Status { int announced = 0; // num of peers we announced this tx to. int sent = 0; // number of peers we sent this transaction to. int inProgress = 0; // number of peers in progress. int failed = 0; // number of peers reported failure. }; /// Fill a status struct where we take the time things in flight into account. Status calcStatus() const; void offeredVia(const std::shared_ptr &peer); void sentVia(const std::shared_ptr &peer); void txRejected(int connectionId, BroadcastTxData::RejectReason reason, const std::string &message); mutable QMutex lock; std::shared_ptr wallet; int txIndex; struct Broadcast { int connectionId = -1; EndPoint ep; bool failed = false; BroadcastTxData::RejectReason rejected = BroadcastTxData::NoReason; std::string rejectMsg; uint64_t sentTime = 0; // ms since epoch. }; QList broadcasts; TxInfoObject *q; // to avoid emitting finished() more then once. bool finished = false; QTimer checkStatusTimer; // this class is multi-threading by need. The callbacks forwarded from the // main class can happen in any thread, so the sentVia/txRejected are not // on our associated thread. // As these methods are also our main events and thus triggers, we notify the // via signals about changes which are connected to our own slots below that // then will be executed in our own thread. // multi-threading for dummies ;-) signals: void broadcastsChanged(); private slots: void checkState(); }; #endif