Added Bitcoin client support.
This commit is contained in:
@@ -16,7 +16,7 @@ set(INSTALL_AS_ROOT ON CACHE BOOL "Install as root")
|
|||||||
set(WITH_POSTGRESQL OFF CACHE BOOL "Build with PostgreSQL")
|
set(WITH_POSTGRESQL OFF CACHE BOOL "Build with PostgreSQL")
|
||||||
set(WITH_SQLITE3 OFF CACHE BOOL "Build with Sqlite3")
|
set(WITH_SQLITE3 OFF CACHE BOOL "Build with Sqlite3")
|
||||||
set(WITH_CURL OFF CACHE BOOL "Build with cURL")
|
set(WITH_CURL OFF CACHE BOOL "Build with cURL")
|
||||||
set(WITH_BITCOIN_CLIENT OFF CACHE BOOL "Build with libbitcoin-client")
|
set(WITH_BITCOIN_CLIENT ON CACHE BOOL "Build with libbitcoin-client")
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
if (INSTALL_AS_ROOT)
|
if (INSTALL_AS_ROOT)
|
||||||
|
|||||||
60
cmake-modules/FindBitcoin-Client.cmake
Normal file
60
cmake-modules/FindBitcoin-Client.cmake
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
###############################################################################
|
||||||
|
# Copyright (c) 2014-2019 libbitcoin-client developers (see COPYING).
|
||||||
|
#
|
||||||
|
# GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
# FindBitcoin-Client
|
||||||
|
#
|
||||||
|
# Use this module by invoking find_package with the form::
|
||||||
|
#
|
||||||
|
# find_package( Bitcoin-Client
|
||||||
|
# [version] # Minimum version
|
||||||
|
# [REQUIRED] # Fail with error if bitcoin-client is not found
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# Defines the following for use:
|
||||||
|
#
|
||||||
|
# bitcoin_client_FOUND - true if headers and requested libraries were found
|
||||||
|
# bitcoin_client_INCLUDE_DIRS - include directories for bitcoin-client libraries
|
||||||
|
# bitcoin_client_LIBRARY_DIRS - link directories for bitcoin-client libraries
|
||||||
|
# bitcoin_client_LIBRARIES - bitcoin-client libraries to be linked
|
||||||
|
# bitcoin_client_PKG - bitcoin-client pkg-config package specification.
|
||||||
|
#
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
if ( Bitcoin-Client_FIND_REQUIRED )
|
||||||
|
set( _bitcoin_client_MSG_STATUS "SEND_ERROR" )
|
||||||
|
else ()
|
||||||
|
set( _bitcoin_client_MSG_STATUS "STATUS" )
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set( bitcoin_client_FOUND false )
|
||||||
|
message( ${_bitcoin_client_MSG_STATUS} "MSVC environment detection for 'bitcoin-client' not currently supported." )
|
||||||
|
else ()
|
||||||
|
# required
|
||||||
|
if ( Bitcoin-Client_FIND_REQUIRED )
|
||||||
|
set( _bitcoin_client_REQUIRED "REQUIRED" )
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# quiet
|
||||||
|
if ( Bitcoin-Client_FIND_QUIETLY )
|
||||||
|
set( _bitcoin_client_QUIET "QUIET" )
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# modulespec
|
||||||
|
if ( Bitcoin-Client_FIND_VERSION_COUNT EQUAL 0 )
|
||||||
|
set( _bitcoin_client_MODULE_SPEC "libbitcoin-client" )
|
||||||
|
else ()
|
||||||
|
if ( Bitcoin-Client_FIND_VERSION_EXACT )
|
||||||
|
set( _bitcoin_client_MODULE_SPEC_OP "=" )
|
||||||
|
else ()
|
||||||
|
set( _bitcoin_client_MODULE_SPEC_OP ">=" )
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set( _bitcoin_client_MODULE_SPEC "libbitcoin-client ${_bitcoin_client_MODULE_SPEC_OP} ${Bitcoin-Client_FIND_VERSION}" )
|
||||||
|
endif()
|
||||||
|
|
||||||
|
pkg_check_modules( bitcoin_client ${_bitcoin_client_REQUIRED} ${_bitcoin_client_QUIET} "${_bitcoin_client_MODULE_SPEC}" )
|
||||||
|
set( bitcoin_client_PKG "${_bitcoin_client_MODULE_SPEC}" )
|
||||||
|
endif()
|
||||||
@@ -1384,6 +1384,57 @@ namespace Apostol {
|
|||||||
|
|
||||||
RouteDeal(AConnection, "GET", sRoute, caAction);
|
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 {
|
} else {
|
||||||
|
|
||||||
AConnection->SendStockReply(CHTTPReply::not_found);
|
AConnection->SendStockReply(CHTTPReply::not_found);
|
||||||
|
|||||||
Reference in New Issue
Block a user