|
|
|
@ -157,25 +157,111 @@ post_get_address_info_handler( const shared_ptr< Session > session )
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct handel_
|
|
|
|
|
{
|
|
|
|
|
using fetch_func = function< void ( const shared_ptr< Session >, const Bytes& ) >;
|
|
|
|
|
|
|
|
|
|
fetch_func request_callback;
|
|
|
|
|
|
|
|
|
|
handel_(const fetch_func& callback):
|
|
|
|
|
request_callback {callback}
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void operator()(const shared_ptr< Session > session)
|
|
|
|
|
{
|
|
|
|
|
const auto request = session->get_request( );
|
|
|
|
|
|
|
|
|
|
size_t content_length = request->get_header( "Content-Length", 0);
|
|
|
|
|
|
|
|
|
|
cout << "post_get_address_info_handler" << endl;
|
|
|
|
|
|
|
|
|
|
session->fetch(content_length, this->request_callback);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
shared_ptr<Resource>
|
|
|
|
|
make_resource(const string& path, const handel_& handler)
|
|
|
|
|
{
|
|
|
|
|
shared_ptr<Resource> resource_ptr = make_shared<Resource>();
|
|
|
|
|
|
|
|
|
|
resource_ptr->set_path(path);
|
|
|
|
|
resource_ptr->set_method_handler( "OPTIONS", generic_options_handler);
|
|
|
|
|
resource_ptr->set_method_handler( "POST", handler );
|
|
|
|
|
|
|
|
|
|
return resource_ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
auto resource_login = make_shared< Resource >( );
|
|
|
|
|
resource_login->set_path( "/login" );
|
|
|
|
|
resource_login->set_method_handler( "POST", post_login_handler );
|
|
|
|
|
resource_login->set_method_handler( "OPTIONS", generic_options_handler);
|
|
|
|
|
auto request_login = [](const shared_ptr< Session > session, const Bytes & body)
|
|
|
|
|
{
|
|
|
|
|
string _body(reinterpret_cast<const char *>(body.data()), body.size());
|
|
|
|
|
|
|
|
|
|
auto get_address_txs = make_shared< Resource >( );
|
|
|
|
|
get_address_txs->set_path( "/get_address_txs" );
|
|
|
|
|
get_address_txs->set_method_handler( "POST", post_get_address_txs_handler );
|
|
|
|
|
get_address_txs->set_method_handler( "OPTIONS", generic_options_handler);
|
|
|
|
|
cout << _body << endl;
|
|
|
|
|
|
|
|
|
|
json j_response {{"new_address", true}};
|
|
|
|
|
|
|
|
|
|
string response_body = j_response.dump();
|
|
|
|
|
|
|
|
|
|
auto response_headers = make_headers({{ "Content-Length", to_string(response_body.size())}});
|
|
|
|
|
|
|
|
|
|
session->close( OK, response_body, response_headers);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto request_get_address_txs = [](const shared_ptr< Session > session, const Bytes & body)
|
|
|
|
|
{
|
|
|
|
|
string _body(reinterpret_cast<const char *>(body.data()), body.size());
|
|
|
|
|
|
|
|
|
|
cout << _body << endl;
|
|
|
|
|
|
|
|
|
|
json j_response {
|
|
|
|
|
{ "total_received", "0"},
|
|
|
|
|
{ "scanned_height", 2012455},
|
|
|
|
|
{ "scanned_block_height", 1195848},
|
|
|
|
|
{ "start_height", 2012455},
|
|
|
|
|
{ "transaction_height", 2012455},
|
|
|
|
|
{ "blockchain_height", 1195848}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
string response_body = j_response.dump();
|
|
|
|
|
|
|
|
|
|
auto response_headers = make_headers({{ "Content-Length", to_string(response_body.size())}});
|
|
|
|
|
|
|
|
|
|
session->close( OK, response_body, response_headers);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto request_get_address_info = [](const shared_ptr< Session > session, const Bytes & body)
|
|
|
|
|
{
|
|
|
|
|
string _body(reinterpret_cast<const char *>(body.data()), body.size());
|
|
|
|
|
|
|
|
|
|
cout << _body << endl;
|
|
|
|
|
|
|
|
|
|
json j_response {
|
|
|
|
|
{"locked_funds", "0"},
|
|
|
|
|
{"total_received", "0"},
|
|
|
|
|
{"total_sent", "0"},
|
|
|
|
|
{"scanned_height", 2012470},
|
|
|
|
|
{"scanned_block_height", 1195850},
|
|
|
|
|
{"start_height", 2012470},
|
|
|
|
|
{"transaction_height", 2012470},
|
|
|
|
|
{"blockchain_height", 1195850},
|
|
|
|
|
{"spent_outputs", nullptr}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
string response_body = j_response.dump();
|
|
|
|
|
|
|
|
|
|
auto response_headers = make_headers({{ "Content-Length", to_string(response_body.size())}});
|
|
|
|
|
|
|
|
|
|
session->close( OK, response_body, response_headers);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto get_address_info = make_shared< Resource >( );
|
|
|
|
|
get_address_info->set_path( "/get_address_info" );
|
|
|
|
|
get_address_info->set_method_handler( "POST", post_get_address_info_handler );
|
|
|
|
|
get_address_info->set_method_handler( "OPTIONS", generic_options_handler);
|
|
|
|
|
|
|
|
|
|
auto login = make_resource("/login" , handel_(request_login));
|
|
|
|
|
auto get_address_txs = make_resource("/get_address_txs" , handel_(request_get_address_txs));
|
|
|
|
|
auto get_address_info = make_resource("/get_address_info", handel_(request_get_address_txs));;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// auto ssl_settings = make_shared< SSLSettings >( );
|
|
|
|
@ -197,7 +283,7 @@ main()
|
|
|
|
|
cout << "Start the service at https://127.0.0.1:1984" << endl;
|
|
|
|
|
|
|
|
|
|
Service service;
|
|
|
|
|
service.publish(resource_login);
|
|
|
|
|
service.publish(login);
|
|
|
|
|
service.publish(get_address_txs);
|
|
|
|
|
service.publish(get_address_info);
|
|
|
|
|
service.start( settings );
|
|
|
|
|