From e73e3bb22b733cd1bc4ec6dc4660015174d3bc46 Mon Sep 17 00:00:00 2001 From: kyonRay Date: Wed, 29 Nov 2023 17:15:03 +0800 Subject: [PATCH] (sdk): impl transaction builder v2 in c sdk. --- bcos-c-sdk/bcos_sdk_c.cpp | 14 ++ bcos-c-sdk/bcos_sdk_c.h | 4 + bcos-c-sdk/bcos_sdk_c_uti_receipt.cpp | 32 ++- bcos-c-sdk/bcos_sdk_c_uti_receipt.h | 2 + bcos-c-sdk/bcos_sdk_c_uti_tx_v2.cpp | 324 ++++++++++++++++++++++++++ bcos-c-sdk/bcos_sdk_c_uti_tx_v2.h | 200 ++++++++++++++++ vcpkg-configuration.json | 2 +- 7 files changed, 575 insertions(+), 3 deletions(-) create mode 100644 bcos-c-sdk/bcos_sdk_c_uti_tx_v2.cpp create mode 100644 bcos-c-sdk/bcos_sdk_c_uti_tx_v2.h diff --git a/bcos-c-sdk/bcos_sdk_c.cpp b/bcos-c-sdk/bcos_sdk_c.cpp index cdd91f57d..cdacef993 100644 --- a/bcos-c-sdk/bcos_sdk_c.cpp +++ b/bcos-c-sdk/bcos_sdk_c.cpp @@ -318,4 +318,18 @@ const char* bcos_sdk_get_group_chain_id(void* sdk, const char* group) auto chainID = groupInfo->chainID(); return strdup(chainID.c_str()); +} + +uint32_t bcos_sdk_get_local_protocol_info(void* sdk) { + bcos_sdk_clear_last_error(); + BCOS_SDK_C_PARAMS_VERIFICATION(sdk, NULL); + + return ((bcos::cppsdk::Sdk*)sdk)->localProtocolInfo(); +} + +uint32_t bcos_sdk_get_negotiated_protocol_info(void* sdk) { + bcos_sdk_clear_last_error(); + BCOS_SDK_C_PARAMS_VERIFICATION(sdk, NULL); + + return ((bcos::cppsdk::Sdk*)sdk)->negotiatedProtocolInfo(); } \ No newline at end of file diff --git a/bcos-c-sdk/bcos_sdk_c.h b/bcos-c-sdk/bcos_sdk_c.h index 48fec951d..335cf2f90 100644 --- a/bcos-c-sdk/bcos_sdk_c.h +++ b/bcos-c-sdk/bcos_sdk_c.h @@ -115,6 +115,10 @@ void bcos_sdk_get_group_wasm_and_crypto(void* sdk, const char* group, int* wasm, * @return const char* : chain id */ const char* bcos_sdk_get_group_chain_id(void* sdk, const char* group); + +uint32_t bcos_sdk_get_local_protocol_info(void* sdk); + +uint32_t bcos_sdk_get_negotiated_protocol_info(void* sdk); // -------------------------------------------------------------------- #ifdef __cplusplus diff --git a/bcos-c-sdk/bcos_sdk_c_uti_receipt.cpp b/bcos-c-sdk/bcos_sdk_c_uti_receipt.cpp index b86b8fc13..61b17284e 100644 --- a/bcos-c-sdk/bcos_sdk_c_uti_receipt.cpp +++ b/bcos-c-sdk/bcos_sdk_c_uti_receipt.cpp @@ -80,8 +80,7 @@ void* bcos_sdk_create_receipt_data_with_json(const char* json) { std::string errorMsg = boost::diagnostic_information(e); BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_create_receipt_data") << LOG_DESC("exception") - << LOG_KV("json", json) - << LOG_KV("error", errorMsg); + << LOG_KV("json", json) << LOG_KV("error", errorMsg); bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); } @@ -167,4 +166,33 @@ const char* bcos_sdk_calc_receipt_data_hash(int crypto_type, void* _receiptData) bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); } return NULL; +} + +const char* bcos_sdk_calc_receipt_data_hash_with_json(int crypto_type, const char* json) +{ + bcos_sdk_clear_last_error(); + BCOS_SDK_C_PARAMS_VERIFICATION(json, NULL); + BCOS_SDK_C_PARAMS_VERIFY_CONDITION( + (crypto_type == BCOS_C_SDK_ECDSA_TYPE || crypto_type == BCOS_C_SDK_SM_TYPE), + "invalid crypto type, it must be BCOS_C_SDK_ECDSA_TYPE(ecdsa crypto type) or " + "BCOS_C_SDK_SM_TYPE(sm crypto type)", + NULL); + + try + { + ReceiptBuilder builder; + auto transactionDataHash = builder.calculateReceiptDataHashWithJson( + crypto_type == BCOS_C_SDK_ECDSA_TYPE ? CryptoType::Secp256K1 : CryptoType::SM2, + std::string(json)); + return strdup(bcos::toHexStringWithPrefix(transactionDataHash).c_str()); + } + catch (const std::exception& e) + { + std::string errorMsg = boost::diagnostic_information(e); + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_calc_transaction_data_hash_with_json") + << LOG_DESC("exception") << LOG_KV("crypto_type", crypto_type) + << LOG_KV("json", json) << LOG_KV("error", errorMsg); + bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); + } + return NULL; } \ No newline at end of file diff --git a/bcos-c-sdk/bcos_sdk_c_uti_receipt.h b/bcos-c-sdk/bcos_sdk_c_uti_receipt.h index 4b9665bda..5b6cea480 100644 --- a/bcos-c-sdk/bcos_sdk_c_uti_receipt.h +++ b/bcos-c-sdk/bcos_sdk_c_uti_receipt.h @@ -52,6 +52,8 @@ void bcos_sdk_destroy_receipt_data(void* transaction_data); const char* bcos_sdk_calc_receipt_data_hash(int crypto_type, void* _receiptData); +const char* bcos_sdk_calc_receipt_data_hash_with_json(int crypto_type, const char* json); + const char* bcos_sdk_encode_receipt_data(void* receipt_data); const char* bcos_sdk_decode_receipt_data(const char* receipt_bytes); diff --git a/bcos-c-sdk/bcos_sdk_c_uti_tx_v2.cpp b/bcos-c-sdk/bcos_sdk_c_uti_tx_v2.cpp new file mode 100644 index 000000000..9dc9b6d97 --- /dev/null +++ b/bcos-c-sdk/bcos_sdk_c_uti_tx_v2.cpp @@ -0,0 +1,324 @@ +/** + * Copyright (C) 2022 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 bcos_sdk_c_uti_tx_v2.cpp + * @author: kyonGuo + * @date 2023/11/28 + */ + +#include "bcos_sdk_c_uti_tx_v2.h" +#include "bcos_sdk_c_error.h" +#include +#include +#include +#include + +using namespace bcos; +using namespace bcos::cppsdk; +using namespace bcos::cppsdk::utilities; + +#include +#include +#include + +void* bcos_sdk_create_transaction_v2_data(const char* group_id, const char* chain_id, + const char* to, const char* input, const char* abi, int64_t block_limit, const char* value, + const char* gas_price, int64_t gas_limit) +{ + bcos_sdk_clear_last_error(); + BCOS_SDK_C_PARAMS_VERIFICATION(group_id, NULL) + BCOS_SDK_C_PARAMS_VERIFICATION(chain_id, NULL) + BCOS_SDK_C_PARAMS_VERIFICATION(input, NULL) + BCOS_SDK_C_PARAMS_VERIFY_CONDITION((block_limit > 0), "block limit must > 0", NULL) + BCOS_SDK_C_PARAMS_VERIFY_CONDITION((gas_limit > 0), "gas limit must > 0", NULL) + + try + { + TransactionBuilderV2 builder; + auto bytesData = fromHexString(input); + auto transactionData = + builder.createTransactionData(1, group_id, chain_id, to, "", *bytesData, abi, + block_limit, value ? value : "", gas_price ? gas_price : "", gas_limit); + return transactionData.release(); + } + catch (const std::exception& e) + { + std::string errorMsg = boost::diagnostic_information(e); + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_create_transaction_data") << LOG_DESC("exception") + << LOG_KV("group_id", group_id) << LOG_KV("chain_id", chain_id) + << LOG_KV("to", std::string(to ? to : "")) << LOG_KV("input", input) + << LOG_KV("abi", std::string(abi ? abi : "")) + << LOG_KV("block_limit", block_limit) + << LOG_KV("value", std::string(value ? value : "")) + << LOG_KV("gas_price", std::string(gas_price ? gas_price : "")) + << LOG_KV("gas_limit", gas_limit) << LOG_KV("error", errorMsg); + bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); + } + + return NULL; +} + +void* bcos_sdk_create_eip1559_transaction_data(const char* group_id, const char* chain_id, + const char* to, const char* input, const char* abi, int64_t block_limit, const char* value, + int64_t gas_limit, const char* max_fee_per_gas, const char* max_priority_fee_per_gas) +{ + bcos_sdk_clear_last_error(); + BCOS_SDK_C_PARAMS_VERIFICATION(group_id, NULL) + BCOS_SDK_C_PARAMS_VERIFICATION(chain_id, NULL) + BCOS_SDK_C_PARAMS_VERIFICATION(input, NULL) + BCOS_SDK_C_PARAMS_VERIFY_CONDITION((block_limit > 0), "block limit must > 0", NULL) + BCOS_SDK_C_PARAMS_VERIFY_CONDITION((gas_limit > 0), "gas limit must > 0", NULL) + + try + { + TransactionBuilderV2 builder; + auto bytesData = fromHexString(input); + auto transactionData = builder.createTransactionData(1, group_id, chain_id, to, "", + *bytesData, abi, block_limit, value ? value : "", "", gas_limit, + max_fee_per_gas ? max_fee_per_gas : "", + max_priority_fee_per_gas ? max_priority_fee_per_gas : ""); + return transactionData.release(); + } + catch (const std::exception& e) + { + std::string errorMsg = boost::diagnostic_information(e); + BCOS_LOG(WARNING) + << LOG_BADGE("bcos_sdk_create_eip1559_transaction_data") << LOG_DESC("exception") + << LOG_KV("group_id", group_id) << LOG_KV("chain_id", chain_id) + << LOG_KV("to", std::string(to ? to : "")) << LOG_KV("input", input) + << LOG_KV("abi", std::string(abi ? abi : "")) << LOG_KV("block_limit", block_limit) + << LOG_KV("value", std::string(value ? value : "")) << LOG_KV("gas_limit", gas_limit) + << LOG_KV("max_fee_per_gas", std::string(max_fee_per_gas ? max_fee_per_gas : "")) + << LOG_KV("max_priority_fee_per_gas", + std::string(max_priority_fee_per_gas ? max_priority_fee_per_gas : "")) + << LOG_KV("error", errorMsg); + bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); + } + return nullptr; +} + + +const char* bcos_sdk_calc_transaction_data_hash_with_full_fields(int crypto_type, + transaction_version version, const char* group_id, const char* chain_id, const char* to, + const char* nonce, const char* input, const char* abi, int64_t block_limit, const char* value, + const char* gas_price, int64_t gas_limit, const char* max_fee_per_gas, + const char* max_priority_fee_per_gas) +{ + bcos_sdk_clear_last_error(); + BCOS_SDK_C_PARAMS_VERIFICATION(group_id, NULL) + BCOS_SDK_C_PARAMS_VERIFICATION(chain_id, NULL) + BCOS_SDK_C_PARAMS_VERIFICATION(input, NULL) + BCOS_SDK_C_PARAMS_VERIFICATION(nonce, NULL) + BCOS_SDK_C_PARAMS_VERIFY_CONDITION((block_limit > 0), "block limit must > 0", NULL) + BCOS_SDK_C_PARAMS_VERIFY_CONDITION((gas_limit > 0), "gas limit must > 0", NULL) + + try + { + auto bytesData = fromHexString(input); + TransactionBuilderV2 builder; + auto transactionDataHash = builder.calculateTransactionDataHash( + crypto_type == BCOS_C_SDK_ECDSA_TYPE ? CryptoType::Secp256K1 : CryptoType::SM2, version, + group_id, chain_id, to ? to : "", nonce, *bytesData, abi ? abi : "", block_limit, + value ? value : "", gas_price ? gas_price : "", gas_limit, + max_fee_per_gas ? max_fee_per_gas : "", + max_priority_fee_per_gas ? max_priority_fee_per_gas : ""); + return strdup(bcos::toHexStringWithPrefix(transactionDataHash).c_str()); + } + catch (const std::exception& e) + { + std::string errorMsg = boost::diagnostic_information(e); + BCOS_LOG(WARNING) + << LOG_BADGE("bcos_sdk_calc_transaction_data_hash_with_full_fields") + << LOG_DESC("exception") << LOG_KV("group_id", group_id) << LOG_KV("chain_id", chain_id) + << LOG_KV("to", std::string(to ? to : "")) + << LOG_KV("nonce", std::string(nonce ? nonce : "")) << LOG_KV("input", input) + << LOG_KV("abi", std::string(abi ? abi : "")) << LOG_KV("block_limit", block_limit) + << LOG_KV("value", std::string(value ? value : "")) + << LOG_KV("gas_price", std::string(gas_price ? gas_price : "")) + << LOG_KV("gas_limit", gas_limit) + << LOG_KV("max_fee_per_gas", std::string(max_fee_per_gas ? max_fee_per_gas : "")) + << LOG_KV("max_priority_fee_per_gas", + std::string(max_priority_fee_per_gas ? max_priority_fee_per_gas : "")) + << LOG_KV("error", errorMsg); + bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); + } + return nullptr; +} + +const char* bcos_sdk_calc_transaction_data_hash_with_json(int crypto_type, const char* json) +{ + bcos_sdk_clear_last_error(); + BCOS_SDK_C_PARAMS_VERIFICATION(json, NULL) + + try + { + TransactionBuilderV2 builder; + auto transactionDataHash = builder.calculateTransactionDataHashWithJson( + crypto_type == BCOS_C_SDK_ECDSA_TYPE ? CryptoType::Secp256K1 : CryptoType::SM2, json); + return strdup(bcos::toHexStringWithPrefix(transactionDataHash).c_str()); + } + catch (const std::exception& e) + { + std::string errorMsg = boost::diagnostic_information(e); + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_calc_transaction_data_hash_with_json") + << LOG_DESC("exception") << LOG_KV("json", json) + << LOG_KV("error", errorMsg); + bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); + } + return nullptr; +} + +const char* bcos_sdk_create_signed_transaction_with_signature(const char* signature, + const char* transaction_hash, transaction_version version, const char* group_id, + const char* chain_id, const char* to, const char* nonce, const char* input, const char* abi, + int64_t block_limit, const char* value, const char* gas_price, int64_t gas_limit, + const char* max_fee_per_gas, const char* max_priority_fee_per_gas, int32_t attribute, + const char* extra_data) +{ + bcos_sdk_clear_last_error(); + BCOS_SDK_C_PARAMS_VERIFICATION(signature, NULL) + BCOS_SDK_C_PARAMS_VERIFICATION(transaction_hash, NULL) + BCOS_SDK_C_PARAMS_VERIFICATION(group_id, NULL) + BCOS_SDK_C_PARAMS_VERIFICATION(chain_id, NULL) + BCOS_SDK_C_PARAMS_VERIFICATION(input, NULL) + BCOS_SDK_C_PARAMS_VERIFY_CONDITION((block_limit > 0), "block limit must > 0", NULL) + BCOS_SDK_C_PARAMS_VERIFY_CONDITION((gas_limit > 0), "gas limit must > 0", NULL) + + try + { + TransactionBuilderV2 builder; + auto bytesData = fromHexString(input); + crypto::HashType tx_hash(fromHex(std::string_view(transaction_hash))); + bytes sign = fromHex(std::string_view(signature)); + + auto transaction = builder.createTransaction(std::move(sign), tx_hash, attribute, + (int32_t)version, group_id, chain_id, to ? to : "", nonce ? nonce : "", *bytesData, + abi ? abi : "", block_limit, value ? value : "", gas_price ? gas_price : "", gas_limit, + max_fee_per_gas ? max_fee_per_gas : "", + max_priority_fee_per_gas ? max_priority_fee_per_gas : "", extra_data ? extra_data : ""); + + auto bytes = builder.encodeTransaction(*transaction); + + return strdup(bcos::toHexStringWithPrefix(*bytes).c_str()); + } + catch (const std::exception& e) + { + std::string errorMsg = boost::diagnostic_information(e); + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_create_signed_transaction_with_signature") + << LOG_DESC("exception") << LOG_KV("signature", signature) + << LOG_KV("transaction_hash", transaction_hash) + << LOG_KV("group_id", group_id) << LOG_KV("chain_id", chain_id) + << LOG_KV("to", std::string(to ? to : "")) + << LOG_KV("nonce", std::string(nonce ? nonce : "")) + << LOG_KV("input", input) << LOG_KV("abi", std::string(abi ? abi : "")) + << LOG_KV("block_limit", block_limit) + << LOG_KV("value", std::string(value ? value : "")) + << LOG_KV("gas_price", std::string(gas_price ? gas_price : "")) + << LOG_KV("gas_limit", gas_limit) + << LOG_KV("max_fee_per_gas", + std::string(max_fee_per_gas ? max_fee_per_gas : "")); + bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); + } + return nullptr; +} + +void bcos_sdk_create_signed_transaction_with_full_fields(void* key_pair, const char* group_id, + const char* chain_id, const char* to, const char* input, const char* abi, int64_t block_limit, + const char* value, const char* gas_price, int64_t gas_limit, int32_t attribute, + const char* extra_data, char** tx_hash, char** signed_tx) +{ + bcos_sdk_clear_last_error(); + BCOS_SDK_C_PARAMS_VERIFICATION(key_pair, ) + BCOS_SDK_C_PARAMS_VERIFICATION(group_id, ) + BCOS_SDK_C_PARAMS_VERIFICATION(chain_id, ) + BCOS_SDK_C_PARAMS_VERIFICATION(input, ) + BCOS_SDK_C_PARAMS_VERIFY_CONDITION((block_limit > 0), "block limit must > 0", ) + BCOS_SDK_C_PARAMS_VERIFY_CONDITION((gas_limit > 0), "gas limit must > 0", ) + BCOS_SDK_C_PARAMS_VERIFICATION(tx_hash, ) + BCOS_SDK_C_PARAMS_VERIFICATION(signed_tx, ) + + try + { + TransactionBuilderV2 builder; + auto bytesData = fromHexString(input); + auto result = builder.createSignedTransaction(*((bcos::crypto::KeyPairInterface*)key_pair), + attribute, 1, group_id, chain_id, to ? to : "", "", *bytesData, abi ? abi : "", + block_limit, value ? value : "", gas_price ? gas_price : "", gas_limit, "", "", + extra_data ? extra_data : ""); + *tx_hash = strdup(result.first.c_str()); + *signed_tx = strdup(bcos::toHexStringWithPrefix(result.second).c_str()); + } + catch (const std::exception& e) + { + std::string errorMsg = boost::diagnostic_information(e); + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_create_signed_transaction_with_full_fields") + << LOG_DESC("exception") << LOG_KV("group_id", group_id) + << LOG_KV("chain_id", chain_id) << LOG_KV("to", std::string(to ? to : "")) + << LOG_KV("input", input) << LOG_KV("abi", std::string(abi ? abi : "")) + << LOG_KV("block_limit", block_limit) + << LOG_KV("value", std::string(value ? value : "")) + << LOG_KV("gas_price", std::string(gas_price ? gas_price : "")) + << LOG_KV("gas_limit", gas_limit) << LOG_KV("attribute", attribute) + << LOG_KV("extra_data", std::string(extra_data ? extra_data : "")) + << LOG_KV("error", errorMsg); + bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); + } +} + +void bcos_sdk_create_signed_eip1559_transaction_with_full_fields(void* key_pair, + const char* group_id, const char* chain_id, const char* to, const char* input, const char* abi, + int64_t block_limit, const char* value, int64_t gas_limit, const char* max_fee_per_gas, + const char* max_priority_fee_per_gas, int32_t attribute, const char* extra_data, char** tx_hash, + char** signed_tx) +{ + bcos_sdk_clear_last_error(); + BCOS_SDK_C_PARAMS_VERIFICATION(key_pair, ) + BCOS_SDK_C_PARAMS_VERIFICATION(group_id, ) + BCOS_SDK_C_PARAMS_VERIFICATION(chain_id, ) + BCOS_SDK_C_PARAMS_VERIFICATION(input, ) + BCOS_SDK_C_PARAMS_VERIFY_CONDITION((block_limit > 0), "block limit must > 0", ) + BCOS_SDK_C_PARAMS_VERIFY_CONDITION((gas_limit > 0), "gas limit must > 0", ) + BCOS_SDK_C_PARAMS_VERIFICATION(tx_hash, ) + BCOS_SDK_C_PARAMS_VERIFICATION(signed_tx, ) + + try + { + TransactionBuilderV2 builder; + auto bytesData = fromHexString(input); + auto result = builder.createSignedTransaction(*((bcos::crypto::KeyPairInterface*)key_pair), + attribute, 1, group_id, chain_id, to ? to : "", "", *bytesData, abi ? abi : "", + block_limit, value ? value : "", "", gas_limit, max_fee_per_gas ? max_fee_per_gas : "", + max_priority_fee_per_gas ? max_priority_fee_per_gas : "", extra_data ? extra_data : ""); + *tx_hash = strdup(result.first.c_str()); + *signed_tx = strdup(bcos::toHexStringWithPrefix(result.second).c_str()); + } + catch (const std::exception& e) + { + std::string errorMsg = boost::diagnostic_information(e); + BCOS_LOG(WARNING) + << LOG_BADGE("bcos_sdk_create_signed_eip1559_transaction_with_full_fields") + << LOG_DESC("exception") << LOG_KV("group_id", group_id) << LOG_KV("chain_id", chain_id) + << LOG_KV("to", std::string(to ? to : "")) << LOG_KV("input", input) + << LOG_KV("abi", std::string(abi ? abi : "")) << LOG_KV("block_limit", block_limit) + << LOG_KV("value", std::string(value ? value : "")) << LOG_KV("gas_limit", gas_limit) + << LOG_KV("max_fee_per_gas", std::string(max_fee_per_gas ? max_fee_per_gas : "")) + << LOG_KV("max_priority_fee_per_gas", + std::string(max_priority_fee_per_gas ? max_priority_fee_per_gas : "")) + << LOG_KV("attribute", attribute) + << LOG_KV("extra_data", std::string(extra_data ? extra_data : "")) + << LOG_KV("error", errorMsg); + bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); + } +} diff --git a/bcos-c-sdk/bcos_sdk_c_uti_tx_v2.h b/bcos-c-sdk/bcos_sdk_c_uti_tx_v2.h new file mode 100644 index 000000000..3812cb030 --- /dev/null +++ b/bcos-c-sdk/bcos_sdk_c_uti_tx_v2.h @@ -0,0 +1,200 @@ +/** + * Copyright (C) 2022 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 bcos_sdk_c_uti_tx_v2.h + * @author: kyonGuo + * @date 2023/11/28 + */ + +#ifndef BCOS_C_SDK_BCOS_SDK_C_UTI_TX_V2_H +#define BCOS_C_SDK_BCOS_SDK_C_UTI_TX_V2_H + +#include "bcos_sdk_c_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +enum transaction_version +{ + TRANSACTION_VERSION_0 = 0, + /* + * @brief enable (value,gasPrice,gasLimit,maxFeePerGas,maxPriorityFeePerGas) fields + * @note version 1 transaction only supported in FISCO BCOS 3.6.0 and later + */ + TRANSACTION_VERSION_1 = 1, +}; + +/** + * @brief create transaction data with version 1 by default + * @note version 1 transaction only supported in FISCO BCOS 3.6.0 and later + * + * @param group_id group id + * @param chain_id chain id + * @param to contract address, if it is a contract creation transaction, it can be empty + * @param input encoded contract method and params + * @param abi contract abi, only create contract need + * @param block_limit block limit + * @param value transfer value + * @param gas_price gas price + * @param gas_limit gas limit + * @return void* transaction data pointer, you should release it after use + */ +void* bcos_sdk_create_transaction_v2_data(const char* group_id, const char* chain_id, + const char* to, const char* input, const char* abi, int64_t block_limit, const char* value, + const char* gas_price, int64_t gas_limit); + +/** + * @brief create eip1559 transaction data with version 1 by default + * @note version 1 transaction only supported in FISCO BCOS 3.6.0 and later + * + * @param group_id group id + * @param chain_id chain id + * @param to contract address, if it is a contract creation transaction, it can be empty + * @param input encoded contract method and params + * @param abi contract abi, only create contract need + * @param block_limit block limit + * @param value transfer value + * @param gas_limit gas limit + * @param max_fee_per_gas max fee per gas + * @param max_priority_fee_per_gas max priority fee per gas + * @return void* transaction data pointer, you should release it after use + */ +void* bcos_sdk_create_eip1559_transaction_data(const char* group_id, const char* chain_id, + const char* to, const char* input, const char* abi, int64_t block_limit, const char* value, + int64_t gas_limit, const char* max_fee_per_gas, const char* max_priority_fee_per_gas); + +/** + * @brief create transaction data with full fields + * @note version 1 transaction only supported in FISCO BCOS 3.6.0 and later + * + * @param crypto_type 0: keccak256, 1: sm3 + * @param version tx version, if version==1, then enable + * (value,gasPrice,gasLimit,maxFeePerGas,maxPriorityFeePerGas) fields + * @param group_id group id + * @param chain_id chain id + * @param to contract address, if it is a contract creation transaction, it can be empty + * @param nonce nonce, random number to avoid duplicate transactions + * @param input encoded contract method and params + * @param abi contract abi, only create contract need + * @param block_limit block limit + * @param value transfer value + * @param gas_price gas price + * @param gas_limit gas limit + * @param max_fee_per_gas max fee per gas + * @param max_priority_fee_per_gas max priority fee per gas + * @return const char* transaction data hash hex string + */ +const char* bcos_sdk_calc_transaction_data_hash_with_full_fields(int crypto_type, transaction_version version, + const char* group_id, const char* chain_id, const char* to, const char* nonce, + const char* input, const char* abi, int64_t block_limit, const char* value, + const char* gas_price, int64_t gas_limit, const char* max_fee_per_gas, + const char* max_priority_fee_per_gas); + +/** + * @brief create transaction data with json string + * @note version 1 transaction only supported in FISCO BCOS 3.6.0 and later + * + * @param crypto_type 0: keccak256, 1: sm3 + * @param json transaction data json string + * @return const char* transaction data hash hex string + * @throw exception if lack of some required fields, or some fields are invalid + */ +const char* bcos_sdk_calc_transaction_data_hash_with_json(int crypto_type, const char* json); + +/** + * @brief create encoded transaction data with external signature + * @note version 1 transaction only supported in FISCO BCOS 3.6.0 and later + * + * @param signature signature hex string, if ECDSA, it is r||s||v, if SM2, it is r||s||pk + * @param transaction_hash transactionData hash hex string + * @param version tx version, only support 0 and 1 now, if version==1, then enable (value,gasPrice,gasLimit,maxFeePerGas,maxPriorityFeePerGas) fields + * @param group_id group id + * @param chain_id chain id + * @param to contract address, if it is a contract creation transaction, it can be empty + * @param nonce nonce, random number to avoid duplicate transactions + * @param input encoded contract method and params + * @param abi contract abi, only create contract need + * @param block_limit block limit + * @param value transfer value + * @param gas_price gas price + * @param gas_limit gas limit + * @param max_fee_per_gas max fee per gas + * @param max_priority_fee_per_gas max priority fee per gas + * @param attribute transaction attribute + * @param extra_data extra data in transaction + * @return const char* encoded transaction hex string + */ +const char* bcos_sdk_create_signed_transaction_with_signature(const char* signature, + const char* transaction_hash, transaction_version version, const char* group_id, const char* chain_id, + const char* to, const char* nonce, const char* input, const char* abi, int64_t block_limit, + const char* value, const char* gas_price, int64_t gas_limit, const char* max_fee_per_gas, + const char* max_priority_fee_per_gas, int32_t attribute, const char* extra_data); + +/** + * @brief create transaction with full fields, with version 1 by default + * @note version 1 transaction only supported in FISCO BCOS 3.6.0 and later + * + * @param key_pair key pair pointer + * @param group_id group id + * @param chain_id chain id + * @param to contract address, if it is a contract creation transaction, it can be empty + * @param nonce nonce, random number to avoid duplicate transactions + * @param input encoded contract method and params + * @param abi contract abi, only create contract need + * @param block_limit block limit + * @param value transfer value + * @param gas_price gas price + * @param gas_limit gas limit + * @param attribute transaction attribute + * @param extra_data extra data in transaction + * @param tx_hash output transaction hash hex string + * @param signed_tx output signed transaction hex string + */ +void bcos_sdk_create_signed_transaction_with_full_fields(void* key_pair, const char* group_id, + const char* chain_id, const char* to, const char* input, const char* abi, int64_t block_limit, + const char* value, const char* gas_price, int64_t gas_limit, int32_t attribute, + const char* extra_data, char** tx_hash, char** signed_tx); + +/** + * @brief create eip1559 transaction with full fields, with version 1 by default + * @note version 1 transaction only supported in FISCO BCOS 3.6.0 and later + * + * @param key_pair key pair pointer + * @param group_id group id + * @param chain_id chain id + * @param to contract address, if it is a contract creation transaction, it can be empty + * @param input encoded contract method and params + * @param abi contract abi, only create contract need + * @param block_limit block limit + * @param value transfer value + * @param gas_limit gas limit + * @param max_fee_per_gas max fee per gas + * @param max_priority_fee_per_gas max priority fee per gas + * @param attribute transaction attribute + * @param extra_data extra data in transaction + * @param tx_hash output transaction hash hex string + * @param signed_tx output signed transaction hex string + */ +void bcos_sdk_create_signed_eip1559_transaction_with_full_fields(void* key_pair, + const char* group_id, const char* chain_id, const char* to, const char* input, const char* abi, + int64_t block_limit, const char* value, int64_t gas_limit, const char* max_fee_per_gas, + const char* max_priority_fee_per_gas, int32_t attribute, const char* extra_data, char** tx_hash, + char** signed_tx); + +#ifdef __cplusplus +} +#endif +#endif // BCOS_C_SDK_BCOS_SDK_C_UTI_TX_V2_H diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json index 98c7092a7..446f88340 100644 --- a/vcpkg-configuration.json +++ b/vcpkg-configuration.json @@ -3,7 +3,7 @@ { "kind": "git", "repository": "https://github.com/FISCO-BCOS/registry", - "baseline": "717d8236aae1c032cfdd9469fd8248c8e49da6d3", + "baseline": "c15466a352b8daede8d2c447670a761ad736c132", "packages": [ "openssl", "hsm-crypto",