diff --git a/programs/light_client/ClientDataModel.cpp b/programs/light_client/ClientDataModel.cpp index 5664f2f5..3a207de4 100644 --- a/programs/light_client/ClientDataModel.cpp +++ b/programs/light_client/ClientDataModel.cpp @@ -18,7 +18,7 @@ Account* ChainDataModel::getAccount(qint64 id) auto acct = new Account(this); acct->setProperty("id", id); - acct->setProperty("name", "LOADING"); + acct->setProperty("accountName", "LOADING"); auto insert_result = m_accounts.insert( acct ); /** execute in app thread */ @@ -31,7 +31,7 @@ Account* ChainDataModel::getAccount(qint64 id) /** execute in main */ Q_EMIT queueExecute( [=](){ this->m_accounts.modify( insert_result.first, - [=]( Account* a ){ a->setProperty("name", name ); } + [=]( Account* a ){ a->setProperty("accountName", name ); } ); }); } @@ -56,27 +56,51 @@ Account* ChainDataModel::getAccount(qint64 id) Account* ChainDataModel::getAccount(QString name) { - auto itr = m_accounts.get<::by_name>().find(name); - if( itr != m_accounts.get<::by_name>().end() ) + { + auto itr = m_accounts.get().begin(); + while( itr != m_accounts.get().end() ) + { + edump(( (*itr)->getAccountName().toStdString())); + if((*itr)->name() == name.toStdString() ) + wlog( "THEY ARE THE SAME" ); + ++itr; + } + } + auto& by_name_index = m_accounts.get(); + { + for( auto itr = by_name_index.begin(); itr != by_name_index.end(); ++itr ) + wdump(( (*itr)->getAccountName().toStdString())); + } + auto itr = by_name_index.find(name.toStdString()); + idump((itr != by_name_index.end())); + if( itr != by_name_index.end() ) { return *itr; } auto acct = new Account(this); acct->setProperty("id", --m_account_query_num ); - acct->setProperty("name", name); + acct->setProperty("accountName", name); auto insert_result = m_accounts.insert( acct ); + edump( (insert_result.second) ); + edump( (int64_t(*insert_result.first))(int64_t(acct)) ); + auto itr2 = by_name_index.find(name.toStdString()); + assert( itr2 != by_name_index.end() ); /** execute in app thread */ m_thread->async( [=](){ try { + ilog( "look up names.." ); auto result = m_db_api->lookup_account_names( {name.toStdString()} ); + idump((result)); if( result.size() && result.front().valid() ) { /** execute in main */ Q_EMIT queueExecute( [=](){ this->m_accounts.modify( insert_result.first, [=]( Account* a ){ + ilog( "setting id ${i}", ("i",result.front()->id.instance()) ); + idump((int64_t(a))); a->setProperty("id", result.front()->id.instance() ); } ); @@ -87,7 +111,7 @@ Account* ChainDataModel::getAccount(QString name) /** execute in main */ Q_EMIT queueExecute( [=](){ acct->deleteLater(); - m_accounts.erase( insert_result.first ); + this->m_accounts.erase( insert_result.first ); }); } } @@ -98,6 +122,7 @@ Account* ChainDataModel::getAccount(QString name) } }); + idump((int64_t(acct))); return acct; } @@ -142,17 +167,20 @@ void GrapheneApplication::start( QString apiurl, QString user, QString pass ) return; } try { - auto con = m_client.connect( apiurl.toStdString() ); + m_client = std::make_shared(); + ilog( "connecting...${s}", ("s",apiurl.toStdString()) ); + auto con = m_client->connect( apiurl.toStdString() ); auto apic = std::make_shared(*con); auto remote_api = apic->get_remote_api< login_api >(1); auto db_api = apic->get_remote_api< database_api >(0); - if( !remote_api->login( user.toStdString(), pass.toStdString() ) ) { + elog( "login failed" ); Q_EMIT loginFailed(); return; } + ilog( "connecting..." ); queueExecute( [=](){ m_model->setDatabaseAPI( db_api ); }); diff --git a/programs/light_client/ClientDataModel.hpp b/programs/light_client/ClientDataModel.hpp index 9aab8112..9e2550d7 100644 --- a/programs/light_client/ClientDataModel.hpp +++ b/programs/light_client/ClientDataModel.hpp @@ -47,11 +47,11 @@ class Balance : public QObject { class Account : public QObject { Q_OBJECT - Q_PROPERTY(QString name MEMBER name NOTIFY nameChanged) + Q_PROPERTY(QString accountName MEMBER accountName NOTIFY accountNameChanged) Q_PROPERTY(qint64 id MEMBER id NOTIFY idChanged) Q_PROPERTY(QQmlListProperty balances READ balances) - QString name; + QString accountName; qint64 id; QList m_balances; @@ -59,18 +59,19 @@ public: Account(QObject* parent = nullptr) : QObject(parent){} - const QString& getName()const { return name; } + const QString& getAccountName()const { return accountName; } qint64 getId()const { return id; } + std::string name()const { return accountName.toStdString(); } QQmlListProperty balances(); signals: - void nameChanged(); + void accountNameChanged(); void idChanged(); }; struct by_id; -struct by_name; +struct by_account_name; /** * @ingroup object_index */ @@ -78,7 +79,8 @@ typedef multi_index_container< Account*, indexed_by< hashed_unique< tag, const_mem_fun >, - ordered_non_unique< tag, const_mem_fun > + hashed_unique< tag, const_mem_fun > +// ordered_non_unique< tag, const_mem_fun > > > account_multi_index_type; @@ -125,8 +127,8 @@ class GrapheneApplication : public QObject { ChainDataModel* m_model = nullptr; bool m_isConnected = false; - fc::http::websocket_client m_client; - fc::future m_done; + std::shared_ptr m_client; + fc::future m_done; void setIsConnected( bool v ); diff --git a/programs/light_client/qml/main.qml b/programs/light_client/qml/main.qml index f7e4ecef..f8b62067 100644 --- a/programs/light_client/qml/main.qml +++ b/programs/light_client/qml/main.qml @@ -61,16 +61,23 @@ ApplicationWindow { text: "Lookup" onClicked: { var acct = app.model.getAccount(nameField.text) + console.log(JSON.stringify(acct)) // @disable-check M126 if (acct == null) console.log("Got back null account") else if (acct.id >= 0) + { + console.log("ID ALREADY SET" ); console.log(JSON.stringify(acct)) + } else + { console.log("Waiting for result...") acct.idChanged.connect(function(loadedAcct) { + console.log( "ID CHANGED" ); console.log(JSON.stringify(loadedAcct)) }) + } } } }