Skip to content

Commit

Permalink
Merge branch 'feature-3.6.0' into feature-3.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyShi22 authored Nov 15, 2023
2 parents 31f84ac + 0cd5640 commit 107c65a
Show file tree
Hide file tree
Showing 17 changed files with 463 additions and 46 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
name: Others CI check
on:
push:
paths-ignore:
- "docs/**"
- "Changelog.md"
- "README.md"
pull_request:
paths-ignore:
- "docs/**"
- "Changelog.md"
- "README.md"
release:
types: [published, push]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build_cppsdk_with_windows:
name: build_cppsdk_with_windows
runs-on: ${{ matrix.os }}
env:
VCPKG_ROOT: c:/vcpkg
strategy:
matrix:
os: [ windows-2019 ]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 5
- uses: actions/cache@v2
id: cache
with:
path: |
deps/
c:/vcpkg
c:/vcpkg/buildtrees
c:/vcpkg/packages
c:/vcpkg/downloads
ccache
key: hunter-msvc-v3-notest-${{ runner.temp }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
restore-keys: |
hunter-msvc-v3-notest-${{ runner.temp }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
- name: update vcpkg
run: |
cd ${{ env.VCPKG_ROOT }} && git fetch --all && git checkout master && git pull
cd -
- name: Add MSbuild to PATH
uses: microsoft/setup-msbuild@v1.1
- name: configure and build
run: mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DALLOCATOR=default -DTESTS=OFF -DFULLNODE=OFF -DWITH_LIGHTNODE=OFF -DWITH_TARS_SERVICES=OFF -DWITH_CPPSDK=ON -DWITH_WASM=OFF -DWITH_TIKV=OFF -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake ../ && cmake --build . --parallel 3
#name: Others CI check
#on:
# push:
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ add_subdirectory(bcos-utilities)
add_subdirectory(concepts)
add_subdirectory(libtask)
add_subdirectory(bcos-protocol)
add_subdirectory(bcos-tars-protocol)
if(NOT ONLY_CPP_SDK AND NOT WITH_SWIG_SDK)
add_subdirectory(bcos-tars-protocol)
endif ()
add_subdirectory(bcos-codec)
include(ProjectITTAPI)
include(ProjectSDF)
Expand Down
10 changes: 9 additions & 1 deletion bcos-crypto/bcos-crypto/hasher/AnyHasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Hasher.h"
#include "bcos-crypto/TrivialObject.h"
#include <bcos-concepts/ByteBuffer.h>
#include <memory>
#include <span>

namespace bcos::crypto::hasher
Expand Down Expand Up @@ -30,6 +31,10 @@ class AnyHasherImpl : public AnyHasherInterface

public:
AnyHasherImpl(Hasher hasher) : m_hasher(std::move(hasher)) {}
AnyHasherImpl(AnyHasherImpl&&) = default;
AnyHasherImpl(const AnyHasherImpl&) = default;
AnyHasherImpl& operator=(AnyHasherImpl&&) = default;
AnyHasherImpl& operator=(const AnyHasherImpl&) = default;
void update(std::span<std::byte const> input) override { m_hasher.update(input); }
void final(std::span<std::byte> output) override { m_hasher.final(output); }
std::unique_ptr<AnyHasherInterface> clone() const override
Expand Down Expand Up @@ -64,17 +69,20 @@ class AnyHasher
m_anyHasher->update(view);
}

void update(std::span<std::byte const> input) { m_anyHasher->update(input); }

void final(concepts::bytebuffer::ByteBuffer auto& output)
{
concepts::resizeTo(output, hashSize());
m_anyHasher->final(
std::span<std::byte>((std::byte*)RANGES::data(output), RANGES::size(output)));
}

void final(std::span<std::byte> output) { m_anyHasher->final(output); }

AnyHasher clone() const { return {m_anyHasher->clone()}; }
size_t hashSize() const { return m_anyHasher->hashSize(); }
};

static_assert(Hasher<AnyHasher>, "Not a valid Hasher!");

} // namespace bcos::crypto::hasher
14 changes: 7 additions & 7 deletions bcos-crypto/bcos-crypto/hasher/Hasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace bcos::crypto::hasher

template <class HasherType>
concept Hasher = requires(HasherType hasher, std::span<std::byte> out) {
requires std::move_constructible<HasherType>;
hasher.update(std::span<std::byte const>{});
hasher.final(out);
{
hasher.clone()
} -> std::same_as<HasherType>;
};
// requires std::move_constructible<HasherType>;
hasher.update(std::span<std::byte const>{});
hasher.final(out);
{
hasher.clone()
} -> std::same_as<HasherType>;
};

} // namespace bcos::crypto::hasher
26 changes: 26 additions & 0 deletions bcos-crypto/bcos-crypto/hasher/OpenSSLHasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ class OpenSSLHasher
}
}

void update(std::span<std::byte const> in)
{
if (!m_init)
{
init();
m_init = true;
}

if (!EVP_DigestUpdate(m_mdCtx.get(), reinterpret_cast<unsigned char const*>(in.data()),
in.size())) [[unlikely]]
{
BOOST_THROW_EXCEPTION(std::runtime_error{"EVP_DigestUpdate error!"});
}
}

void final(bcos::crypto::trivial::Object auto& out)
{
m_init = false;
Expand All @@ -109,6 +124,17 @@ class OpenSSLHasher
}
}

