Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ src_libbitcoin_node_la_SOURCES = \
src/chasers/chaser_template.cpp \
src/chasers/chaser_transaction.cpp \
src/chasers/chaser_validate.cpp \
src/messages/block.cpp \
src/messages/transaction.cpp \
src/protocols/protocol.cpp \
src/protocols/protocol_block_in_106.cpp \
src/protocols/protocol_block_in_31800.cpp \
Expand Down Expand Up @@ -149,6 +151,12 @@ include_bitcoin_node_impl_chasersdir = ${includedir}/bitcoin/node/impl/chasers
include_bitcoin_node_impl_chasers_HEADERS = \
include/bitcoin/node/impl/chasers/chaser_organize.ipp

include_bitcoin_node_messagesdir = ${includedir}/bitcoin/node/messages
include_bitcoin_node_messages_HEADERS = \
include/bitcoin/node/messages/block.hpp \
include/bitcoin/node/messages/messages.hpp \
include/bitcoin/node/messages/transaction.hpp

include_bitcoin_node_protocolsdir = ${includedir}/bitcoin/node/protocols
include_bitcoin_node_protocols_HEADERS = \
include/bitcoin/node/protocols/protocol.hpp \
Expand Down
5 changes: 5 additions & 0 deletions builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
<ClCompile Include="..\..\..\..\src\configuration.cpp" />
<ClCompile Include="..\..\..\..\src\error.cpp" />
<ClCompile Include="..\..\..\..\src\full_node.cpp" />
<ClCompile Include="..\..\..\..\src\messages\block.cpp" />
<ClCompile Include="..\..\..\..\src\messages\transaction.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol_block_in_106.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol_block_in_31800.cpp" />
Expand Down Expand Up @@ -183,6 +185,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\error.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\events.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\full_node.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\messages\block.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\messages\messages.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\messages\transaction.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_block_in_106.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_block_in_31800.hpp" />
Expand Down
45 changes: 33 additions & 12 deletions builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,37 @@
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="include">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000005}</UniqueIdentifier>
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000006}</UniqueIdentifier>
</Filter>
<Filter Include="include\bitcoin">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000006}</UniqueIdentifier>
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000007}</UniqueIdentifier>
</Filter>
<Filter Include="include\bitcoin\node">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000007}</UniqueIdentifier>
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000008}</UniqueIdentifier>
</Filter>
<Filter Include="include\bitcoin\node\channels">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000008}</UniqueIdentifier>
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000009}</UniqueIdentifier>
</Filter>
<Filter Include="include\bitcoin\node\chasers">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000009}</UniqueIdentifier>
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-00000000000A}</UniqueIdentifier>
</Filter>
<Filter Include="include\bitcoin\node\impl">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-00000000000A}</UniqueIdentifier>
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-00000000000B}</UniqueIdentifier>
</Filter>
<Filter Include="include\bitcoin\node\impl\chasers">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-00000000000D}</UniqueIdentifier>
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-00000000000F}</UniqueIdentifier>
</Filter>
<Filter Include="include\bitcoin\node\messages">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-00000000000C}</UniqueIdentifier>
</Filter>
<Filter Include="include\bitcoin\node\protocols">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-00000000000B}</UniqueIdentifier>
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-00000000000D}</UniqueIdentifier>
</Filter>
<Filter Include="include\bitcoin\node\sessions">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-00000000000C}</UniqueIdentifier>
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-00000000000E}</UniqueIdentifier>
</Filter>
<Filter Include="resource">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-00000000000E}</UniqueIdentifier>
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000001}</UniqueIdentifier>
</Filter>
<Filter Include="src">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000000}</UniqueIdentifier>
Expand All @@ -46,12 +49,15 @@
<Filter Include="src\chasers">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000002}</UniqueIdentifier>
</Filter>
<Filter Include="src\protocols">
<Filter Include="src\messages">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000003}</UniqueIdentifier>
</Filter>
<Filter Include="src\sessions">
<Filter Include="src\protocols">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000004}</UniqueIdentifier>
</Filter>
<Filter Include="src\sessions">
<UniqueIdentifier>{5FFB5F52-0772-4404-0000-000000000005}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\src\block_arena.cpp">
Expand Down Expand Up @@ -102,6 +108,12 @@
<ClCompile Include="..\..\..\..\src\full_node.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\messages\block.cpp">
<Filter>src\messages</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\messages\transaction.cpp">
<Filter>src\messages</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\protocols\protocol.cpp">
<Filter>src\protocols</Filter>
</ClCompile>
Expand Down Expand Up @@ -236,6 +248,15 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\full_node.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\messages\block.hpp">
<Filter>include\bitcoin\node\messages</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\messages\messages.hpp">
<Filter>include\bitcoin\node\messages</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\messages\transaction.hpp">
<Filter>include\bitcoin\node\messages</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol.hpp">
<Filter>include\bitcoin\node\protocols</Filter>
</ClInclude>
Expand Down
3 changes: 3 additions & 0 deletions include/bitcoin/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#include <bitcoin/node/chasers/chaser_transaction.hpp>
#include <bitcoin/node/chasers/chaser_validate.hpp>
#include <bitcoin/node/chasers/chasers.hpp>
#include <bitcoin/node/messages/block.hpp>
#include <bitcoin/node/messages/messages.hpp>
#include <bitcoin/node/messages/transaction.hpp>
#include <bitcoin/node/protocols/protocol.hpp>
#include <bitcoin/node/protocols/protocol_block_in_106.hpp>
#include <bitcoin/node/protocols/protocol_block_in_31800.hpp>
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/node/define.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,6 @@ using type_id = network::messages::peer::inventory_item::type_id;
// /channels : define configuration
// full_node : define /chasers
// session : define [forward: full_node]
// /messages : define
// /protocols : define /channels [session.hpp]
// /sessions : define /protocols [forward: full_node]
62 changes: 62 additions & 0 deletions include/bitcoin/node/messages/block.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Copyright (c) 2011-2026 libbitcoin developers (see AUTHORS)
*
* This file is part of libbitcoin.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBBITCOIN_NODE_MESSAGES_BLOCK_HPP
#define LIBBITCOIN_NODE_MESSAGES_BLOCK_HPP

