Пример #1
0
Status
loginServerKeyAdd(AuthJson authJson, JsonPtr keyBox, std::string syncKey)
{
    const auto url = ABC_SERVER_ROOT "/v2/login/keys";

    // Repos to create (optional):
    JsonArray newSyncKeys;
    if (syncKey.size())
        ABC_CHECK(newSyncKeys.append(json_string(syncKey.c_str())));

    // Key boxes to upload:
    JsonArray keyBoxes;
    ABC_CHECK(keyBoxes.append(keyBox));

    /// Assemble request:
    JsonObject requestJson;
    ABC_CHECK(requestJson.set("newSyncKeys", newSyncKeys));
    ABC_CHECK(requestJson.set("keyBoxes", keyBoxes));
    ABC_CHECK(authJson.set("data", requestJson));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().request(reply, url, "POST", authJson.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply));

    return Status();
}
Пример #2
0
Status
loginServerUploadLogs(Account *account)
{
    const auto url = ABC_SERVER_ROOT "/v1/account/debug";
    ServerRequestJson json;

    if (account)
    {
        json.setup(account->login); // Failure is fine

        JsonArray jsonArray;
        auto ids = account->wallets.list();
        for (const auto &id: ids)
        {
            std::shared_ptr<Wallet> wallet = cacheWalletSoft(id);
            if (wallet)
            {
                const auto name = wallet->name();
                logInfo("Wallet '" + name + "' " + id);

                const auto addresses = wallet->addresses.list();
                for (const auto &address: addresses)
                    logInfo(address);
            }

            DataChunk watchData;
            if (fileLoad(watchData, WalletPaths(id).cachePath()))
            {
                jsonArray.append(
                    json_string(base64Encode(watchData).c_str()));
            }
        }
        json.set("watchers", jsonArray); // Failure is fine

        AutoFree<tABC_AccountSettings, accountSettingsFree> settings;
        settings.get() = accountSettingsLoad(*account);
        std::string servers(settings->szOverrideBitcoinServerList);
        std::string strOverride = (settings->bOverrideBitcoinServers ? "true" :
                                   "false");

        logInfo("bOverrideBitcoinServers:" + strOverride);
        logInfo("szOverrideBitcoinServerList:" + servers);
    }

    DataChunk logData = debugLogLoad();
    json.set("log", base64Encode(logData)); // Failure is fine

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));

    return Status();
}
Пример #3
0
void
StratumConnection::getAddressHistory(
    const bc::client::obelisk_codec::error_handler &onError,
    const bc::client::obelisk_codec::fetch_history_handler &onReply,
    const bc::payment_address &address, size_t fromHeight)
{
    JsonArray params;
    params.append(json_string(address.encoded().c_str()));

    auto errorShim = [onError](Status status)
    {
        onError(std::make_error_code(std::errc::bad_message));
    };

    auto decoder = [onReply](JsonPtr payload) -> Status
    {
        JsonArray arrayJson(payload);

        bc::client::history_list history;
        size_t size = arrayJson.size();
        history.reserve(size);
        for (size_t i = 0; i < size; i++)
        {
            struct HistoryJson:
                public JsonObject
            {
                ABC_JSON_CONSTRUCTORS(HistoryJson, JsonObject)
                ABC_JSON_STRING(txid, "tx_hash", nullptr)
                ABC_JSON_INTEGER(height, "height", 0)
            };
            HistoryJson json(arrayJson[i]);

            bc::hash_digest hash;
            if (!json.txidOk() || !bc::decode_hash(hash, json.txid()))
                return ABC_ERROR(ABC_CC_Error, "Bad txid");

            bc::client::history_row row;
            row.output.hash = hash;
            row.output_height = json.height();
            row.spend.hash = bc::null_hash;
            history.push_back(row);
        }

        onReply(history);
        return Status();
    };
Пример #4
0
Status
loginServerMessages(JsonPtr &result, const std::list<std::string> &usernames)
{
    const auto url = ABC_SERVER_ROOT "/v2/messages";

    // Compute all userIds:
    JsonArray loginIds;
    std::map<std::string, std::string> loginIdMap;
    for (const auto &username: usernames)
    {
        std::shared_ptr<LoginStore> store;
        ABC_CHECK(LoginStore::create(store, username));
        const auto loginId = base64Encode(store->userId());
        loginIds.append(json_string(loginId.c_str()));
        loginIdMap[loginId] = username;
    }

    JsonObject request;
    ABC_CHECK(request.set("loginIds", loginIds));

    // Make the request:
    HttpReply reply;
    ABC_CHECK(AirbitzRequest().request(reply, url, "POST", request.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply));

    // Insert the original usernames into the results:
    JsonArray arrayJson(replyJson.results());
    size_t size = arrayJson.size();
    for (size_t i = 0; i < size; i++)
    {
        JsonObject objectJson(arrayJson[i]);
        const auto loginId = objectJson.getString("loginId", nullptr);
        if (!loginId) continue;
        const auto username = loginIdMap.find(loginId);
        if (username == loginIdMap.end()) continue;
        ABC_CHECK(objectJson.set("username", username->second));
    }

    result = arrayJson;
    return Status();
}
Пример #5
0
void
StratumConnection::getTx(
    const bc::client::obelisk_codec::error_handler &onError,
    const bc::client::obelisk_codec::fetch_transaction_handler &onReply,
    const bc::hash_digest &txid)
{
    JsonArray params;
    params.append(json_string(bc::encode_hash(txid).c_str()));

    auto errorShim = [onError](Status status)
    {
        onError(std::make_error_code(std::errc::bad_message));
    };

    auto decoder = [onReply](JsonPtr payload) -> Status
    {
        if (!json_is_string(payload.get()))
            return ABC_ERROR(ABC_CC_JSONError, "Bad reply format");

        bc::data_chunk rawTx;
        if (!base16Decode(rawTx, json_string_value(payload.get())))
            return ABC_ERROR(ABC_CC_ParseError, "Bad transaction format");

        // Convert rawTx to bc::transaction_type:
        bc::transaction_type tx;
        try
        {
            auto deserial = bc::make_deserializer(rawTx.begin(), rawTx.end());
            bc::satoshi_load(deserial.iterator(), deserial.end(), tx);
        }
        catch (bc::end_of_stream)
        {
            return ABC_ERROR(ABC_CC_ParseError, "Bad transaction format");
        }

        onReply(tx);
        return Status();
    };

    sendMessage("blockchain.transaction.get", params, errorShim, decoder);
}
Пример #6
0
Status
loginServerUploadLogs(const Account *account)
{
    const auto url = ABC_SERVER_ROOT "/account/debug";
    JsonPtr json;
    HttpReply reply;
    DataChunk logData = debugLogLoad();

    if (account)
    {
        JsonArray jsonArray;
        auto ids = account->wallets.list();
        for (const auto &id: ids)
        {
            std::shared_ptr<Wallet> wallet;
            if (cacheWallet(wallet, nullptr, id.c_str()))
            {
                DataChunk watchData;
                ABC_CHECK(fileLoad(watchData, watcherPath(*wallet)));
                jsonArray.append(
                    json_string(base64Encode(watchData).c_str()));
            }
        }

        json.reset(json_pack("{ss, ss, ss}",
                             ABC_SERVER_JSON_L1_FIELD, base64Encode(account->login.lobby.authId()).c_str(),
                             ABC_SERVER_JSON_LP1_FIELD, base64Encode(account->login.authKey()).c_str(),
                             "log", base64Encode(logData).c_str()));
        if (jsonArray)
            json_object_set(json.get(), "watchers", jsonArray.get());
    }
    else
    {
        json.reset(json_pack("{ss}", "log", base64Encode(logData).c_str()));
    }

    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    return Status();
}