Esempio n. 1
0
Status
loginServerOtpStatus(const Login &login, bool &on, long &timeout)
{
    const auto url = ABC_SERVER_ROOT "/v1/otp/status";
    ServerRequestJson json;
    ABC_CHECK(json.setup(login));

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

    struct ResultJson:
        public JsonObject
    {
        ABC_JSON_CONSTRUCTORS(ResultJson, JsonObject)
        ABC_JSON_BOOLEAN(on, "on", false)
        ABC_JSON_INTEGER(timeout, "otp_timeout", 0)
    } resultJson(replyJson.results());

    on = resultJson.on();
    if (on)
    {
        ABC_CHECK(resultJson.timeoutOk());
        timeout = resultJson.timeout();
    }
    return Status();
}
Esempio n. 2
0
Status
loginServerGetPinPackage(DataSlice DID, DataSlice LPIN1, std::string &result,
                         AuthError &authError)
{
    const auto url = ABC_SERVER_ROOT "/v1/account/pinpackage/get";
    ServerRequestJson json;
    ABC_CHECK(json.set(ABC_SERVER_JSON_DID_FIELD, base64Encode(DID)));
    ABC_CHECK(json.set(ABC_SERVER_JSON_LPIN1_FIELD, base64Encode(LPIN1)));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply, &authError));

    struct ResultJson:
        public JsonObject
    {
        ABC_JSON_CONSTRUCTORS(ResultJson, JsonObject)
        ABC_JSON_STRING(package, "pin_package", nullptr)
    } resultJson(replyJson.results());

    ABC_CHECK(resultJson.packageOk());
    result = resultJson.package();
    return Status();
}
Esempio n. 3
0
Status
loginServerGetLoginPackage(const Lobby &lobby,
                           DataSlice LP1, DataSlice LRA1, LoginPackage &result, JsonPtr &rootKeyBox)
{
    const auto url = ABC_SERVER_ROOT "/account/loginpackage/get";
    ServerRequestJson json;
    ABC_CHECK(json.setup(lobby));
    if (LP1.size())
        ABC_CHECK(json.authKeySet(base64Encode(LP1)));
    if (LRA1.size())
        ABC_CHECK(json.recoveryAuthKeySet(base64Encode(LRA1)));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply.body));
    ABC_CHECK(replyJson.ok());

    struct ResultJson:
        public JsonObject
    {
        ABC_JSON_CONSTRUCTORS(ResultJson, JsonObject)
        ABC_JSON_STRING(package, "login_package", nullptr)
        ABC_JSON_VALUE(rootKeyBox, "rootKeyBox", JsonPtr)
    } resultJson(replyJson.results());

    ABC_CHECK(resultJson.packageOk());
    ABC_CHECK(result.decode(resultJson.package()));
    if (json_is_object(resultJson.rootKeyBox().get()))
        rootKeyBox = resultJson.rootKeyBox();
    return Status();
}
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();
    };
Esempio n. 5
0
Status
loginServerGetCarePackage(const Lobby &lobby, CarePackage &result)
{
    const auto url = ABC_SERVER_ROOT "/account/carepackage/get";
    ServerRequestJson json;
    ABC_CHECK(json.setup(lobby));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply.body));
    ABC_CHECK(replyJson.ok());

    struct ResultJson:
        public JsonObject
    {
        ABC_JSON_CONSTRUCTORS(ResultJson, JsonObject)
        ABC_JSON_STRING(package, "care_package", nullptr)
    } resultJson(replyJson.results());

    ABC_CHECK(resultJson.packageOk());
    ABC_CHECK(result.decode(resultJson.package()));
    return Status();
}