diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 8d455307f6..1f1d62e03e 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -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: diff --git a/CMakeLists.txt b/CMakeLists.txt index e1ca299ea3..dd7f9e5e3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/bcos-crypto/bcos-crypto/hasher/AnyHasher.h b/bcos-crypto/bcos-crypto/hasher/AnyHasher.h index a90b1cf6eb..d97022f933 100644 --- a/bcos-crypto/bcos-crypto/hasher/AnyHasher.h +++ b/bcos-crypto/bcos-crypto/hasher/AnyHasher.h @@ -2,6 +2,7 @@ #include "Hasher.h" #include "bcos-crypto/TrivialObject.h" #include +#include #include namespace bcos::crypto::hasher @@ -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 input) override { m_hasher.update(input); } void final(std::span output) override { m_hasher.final(output); } std::unique_ptr clone() const override @@ -64,6 +69,8 @@ class AnyHasher m_anyHasher->update(view); } + void update(std::span input) { m_anyHasher->update(input); } + void final(concepts::bytebuffer::ByteBuffer auto& output) { concepts::resizeTo(output, hashSize()); @@ -71,10 +78,11 @@ class AnyHasher std::span((std::byte*)RANGES::data(output), RANGES::size(output))); } + void final(std::span output) { m_anyHasher->final(output); } + AnyHasher clone() const { return {m_anyHasher->clone()}; } size_t hashSize() const { return m_anyHasher->hashSize(); } }; static_assert(Hasher, "Not a valid Hasher!"); - } // namespace bcos::crypto::hasher \ No newline at end of file diff --git a/bcos-crypto/bcos-crypto/hasher/Hasher.h b/bcos-crypto/bcos-crypto/hasher/Hasher.h index 2f9df242b1..eaf978f596 100644 --- a/bcos-crypto/bcos-crypto/hasher/Hasher.h +++ b/bcos-crypto/bcos-crypto/hasher/Hasher.h @@ -9,12 +9,12 @@ namespace bcos::crypto::hasher template concept Hasher = requires(HasherType hasher, std::span out) { - requires std::move_constructible; - hasher.update(std::span{}); - hasher.final(out); - { - hasher.clone() - } -> std::same_as; - }; +// requires std::move_constructible; + hasher.update(std::span{}); + hasher.final(out); + { + hasher.clone() + } -> std::same_as; +}; } // namespace bcos::crypto::hasher \ No newline at end of file diff --git a/bcos-crypto/bcos-crypto/hasher/OpenSSLHasher.h b/bcos-crypto/bcos-crypto/hasher/OpenSSLHasher.h index 2d070de65c..cf535c02b1 100644 --- a/bcos-crypto/bcos-crypto/hasher/OpenSSLHasher.h +++ b/bcos-crypto/bcos-crypto/hasher/OpenSSLHasher.h @@ -96,6 +96,21 @@ class OpenSSLHasher } } + void update(std::span in) + { + if (!m_init) + { + init(); + m_init = true; + } + + if (!EVP_DigestUpdate(m_mdCtx.get(), reinterpret_cast(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; @@ -109,6 +124,17 @@ class OpenSSLHasher } } + void final(std::span out) + { + m_init = false; + + if (!EVP_DigestFinal(m_mdCtx.get(), reinterpret_cast(out.data()), nullptr)) + [[unlikely]] + { + BOOST_THROW_EXCEPTION(std::runtime_error{"EVP_DigestFinal error!"}); + } + } + constexpr const EVP_MD* chooseMD() { if constexpr (hasherType == SM3) diff --git a/bcos-framework/bcos-framework/protocol/Transaction.h b/bcos-framework/bcos-framework/protocol/Transaction.h index 707c8c5f12..613cb349d2 100644 --- a/bcos-framework/bcos-framework/protocol/Transaction.h +++ b/bcos-framework/bcos-framework/protocol/Transaction.h @@ -23,7 +23,9 @@ #include #include #include +#if !ONLY_CPP_SDK #include +#endif #include #include #include @@ -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()) { diff --git a/bcos-sdk/CMakeLists.txt b/bcos-sdk/CMakeLists.txt index 3437d572ed..8aa779ea14 100644 --- a/bcos-sdk/CMakeLists.txt +++ b/bcos-sdk/CMakeLists.txt @@ -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) @@ -12,15 +21,7 @@ add_library(${BCOS_CPP_SDK_TARGET} ${SRC_LIST}) target_include_directories(${BCOS_CPP_SDK_TARGET} PUBLIC $ $) -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() diff --git a/bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilder.cpp b/bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilder.cpp index cc5cf35ed2..837eacbfb2 100644 --- a/bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilder.cpp +++ b/bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilder.cpp @@ -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(); + _receipt->readFromJsonString(_json); + return calculateReceiptDataHash(_cryptoType, *_receipt); +} + bcos::crypto::HashType bcos::cppsdk::utilities::ReceiptBuilder::calculateReceiptDataHash( bcos::cppsdk::utilities::CryptoType _cryptoType, const bcostars::TransactionReceiptData& _receiptData) diff --git a/bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilder.h b/bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilder.h index fe566822b8..f77af0342e 100644 --- a/bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilder.h +++ b/bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilder.h @@ -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; diff --git a/bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilderInterface.h b/bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilderInterface.h index b0845aef7c..94ea0a9d00 100644 --- a/bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilderInterface.h +++ b/bcos-sdk/bcos-cpp-sdk/utilities/receipt/ReceiptBuilderInterface.h @@ -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 * diff --git a/bcos-sdk/bcos-cpp-sdk/utilities/tx/Transaction.h b/bcos-sdk/bcos-cpp-sdk/utilities/tx/Transaction.h index bcc7c8d02b..8709308f8f 100644 --- a/bcos-sdk/bcos-cpp-sdk/utilities/tx/Transaction.h +++ b/bcos-sdk/bcos-cpp-sdk/utilities/tx/Transaction.h @@ -24,7 +24,7 @@ struct TransactionData : public tars::TarsStructBase { public: static std::string className() { return "bcostars.TransactionData"; } - static std::string MD5() { return "ea41d47be6b852a5c3edcfe7a805be85"; } + static std::string MD5() { return "8147ae64a9fd777c7d425e7796bf503b"; } TransactionData() { resetDefault(); } void resetDefault() { @@ -36,6 +36,11 @@ struct TransactionData : public tars::TarsStructBase to = ""; input.clear(); abi = ""; + value = ""; + gasPrice = ""; + gasLimit = 0; + maxFeePerGas = ""; + maxPriorityFeePerGas = ""; } template void writeTo(tars::TarsOutputStream& _os) const @@ -54,6 +59,26 @@ struct TransactionData : public tars::TarsStructBase { _os.write(abi, 8); } + if (value != "") + { + _os.write(value, 9); + } + if (gasPrice != "") + { + _os.write(gasPrice, 10); + } + if (gasLimit != 0) + { + _os.write(gasLimit, 11); + } + if (maxFeePerGas != "") + { + _os.write(maxFeePerGas, 12); + } + if (maxPriorityFeePerGas != "") + { + _os.write(maxPriorityFeePerGas, 13); + } } template void readFrom(tars::TarsInputStream& _is) @@ -67,6 +92,11 @@ struct TransactionData : public tars::TarsStructBase _is.read(to, 6, false); _is.read(input, 7, true); _is.read(abi, 8, false); + _is.read(value, 9, false); + _is.read(gasPrice, 10, false); + _is.read(gasLimit, 11, false); + _is.read(maxFeePerGas, 12, false); + _is.read(maxPriorityFeePerGas, 13, false); } tars::JsonValueObjPtr writeToJson() const { @@ -79,6 +109,14 @@ struct TransactionData : public tars::TarsStructBase p->value["to"] = tars::JsonOutput::writeJson(to); p->value["input"] = tars::JsonOutput::writeJson(bcos::toHexStringWithPrefix(input)); p->value["abi"] = tars::JsonOutput::writeJson(abi); + if ((int)version == 1) + { + p->value["value"] = tars::JsonOutput::writeJson(value); + p->value["gasPrice"] = tars::JsonOutput::writeJson(gasPrice); + p->value["gasLimit"] = tars::JsonOutput::writeJson(gasLimit); + p->value["maxFeePerGas"] = tars::JsonOutput::writeJson(maxFeePerGas); + p->value["maxPriorityFeePerGas"] = tars::JsonOutput::writeJson(maxPriorityFeePerGas); + } return p; } std::string writeToJsonString() const { return tars::TC_Json::writeValue(writeToJson()); } @@ -104,6 +142,15 @@ struct TransactionData : public tars::TarsStructBase auto inputBytes = bcos::fromHexString(inputHex); std::copy(inputBytes->begin(), inputBytes->end(), std::back_inserter(input)); tars::JsonInput::readJson(abi, pObj->value["abi"], false); + if ((int)version == 1) + { + tars::JsonInput::readJson(value, pObj->value["value"], false); + tars::JsonInput::readJson(gasPrice, pObj->value["gasPrice"], false); + tars::JsonInput::readJson(gasLimit, pObj->value["gasLimit"], false); + tars::JsonInput::readJson(maxFeePerGas, pObj->value["maxFeePerGas"], false); + tars::JsonInput::readJson( + maxPriorityFeePerGas, pObj->value["maxPriorityFeePerGas"], false); + } } void readFromJsonString(const std::string& str) { readFromJson(tars::TC_Json::getValue(str)); } std::ostream& display(std::ostream& _os, int _level = 0) const @@ -117,6 +164,11 @@ struct TransactionData : public tars::TarsStructBase _ds.display(to, "to"); _ds.display(input, "input"); _ds.display(abi, "abi"); + _ds.display(value, "value"); + _ds.display(gasPrice, "gasPrice"); + _ds.display(gasLimit, "gasLimit"); + _ds.display(maxFeePerGas, "maxFeePerGas"); + _ds.display(maxPriorityFeePerGas, "maxPriorityFeePerGas"); return _os; } std::ostream& displaySimple(std::ostream& _os, int _level = 0) const @@ -130,6 +182,11 @@ struct TransactionData : public tars::TarsStructBase _ds.displaySimple(to, true); _ds.displaySimple(input, true); _ds.displaySimple(abi, false); + _ds.displaySimple(value, true); + _ds.displaySimple(gasPrice, true); + _ds.displaySimple(gasLimit, true); + _ds.displaySimple(maxFeePerGas, true); + _ds.displaySimple(maxPriorityFeePerGas, false); return _os; } @@ -156,6 +213,24 @@ struct TransactionData : public tars::TarsStructBase // encode abi hasher.update(bcos::bytesConstRef((bcos::byte*)abi.data(), abi.size())); + if ((int)version == 1) + { + // encode value + hasher.update(bcos::bytesConstRef((bcos::byte*)value.data(), value.size())); + // encode gasPrice + hasher.update(bcos::bytesConstRef((bcos::byte*)gasPrice.data(), gasPrice.size())); + // encode gasLimit + int64_t networkGasLimit = boost::endian::native_to_big((int64_t)gasLimit); + hasher.update(bcos::bytesConstRef( + (bcos::byte*)(&networkGasLimit), sizeof(networkGasLimit) / sizeof(uint8_t))); + // encode maxFeePerGas + hasher.update( + bcos::bytesConstRef((bcos::byte*)maxFeePerGas.data(), maxFeePerGas.size())); + // encode maxPriorityFeePerGas + hasher.update(bcos::bytesConstRef( + (bcos::byte*)maxPriorityFeePerGas.data(), maxPriorityFeePerGas.size())); + } + hasher.final(hashResult); return hashResult; @@ -170,12 +245,19 @@ struct TransactionData : public tars::TarsStructBase std::string to; std::vector input; std::string abi; + std::string value; + std::string gasPrice; + tars::Int64 gasLimit; + std::string maxFeePerGas; + std::string maxPriorityFeePerGas; }; inline bool operator==(const TransactionData& l, const TransactionData& r) { return l.version == r.version && l.chainID == r.chainID && l.groupID == r.groupID && l.blockLimit == r.blockLimit && l.nonce == r.nonce && l.to == r.to && - l.input == r.input && l.abi == r.abi; + l.input == r.input && l.abi == r.abi && l.value == r.value && l.gasPrice == r.gasPrice && + l.gasLimit == r.gasLimit && l.maxFeePerGas == r.maxFeePerGas && + l.maxPriorityFeePerGas == r.maxPriorityFeePerGas; } inline bool operator!=(const TransactionData& l, const TransactionData& r) { diff --git a/bcos-sdk/bcos-cpp-sdk/utilities/tx/TransactionBuilderService.h b/bcos-sdk/bcos-cpp-sdk/utilities/tx/TransactionBuilderService.h index b031d12bb1..7e54805872 100644 --- a/bcos-sdk/bcos-cpp-sdk/utilities/tx/TransactionBuilderService.h +++ b/bcos-sdk/bcos-cpp-sdk/utilities/tx/TransactionBuilderService.h @@ -20,6 +20,7 @@ #pragma once #include #include +//#include #include #include #include diff --git a/bcos-sdk/bcos-cpp-sdk/utilities/tx/TransactionBuilderV2.h b/bcos-sdk/bcos-cpp-sdk/utilities/tx/TransactionBuilderV2.h new file mode 100644 index 0000000000..2f3c183767 --- /dev/null +++ b/bcos-sdk/bcos-cpp-sdk/utilities/tx/TransactionBuilderV2.h @@ -0,0 +1,177 @@ +/** + * Copyright (C) 2023 FISCO BCOS. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @file TransactionBuilderV2.h + * @author: kyonGuo + * @date 2023/11/9 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace bcos::cppsdk::utilities +{ +class TransactionBuilderV2 : public TransactionBuilder +{ +public: + // /** + // * @brief Create a Transaction Data object with full params + // * + // * @param _version tx version, if version==1, then enable + // * (value,gasPrice,gasLimit,maxFeePerGas,maxPriorityFeePerGas) fields + // * @param _groupID group id + // * @param _chainID chain id + // * @param _to contract address, if empty, then create contract + // * @param _nonce nonce, random number to avoid duplicate transactions + // * @param _data encoded contract method and params + // * @param _abi contract abi, only create contract need + // * @param _blockLimit block limit + // * @param _value transfer value + // * @param _gasPrice gas price + // * @param _gasLimit gas limit + // * @param _maxFeePerGas max fee per gas + // * @param _maxPriorityFeePerGas max priority fee per gas + // * @throw Exception if lack of some required fields, or some fields are invalid + // * @return bcostars::TransactionDataUniquePtr + // */ + virtual bcostars::TransactionDataUniquePtr createTransactionData(int64_t _version, + std::string _groupID, std::string _chainID, std::string _to, std::string _nonce, + bcos::bytes _input, std::string _abi, int64_t _blockLimit, std::string _value = "", + std::string _gasPrice = "", int64_t _gasLimit = 0, std::string _maxFeePerGas = "", + std::string _maxPriorityFeePerGas = ""); + + // /** + // * @brief calculate TransactionData hash with full fields + // * + // * @param _cryptoType 0: keccak256, 1: sm3 + // * @param _version tx version, if version==1, then enable + // * (value,gasPrice,gasLimit,maxFeePerGas,maxPriorityFeePerGas) fields + // * @param _groupID group id + // * @param _chainID chain id + // * @param _to contract address, if empty, then create contract + // * @param _nonce nonce, random number to avoid duplicate transactions + // * @param _data encoded contract method and params + // * @param _abi contract abi, only create contract need + // * @param _blockLimit block limit + // * @param _value transfer value + // * @param _gasPrice gas price + // * @param _gasLimit gas limit + // * @param _maxFeePerGas max fee per gas + // * @param _maxPriorityFeePerGas max priority fee per gas + // * @return crypto::HashType + // */ + virtual crypto::HashType calculateTransactionDataHash(CryptoType _cryptoType, int64_t _version, + std::string _groupID, std::string _chainID, std::string _to, std::string _nonce, + bcos::bytes _input, std::string _abi, int64_t _blockLimit, std::string _value = "", + std::string _gasPrice = "", int64_t _gasLimit = 0, std::string _maxFeePerGas = "", + std::string _maxPriorityFeePerGas = ""); + + + // /** + // * @brief calculate TransactionData hash with jsonData + // * + // * @param _cryptoType 0: keccak256, 1: sm3 + // * @param _json + // * version:number + // * groupID:string + // * chainID:string + // * to:string + // * input:hex string + // * abi:string + // * blockLimit:number + // * nonce:string + // * value:string + // * gasPrice:string + // * gasLimit:number + // * maxFeePerGas:string + // * maxPriorityFeePerGas:string + // * @throw Exception if lack of some required fields + // * @return HashType + // */ + virtual crypto::HashType calculateTransactionDataHashWithJson( + CryptoType _cryptoType, std::string _jsonData); + + // /** + // * @brief Create a Transaction object with full fields + // * + // * @param _transactionData + // * @param _signData + // * @param _hash + // * @param _attribute + // * @param _extraData + // * @param _version tx version, if version==1, then enable + // * (value,gasPrice,gasLimit,maxFeePerGas,maxPriorityFeePerGas) fields + // * @param _groupID group id + // * @param _chainID chain id + // * @param _to contract address, if empty, then create contract + // * @param _nonce nonce, random number to avoid duplicate transactions + // * @param _data encoded contract method and params + // * @param _abi contract abi, only create contract need + // * @param _blockLimit block limit + // * @param _value transfer value + // * @param _gasPrice gas price + // * @param _gasLimit gas limit + // * @param _maxFeePerGas max fee per gas + // * @param _maxPriorityFeePerGas max priority fee per gas + // * @return bcostars::TransactionUniquePtr + // */ + virtual bcostars::TransactionUniquePtr createTransaction(bcos::bytes _signData, + crypto::HashType _hash, int32_t _attribute, int64_t _version, std::string _groupID, + std::string _chainID, std::string _to, std::string _nonce, bcos::bytes _input, + std::string _abi, int64_t _blockLimit, std::string _value = "", std::string _gasPrice = "", + int64_t _gasLimit = 0, std::string _maxFeePerGas = "", + std::string _maxPriorityFeePerGas = "", std::string _extraData = ""); + + // /** + // * @brief Create a Signed Transaction object + // * + // * @param _keyPair key pair + // * @param _groupID group id + // * @param _chainID chain id + // * @param _to contract address, if empty, then create contract + // * @param _data encoded contract method and params + // * @param _abi contract abi, only create contract need + // * @param _blockLimit block limit + // * @param _attribute transaction attribute + // * @param _extraData extra data + // * @param _version tx version, if version==1, then enable + // * (value,gasPrice,gasLimit,maxFeePerGas,maxPriorityFeePerGas) fields + // * @param _value transfer value + // * @param _gasPrice gas price + // * @param _gasLimit gas limit + // * @param _maxFeePerGas max fee per gas + // * @param _maxPriorityFeePerGas max priority fee per gas + // * @param _nonce nonce, random number to avoid duplicate transactions + // * @throw Exception if lack of some required fields + // * @return std::pair + // */ + virtual std::pair createSignedTransaction( + bcos::crypto::KeyPairInterface _keyPair, int32_t _attribute, int64_t _version, + std::string _groupID, std::string _chainID, std::string _to, std::string _nonce, + bcos::bytes _input, std::string _abi, int64_t _blockLimit, std::string _value = "", + std::string _gasPrice = "", int64_t _gasLimit = 0, std::string _maxFeePerGas = "", + std::string _maxPriorityFeePerGas = "", std::string _extraData = ""); +}; +} // namespace bcos::cppsdk::utilities \ No newline at end of file diff --git a/bcos-utilities/CMakeLists.txt b/bcos-utilities/CMakeLists.txt index 496f87b4b7..465341cb6a 100644 --- a/bcos-utilities/CMakeLists.txt +++ b/bcos-utilities/CMakeLists.txt @@ -2,17 +2,28 @@ project(bcos-utilities VERSION ${VERSION}) find_package(Boost REQUIRED COMPONENTS log filesystem chrono thread serialization) -find_package(zstd CONFIG REQUIRED) -find_package(redis++ CONFIG REQUIRED) +if(NOT ONLY_CPP_SDK) + find_package(zstd CONFIG REQUIRED) + find_package(redis++ CONFIG REQUIRED) +endif () # aux_source_directory(bcos-utilities SRCS) file(GLOB_RECURSE SRCS "bcos-utilities/*.cpp") +if (ONLY_CPP_SDK) + list(REMOVE_ITEM SRCS "${CMAKE_CURRENT_SOURCE_DIR}/bcos-utilities/ratelimiter/DistributedRateLimiter.cpp") + list(REMOVE_ITEM SRCS "${CMAKE_CURRENT_SOURCE_DIR}/bcos-utilities/ZstdCompress.cpp") + list(REMOVE_ITEM SRCS "${CMAKE_CURRENT_SOURCE_DIR}/bcos-utilities/ITTAPI.h") +endif () add_library(bcos-utilities ${SRCS}) target_include_directories(bcos-utilities PUBLIC $ $) -target_link_libraries(bcos-utilities PUBLIC Boost::log Boost::filesystem Boost::chrono Boost::thread Boost::serialization redis++::redis++_static zstd::libzstd_static ittapi) +if (ONLY_CPP_SDK) + target_link_libraries(bcos-utilities PUBLIC Boost::log Boost::filesystem Boost::chrono Boost::thread Boost::serialization) +else () + target_link_libraries(bcos-utilities PUBLIC Boost::log Boost::filesystem Boost::chrono Boost::thread Boost::serialization redis++::redis++_static zstd::libzstd_static ittapi) +endif () if(TESTS) enable_testing() diff --git a/cmake/CompilerSettings.cmake b/cmake/CompilerSettings.cmake index 144b348a39..18e533f0ae 100644 --- a/cmake/CompilerSettings.cmake +++ b/cmake/CompilerSettings.cmake @@ -164,7 +164,8 @@ if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR("${CMAKE_CXX_COMPILER_ID}" MATC endif() endif() elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") - add_definitions(-DUSE_STD_RANGES) + add_compile_definitions(NOMINMAX) + #add_definitions(-DUSE_STD_RANGES) add_compile_options(/std:c++latest) add_compile_options(-bigobj) diff --git a/cmake/Options.cmake b/cmake/Options.cmake index f4f87756b3..f21a06e1ea 100644 --- a/cmake/Options.cmake +++ b/cmake/Options.cmake @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------ - # Copyright (C) 2021 FISCO BCOS. +# Copyright (C) 2021 FISCO BCOS. # SPDX-License-Identifier: Apache-2.0 # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -79,12 +79,24 @@ macro(configure_project) default_option(WITH_BENCHMARK ON) default_option(WITH_WASM ON) default_option(WITH_VTUNE_ITT OFF) + default_option(ONLY_CPP_SDK OFF) + + if((NOT FULLNODE) AND (NOT WITH_LIGHTNODE) AND WITH_CPPSDK) + set(ONLY_CPP_SDK ON) + endif() if(NOT WITH_VTUNE_ITT) add_definitions(-DINTEL_NO_ITTNOTIFY_API) endif() if(FULLNODE) list(APPEND VCPKG_MANIFEST_FEATURES "fullnode") + endif () + if (TESTS) + list(APPEND VCPKG_MANIFEST_FEATURES "tests") + endif () + if (ONLY_CPP_SDK) + add_compile_definitions(ONLY_CPP_SDK) + #list(APPEND VCPKG_MANIFEST_FEATURES "cppsdk") endif() if(WITH_LIGHTNODE) list(APPEND VCPKG_MANIFEST_FEATURES "lightnode") @@ -163,6 +175,7 @@ macro(print_config NAME) message("-- WITH_SWIG_SDK Enable swig sdk ${WITH_SWIG_SDK}") message("-- WITH_WASM Enable wasm ${WITH_WASM}") message("-- WITH_VTUNE_ITT Enable vtune itt api support ${WITH_VTUNE_ITT}") + message("-- ONLY_CPP_SDK Only build cpp sdk ${ONLY_CPP_SDK}") message("------------------------------------------------------------------------") message("") endmacro() \ No newline at end of file diff --git a/vcpkg.json b/vcpkg.json index 5824087a86..c2e3d5d4fb 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -13,7 +13,6 @@ "host": true }, "magic-enum", - "indicators", "boost-log", "boost-beast", "boost-uuid", @@ -31,35 +30,16 @@ "boost-program-options", "boost-variant2", "ms-gsl", - "zstd", "tbb", - "zlib", - { - "name": "redis-plus-plus", - "version>=": "1.3.2" - }, { "name": "jsoncpp", "version>=": "1.9.5" }, - { - "name": "protobuf", - "version>=": "3.19.4" - }, - { - "name": "cryptopp", - "version>=": "8.6.0" - }, - { - "name": "tarscpp", - "version>=": "3.0.3-1#1" - }, { "name": "openssl", "version>=": "1.1.1-tassl" }, "fmt", - "benchmark", { "name": "secp256k1", "version>=": "2022-12-13#1", @@ -90,7 +70,23 @@ "zstd" ] }, - "zstd" + "zstd", + { + "name": "protobuf", + "version>=": "3.19.4" + }, + { + "name": "cryptopp", + "version>=": "8.6.0" + }, + { + "name": "redis-plus-plus", + "version>=": "1.3.2" + }, + { + "name": "tarscpp", + "version>=": "3.0.3-1#1" + } ] }, "lightnode": { @@ -101,6 +97,27 @@ "features": [ "zstd" ] + }, + { + "name": "redis-plus-plus", + "version>=": "1.3.2" + }, + "zstd", + { + "name": "tarscpp", + "version>=": "3.0.3-1#1" + } + ] + }, + "tests": { + "description": "for test dependencies", + "dependencies": [ + "indicators", + "benchmark", + "zlib", + { + "name": "tarscpp", + "version>=": "3.0.3-1#1" } ] },