108 lines
4.2 KiB
C++
108 lines
4.2 KiB
C++
/*
|
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* 1. Any modified source or binaries are used only with the BitShares network.
|
|
*
|
|
* 2. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
*
|
|
* 3. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
*/
|
|
#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"
|
|
|
|
#include <QDateTime>
|
|
#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;
|
|
|
|
class Transaction;
|
|
class ChainDataModel : public QObject {
|
|
Q_OBJECT
|
|
Q_PROPERTY(QDateTime chainTime READ chainTime NOTIFY blockReceived)
|
|
|
|
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);
|
|
|
|
QDateTime chainTime() const;
|
|
|
|
ChainDataModel(){}
|
|
ChainDataModel(fc::thread& t, QObject* parent = nullptr);
|
|
|
|
void setDatabaseAPI(fc::api<graphene::app::database_api> dbapi);
|
|
void setNetworkAPI(fc::api<graphene::app::network_broadcast_api> napi);
|
|
|
|
const graphene::chain::global_property_object& global_properties() const { return m_global_properties; }
|
|
const graphene::chain::dynamic_global_property_object& dynamic_global_properties() const { return m_dynamic_global_properties; }
|
|
const graphene::chain::chain_property_object& chain_properties() const { return m_chain_properties; }
|
|
|
|
public Q_SLOTS:
|
|
void broadcast(Transaction* transaction);
|
|
|
|
Q_SIGNALS:
|
|
void queueExecute(const std::function<void()>&);
|
|
void exceptionThrown(QString message);
|
|
void blockReceived();
|
|
|
|
private:
|
|
fc::thread* m_rpc_thread = nullptr;
|
|
std::string m_api_url;
|
|
fc::api<graphene::app::database_api> m_db_api;
|
|
fc::api<graphene::app::network_broadcast_api> m_net_api;
|
|
|
|
graphene::chain::global_property_object m_global_properties;
|
|
graphene::chain::dynamic_global_property_object m_dynamic_global_properties;
|
|
graphene::chain::chain_property_object m_chain_properties;
|
|
|
|
ObjectId m_account_query_num = -1;
|
|
account_multi_index_type m_accounts;
|
|
asset_multi_index_type m_assets;
|
|
};
|
|
|