2020-09-18 11:29:06 +08:00
|
|
|
#include"Boltz/Connection.hpp"
|
|
|
|
|
#include"Ev/Io.hpp"
|
|
|
|
|
#include"Ev/start.hpp"
|
|
|
|
|
#include"Ev/ThreadPool.hpp"
|
|
|
|
|
#include"Jsmn/Object.hpp"
|
|
|
|
|
#include"Json/Out.hpp"
|
|
|
|
|
#include"Util/make_unique.hpp"
|
2026-05-14 12:06:46 -07:00
|
|
|
#include<cstdlib>
|
2020-09-18 11:29:06 +08:00
|
|
|
#include<iostream>
|
|
|
|
|
#include<sstream>
|
|
|
|
|
#include<string>
|
|
|
|
|
|
|
|
|
|
/* argv[1] == /api
|
|
|
|
|
* argv[2] == JSON
|
2026-05-14 12:06:46 -07:00
|
|
|
*
|
|
|
|
|
* Environment overrides:
|
|
|
|
|
* BOLTZ_API_BASE URL prefix (default: https://boltz.exchange/api)
|
|
|
|
|
* BOLTZ_PROXY libcurl proxy (e.g. socks5h://127.0.0.1:9050)
|
2020-09-18 11:29:06 +08:00
|
|
|
*/
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
|
if (argc < 2 || argc > 3) {
|
|
|
|
|
std::cerr << "Usage: dev-boltz-api /url json" << std::endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
auto api = std::string(argv[1]);
|
|
|
|
|
auto json = std::unique_ptr<Json::Out>(nullptr);
|
|
|
|
|
if (argc == 3) {
|
|
|
|
|
auto json_arg = ([argv]() {
|
|
|
|
|
auto is = std::istringstream(std::string(argv[2]));
|
|
|
|
|
auto rv = Jsmn::Object();
|
|
|
|
|
is >> rv;
|
|
|
|
|
return rv;
|
|
|
|
|
})();
|
|
|
|
|
json = Util::make_unique<Json::Out>(
|
|
|
|
|
Json::Out(json_arg)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-14 12:06:46 -07:00
|
|
|
auto base = std::string("https://boltz.exchange/api");
|
|
|
|
|
if (auto e = std::getenv("BOLTZ_API_BASE")) base = e;
|
|
|
|
|
auto proxy = std::string("");
|
|
|
|
|
if (auto e = std::getenv("BOLTZ_PROXY")) proxy = e;
|
|
|
|
|
|
2020-09-18 11:29:06 +08:00
|
|
|
Ev::ThreadPool tp;
|
2026-05-14 12:06:46 -07:00
|
|
|
auto cc = Boltz::Connection(tp, base, proxy);
|
2020-09-18 11:29:06 +08:00
|
|
|
|
|
|
|
|
auto code = Ev::lift().then([&]() {
|
|
|
|
|
return cc.api(api, std::move(json));
|
|
|
|
|
}).then([](Jsmn::Object result) {
|
|
|
|
|
std::cout << result << std::endl;
|
|
|
|
|
return Ev::lift(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return Ev::start(code);
|
|
|
|
|
}
|