2015-10-12 17:02:59 +00:00
|
|
|
/*
|
2015-10-12 17:48:40 +00:00
|
|
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
|
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* The MIT License
|
2015-10-12 17:48:40 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +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
|
|
|
*
|
2016-01-06 09:51:18 +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
|
|
|
*
|
2016-01-06 09:51:18 +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 15:10:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
|
|
|
|
|
|
|
|
|
#include <fc/network/http/websocket.hpp>
|
|
|
|
|
#include <graphene/app/api.hpp>
|
|
|
|
|
|
|
|
|
|
#include "BoostMultiIndex.hpp"
|
|
|
|
|
#include "Asset.hpp"
|
|
|
|
|
#include "Account.hpp"
|
|
|
|
|
|
2015-08-03 15:59:02 +00:00
|
|
|
#include <QDateTime>
|
2015-07-22 15:10:52 +00:00
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
|
|
using graphene::chain::by_id;
|
|
|
|
|
|
|
|
|
|
namespace fc {
|
|
|
|
|
class thread;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct by_symbol_name;
|
|
|
|
|
typedef multi_index_container<
|
|
|
|
|
Asset*,
|
|
|
|
|
indexed_by<
|
|
|
|
|
hashed_unique< tag<by_id>, const_mem_fun<GrapheneObject, ObjectId, &GrapheneObject::id > >,
|
|
|
|
|
ordered_unique< tag<by_symbol_name>, const_mem_fun<Asset, QString, &Asset::symbol> >
|
|
|
|
|
>
|
|
|
|
|
> asset_multi_index_type;
|
|
|
|
|
|
|
|
|
|
struct by_account_name;
|
|
|
|
|
typedef multi_index_container<
|
|
|
|
|
Account*,
|
|
|
|
|
indexed_by<
|
|
|
|
|
hashed_unique< tag<by_id>, const_mem_fun<GrapheneObject, ObjectId, &GrapheneObject::id > >,
|
|
|
|
|
ordered_unique< tag<by_account_name>, const_mem_fun<Account, QString, &Account::name> >
|
|
|
|
|
>
|
|
|
|
|
> account_multi_index_type;
|
|
|
|
|
|
2015-07-31 21:56:22 +00:00
|
|
|
class Transaction;
|
2015-07-22 15:10:52 +00:00
|
|
|
class ChainDataModel : public QObject {
|
|
|
|
|
Q_OBJECT
|
2015-08-03 15:59:02 +00:00
|
|
|
Q_PROPERTY(QDateTime chainTime READ chainTime NOTIFY blockReceived)
|
2015-07-22 15:10:52 +00:00
|
|
|
|
|
|
|
|
void processUpdatedObject(const fc::variant& update);
|
|
|
|
|
|
|
|
|
|
void getAssetImpl(QString assetIdentifier, Asset* const * assetInContainer);
|
|
|
|
|
void getAccountImpl(QString accountIdentifier, Account* const * accountInContainer);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Q_INVOKABLE Account* getAccount(ObjectId id);
|
|
|
|
|
Q_INVOKABLE Account* getAccount(QString name);
|
|
|
|
|
Q_INVOKABLE Asset* getAsset(ObjectId id);
|
|
|
|
|
Q_INVOKABLE Asset* getAsset(QString symbol);
|
|
|
|
|
|
2015-08-03 15:59:02 +00:00
|
|
|
QDateTime chainTime() const;
|
|
|
|
|
|
2015-07-22 15:10:52 +00:00
|
|
|
ChainDataModel(){}
|
|
|
|
|
ChainDataModel(fc::thread& t, QObject* parent = nullptr);
|
|
|
|
|
|
|
|
|
|
void setDatabaseAPI(fc::api<graphene::app::database_api> dbapi);
|
2015-07-31 21:56:22 +00:00
|
|
|
void setNetworkAPI(fc::api<graphene::app::network_broadcast_api> napi);
|
2015-07-22 15:10:52 +00:00
|
|
|
|
|
|
|
|
const graphene::chain::global_property_object& global_properties() const { return m_global_properties; }
|
2015-07-31 21:56:22 +00:00
|
|
|
const graphene::chain::dynamic_global_property_object& dynamic_global_properties() const { return m_dynamic_global_properties; }
|
2015-08-19 14:23:06 +00:00
|
|
|
const graphene::chain::chain_property_object& chain_properties() const { return m_chain_properties; }
|
2015-07-31 21:56:22 +00:00
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
|
void broadcast(Transaction* transaction);
|
2015-07-22 15:10:52 +00:00
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
|
void queueExecute(const std::function<void()>&);
|
|
|
|
|
void exceptionThrown(QString message);
|
2015-08-03 15:59:02 +00:00
|
|
|
void blockReceived();
|
2015-07-22 15:10:52 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
fc::thread* m_rpc_thread = nullptr;
|
|
|
|
|
std::string m_api_url;
|
|
|
|
|
fc::api<graphene::app::database_api> m_db_api;
|
2015-07-31 21:56:22 +00:00
|
|
|
fc::api<graphene::app::network_broadcast_api> m_net_api;
|
2015-07-22 15:10:52 +00:00
|
|
|
|
|
|
|
|
graphene::chain::global_property_object m_global_properties;
|
2015-07-31 21:56:22 +00:00
|
|
|
graphene::chain::dynamic_global_property_object m_dynamic_global_properties;
|
2015-08-19 14:23:06 +00:00
|
|
|
graphene::chain::chain_property_object m_chain_properties;
|
2015-07-22 15:10:52 +00:00
|
|
|
|
|
|
|
|
ObjectId m_account_query_num = -1;
|
|
|
|
|
account_multi_index_type m_accounts;
|
|
|
|
|
asset_multi_index_type m_assets;
|
|
|
|
|
};
|
|
|
|
|
|