peerplays_migrated/programs/light_client/Transaction.hpp

106 lines
3.3 KiB
C++
Raw Normal View History

2015-10-12 17:02:59 +00:00
/*
2015-10-12 17:48:40 +00:00
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
*
* The MIT License
2015-10-12 17:48:40 +00:00
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
2015-10-12 17:48:40 +00:00
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
2015-10-12 17:02:59 +00:00
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
2015-10-12 17:02:59 +00:00
*/
2015-07-22 21:38:44 +00:00
#pragma once
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#include <graphene/chain/protocol/transaction.hpp>
2015-08-03 15:59:02 +00:00
#include <QDateTime>
2015-07-22 21:38:44 +00:00
#include <QObject>
#include <QQmlListProperty>
2015-08-03 15:59:02 +00:00
#include <QDebug>
2015-07-22 21:38:44 +00:00
class OperationBase;
class Transaction : public QObject {
Q_OBJECT
public:
enum Status { Unbroadcasted, Pending, Complete, Failed };
Q_ENUM(Status);
Status status() const { return m_status; }
QString statusString() const;
2015-07-22 21:38:44 +00:00
QQmlListProperty<OperationBase> operations();
OperationBase* operationAt(int index) const;
int operationCount() const {
return m_transaction.operations.size();
}
graphene::chain::signed_transaction& internalTransaction() {
return m_transaction;
}
2015-08-03 15:59:02 +00:00
QDateTime expiration() const
{
return QDateTime::fromTime_t(m_transaction.expiration.sec_since_epoch());
}
public Q_SLOTS:
2015-07-22 21:38:44 +00:00
void setStatus(Status status)
{
if (status == m_status)
return;
m_status = status;
2015-08-03 15:59:02 +00:00
qDebug() << status;
2015-07-22 21:38:44 +00:00
emit statusChanged(status);
}
/**
* @brief Append the operation to the transaction
* @param op The operation to append. This Transaction will take ownership of the operation.
*/
void appendOperation(OperationBase* op);
void clearOperations() {
m_transaction.operations.clear();
Q_EMIT operationsChanged();
}
2015-08-03 15:59:02 +00:00
void setExpiration(QDateTime expiration)
{
fc::time_point_sec exp(expiration.toTime_t());
if (exp == m_transaction.expiration)
return;
m_transaction.expiration = exp;
emit expirationChanged(expiration);
}
2015-07-22 21:38:44 +00:00
signals:
void statusChanged(Status status);
void operationsChanged();
2015-08-03 15:59:02 +00:00
void expirationChanged(QDateTime expiration);
2015-07-22 21:38:44 +00:00
private:
Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged)
Q_PROPERTY(QString statusString READ statusString NOTIFY statusChanged STORED false)
2015-07-22 21:38:44 +00:00
Q_PROPERTY(QQmlListProperty<OperationBase> operations READ operations NOTIFY operationsChanged)
2015-08-03 15:59:02 +00:00
Q_PROPERTY(QDateTime expiration READ expiration WRITE setExpiration NOTIFY expirationChanged)
2015-07-22 21:38:44 +00:00
Status m_status = Unbroadcasted;
graphene::chain::signed_transaction m_transaction;
2015-07-22 21:38:44 +00:00
};