Added Bitcoin client support.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user