void final(std::span<std::byte> out)
{
m_init = false;

if (!EVP_DigestFinal(m_mdCtx.get(), reinterpret_cast<unsigned char*>(out.data()), nullptr))
[[unlikely]]
{
BOOST_THROW_EXCEPTION(std::runtime_error{"EVP_DigestFinal error!"});
}
}

constexpr const EVP_MD* chooseMD()
{
if constexpr (hasherType == SM3)
Expand Down
4 changes: 4 additions & 0 deletions bcos-framework/bcos-framework/protocol/Transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include <bcos-crypto/interfaces/crypto/KeyInterface.h>
#include <bcos-utilities/Common.h>
#include <bcos-utilities/Error.h>
#if !ONLY_CPP_SDK
#include <bcos-utilities/ITTAPI.h>
#endif
#include <boost/throw_exception.hpp>
#include <concepts>
#include <shared_mutex>
Expand Down Expand Up @@ -69,8 +71,10 @@ class Transaction

virtual void verify(crypto::Hash& hashImpl, crypto::SignatureCrypto& signatureImpl) const
{
#if !ONLY_CPP_SDK
ittapi::Report report(ittapi::ITT_DOMAINS::instance().TRANSACTION,
ittapi::ITT_DOMAINS::instance().VERIFY_TRANSACTION);
#endif
// The tx has already been verified
if (!sender().empty())
{
Expand Down
19 changes: 10 additions & 9 deletions bcos-sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
file(GLOB_RECURSE SRC_LIST "bcos-cpp-sdk/*.cpp")
list(APPEND LINK_LIB_LIST bcos-crypto bcos-boostssl bcos-utilities jsoncpp_static OpenSSL::SSL OpenSSL::Crypto)
if (ONLY_CPP_SDK AND (NOT WITH_SWIG_SDK))
list(REMOVE_ITEM SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/bcos-cpp-sdk/tarsRPC/CoRPCClient.cpp")
list(REMOVE_ITEM SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/bcos-cpp-sdk/tarsRPC/RPCClient.cpp")
list(REMOVE_ITEM SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/bcos-cpp-sdk/tarsRPC/detail/Core.cpp")
else ()
list(APPEND LINK_LIB_LIST ${TARS_PROTOCOL_TARGET})
find_package(range-v3 REQUIRED)
endif ()

find_package(Boost REQUIRED log serialization)
find_package(wedprcrypto REQUIRED)
Expand All @@ -12,15 +21,7 @@ add_library(${BCOS_CPP_SDK_TARGET} ${SRC_LIST})
target_include_directories(${BCOS_CPP_SDK_TARGET} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/bcos-cpp-sdk>)
target_link_libraries(${BCOS_CPP_SDK_TARGET} PUBLIC
wedprcrypto::crypto
${TARS_PROTOCOL_TARGET}
bcos-crypto
bcos-boostssl
bcos-utilities
jsoncpp_static
OpenSSL::SSL
OpenSSL::Crypto)
target_link_libraries(${BCOS_CPP_SDK_TARGET} PUBLIC ${LINK_LIB_LIST})

if (TESTS)
enable_testing()
Expand Down
8 changes: 8 additions & 0 deletions bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ bcostars::ReceiptDataUniquePtr bcos::cppsdk::utilities::ReceiptBuilder::createRe
return _receipt;
}

bcos::crypto::HashType bcos::cppsdk::utilities::ReceiptBuilder::calculateReceiptDataHashWithJson(
bcos::cppsdk::utilities::CryptoType _cryptoType, const std::string& _json)
{
auto _receipt = std::make_unique<bcostars::TransactionReceiptData>();
_receipt->readFromJsonString(_json);
return calculateReceiptDataHash(_cryptoType, *_receipt);
}

bcos::crypto::HashType bcos::cppsdk::utilities::ReceiptBuilder::calculateReceiptDataHash(
bcos::cppsdk::utilities::CryptoType _cryptoType,
const bcostars::TransactionReceiptData& _receiptData)
Expand Down
4 changes: 4 additions & 0 deletions bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class ReceiptBuilder : public ReceiptBuilderInterface
* @return bcostars::TransactionDataUniquePtr
*/
bcostars::ReceiptDataUniquePtr createReceiptDataWithJson(const std::string& _json) override;

crypto::HashType calculateReceiptDataHashWithJson(
bcos::cppsdk::utilities::CryptoType _cryptoType, const std::string& _json) override;

crypto::HashType calculateReceiptDataHash(
CryptoType _cryptoType, const bcostars::TransactionReceiptData& _receiptData) override;
bytesConstPtr encodeReceipt(const bcostars::TransactionReceiptData& _receipt) override;
Expand Down
10 changes: 10 additions & 0 deletions bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ class ReceiptBuilderInterface
*/
virtual bcostars::ReceiptDataUniquePtr createReceiptDataWithJson(const std::string& _json) = 0;

/**
* @brief calculate receipt data hash with json
*
* @param _cryptoType
* @param _json
* @return crypto::HashType
*/
virtual crypto::HashType calculateReceiptDataHashWithJson(
bcos::cppsdk::utilities::CryptoType _cryptoType, const std::string& _json) = 0;

/**
* @brief
*
Expand Down
Loading

0 comments on commit 107c65a

Please sign in to comment.