#include <bitcoin/node/define.hpp>

namespace libbitcoin {
namespace node {
namespace messages {

/// Based on network::messages::peer::block.
struct BCN_API block
{
typedef std::shared_ptr<const block> cptr;

static const network::messages::peer::identifier id;
static const std::string command;
static const uint32_t version_minimum;
static const uint32_t version_maximum;

// TODO: optimized translation direct to store.
////static cptr deserialize(uint32_t version, const system::data_chunk& data,
//// bool witness=true) NOEXCEPT;
////static block deserialize(uint32_t version, system::reader& source,
//// bool witness=true) NOEXCEPT;

/// These return false if witness or version is inconsistent with block data.
bool serialize(uint32_t version, const system::data_slab& data,
bool witness=true) const NOEXCEPT;
void serialize(uint32_t version, system::writer& sink,
bool witness=true) const NOEXCEPT;
size_t size(uint32_t version, bool witness=true) const NOEXCEPT;

/// Wire serialized block.
system::data_chunk block_data{};

/// Block contains witness data (if applicable).
const bool witnessed_{};
};

} // namespace messages
} // namespace node
} // namespace libbitcoin

#endif
25 changes: 25 additions & 0 deletions include/bitcoin/node/messages/messages.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2011-2026 libbitcoin developers (see AUTHORS)
*
* This file is part of libbitcoin.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBBITCOIN_NODE_MESSAGES_MESSAGES_HPP
#define LIBBITCOIN_NODE_MESSAGES_MESSAGES_HPP

#include <bitcoin/node/messages/block.hpp>
#include <bitcoin/node/messages/transaction.hpp>

#endif
66 changes: 66 additions & 0 deletions include/bitcoin/node/messages/transaction.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright (c) 2011-2026 libbitcoin developers (see AUTHORS)
*
* This file is part of libbitcoin.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBBITCOIN_NODE_MESSAGES_TRANSACTION_HPP
#define LIBBITCOIN_NODE_MESSAGES_TRANSACTION_HPP

#include <optional>
#include <bitcoin/node/define.hpp>

namespace libbitcoin {
namespace node {
namespace messages {

/// Based on network::messages::peer::transaction.
struct BCN_API transaction
{
typedef std::shared_ptr<const transaction> cptr;

static const network::messages::peer::identifier id;
static const std::string command;
static const uint32_t version_minimum;
static const uint32_t version_maximum;

// TODO: optimized translation direct to store.
////static cptr deserialize(uint32_t version, const system::data_chunk& data,
//// bool witness=true) NOEXCEPT;
////static transaction deserialize(uint32_t version, system::reader& source,
//// bool witness=true) NOEXCEPT;

/// These return false if witness or version is inconsistent with tx data.
bool serialize(uint32_t version, const system::data_slab& data,
bool witness=true) const NOEXCEPT;
void serialize(uint32_t version, system::writer& sink,
bool witness=true) const NOEXCEPT;
size_t size(uint32_t version, bool witness=true) const NOEXCEPT;

/// Wire serialized transaction.
system::data_chunk tx_data{};

/// Non-witness hash of the transaction (for non-witness send optimize).
system::hash_digest hash{};

/// Transaction contains witness data (if applicable).
const bool witnessed_{};
};

} // namespace messages
} // namespace node
} // namespace libbitcoin

#endif
2 changes: 1 addition & 1 deletion include/bitcoin/node/sessions/session_peer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class session_peer

using namespace system;
using namespace network;
using namespace messages::peer;
using namespace network::messages::peer;
using base = session_peer<NetworkSession>;

const auto self = this->template shared_from_base<base>();
Expand Down
65 changes: 65 additions & 0 deletions src/messages/block.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright (c) 2011-2026 libbitcoin developers (see AUTHORS)
*
* This file is part of libbitcoin.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <bitcoin/node/messages/block.hpp>

#include <bitcoin/node/define.hpp>

namespace libbitcoin {
namespace node {
namespace messages {

using namespace system;
using namespace network::messages::peer;

const std::string block::command = "block";
const identifier block::id = identifier::block;
const uint32_t block::version_minimum = level::minimum_protocol;
const uint32_t block::version_maximum = level::maximum_protocol;

// data_slab is preallocated after the message header using size().
bool block::serialize(uint32_t version, const data_slab& data,
bool witness) const NOEXCEPT
{
if (witness != witnessed_)
return false;

system::stream::out::fast out{ data };
system::write::bytes::fast writer{ out };
serialize(version, writer, witness);
return writer;
}

// Sender must ensure that version/witness are consistent with channel.
void block::serialize(uint32_t, writer& sink,
bool BC_DEBUG_ONLY(witness)) const NOEXCEPT
{
BC_ASSERT(witness == witnessed_);
sink.write_bytes(block_data);
}

// Sender must ensure that version/witness are consistent with channel.
size_t block::size(uint32_t, bool BC_DEBUG_ONLY(witness)) const NOEXCEPT
{
BC_ASSERT(witness == witnessed_);
return block_data.size();
}

} // namespace messages
} // namespace node
} // namespace libbitcoin
Loading