Skip to content

Commit 0ce322a

Browse files
authored
Merge pull request #879 from evoskuil/master
Refactor html/explore protocols.
2 parents a9bcf46 + c17d87d commit 0ce322a

File tree

10 files changed

+270
-259
lines changed

10 files changed

+270
-259
lines changed

console/embedded/explore_css.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121
namespace libbitcoin {
2222
namespace server {
2323

24-
DEFINE_EMBEDDED_PAGE(explore_pages, char, css, "")
24+
// Simple test css for embedded page, links in font.
25+
DEFINE_EMBEDDED_PAGE(explore_pages, char, css,
26+
R"(@font-face
27+
{
28+
font-family: 'Boston';
29+
src: url('boston.woff2');
30+
})")
2531

2632
} // namespace server
2733
} // namespace libbitcoin

console/embedded/explore_ecma.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
namespace libbitcoin {
2222
namespace server {
2323

24-
DEFINE_EMBEDDED_PAGE(explore_pages, char, ecma, "")
24+
// Simple test ecma script for embedded page.
25+
DEFINE_EMBEDDED_PAGE(explore_pages, char, ecma,
26+
R"(document.addEventListener('DOMContentLoaded', function()
27+
{
28+
console.log('pong');
29+
});)")
2530

2631
} // namespace server
2732
} // namespace libbitcoin

console/embedded/explore_font.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@
2121
namespace libbitcoin {
2222
namespace server {
2323

24-
DEFINE_EMBEDDED_PAGE(explore_pages, char, font, "")
24+
DEFINE_EMBEDDED_PAGE(explore_pages, uint8_t, font,
25+
{
26+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
27+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
28+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
34+
})
2535

2636
} // namespace server
2737
} // namespace libbitcoin

console/embedded/explore_html.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,22 @@
2121
namespace libbitcoin {
2222
namespace server {
2323

24-
// Empty page disabled embedded size.
25-
DEFINE_EMBEDDED_PAGE(explore_pages, char, html, "")
24+
// Simple test html for embedded page, links in css and page icon.
25+
DEFINE_EMBEDDED_PAGE(explore_pages, char, html,
26+
R"(<html>
27+
<head>
28+
<title>Libbitcoin Block Explorer</title>
29+
<meta charset="utf-8">
30+
<meta name="description" content="libbitcoin block explorer site">
31+
<link rel="stylesheet" href="style.css"/>
32+
<link rel="icon" href="icon.png" type="image/png"/>
33+
<link rel="preload" href="boston.woff2" type="font/woff2" as="font">
34+
<script src="script.js" defer></script>
35+
</head>
36+
<body>
37+
<p>Hello world!</p>
38+
</body>
39+
</html>)")
2640

2741
} // namespace server
2842
} // namespace libbitcoin

console/embedded/explore_icon.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@
2121
namespace libbitcoin {
2222
namespace server {
2323

24-
DEFINE_EMBEDDED_PAGE(explore_pages, char, icon, "")
24+
DEFINE_EMBEDDED_PAGE(explore_pages, uint8_t, icon,
25+
{
26+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
27+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
28+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
34+
})
2535

2636
} // namespace server
2737
} // namespace libbitcoin

console/main.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@ int bc::system::main(int argc, char* argv[])
8686
std::ios_base::sync_with_stdio(false);
8787
set_utf8_stdio();
8888

89-
// HACK: web_server used for both!
9089
const server::web_pages web_server{};
9190
const server::explore_pages block_explorer{};
92-
parser metadata(chain::selection::mainnet, web_server, web_server);
91+
parser metadata(chain::selection::mainnet, block_explorer, web_server);
9392

9493
const auto& args = const_cast<const char**>(argv);
9594

@@ -100,11 +99,11 @@ int bc::system::main(int argc, char* argv[])
10099
symbols_path = metadata.configured.log.symbols;
101100
#endif
102101

103-
// requires _WIN32_WINNT set to 0x0602 (defaults 0x0602 in vc++ 2022).
104-
#if defined(HAVE_MSC) && defined(MEMORY_PRIORITY_INFORMATION)
102+
// Requires _WIN32_WINNT set to 0x0602 (defaults 0x0602 in vc++ 2022).
103+
#if defined(HAVE_MSC) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
105104

106-
// Set low memory priority on the current process.
107-
const MEMORY_PRIORITY_INFORMATION priority{ MEMORY_PRIORITY_LOW };
105+
// Set low memory priority on the current process (testing).
106+
MEMORY_PRIORITY_INFORMATION priority{ MEMORY_PRIORITY_LOW };
108107
SetProcessInformation(
109108
GetCurrentProcess(),
110109
ProcessMemoryPriority,

include/bitcoin/node/protocols/protocol_explore.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class BCN_API protocol_explore
5151
/// Receivers.
5252
void handle_receive_get(const code& ec,
5353
const network::http::method::get& request) NOEXCEPT override;
54+
55+
/// Dispatch.
56+
virtual bool dispatch_object(
57+
const network::http::request& request) NOEXCEPT;
5458
};
5559

5660
} // namespace node

include/bitcoin/node/protocols/protocol_html.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class BCN_API protocol_html
5151
void handle_receive_get(const code& ec,
5252
const network::http::method::get& request) NOEXCEPT override;
5353

54+
/// Dispatch.
55+
virtual bool dispatch_embedded(
56+
const network::http::request& request) NOEXCEPT;
57+
5458
/// Senders.
5559
virtual void send_json(const network::http::request& request,
5660
boost::json::value&& model, size_t size_hint) NOEXCEPT;
@@ -67,6 +71,8 @@ class BCN_API protocol_html
6771
/// Utilities.
6872
bool is_allowed_origin(const network::http::fields& fields,
6973
size_t version) const NOEXCEPT;
74+
std::filesystem::path to_path(
75+
const std::string& target = "/") const NOEXCEPT;
7076
std::filesystem::path to_local_path(
7177
const std::string& target = "/") const NOEXCEPT;
7278

0 commit comments

Comments
 (0)