Added Bitcoin client support.

This commit is contained in:
Преподобный Ален
2022-04-25 13:42:44 +03:00
parent b56d859792
commit a41422528f
3 changed files with 112 additions and 1 deletions

View File

@@ -1384,6 +1384,57 @@ namespace Apostol {
RouteDeal(AConnection, "GET", sRoute, caAction);
} else if (caCommand == "bc" && caAction == "history") {
const auto& caAccount = pRequest->Params["account"];
if (caAccount.IsEmpty()) {
AConnection->SendStockReply(CHTTPReply::bad_request);
return;
}
try {
const wallet::payment_address address(std::string(caAccount.c_str()));
CJSON history;
fetch_history(address, history);
pReply->Content = history.ToString();
} catch (Delphi::Exception::Exception &E) {
ExceptionToJson(CHTTPReply::bad_request, E, pReply->Content);
Log()->Error(APP_LOG_EMERG, 0, E.what());
}
AConnection->SendReply(CHTTPReply::ok, nullptr, true);
} else if (caCommand == "bc" && caAction == "header") {
const auto& LHeight = pRequest->Params["height"];
const auto& LHash = pRequest->Params["hash"];
if (LHeight.IsEmpty() && LHash.IsEmpty()) {
AConnection->SendStockReply(CHTTPReply::bad_request);
return;
}
try {
CJSON header;
if (!LHash.IsEmpty()) {
fetch_header(hash256(std::string(LHash.c_str())), header);
} else {
uint32_t height = StrToInt(LHeight.c_str());
fetch_header(height, header);
}
pReply->Content = header.ToString();
} catch (Delphi::Exception::Exception &E) {
ExceptionToJson(CHTTPReply::bad_request, E, pReply->Content);
Log()->Error(APP_LOG_EMERG, 0, E.what());
}
AConnection->SendReply(CHTTPReply::ok, nullptr, true);
} else {
AConnection->SendStockReply(CHTTPReply::not_found);