From 972c9a640796d6a8c55ddea8be82368be772a6ce Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Fri, 24 Jul 2015 13:57:47 -0400 Subject: [PATCH] [GUI] Remove broken toQstring function --- programs/light_client/Account.hpp | 12 +++---- programs/light_client/ChainDataModel.cpp | 2 +- programs/light_client/GrapheneObject.hpp | 2 -- programs/light_client/Wallet.cpp | 41 ++++++++++++------------ programs/light_client/Wallet.hpp | 15 ++++----- 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/programs/light_client/Account.hpp b/programs/light_client/Account.hpp index f816d6d2..6f190f21 100644 --- a/programs/light_client/Account.hpp +++ b/programs/light_client/Account.hpp @@ -27,19 +27,19 @@ class Account : public GrapheneObject { public: Account(ObjectId id = -1, QString name = QString(), QObject* parent = nullptr) - : GrapheneObject(id, parent) + : GrapheneObject(id, parent) { m_account.name = name.toStdString(); } - void setAccountObject( const account_object& obj ) + void setAccountObject(const account_object& obj) { auto old_name = m_account.name; m_account = obj; - if( old_name != m_account.name ) + if (old_name != m_account.name) Q_EMIT nameChanged(); } - QString name()const { return toQString(m_account.name); } + QString name()const { return QString::fromStdString(m_account.name); } QQmlListProperty balances(); void setBalances(QList balances) { @@ -52,11 +52,11 @@ public: void update(const account_balance_object& balance); - /** + /** * Anything greater than 1.0 means full authority. * Anything between (0 and 1.0) means partial authority * 0 means no authority. - * + * * @return the percent of direct control the wallet has over the account. */ Q_INVOKABLE double getOwnerControl( Wallet* w )const; diff --git a/programs/light_client/ChainDataModel.cpp b/programs/light_client/ChainDataModel.cpp index 9f8c9ebe..159ef616 100644 --- a/programs/light_client/ChainDataModel.cpp +++ b/programs/light_client/ChainDataModel.cpp @@ -195,7 +195,7 @@ void ChainDataModel::getAccountImpl(QString accountIdentifier, Account* const * } else { m_accounts.modify(itr, [this,&accountPackage](Account* a){ a->setProperty("id", ObjectId(accountPackage->account.id.instance())); - a->setAccountObject( accountPackage->account ); + a->setAccountObject(accountPackage->account); // Set balances QList balances; diff --git a/programs/light_client/GrapheneObject.hpp b/programs/light_client/GrapheneObject.hpp index a14c89fd..0c53c562 100644 --- a/programs/light_client/GrapheneObject.hpp +++ b/programs/light_client/GrapheneObject.hpp @@ -5,8 +5,6 @@ #include -QString toQString( const std::string& s ); - using ObjectId = qint64; Q_DECLARE_METATYPE(ObjectId) diff --git a/programs/light_client/Wallet.cpp b/programs/light_client/Wallet.cpp index 42ed3bb7..dd62ca8d 100644 --- a/programs/light_client/Wallet.cpp +++ b/programs/light_client/Wallet.cpp @@ -3,10 +3,9 @@ #include #include -QString toQString( const std::string& s ) { QString result; result.fromStdString( s ); return result; } -QString toQString( public_key_type k ) { return toQString( fc::variant(k).as_string() ); } +QString toQString(public_key_type k) { return QString::fromStdString(fc::variant(k).as_string()); } -Wallet::Wallet( QObject* parent ) +Wallet::Wallet(QObject* parent) :QObject(parent) { } @@ -16,10 +15,10 @@ Wallet::~Wallet() close(); } -bool Wallet::open( QString file_path ) +bool Wallet::open(QString file_path) { - fc::path p( file_path.toStdString() ); - if( !fc::exists( p ) ) + fc::path p(file_path.toStdString()); + if( !fc::exists(p) ) { ilog( "Unable to open wallet file '${f}', it does not exist", ("f",p) ); return false; @@ -30,7 +29,7 @@ bool Wallet::open( QString file_path ) for( const auto& key : _data.encrypted_private_keys ) { if( key.second.label != string() ) - _label_to_key[toQString(key.second.label)] = toQString( key.first ); + _label_to_key[QString::fromStdString(key.second.label)] = toQString(key.first); if( key.second.encrypted_private_key.size() ) _available_private_keys.insert( key.first ); } @@ -194,7 +193,7 @@ bool Wallet::hasPrivateKey( QString pubkey, bool include_with_brain_key ) auto itr = _data.encrypted_private_keys.find(pub); if( itr == _data.encrypted_private_keys.end() ) return false; - if( itr->second.encrypted_private_key.size() ) + if( itr->second.encrypted_private_key.size() ) return true; if( include_with_brain_key && itr->second.brain_sequence >= 0 ) { @@ -217,7 +216,7 @@ QString Wallet::getPrivateKey( QString pubkey ) if( itr->second.encrypted_private_key.size() == 0 ) return QString(); auto plain = fc::aes_decrypt( _decrypted_master_key, itr->second.encrypted_private_key ); - return toQString( fc::raw::unpack(plain) ); + return QString::fromStdString( fc::raw::unpack(plain) ); } QString Wallet::getPublicKey( QString wif_private_key )const @@ -227,7 +226,7 @@ QString Wallet::getPublicKey( QString wif_private_key )const auto pub = public_key_type(priv->get_public_key()); - return toQString( fc::variant( pub ).as_string() ); + return QString::fromStdString( fc::variant( pub ).as_string() ); } QString Wallet::getActivePrivateKey( QString owner_pub_key, uint32_t seq ) @@ -251,7 +250,7 @@ QString Wallet::getActivePrivateKey( QString owner_pub_key, uint32_t seq ) _data.encrypted_private_keys[active_pub_key].brain_sequence = seq; _available_private_keys.insert( active_pub_key ); - return toQString(wif); + return QString::fromStdString(wif); } QString Wallet::getOwnerPrivateKey( uint32_t seq ) @@ -273,7 +272,7 @@ QString Wallet::getOwnerPrivateKey( uint32_t seq ) _data.encrypted_private_keys[owner_pub_key].brain_sequence = seq; _available_private_keys.insert( owner_pub_key ); - return toQString( wif ); + return QString::fromStdString( wif ); } QString Wallet::getActivePublicKey( QString active_pub, uint32_t seq ) @@ -294,11 +293,11 @@ QString Wallet::getKeyLabel( QString pubkey ) auto itr = _data.encrypted_private_keys.find( key ); if( itr == _data.encrypted_private_keys.end() ) return QString(); - return toQString( itr->second.label ); + return QString::fromStdString( itr->second.label ); } /** * The same label may not be assigned to more than one key, this method will - * fail if a key with the same label already exists. + * fail if a key with the same label already exists. * * @return true if the label was set */ @@ -310,7 +309,7 @@ bool Wallet::setKeyLabel( QString pubkey, QString label ) auto old_label = _data.encrypted_private_keys[pub].label; _data.encrypted_private_keys[pub].label = string(); if( old_label.size() ) - _label_to_key.erase( toQString( old_label ) ); + _label_to_key.erase( QString::fromStdString( old_label ) ); return true; } @@ -336,7 +335,7 @@ QList > Wallet::getAllPublicKeys( bool only_if_private )c for( const auto& item : _data.encrypted_private_keys ) { if( only_if_private && !item.second.encrypted_private_key.size() ) continue; - result.push_back( qMakePair( toQString( item.first ), toQString( item.second.label ) ) ); + result.push_back( qMakePair( toQString( item.first ), QString::fromStdString( item.second.label ) ) ); } return result; @@ -359,9 +358,9 @@ bool Wallet::importPublicKey( QString pubkey, QString label ) return setKeyLabel( pubkey, label ); } -/** +/** * @param wifkey a private key in (WIF) Wallet Import Format - * @pre !isLocked() + * @pre !isLocked() **/ bool Wallet::importPrivateKey( QString wifkey, QString label ) { @@ -390,14 +389,14 @@ bool Wallet::removePublicKey( QString pubkey ) auto itr = _data.encrypted_private_keys.find(pub); if( itr != _data.encrypted_private_keys.end() ) { - _label_to_key.erase( toQString(itr->second.label) ); + _label_to_key.erase( QString::fromStdString(itr->second.label) ); _data.encrypted_private_keys.erase(itr); return true; } return false; } -/** removes only the private key, keeping the public key and label +/** removes only the private key, keeping the public key and label * * @pre isOpen() && !isLocked() **/ @@ -416,7 +415,7 @@ bool Wallet::removePrivateKey( QString pubkey ) /** * @pre !isLocked() */ -vector Wallet::signDigest( const digest_type& d, +vector Wallet::signDigest( const digest_type& d, const set& keys )const { vector result; diff --git a/programs/light_client/Wallet.hpp b/programs/light_client/Wallet.hpp index 3e00b007..9a0f60a5 100644 --- a/programs/light_client/Wallet.hpp +++ b/programs/light_client/Wallet.hpp @@ -16,7 +16,6 @@ using graphene::chain::digest_type; using graphene::chain::signature_type; using fc::optional; -QString toQString( const std::string& s ); QString toQString( public_key_type k ); struct key_data @@ -38,12 +37,12 @@ struct wallet_file map encrypted_private_keys; }; -FC_REFLECT( wallet_file, +FC_REFLECT( wallet_file, (encrypted_brain_key) (brain_key_digest) (encrypted_master_key) (master_key_digest) - (encrypted_private_keys) + (encrypted_private_keys) ); @@ -86,7 +85,7 @@ class Wallet : public QObject /** * @pre !isLocked(); * @post save() - * @return WIF private key + * @return WIF private key */ Q_INVOKABLE QString getActivePrivateKey( QString owner_public_key, uint32_t sequence ); Q_INVOKABLE QString getActivePublicKey( QString owner_public_key, uint32_t sequence ); @@ -95,7 +94,7 @@ class Wallet : public QObject * @pre !isLocked(); * @pre hasBrainKey(); * @post save() - * @return WIF private key + * @return WIF private key */ Q_INVOKABLE QString getOwnerPrivateKey( uint32_t sequence ); Q_INVOKABLE QString getOwnerPublicKey( uint32_t sequence ); @@ -110,9 +109,9 @@ class Wallet : public QObject /** imports a public key and assigns it a label */ Q_INVOKABLE bool importPublicKey( QString pubkey, QString label = QString() ); - /** + /** * @param wifkey a private key in (WIF) Wallet Import Format - * @pre !isLocked() + * @pre !isLocked() **/ Q_INVOKABLE bool importPrivateKey( QString wifkey, QString label = QString() ); @@ -131,7 +130,7 @@ class Wallet : public QObject /** * @pre !isLocked() */ - vector signDigest( const digest_type& d, + vector signDigest( const digest_type& d, const set& keys )const; const flat_set& getAvailablePrivateKeys()const;