#pragma once #pragma GCC diagnostic ignored "-Wunknown-pragmas" #include #include #include #include #include #include #include #include #include #include using boost::multi_index_container; using namespace boost::multi_index; Q_DECLARE_METATYPE(std::function) class GrapheneObject : public QObject { Q_OBJECT Q_PROPERTY(qint64 id MEMBER id NOTIFY idChanged) public: qint64 id; Q_SIGNALS: void idChanged(); }; class Asset : public GrapheneObject { Q_OBJECT Q_PROPERTY(QString symbol MEMBER symbol) Q_PROPERTY(quint32 precision MEMBER precision) public: QString symbol; quint32 precision; Q_SIGNALS: void symbolChanged(); }; struct by_id; struct by_symbol_name; typedef multi_index_container< Asset*, indexed_by< hashed_unique< tag, member >, ordered_unique< tag, member > > > asset_multi_index_type; class Balance : public GrapheneObject { Q_OBJECT Q_PROPERTY(Asset* type MEMBER type) Q_PROPERTY(qint64 amount MEMBER amount) Asset* type; qint64 amount; }; class Account : public GrapheneObject { Q_OBJECT Q_PROPERTY(QString name MEMBER name NOTIFY nameChanged) Q_PROPERTY(QQmlListProperty balances READ balances) QList m_balances; public: const QString& getName()const { return name; } QQmlListProperty balances(); QString name; Q_SIGNALS: void nameChanged(); }; struct by_account_name; typedef multi_index_container< Account*, indexed_by< hashed_unique< tag, member >, ordered_unique< tag, member > > > account_multi_index_type; class ChainDataModel : public QObject { Q_OBJECT public: Q_INVOKABLE Account* getAccount(qint64 id); Q_INVOKABLE Account* getAccount(QString name); Q_INVOKABLE Asset* getAsset(qint64 id); Q_INVOKABLE Asset* getAsset(QString symbol); ChainDataModel(){} ChainDataModel( fc::thread& t, QObject* parent = nullptr ); void setDatabaseAPI( fc::api dbapi ){ m_db_api = dbapi; } Q_SIGNALS: void queueExecute( const std::function& ); void exceptionThrown( QString message ); private: fc::thread* m_thread = nullptr; std::string m_api_url; fc::api m_db_api; qint64 m_account_query_num = -1; account_multi_index_type m_accounts; asset_multi_index_type m_assets; }; class GrapheneApplication : public QObject { Q_OBJECT Q_PROPERTY(ChainDataModel* model READ model CONSTANT) Q_PROPERTY(bool isConnected READ isConnected NOTIFY isConnectedChanged) fc::thread m_thread; ChainDataModel* m_model = nullptr; bool m_isConnected = false; std::shared_ptr m_client; fc::future m_done; void setIsConnected( bool v ); Q_SLOT void execute( const std::function& )const; public: GrapheneApplication( QObject* parent = nullptr ); ~GrapheneApplication(); ChainDataModel* model() const { return m_model; } Q_INVOKABLE void start(QString apiUrl, QString user, QString pass ); bool isConnected() const { return m_isConnected; } Q_SIGNALS: void exceptionThrown( QString message ); void loginFailed(); void isConnectedChanged(bool isConnected); void queueExecute( const std::function& ); };