コード例 #1
0
ファイル: Ledger.cpp プロジェクト: SeijiEmery/hifi
void Ledger::updateLocation(const QString& asset_id, const QString& location, const bool& alsoUpdateSiblings, const bool controlledFailure) {
    auto wallet = DependencyManager::get<Wallet>();
    auto walletScriptingInterface = DependencyManager::get<WalletScriptingInterface>();
    uint walletStatus = walletScriptingInterface->getWalletStatus();

    if (walletStatus != (uint)wallet->WALLET_STATUS_READY) {
        emit walletScriptingInterface->walletNotSetup();
        qDebug(commerce) << "User attempted to update the location of a certificate, but their wallet wasn't ready. Status:" << walletStatus;
    } else {
        QStringList cachedPublicKeys = wallet->listPublicKeys();
        if (!cachedPublicKeys.isEmpty()) {
            QString key = cachedPublicKeys[0];
            QJsonObject transaction;
            transaction["certificate_id"] = asset_id;
            transaction["place_name"] = location;
            if (alsoUpdateSiblings) {
                transaction["also_update_siblings"] = true;
            }
            QJsonDocument transactionDoc{ transaction };
            auto transactionString = transactionDoc.toJson(QJsonDocument::Compact);
            signedSend("transaction", transactionString, key, "location", "updateLocationSuccess", "updateLocationFailure", controlledFailure);
        } else {
            qDebug(commerce) << "User attempted to update the location of a certificate, but cachedPublicKeys was empty!";
        }
    }
}
コード例 #2
0
ファイル: Wallet.cpp プロジェクト: Atlante45/hifi
Wallet::Wallet() {
    auto nodeList = DependencyManager::get<NodeList>();
    auto ledger = DependencyManager::get<Ledger>();
    auto& packetReceiver = nodeList->getPacketReceiver();
    _passphrase = new QString("");

    packetReceiver.registerListener(PacketType::ChallengeOwnership, this, "handleChallengeOwnershipPacket");
    packetReceiver.registerListener(PacketType::ChallengeOwnershipRequest, this, "handleChallengeOwnershipPacket");

    connect(ledger.data(), &Ledger::accountResult, this, [](QJsonObject result) {
        auto wallet = DependencyManager::get<Wallet>();
        auto walletScriptingInterface = DependencyManager::get<WalletScriptingInterface>();
        uint status;
        QString keyStatus = result.contains("data") ? result["data"].toObject()["keyStatus"].toString() : "";

        if (wallet->getKeyFilePath().isEmpty() || !wallet->getSecurityImage()) {
            if (keyStatus == "preexisting") {
                status = (uint) WalletStatus::WALLET_STATUS_PREEXISTING;
            } else {
                status = (uint) WalletStatus::WALLET_STATUS_NOT_SET_UP;
            }
        } else if (!wallet->walletIsAuthenticatedWithPassphrase()) {
            status = (uint) WalletStatus::WALLET_STATUS_NOT_AUTHENTICATED;
        } else if (keyStatus == "conflicting") {
            status = (uint) WalletStatus::WALLET_STATUS_CONFLICTING;
        } else {
            status = (uint) WalletStatus::WALLET_STATUS_READY;
        }
        walletScriptingInterface->setWalletStatus(status);
    });

    connect(ledger.data(), &Ledger::accountResult, this, &Wallet::sendChallengeOwnershipResponses);

    auto accountManager = DependencyManager::get<AccountManager>();
    connect(accountManager.data(), &AccountManager::usernameChanged, this, [&]() {
        getWalletStatus();
        clear();
    });
}
コード例 #3
0
ファイル: Wallet.cpp プロジェクト: howard-stearns/hifi
Wallet::Wallet() {
    auto nodeList = DependencyManager::get<NodeList>();
    auto ledger = DependencyManager::get<Ledger>();
    auto& packetReceiver = nodeList->getPacketReceiver();

    packetReceiver.registerListener(PacketType::ChallengeOwnership, this, "handleChallengeOwnershipPacket");
    packetReceiver.registerListener(PacketType::ChallengeOwnershipRequest, this, "handleChallengeOwnershipPacket");

    connect(ledger.data(), &Ledger::accountResult, this, [&]() {
        auto wallet = DependencyManager::get<Wallet>();
        auto walletScriptingInterface = DependencyManager::get<WalletScriptingInterface>();
        uint status;

        if (wallet->getKeyFilePath() == "" || !wallet->getSecurityImage()) {
            status = (uint)WalletStatus::WALLET_STATUS_NOT_SET_UP;
        } else if (!wallet->walletIsAuthenticatedWithPassphrase()) {
            status = (uint)WalletStatus::WALLET_STATUS_NOT_AUTHENTICATED;
        } else {
            status = (uint)WalletStatus::WALLET_STATUS_READY;
        }

        walletScriptingInterface->setWalletStatus(status);
    });

    auto accountManager = DependencyManager::get<AccountManager>();
    connect(accountManager.data(), &AccountManager::usernameChanged, this, [&]() {
        getWalletStatus();
        _publicKeys.clear();

        if (_securityImage) {
            delete _securityImage;
        }
        _securityImage = nullptr;

        // tell the provider we got nothing
        updateImageProvider();
        _passphrase->clear();
    });
}
コード例 #4
0
ファイル: QmlCommerce.cpp プロジェクト: howard-stearns/hifi
void QmlCommerce::getWalletStatus() {
    auto wallet = DependencyManager::get<Wallet>();
    wallet->getWalletStatus();
}