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(); }
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(); };