From 130bb282291607681cf72820d90a711b2111205c Mon Sep 17 00:00:00 2001 From: kyonRay Date: Thu, 1 Feb 2024 19:33:25 +0800 Subject: [PATCH] (tx): change transaction v2 to v1. --- bcos-c-sdk/bcos_sdk_c_common.cpp | 4 + bcos-c-sdk/bcos_sdk_c_common.h | 6 +- bcos-c-sdk/bcos_sdk_c_uti_tx_struct.cpp | 360 +++++---- bcos-c-sdk/bcos_sdk_c_uti_tx_struct.h | 48 +- ...uti_tx_v2.cpp => bcos_sdk_c_uti_tx_v1.cpp} | 22 +- ...k_c_uti_tx_v2.h => bcos_sdk_c_uti_tx_v1.h} | 10 +- bindings/java/jni/scripts/java2jni.sh | 2 +- ...ilities_tx_TransactionBuilderV1JniObj.cpp} | 36 +- ...utilities_tx_TransactionBuilderV1JniObj.h} | 34 +- ...ties_tx_TransactionStructBuilderJniObj.cpp | 128 ++-- ...lities_tx_TransactionStructBuilderJniObj.h | 10 +- ...es_tx_TransactionStructBuilderV2JniObj.cpp | 724 ------------------ ...ties_tx_TransactionStructBuilderV2JniObj.h | 77 -- .../sdk/jni/utilities/tx/Transaction.java | 2 +- ...j.java => TransactionBuilderV1JniObj.java} | 2 +- ...tionDataV2.java => TransactionDataV1.java} | 2 +- .../tx/TransactionStructBuilderJniObj.java | 8 +- .../jni/utilities/tx/TransactionVersion.java | 36 +- .../bcos/sdk/jni/test/tx/TestTxStruct.java | 388 +++++----- .../bcos/sdk/jni/test/tx/TestTxStructV1.java | 272 +++++++ .../bcos/sdk/jni/test/tx/TestTxStructV2.java | 293 ------- sample/tx/CMakeLists.txt | 4 +- ...x_struct_v2_test.c => tx_struct_v1_test.c} | 168 ++-- ...ructV2.cpp => testTransactionStructV1.cpp} | 252 +++--- vcpkg-configuration.json | 2 +- 25 files changed, 1044 insertions(+), 1846 deletions(-) rename bcos-c-sdk/{bcos_sdk_c_uti_tx_v2.cpp => bcos_sdk_c_uti_tx_v1.cpp} (97%) rename bcos-c-sdk/{bcos_sdk_c_uti_tx_v2.h => bcos_sdk_c_uti_tx_v1.h} (97%) rename bindings/java/jni/src/main/c/jni/{org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj.cpp => org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj.cpp} (96%) rename bindings/java/jni/src/main/c/jni/{org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj.h => org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj.h} (86%) delete mode 100644 bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj.cpp delete mode 100644 bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj.h rename bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/{TransactionBuilderV2JniObj.java => TransactionBuilderV1JniObj.java} (99%) rename bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/{TransactionDataV2.java => TransactionDataV1.java} (94%) create mode 100644 bindings/java/jni/src/test/java/org/fisco/bcos/sdk/jni/test/tx/TestTxStructV1.java delete mode 100644 bindings/java/jni/src/test/java/org/fisco/bcos/sdk/jni/test/tx/TestTxStructV2.java rename sample/tx/{tx_struct_v2_test.c => tx_struct_v1_test.c} (74%) rename test/{testTransactionStructV2.cpp => testTransactionStructV1.cpp} (85%) diff --git a/bcos-c-sdk/bcos_sdk_c_common.cpp b/bcos-c-sdk/bcos_sdk_c_common.cpp index 2cb7d34b7..e9683ea1c 100644 --- a/bcos-c-sdk/bcos_sdk_c_common.cpp +++ b/bcos-c-sdk/bcos_sdk_c_common.cpp @@ -59,6 +59,10 @@ struct bcos_sdk_c_config* bcos_sdk_c_config_create_empty() char* my_strdup(const char* s) { + if (s == NULL) + { + return NULL; + } size_t len = strlen(s) + 1; char* result = (char*)malloc(len); if (result == (char*)0) diff --git a/bcos-c-sdk/bcos_sdk_c_common.h b/bcos-c-sdk/bcos_sdk_c_common.h index f381f2182..cd9beefd0 100644 --- a/bcos-c-sdk/bcos_sdk_c_common.h +++ b/bcos-c-sdk/bcos_sdk_c_common.h @@ -209,7 +209,7 @@ struct bcos_sdk_c_transaction_data struct bcos_sdk_c_bytes* input; }; -struct bcos_sdk_c_transaction_data_v2 +struct bcos_sdk_c_transaction_data_v1 { int32_t version; int64_t block_limit; @@ -241,9 +241,9 @@ struct bcos_sdk_c_transaction char* extra_data; }; -struct bcos_sdk_c_transaction_v2 +struct bcos_sdk_c_transaction_v1 { - struct bcos_sdk_c_transaction_data_v2* transaction_data; + struct bcos_sdk_c_transaction_data_v1* transaction_data; struct bcos_sdk_c_bytes* data_hash; struct bcos_sdk_c_bytes* signature; struct bcos_sdk_c_bytes* sender; diff --git a/bcos-c-sdk/bcos_sdk_c_uti_tx_struct.cpp b/bcos-c-sdk/bcos_sdk_c_uti_tx_struct.cpp index bd2817932..fa37c723d 100644 --- a/bcos-c-sdk/bcos_sdk_c_uti_tx_struct.cpp +++ b/bcos-c-sdk/bcos_sdk_c_uti_tx_struct.cpp @@ -126,38 +126,38 @@ struct bcos_sdk_c_transaction_data* transaction_data_copy( return NULL; } -struct bcos_sdk_c_transaction_data_v2* transaction_data_copy_v2( - const bcos_sdk_c_transaction_data_v2* tx_data_src) +struct bcos_sdk_c_transaction_data_v1* transaction_data_copy_v1( + const bcos_sdk_c_transaction_data_v1* tx_data_src) { bcos_sdk_clear_last_error(); BCOS_SDK_C_PARAMS_VERIFICATION(tx_data_src, NULL); try { - struct bcos_sdk_c_transaction_data_v2* transaction_data_struct_v2 = - (struct bcos_sdk_c_transaction_data_v2*)malloc( - sizeof(struct bcos_sdk_c_transaction_data_v2)); - transaction_data_struct_v2->version = tx_data_src->version; - transaction_data_struct_v2->block_limit = tx_data_src->block_limit; - transaction_data_struct_v2->chain_id = my_strdup(tx_data_src->chain_id); - transaction_data_struct_v2->group_id = my_strdup(tx_data_src->group_id); - transaction_data_struct_v2->nonce = my_strdup(tx_data_src->nonce); - transaction_data_struct_v2->to = my_strdup(tx_data_src->to); - transaction_data_struct_v2->abi = my_strdup(tx_data_src->abi); - transaction_data_struct_v2->input = bytes_struct_copy(tx_data_src->input); - transaction_data_struct_v2->value = my_strdup(tx_data_src->value); - transaction_data_struct_v2->gas_price = my_strdup(tx_data_src->gas_price); - transaction_data_struct_v2->gas_limit = tx_data_src->gas_limit; - transaction_data_struct_v2->max_fee_per_gas = my_strdup(tx_data_src->max_fee_per_gas); - transaction_data_struct_v2->max_priority_fee_per_gas = + struct bcos_sdk_c_transaction_data_v1* transaction_data_struct_v1 = + (struct bcos_sdk_c_transaction_data_v1*)malloc( + sizeof(struct bcos_sdk_c_transaction_data_v1)); + transaction_data_struct_v1->version = tx_data_src->version; + transaction_data_struct_v1->block_limit = tx_data_src->block_limit; + transaction_data_struct_v1->chain_id = my_strdup(tx_data_src->chain_id); + transaction_data_struct_v1->group_id = my_strdup(tx_data_src->group_id); + transaction_data_struct_v1->nonce = my_strdup(tx_data_src->nonce); + transaction_data_struct_v1->to = my_strdup(tx_data_src->to); + transaction_data_struct_v1->abi = my_strdup(tx_data_src->abi); + transaction_data_struct_v1->input = bytes_struct_copy(tx_data_src->input); + transaction_data_struct_v1->value = my_strdup(tx_data_src->value); + transaction_data_struct_v1->gas_price = my_strdup(tx_data_src->gas_price); + transaction_data_struct_v1->gas_limit = tx_data_src->gas_limit; + transaction_data_struct_v1->max_fee_per_gas = my_strdup(tx_data_src->max_fee_per_gas); + transaction_data_struct_v1->max_priority_fee_per_gas = my_strdup(tx_data_src->max_priority_fee_per_gas); - return transaction_data_struct_v2; + return transaction_data_struct_v1; } catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("transaction_data_copy_v2") << LOG_DESC("exception") + BCOS_LOG(WARNING) << LOG_BADGE("transaction_data_copy_v1") << LOG_DESC("exception") << LOG_KV("tx_data_src", tx_data_src) << LOG_KV("error", errorMsg); bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); } @@ -208,44 +208,42 @@ struct bcos_sdk_c_transaction_data* convert_tars_transaction_data_to_struct( return NULL; } -struct bcos_sdk_c_transaction_data_v2* convert_tars_transaction_data_to_struct_v2( +struct bcos_sdk_c_transaction_data_v1* convert_tars_transaction_data_to_struct_v1( bcostars::TransactionDataUniquePtr tars_transaction_data) { bcos_sdk_clear_last_error(); BCOS_SDK_C_PARAMS_VERIFICATION(tars_transaction_data, NULL); - BCOS_SDK_C_PARAMS_VERIFY_CONDITION( - (tars_transaction_data->version == 1), "version of tars tx data V2 must be 1", NULL); try { - struct bcos_sdk_c_transaction_data_v2* transaction_data_struct_v2 = - (struct bcos_sdk_c_transaction_data_v2*)malloc( - sizeof(struct bcos_sdk_c_transaction_data_v2)); + struct bcos_sdk_c_transaction_data_v1* transaction_data_struct_v1 = + (struct bcos_sdk_c_transaction_data_v1*)malloc( + sizeof(struct bcos_sdk_c_transaction_data_v1)); struct bcos_sdk_c_bytes* input_bytes = create_bytes_struct( tars_transaction_data->input.size(), tars_transaction_data->input.data()); - transaction_data_struct_v2->input = input_bytes; - transaction_data_struct_v2->version = tars_transaction_data->version; - transaction_data_struct_v2->block_limit = tars_transaction_data->blockLimit; - transaction_data_struct_v2->chain_id = my_strdup(tars_transaction_data->chainID.data()); - transaction_data_struct_v2->group_id = my_strdup(tars_transaction_data->groupID.data()); - transaction_data_struct_v2->nonce = my_strdup(tars_transaction_data->nonce.data()); - transaction_data_struct_v2->to = my_strdup(tars_transaction_data->to.data()); - transaction_data_struct_v2->abi = my_strdup(tars_transaction_data->abi.data()); - transaction_data_struct_v2->value = my_strdup(tars_transaction_data->value.data()); - transaction_data_struct_v2->gas_price = my_strdup(tars_transaction_data->gasPrice.data()); - transaction_data_struct_v2->gas_limit = tars_transaction_data->gasLimit; - transaction_data_struct_v2->max_fee_per_gas = + transaction_data_struct_v1->input = input_bytes; + transaction_data_struct_v1->version = tars_transaction_data->version; + transaction_data_struct_v1->block_limit = tars_transaction_data->blockLimit; + transaction_data_struct_v1->chain_id = my_strdup(tars_transaction_data->chainID.data()); + transaction_data_struct_v1->group_id = my_strdup(tars_transaction_data->groupID.data()); + transaction_data_struct_v1->nonce = my_strdup(tars_transaction_data->nonce.data()); + transaction_data_struct_v1->to = my_strdup(tars_transaction_data->to.data()); + transaction_data_struct_v1->abi = my_strdup(tars_transaction_data->abi.data()); + transaction_data_struct_v1->value = my_strdup(tars_transaction_data->value.data()); + transaction_data_struct_v1->gas_price = my_strdup(tars_transaction_data->gasPrice.data()); + transaction_data_struct_v1->gas_limit = tars_transaction_data->gasLimit; + transaction_data_struct_v1->max_fee_per_gas = my_strdup(tars_transaction_data->maxFeePerGas.data()); - transaction_data_struct_v2->max_priority_fee_per_gas = + transaction_data_struct_v1->max_priority_fee_per_gas = my_strdup(tars_transaction_data->maxPriorityFeePerGas.data()); - return transaction_data_struct_v2; + return transaction_data_struct_v1; } catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("convert_tars_transaction_data_to_struct_v2") + BCOS_LOG(WARNING) << LOG_BADGE("convert_tars_transaction_data_to_struct_v1") << LOG_DESC("exception") << LOG_KV("transaction data", tars_transaction_data) << LOG_KV("error", errorMsg); @@ -294,8 +292,8 @@ bcostars::TransactionDataUniquePtr convert_transaction_data_to_tars( return NULL; } -bcostars::TransactionDataUniquePtr convert_transaction_data_to_tars_v2( - struct bcos_sdk_c_transaction_data_v2* transaction_data) +bcostars::TransactionDataUniquePtr convert_transaction_data_to_tars_v1( + struct bcos_sdk_c_transaction_data_v1* transaction_data) { bcos_sdk_clear_last_error(); BCOS_SDK_C_PARAMS_VERIFICATION(transaction_data, NULL); @@ -303,36 +301,36 @@ bcostars::TransactionDataUniquePtr convert_transaction_data_to_tars_v2( BCOS_SDK_C_PARAMS_VERIFICATION(transaction_data->chain_id, NULL); BCOS_SDK_C_PARAMS_VERIFICATION(transaction_data->input, NULL); BCOS_SDK_C_PARAMS_VERIFICATION(transaction_data->value, NULL); - BCOS_SDK_C_PARAMS_VERIFY_CONDITION( - (transaction_data->version == 1), "version of tx data struct V2 must be 1", NULL); try { - auto tars_transaction_data_v2 = std::make_unique(); + auto tars_transaction_data_v1 = std::make_unique(); + tars_transaction_data_v1->input.reserve(transaction_data->input->length); for (size_t i = 0; i < transaction_data->input->length; ++i) { - tars_transaction_data_v2->input.push_back(transaction_data->input->buffer[i]); + tars_transaction_data_v1->input.push_back( + static_cast(transaction_data->input->buffer[i])); } - tars_transaction_data_v2->version = (tars::Int32)transaction_data->version; - tars_transaction_data_v2->blockLimit = (tars::Int64)transaction_data->block_limit; - tars_transaction_data_v2->chainID = std::string(transaction_data->chain_id); - tars_transaction_data_v2->groupID = std::string(transaction_data->group_id); - tars_transaction_data_v2->nonce = std::string(transaction_data->nonce); - tars_transaction_data_v2->to = std::string(transaction_data->to); - tars_transaction_data_v2->abi = std::string(transaction_data->abi); - tars_transaction_data_v2->value = std::string(transaction_data->value); - tars_transaction_data_v2->gasPrice = std::string(transaction_data->gas_price); - tars_transaction_data_v2->gasLimit = (tars::Int64)transaction_data->gas_limit; - tars_transaction_data_v2->maxFeePerGas = std::string(transaction_data->max_fee_per_gas); - tars_transaction_data_v2->maxPriorityFeePerGas = + tars_transaction_data_v1->version = (tars::Int32)transaction_data->version; + tars_transaction_data_v1->blockLimit = (tars::Int64)transaction_data->block_limit; + tars_transaction_data_v1->chainID = std::string(transaction_data->chain_id); + tars_transaction_data_v1->groupID = std::string(transaction_data->group_id); + tars_transaction_data_v1->nonce = std::string(transaction_data->nonce); + tars_transaction_data_v1->to = std::string(transaction_data->to); + tars_transaction_data_v1->abi = std::string(transaction_data->abi); + tars_transaction_data_v1->value = std::string(transaction_data->value); + tars_transaction_data_v1->gasPrice = std::string(transaction_data->gas_price); + tars_transaction_data_v1->gasLimit = (tars::Int64)transaction_data->gas_limit; + tars_transaction_data_v1->maxFeePerGas = std::string(transaction_data->max_fee_per_gas); + tars_transaction_data_v1->maxPriorityFeePerGas = std::string(transaction_data->max_priority_fee_per_gas); - return tars_transaction_data_v2; + return tars_transaction_data_v1; } catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("convert_transaction_data_to_tars_v2") + BCOS_LOG(WARNING) << LOG_BADGE("convert_transaction_data_to_tars_v1") << LOG_DESC("exception") << LOG_KV("transaction data", transaction_data) << LOG_KV("error", errorMsg); bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); @@ -387,8 +385,8 @@ bcostars::TransactionUniquePtr convert_transaction_to_tars( return NULL; } -bcostars::TransactionUniquePtr convert_transaction_to_tars_v2( - struct bcos_sdk_c_transaction_v2* transaction) +bcostars::TransactionUniquePtr convert_transaction_to_tars_v1( + struct bcos_sdk_c_transaction_v1* transaction) { bcos_sdk_clear_last_error(); BCOS_SDK_C_PARAMS_VERIFICATION(transaction, NULL); @@ -399,7 +397,7 @@ bcostars::TransactionUniquePtr convert_transaction_to_tars_v2( { auto tars_transaction = std::make_unique(); auto TransactionDataUniquePtr = - convert_transaction_data_to_tars_v2(transaction->transaction_data); + convert_transaction_data_to_tars_v1(transaction->transaction_data); tars_transaction->data = *TransactionDataUniquePtr; for (size_t i = 0; i < transaction->data_hash->length; ++i) { @@ -425,7 +423,7 @@ bcostars::TransactionUniquePtr convert_transaction_to_tars_v2( catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("convert_transaction_to_tars_v2") << LOG_DESC("exception") + BCOS_LOG(WARNING) << LOG_BADGE("convert_transaction_to_tars_v1") << LOG_DESC("exception") << LOG_KV("transaction", transaction) << LOG_KV("error", errorMsg); bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); } @@ -474,7 +472,7 @@ struct bcos_sdk_c_transaction* convert_tars_transaction_to_struct( return NULL; } -struct bcos_sdk_c_transaction_v2* convert_tars_transaction_to_struct_v2( +struct bcos_sdk_c_transaction_v1* convert_tars_transaction_to_struct_v1( bcostars::TransactionUniquePtr tars_transaction) { bcos_sdk_clear_last_error(); @@ -482,8 +480,8 @@ struct bcos_sdk_c_transaction_v2* convert_tars_transaction_to_struct_v2( try { - struct bcos_sdk_c_transaction_v2* transaction_struct_v2 = - (struct bcos_sdk_c_transaction_v2*)malloc(sizeof(struct bcos_sdk_c_transaction_v2)); + struct bcos_sdk_c_transaction_v1* transaction_struct_v1 = + (struct bcos_sdk_c_transaction_v1*)malloc(sizeof(struct bcos_sdk_c_transaction_v1)); struct bcos_sdk_c_bytes* data_hash_bytes = create_bytes_struct( tars_transaction->dataHash.size(), tars_transaction->dataHash.data()); struct bcos_sdk_c_bytes* signature_bytes = create_bytes_struct( @@ -493,20 +491,20 @@ struct bcos_sdk_c_transaction_v2* convert_tars_transaction_to_struct_v2( auto transactionDataUniquePtr = std::make_unique(tars_transaction->data); - transaction_struct_v2->transaction_data = - convert_tars_transaction_data_to_struct_v2(std::move(transactionDataUniquePtr)); - transaction_struct_v2->data_hash = data_hash_bytes; - transaction_struct_v2->signature = signature_bytes; - transaction_struct_v2->sender = sender_bytes; - transaction_struct_v2->import_time = tars_transaction->importTime; - transaction_struct_v2->attribute = tars_transaction->attribute; - transaction_struct_v2->extra_data = my_strdup(tars_transaction->extraData.data()); - return transaction_struct_v2; + transaction_struct_v1->transaction_data = + convert_tars_transaction_data_to_struct_v1(std::move(transactionDataUniquePtr)); + transaction_struct_v1->data_hash = data_hash_bytes; + transaction_struct_v1->signature = signature_bytes; + transaction_struct_v1->sender = sender_bytes; + transaction_struct_v1->import_time = tars_transaction->importTime; + transaction_struct_v1->attribute = tars_transaction->attribute; + transaction_struct_v1->extra_data = my_strdup(tars_transaction->extraData.data()); + return transaction_struct_v1; } catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("convert_tars_transaction_to_struct_v2") + BCOS_LOG(WARNING) << LOG_BADGE("convert_tars_transaction_to_struct_v1") << LOG_DESC("exception") << LOG_KV("transaction", tars_transaction) << LOG_KV("error", errorMsg); bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); @@ -1189,7 +1187,7 @@ struct bcos_sdk_c_transaction* bcos_sdk_decode_transaction_struct_from_json( return NULL; } -struct bcos_sdk_c_transaction_data_v2* bcos_sdk_create_transaction_data_struct_with_hex_input_v2( +struct bcos_sdk_c_transaction_data_v1* bcos_sdk_create_transaction_data_struct_with_hex_input_v1( 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, const char* max_fee_per_gas, const char* max_priority_fee_per_gas) @@ -1208,34 +1206,34 @@ struct bcos_sdk_c_transaction_data_v2* bcos_sdk_create_transaction_data_struct_w try { - struct bcos_sdk_c_transaction_data_v2* transaction_data_struct_v2 = - (struct bcos_sdk_c_transaction_data_v2*)malloc( - sizeof(struct bcos_sdk_c_transaction_data_v2)); + struct bcos_sdk_c_transaction_data_v1* transaction_data_struct_v1 = + (struct bcos_sdk_c_transaction_data_v1*)malloc( + sizeof(struct bcos_sdk_c_transaction_data_v1)); auto bytesInput = fromHexString(input); TransactionBuilder builder; std::string nonceStr = builder.generateRandomStr(); - transaction_data_struct_v2->version = 1; - transaction_data_struct_v2->block_limit = block_limit; - transaction_data_struct_v2->group_id = my_strdup(group_id); - transaction_data_struct_v2->chain_id = my_strdup(chain_id); - transaction_data_struct_v2->to = to ? my_strdup(to) : my_strdup(""); - transaction_data_struct_v2->abi = abi ? my_strdup(abi) : my_strdup(""); - transaction_data_struct_v2->nonce = my_strdup(nonceStr.data()); - transaction_data_struct_v2->input = + transaction_data_struct_v1->version = 1; + transaction_data_struct_v1->block_limit = block_limit; + transaction_data_struct_v1->group_id = my_strdup(group_id); + transaction_data_struct_v1->chain_id = my_strdup(chain_id); + transaction_data_struct_v1->to = to ? my_strdup(to) : my_strdup(""); + transaction_data_struct_v1->abi = abi ? my_strdup(abi) : my_strdup(""); + transaction_data_struct_v1->nonce = my_strdup(nonceStr.data()); + transaction_data_struct_v1->input = create_bytes_struct(bytesInput->size(), reinterpret_cast(bytesInput->data())); - transaction_data_struct_v2->value = my_strdup(value); - transaction_data_struct_v2->gas_price = my_strdup(gas_price); - transaction_data_struct_v2->gas_limit = gas_limit; - transaction_data_struct_v2->max_fee_per_gas = my_strdup(max_fee_per_gas); - transaction_data_struct_v2->max_priority_fee_per_gas = my_strdup(max_priority_fee_per_gas); + transaction_data_struct_v1->value = my_strdup(value); + transaction_data_struct_v1->gas_price = my_strdup(gas_price); + transaction_data_struct_v1->gas_limit = gas_limit; + transaction_data_struct_v1->max_fee_per_gas = my_strdup(max_fee_per_gas); + transaction_data_struct_v1->max_priority_fee_per_gas = my_strdup(max_priority_fee_per_gas); - return transaction_data_struct_v2; + return transaction_data_struct_v1; } catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_create_transaction_data_struct_with_hex_input_v2") + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_create_transaction_data_struct_with_hex_input_v1") << 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 : "")) @@ -1250,7 +1248,7 @@ struct bcos_sdk_c_transaction_data_v2* bcos_sdk_create_transaction_data_struct_w return NULL; } -struct bcos_sdk_c_transaction_data_v2* bcos_sdk_create_transaction_data_struct_with_bytes_v2( +struct bcos_sdk_c_transaction_data_v1* bcos_sdk_create_transaction_data_struct_with_bytes_v1( const char* group_id, const char* chain_id, const char* to, const unsigned char* bytes_input, uint32_t bytes_input_length, const char* abi, int64_t block_limit, const char* value, const char* gas_price, int64_t gas_limit, const char* max_fee_per_gas, @@ -1271,33 +1269,33 @@ struct bcos_sdk_c_transaction_data_v2* bcos_sdk_create_transaction_data_struct_w try { - struct bcos_sdk_c_transaction_data_v2* transaction_data_struct_v2 = - (struct bcos_sdk_c_transaction_data_v2*)malloc( - sizeof(struct bcos_sdk_c_transaction_data_v2)); + struct bcos_sdk_c_transaction_data_v1* transaction_data_struct_v1 = + (struct bcos_sdk_c_transaction_data_v1*)malloc( + sizeof(struct bcos_sdk_c_transaction_data_v1)); TransactionBuilder builder; std::string nonceStr = builder.generateRandomStr(); - transaction_data_struct_v2->version = 1; - transaction_data_struct_v2->block_limit = block_limit; - transaction_data_struct_v2->group_id = my_strdup(group_id); - transaction_data_struct_v2->chain_id = my_strdup(chain_id); - transaction_data_struct_v2->to = to ? my_strdup(to) : my_strdup(""); - transaction_data_struct_v2->abi = abi ? my_strdup(abi) : my_strdup(""); - transaction_data_struct_v2->nonce = my_strdup(nonceStr.data()); - transaction_data_struct_v2->input = create_bytes_struct( + transaction_data_struct_v1->version = 1; + transaction_data_struct_v1->block_limit = block_limit; + transaction_data_struct_v1->group_id = my_strdup(group_id); + transaction_data_struct_v1->chain_id = my_strdup(chain_id); + transaction_data_struct_v1->to = to ? my_strdup(to) : my_strdup(""); + transaction_data_struct_v1->abi = abi ? my_strdup(abi) : my_strdup(""); + transaction_data_struct_v1->nonce = my_strdup(nonceStr.data()); + transaction_data_struct_v1->input = create_bytes_struct( bytes_input_length, const_cast(reinterpret_cast(bytes_input))); - transaction_data_struct_v2->value = my_strdup(value); - transaction_data_struct_v2->gas_price = my_strdup(gas_price); - transaction_data_struct_v2->gas_limit = gas_limit; - transaction_data_struct_v2->max_fee_per_gas = my_strdup(max_fee_per_gas); - transaction_data_struct_v2->max_priority_fee_per_gas = my_strdup(max_priority_fee_per_gas); + transaction_data_struct_v1->value = my_strdup(value); + transaction_data_struct_v1->gas_price = my_strdup(gas_price); + transaction_data_struct_v1->gas_limit = gas_limit; + transaction_data_struct_v1->max_fee_per_gas = my_strdup(max_fee_per_gas); + transaction_data_struct_v1->max_priority_fee_per_gas = my_strdup(max_priority_fee_per_gas); - return transaction_data_struct_v2; + return transaction_data_struct_v1; } catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_create_transaction_data_struct_with_bytes_v2") + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_create_transaction_data_struct_with_bytes_v1") << LOG_DESC("exception") << LOG_KV("group_id", group_id) << LOG_KV("chain_id", chain_id) << LOG_KV("to", std::string(to ? to : "")) << LOG_KV("bytes_input", bytes_input) @@ -1314,8 +1312,8 @@ struct bcos_sdk_c_transaction_data_v2* bcos_sdk_create_transaction_data_struct_w return NULL; } -void bcos_sdk_destroy_transaction_data_struct_v2( - struct bcos_sdk_c_transaction_data_v2* transaction_data) +void bcos_sdk_destroy_transaction_data_struct_v1( + struct bcos_sdk_c_transaction_data_v1* transaction_data) { if (transaction_data == NULL) { @@ -1379,15 +1377,15 @@ void bcos_sdk_destroy_transaction_data_struct_v2( bcos_sdk_c_free(transaction_data); } -const char* bcos_sdk_encode_transaction_data_struct_to_hex_v2( - struct bcos_sdk_c_transaction_data_v2* transaction_data) +const char* bcos_sdk_encode_transaction_data_struct_to_hex_v1( + struct bcos_sdk_c_transaction_data_v1* transaction_data) { bcos_sdk_clear_last_error(); BCOS_SDK_C_PARAMS_VERIFICATION(transaction_data, NULL); try { - auto tars_transaction_data = convert_transaction_data_to_tars_v2(transaction_data); + auto tars_transaction_data = convert_transaction_data_to_tars_v1(transaction_data); TransactionBuilder builder; auto encodedTransactionData = builder.encodeTransactionData(*tars_transaction_data); auto hex_tx_data_str = bcos::toHexString(*encodedTransactionData); @@ -1396,7 +1394,7 @@ const char* bcos_sdk_encode_transaction_data_struct_to_hex_v2( catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_encode_transaction_data_struct_to_hex_v2") + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_encode_transaction_data_struct_to_hex_v1") << LOG_DESC("exception") << LOG_KV("transaction_data", transaction_data) << LOG_KV("error", errorMsg); bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); @@ -1405,22 +1403,22 @@ const char* bcos_sdk_encode_transaction_data_struct_to_hex_v2( return NULL; } -const char* bcos_sdk_encode_transaction_data_struct_to_json_v2( - struct bcos_sdk_c_transaction_data_v2* transaction_data) +const char* bcos_sdk_encode_transaction_data_struct_to_json_v1( + struct bcos_sdk_c_transaction_data_v1* transaction_data) { bcos_sdk_clear_last_error(); BCOS_SDK_C_PARAMS_VERIFICATION(transaction_data, NULL); try { - auto tars_transaction_data_v2 = convert_transaction_data_to_tars_v2(transaction_data); - auto json_str = tars_transaction_data_v2->writeToJsonString(); + auto tars_transaction_data_v1 = convert_transaction_data_to_tars_v1(transaction_data); + auto json_str = tars_transaction_data_v1->writeToJsonString(); return strdup(json_str.c_str()); } catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_encode_transaction_data_struct_to_json_v2") + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_encode_transaction_data_struct_to_json_v1") << LOG_DESC("exception") << LOG_KV("transaction_data", transaction_data) << LOG_KV("error", errorMsg); bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); @@ -1429,7 +1427,7 @@ const char* bcos_sdk_encode_transaction_data_struct_to_json_v2( return NULL; } -struct bcos_sdk_c_transaction_data_v2* bcos_sdk_decode_transaction_data_struct_from_hex_v2( +struct bcos_sdk_c_transaction_data_v1* bcos_sdk_decode_transaction_data_struct_from_hex_v1( const char* transaction_data_hex_str) { bcos_sdk_clear_last_error(); @@ -1443,13 +1441,13 @@ struct bcos_sdk_c_transaction_data_v2* bcos_sdk_decode_transaction_data_struct_f { TransactionBuilder builder; auto tx_data_bytes = fromHexString(transaction_data_hex_str); - auto tars_tx_data_v2 = builder.decodeTransactionData(*tx_data_bytes); - return convert_tars_transaction_data_to_struct_v2(std::move(tars_tx_data_v2)); + auto tars_tx_data_v1 = builder.decodeTransactionData(*tx_data_bytes); + return convert_tars_transaction_data_to_struct_v1(std::move(tars_tx_data_v1)); } catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_decode_transaction_data_struct_v2") + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_decode_transaction_data_struct_v1") << LOG_DESC("exception") << LOG_KV("error", errorMsg); bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); } @@ -1457,7 +1455,7 @@ struct bcos_sdk_c_transaction_data_v2* bcos_sdk_decode_transaction_data_struct_f return NULL; } -struct bcos_sdk_c_transaction_data_v2* bcos_sdk_decode_transaction_data_struct_from_json_v2( +struct bcos_sdk_c_transaction_data_v1* bcos_sdk_decode_transaction_data_struct_from_json_v1( const char* transaction_data_json_str) { bcos_sdk_clear_last_error(); @@ -1471,12 +1469,12 @@ struct bcos_sdk_c_transaction_data_v2* bcos_sdk_decode_transaction_data_struct_f auto transactionData = builder.createTransactionDataWithJson(std::string(transaction_data_json_str)); - return convert_tars_transaction_data_to_struct_v2(std::move(transactionData)); + return convert_tars_transaction_data_to_struct_v1(std::move(transactionData)); } catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_decode_transaction_data_struct_from_json_v2") + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_decode_transaction_data_struct_from_json_v1") << LOG_DESC("exception") << LOG_KV("transaction_data_json_str", transaction_data_json_str) << LOG_KV("error", errorMsg); @@ -1486,8 +1484,8 @@ struct bcos_sdk_c_transaction_data_v2* bcos_sdk_decode_transaction_data_struct_f return NULL; } -const char* bcos_sdk_calc_transaction_data_struct_hash_v2( - int crypto_type, struct bcos_sdk_c_transaction_data_v2* transaction_data) +const char* bcos_sdk_calc_transaction_data_struct_hash_v1( + int crypto_type, struct bcos_sdk_c_transaction_data_v1* transaction_data) { bcos_sdk_clear_last_error(); BCOS_SDK_C_PARAMS_VERIFICATION(transaction_data, NULL); @@ -1499,17 +1497,17 @@ const char* bcos_sdk_calc_transaction_data_struct_hash_v2( try { - auto tars_transaction_data_v2 = convert_transaction_data_to_tars_v2(transaction_data); + auto tars_transaction_data_v1 = convert_transaction_data_to_tars_v1(transaction_data); TransactionBuilder builder; auto transactionDataHash = builder.calculateTransactionDataHash( crypto_type == BCOS_C_SDK_ECDSA_TYPE ? CryptoType::Secp256K1 : CryptoType::SM2, - *tars_transaction_data_v2); + *tars_transaction_data_v1); 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_struct_hash_v2") + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_calc_transaction_data_struct_hash_v1") << LOG_DESC("exception") << LOG_KV("crypto_type", crypto_type) << LOG_KV("transaction_data", transaction_data) << LOG_KV("error", errorMsg); @@ -1519,7 +1517,7 @@ const char* bcos_sdk_calc_transaction_data_struct_hash_v2( return NULL; } -const char* bcos_sdk_calc_transaction_data_struct_hash_with_hex_v2( +const char* bcos_sdk_calc_transaction_data_struct_hash_with_hex_v1( int crypto_type, const char* transaction_data_hex) { bcos_sdk_clear_last_error(); @@ -1534,20 +1532,20 @@ const char* bcos_sdk_calc_transaction_data_struct_hash_with_hex_v2( try { - struct bcos_sdk_c_transaction_data_v2* transaction_data_struct_v2 = - bcos_sdk_decode_transaction_data_struct_from_hex_v2(transaction_data_hex); - auto tars_transaction_data_v2 = - convert_transaction_data_to_tars_v2(transaction_data_struct_v2); + struct bcos_sdk_c_transaction_data_v1* transaction_data_struct_v1 = + bcos_sdk_decode_transaction_data_struct_from_hex_v1(transaction_data_hex); + auto tars_transaction_data_v1 = + convert_transaction_data_to_tars_v1(transaction_data_struct_v1); TransactionBuilder builder; auto transactionDataHash = builder.calculateTransactionDataHash( crypto_type == BCOS_C_SDK_ECDSA_TYPE ? CryptoType::Secp256K1 : CryptoType::SM2, - *tars_transaction_data_v2); + *tars_transaction_data_v1); 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_struct_hash_with_hex_v2") + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_calc_transaction_data_struct_hash_with_hex_v1") << LOG_DESC("exception") << LOG_KV("crypto_type", crypto_type) << LOG_KV("transaction_data_hex", transaction_data_hex) << LOG_KV("error", errorMsg); @@ -1557,8 +1555,8 @@ const char* bcos_sdk_calc_transaction_data_struct_hash_with_hex_v2( return NULL; } -struct bcos_sdk_c_transaction_v2* bcos_sdk_create_transaction_struct_v2( - struct bcos_sdk_c_transaction_data_v2* transaction_data, const char* signature, +struct bcos_sdk_c_transaction_v1* bcos_sdk_create_transaction_struct_v1( + struct bcos_sdk_c_transaction_data_v1* transaction_data, const char* signature, const char* transaction_data_hash, int32_t attribute, const char* extra_data) { bcos_sdk_clear_last_error(); @@ -1572,13 +1570,13 @@ struct bcos_sdk_c_transaction_v2* bcos_sdk_create_transaction_struct_v2( try { - struct bcos_sdk_c_transaction_v2* transaction_struct_v2 = - (struct bcos_sdk_c_transaction_v2*)malloc(sizeof(struct bcos_sdk_c_transaction_v2)); - transaction_struct_v2->transaction_data = transaction_data_copy_v2(transaction_data); - transaction_struct_v2->sender = NULL; - transaction_struct_v2->import_time = 0; - transaction_struct_v2->attribute = attribute; - transaction_struct_v2->extra_data = extra_data ? my_strdup(extra_data) : my_strdup(""); + struct bcos_sdk_c_transaction_v1* transaction_struct_v1 = + (struct bcos_sdk_c_transaction_v1*)malloc(sizeof(struct bcos_sdk_c_transaction_v1)); + transaction_struct_v1->transaction_data = transaction_data_copy_v1(transaction_data); + transaction_struct_v1->sender = NULL; + transaction_struct_v1->import_time = 0; + transaction_struct_v1->attribute = attribute; + transaction_struct_v1->extra_data = my_strdup(extra_data); // signature auto signatureWithoutHex = fromHexString(signature); struct bcos_sdk_c_bytes* signature_bytes = @@ -1586,7 +1584,7 @@ struct bcos_sdk_c_transaction_v2* bcos_sdk_create_transaction_struct_v2( signature_bytes->length = signatureWithoutHex->size(); signature_bytes->buffer = (uint8_t*)malloc(signatureWithoutHex->size()); memcpy(signature_bytes->buffer, signatureWithoutHex->data(), signatureWithoutHex->size()); - transaction_struct_v2->signature = signature_bytes; + transaction_struct_v1->signature = signature_bytes; // data_hash auto dataHashArray = bcos::crypto::HashType(transaction_data_hash); struct bcos_sdk_c_bytes* data_hash_bytes = @@ -1594,14 +1592,14 @@ struct bcos_sdk_c_transaction_v2* bcos_sdk_create_transaction_struct_v2( data_hash_bytes->length = dataHashArray.size(); data_hash_bytes->buffer = (uint8_t*)malloc(dataHashArray.size()); memcpy(data_hash_bytes->buffer, dataHashArray.data(), dataHashArray.size()); - transaction_struct_v2->data_hash = data_hash_bytes; + transaction_struct_v1->data_hash = data_hash_bytes; - return transaction_struct_v2; + return transaction_struct_v1; } catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_create_transaction_struct_v2") + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_create_transaction_struct_v1") << LOG_DESC("exception") << LOG_KV("signature", signature) << LOG_KV("transaction_data_hash", transaction_data_hash) << LOG_KV("attribute", attribute) << LOG_KV("extra_data", extra_data) @@ -1612,7 +1610,7 @@ struct bcos_sdk_c_transaction_v2* bcos_sdk_create_transaction_struct_v2( return NULL; } -void bcos_sdk_destroy_transaction_struct_v2(struct bcos_sdk_c_transaction_v2* transaction) +void bcos_sdk_destroy_transaction_struct_v1(struct bcos_sdk_c_transaction_v1* transaction) { if (transaction == NULL) { @@ -1621,7 +1619,7 @@ void bcos_sdk_destroy_transaction_struct_v2(struct bcos_sdk_c_transaction_v2* tr if (transaction && transaction->transaction_data) { - bcos_sdk_destroy_transaction_data_struct_v2(transaction->transaction_data); + bcos_sdk_destroy_transaction_data_struct_v1(transaction->transaction_data); } if (transaction && transaction->data_hash) @@ -1659,8 +1657,8 @@ void bcos_sdk_destroy_transaction_struct_v2(struct bcos_sdk_c_transaction_v2* tr bcos_sdk_c_free(transaction); } -const char* bcos_sdk_create_encoded_transaction_v2( - struct bcos_sdk_c_transaction_data_v2* transaction_data, const char* signature, +const char* bcos_sdk_create_encoded_transaction_v1( + struct bcos_sdk_c_transaction_data_v1* transaction_data, const char* signature, const char* transaction_data_hash, int32_t attribute, const char* extra_data) { bcos_sdk_clear_last_error(); @@ -1675,8 +1673,8 @@ const char* bcos_sdk_create_encoded_transaction_v2( try { TransactionBuilder builder; - auto tars_tx_data_v2 = convert_transaction_data_to_tars_v2(transaction_data); - auto signedBytes = builder.createSignedTransaction(*tars_tx_data_v2, + auto tars_tx_data_v1 = convert_transaction_data_to_tars_v1(transaction_data); + auto signedBytes = builder.createSignedTransaction(*tars_tx_data_v1, *fromHexString(signature), bcos::crypto::HashType(transaction_data_hash), attribute, extra_data ? std::string(extra_data) : std::string()); return strdup(bcos::toHexStringWithPrefix(*signedBytes).c_str()); @@ -1684,7 +1682,7 @@ const char* bcos_sdk_create_encoded_transaction_v2( catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_create_encoded_transaction_v2") + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_create_encoded_transaction_v1") << LOG_DESC("exception") << LOG_KV("signature", signature) << LOG_KV("transaction_data_hash", transaction_data_hash) << LOG_KV("attribute", attribute) << LOG_KV("extra_data", extra_data) @@ -1694,24 +1692,24 @@ const char* bcos_sdk_create_encoded_transaction_v2( return NULL; } -const char* bcos_sdk_encode_transaction_struct_to_hex_v2( - struct bcos_sdk_c_transaction_v2* transaction) +const char* bcos_sdk_encode_transaction_struct_to_hex_v1( + struct bcos_sdk_c_transaction_v1* transaction) { bcos_sdk_clear_last_error(); BCOS_SDK_C_PARAMS_VERIFICATION(transaction, NULL); try { - auto tars_transaction_v2 = convert_transaction_to_tars_v2(transaction); + auto tars_transaction_v1 = convert_transaction_to_tars_v1(transaction); TransactionBuilder builder; - auto encodedTransaction = builder.encodeTransaction(*tars_transaction_v2); + auto encodedTransaction = builder.encodeTransaction(*tars_transaction_v1); auto hex_tx_str = toHexStringWithPrefix(*encodedTransaction); return strdup(hex_tx_str.c_str()); } catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_encode_transaction_struct_to_hex_v2") + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_encode_transaction_struct_to_hex_v1") << LOG_DESC("exception") << LOG_KV("transaction", transaction) << LOG_KV("error", errorMsg); bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); @@ -1720,22 +1718,22 @@ const char* bcos_sdk_encode_transaction_struct_to_hex_v2( return NULL; } -const char* bcos_sdk_encode_transaction_struct_to_json_v2( - struct bcos_sdk_c_transaction_v2* transaction) +const char* bcos_sdk_encode_transaction_struct_to_json_v1( + struct bcos_sdk_c_transaction_v1* transaction) { bcos_sdk_clear_last_error(); BCOS_SDK_C_PARAMS_VERIFICATION(transaction, NULL); try { - auto tars_transaction_v2 = convert_transaction_to_tars_v2(transaction); - auto json_str = tars_transaction_v2->writeToJsonString(); + auto tars_transaction_v1 = convert_transaction_to_tars_v1(transaction); + auto json_str = tars_transaction_v1->writeToJsonString(); return strdup(json_str.c_str()); } catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_encode_transaction_struct_to_json_v2") + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_encode_transaction_struct_to_json_v1") << LOG_DESC("exception") << LOG_KV("transaction", transaction) << LOG_KV("error", errorMsg); bcos_sdk_set_last_error_msg(-1, errorMsg.c_str()); @@ -1744,7 +1742,7 @@ const char* bcos_sdk_encode_transaction_struct_to_json_v2( return NULL; } -struct bcos_sdk_c_transaction_v2* bcos_sdk_decode_transaction_struct_from_hex_v2( +struct bcos_sdk_c_transaction_v1* bcos_sdk_decode_transaction_struct_from_hex_v1( const char* transaction_hex_str) { bcos_sdk_clear_last_error(); @@ -1759,7 +1757,7 @@ struct bcos_sdk_c_transaction_v2* bcos_sdk_decode_transaction_struct_from_hex_v2 TransactionBuilder builder; auto tx_bytes = fromHexString(transaction_hex_str); auto tars_tx = builder.decodeTransaction(*tx_bytes); - return convert_tars_transaction_to_struct_v2(std::move(tars_tx)); + return convert_tars_transaction_to_struct_v1(std::move(tars_tx)); } catch (const std::exception& e) { @@ -1774,7 +1772,7 @@ struct bcos_sdk_c_transaction_v2* bcos_sdk_decode_transaction_struct_from_hex_v2 return NULL; } -struct bcos_sdk_c_transaction_v2* bcos_sdk_decode_transaction_struct_from_json_v2( +struct bcos_sdk_c_transaction_v1* bcos_sdk_decode_transaction_struct_from_json_v1( const char* transaction_json_str) { bcos_sdk_clear_last_error(); @@ -1787,12 +1785,12 @@ struct bcos_sdk_c_transaction_v2* bcos_sdk_decode_transaction_struct_from_json_v TransactionBuilder builder; auto transaction = builder.createTransactionWithJson(std::string(transaction_json_str)); - return convert_tars_transaction_to_struct_v2(std::move(transaction)); + return convert_tars_transaction_to_struct_v1(std::move(transaction)); } catch (const std::exception& e) { std::string errorMsg = boost::diagnostic_information(e); - BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_decode_transaction_struct_from_json_v2") + BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_decode_transaction_struct_from_json_v1") << LOG_DESC("exception") << LOG_KV("transaction_json_str", transaction_json_str) << LOG_KV("error", errorMsg); diff --git a/bcos-c-sdk/bcos_sdk_c_uti_tx_struct.h b/bcos-c-sdk/bcos_sdk_c_uti_tx_struct.h index 1f76c9968..f45bce564 100644 --- a/bcos-c-sdk/bcos_sdk_c_uti_tx_struct.h +++ b/bcos-c-sdk/bcos_sdk_c_uti_tx_struct.h @@ -194,59 +194,59 @@ struct bcos_sdk_c_transaction* bcos_sdk_decode_transaction_struct_from_hex( struct bcos_sdk_c_transaction* bcos_sdk_decode_transaction_struct_from_json( const char* transaction_json_str); -struct bcos_sdk_c_transaction_data_v2* bcos_sdk_create_transaction_data_struct_with_hex_input_v2( +struct bcos_sdk_c_transaction_data_v1* bcos_sdk_create_transaction_data_struct_with_hex_input_v1( 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, const char* max_fee_per_gas, const char* max_priority_fee_per_gas); -struct bcos_sdk_c_transaction_data_v2* bcos_sdk_create_transaction_data_struct_with_bytes_v2( +struct bcos_sdk_c_transaction_data_v1* bcos_sdk_create_transaction_data_struct_with_bytes_v1( const char* group_id, const char* chain_id, const char* to, const unsigned char* bytes_input, uint32_t bytes_input_length, 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); -void bcos_sdk_destroy_transaction_data_struct_v2( - struct bcos_sdk_c_transaction_data_v2* transaction_data); +void bcos_sdk_destroy_transaction_data_struct_v1( + struct bcos_sdk_c_transaction_data_v1* transaction_data); -const char* bcos_sdk_encode_transaction_data_struct_to_hex_v2( - struct bcos_sdk_c_transaction_data_v2* transaction_data); +const char* bcos_sdk_encode_transaction_data_struct_to_hex_v1( + struct bcos_sdk_c_transaction_data_v1* transaction_data); -const char* bcos_sdk_encode_transaction_data_struct_to_json_v2( - struct bcos_sdk_c_transaction_data_v2* transaction_data); +const char* bcos_sdk_encode_transaction_data_struct_to_json_v1( + struct bcos_sdk_c_transaction_data_v1* transaction_data); -struct bcos_sdk_c_transaction_data_v2* bcos_sdk_decode_transaction_data_struct_from_hex_v2( +struct bcos_sdk_c_transaction_data_v1* bcos_sdk_decode_transaction_data_struct_from_hex_v1( const char* transaction_data_hex_str); -struct bcos_sdk_c_transaction_data_v2* bcos_sdk_decode_transaction_data_struct_from_json_v2( +struct bcos_sdk_c_transaction_data_v1* bcos_sdk_decode_transaction_data_struct_from_json_v1( const char* transaction_data_json_str); -const char* bcos_sdk_calc_transaction_data_struct_hash_v2( - int crypto_type, struct bcos_sdk_c_transaction_data_v2* transaction_data); +const char* bcos_sdk_calc_transaction_data_struct_hash_v1( + int crypto_type, struct bcos_sdk_c_transaction_data_v1* transaction_data); -const char* bcos_sdk_calc_transaction_data_struct_hash_with_hex_v2( +const char* bcos_sdk_calc_transaction_data_struct_hash_with_hex_v1( int crypto_type, const char* transaction_data_hex); -struct bcos_sdk_c_transaction_v2* bcos_sdk_create_transaction_struct_v2( - struct bcos_sdk_c_transaction_data_v2* transaction_data, const char* signature, +struct bcos_sdk_c_transaction_v1* bcos_sdk_create_transaction_struct_v1( + struct bcos_sdk_c_transaction_data_v1* transaction_data, const char* signature, const char* transaction_data_hash, int32_t attribute, const char* extra_data); -void bcos_sdk_destroy_transaction_struct_v2(struct bcos_sdk_c_transaction_v2* transaction); +void bcos_sdk_destroy_transaction_struct_v1(struct bcos_sdk_c_transaction_v1* transaction); -const char* bcos_sdk_create_encoded_transaction_v2( - struct bcos_sdk_c_transaction_data_v2* transaction_data, const char* signature, +const char* bcos_sdk_create_encoded_transaction_v1( + struct bcos_sdk_c_transaction_data_v1* transaction_data, const char* signature, const char* transaction_data_hash, int32_t attribute, const char* extra_data); -const char* bcos_sdk_encode_transaction_struct_to_hex_v2( - struct bcos_sdk_c_transaction_v2* transaction); +const char* bcos_sdk_encode_transaction_struct_to_hex_v1( + struct bcos_sdk_c_transaction_v1* transaction); -const char* bcos_sdk_encode_transaction_struct_to_json_v2( - struct bcos_sdk_c_transaction_v2* transaction); +const char* bcos_sdk_encode_transaction_struct_to_json_v1( + struct bcos_sdk_c_transaction_v1* transaction); -struct bcos_sdk_c_transaction_v2* bcos_sdk_decode_transaction_struct_from_hex_v2( +struct bcos_sdk_c_transaction_v1* bcos_sdk_decode_transaction_struct_from_hex_v1( const char* transaction_hex_str); -struct bcos_sdk_c_transaction_v2* bcos_sdk_decode_transaction_struct_from_json_v2( +struct bcos_sdk_c_transaction_v1* bcos_sdk_decode_transaction_struct_from_json_v1( const char* transaction_json_str); #ifdef __cplusplus diff --git a/bcos-c-sdk/bcos_sdk_c_uti_tx_v2.cpp b/bcos-c-sdk/bcos_sdk_c_uti_tx_v1.cpp similarity index 97% rename from bcos-c-sdk/bcos_sdk_c_uti_tx_v2.cpp rename to bcos-c-sdk/bcos_sdk_c_uti_tx_v1.cpp index f6257bb62..85ba13674 100644 --- a/bcos-c-sdk/bcos_sdk_c_uti_tx_v2.cpp +++ b/bcos-c-sdk/bcos_sdk_c_uti_tx_v1.cpp @@ -13,17 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @file bcos_sdk_c_uti_tx_v2.cpp + * @file bcos_sdk_c_uti_tx_v1.cpp * @author: kyonGuo * @date 2023/11/28 */ -#include "bcos_sdk_c_uti_tx_v2.h" +#include "bcos_sdk_c_uti_tx_v1.h" #include "bcos_sdk_c_error.h" #include #include #include -#include +#include using namespace bcos; using namespace bcos::cppsdk; @@ -33,7 +33,7 @@ using namespace bcos::cppsdk::utilities; #include #include -void* bcos_sdk_create_transaction_v2_data(const char* group_id, const char* chain_id, +void* bcos_sdk_create_transaction_v1_data(const char* group_id, const char* chain_id, const char* to, const char* nonce, const unsigned char* input, long inputSize, const char* abi, int64_t block_limit, const char* value, const char* gas_price, int64_t gas_limit) { @@ -46,7 +46,7 @@ void* bcos_sdk_create_transaction_v2_data(const char* group_id, const char* chai try { - TransactionBuilderV2 builder; + TransactionBuilderV1 builder; auto bytesData = bytes(input, input + inputSize * sizeof(byte)); auto transactionData = builder.createTransactionData(1, group_id, chain_id, to, nonce ? nonce : "", std::move(bytesData), abi, block_limit, value ? value : "", @@ -86,7 +86,7 @@ void* bcos_sdk_create_eip1559_transaction_data(const char* group_id, const char* try { - TransactionBuilderV2 builder; + TransactionBuilderV1 builder; auto bytesData = bytes(input, input + inputSize * sizeof(byte)); auto transactionData = builder.createTransactionData(1, group_id, chain_id, to, nonce ? nonce : "", std::move(bytesData), abi, block_limit, value ? value : "", "", @@ -133,7 +133,7 @@ const char* bcos_sdk_calc_transaction_data_hash_with_full_fields(int crypto_type try { auto bytesData = bytes(input, input + inputSize * sizeof(byte)); - TransactionBuilderV2 builder; + TransactionBuilderV1 builder; auto transactionDataHash = builder.calculateTransactionDataHash( crypto_type == BCOS_C_SDK_ECDSA_TYPE ? CryptoType::Secp256K1 : CryptoType::SM2, version, group_id, chain_id, to ? to : "", nonce, std::move(bytesData), abi ? abi : "", @@ -171,7 +171,7 @@ const char* bcos_sdk_calc_transaction_data_hash_with_json(int crypto_type, const try { - TransactionBuilderV2 builder; + TransactionBuilderV1 builder; auto transactionDataHash = builder.calculateTransactionDataHashWithJson( crypto_type == BCOS_C_SDK_ECDSA_TYPE ? CryptoType::Secp256K1 : CryptoType::SM2, json); return strdup(bcos::toHexStringWithPrefix(transactionDataHash).c_str()); @@ -205,7 +205,7 @@ const char* bcos_sdk_create_signed_transaction_with_signature(const unsigned cha try { - TransactionBuilderV2 builder; + TransactionBuilderV1 builder; auto bytesData = bytes(input, input + inputSize * sizeof(byte)); auto hash = std::string_view(transaction_hash); crypto::HashType tx_hash(fromHex(hash, hash.starts_with("0x") ? "0x" : "")); @@ -260,7 +260,7 @@ void bcos_sdk_create_signed_transaction_with_full_fields(void* key_pair, const c try { - TransactionBuilderV2 builder; + TransactionBuilderV1 builder; auto bytesData = bytes(input, input + inputSize * sizeof(byte)); auto result = builder.createSignedTransaction(*static_cast(key_pair), @@ -309,7 +309,7 @@ void bcos_sdk_create_signed_eip1559_transaction_with_full_fields(void* key_pair, try { - TransactionBuilderV2 builder; + TransactionBuilderV1 builder; auto bytesData = bytes(input, input + inputSize * sizeof(byte)); auto result = builder.createSignedTransaction( *static_cast(key_pair), attribute, 1, group_id, diff --git a/bcos-c-sdk/bcos_sdk_c_uti_tx_v2.h b/bcos-c-sdk/bcos_sdk_c_uti_tx_v1.h similarity index 97% rename from bcos-c-sdk/bcos_sdk_c_uti_tx_v2.h rename to bcos-c-sdk/bcos_sdk_c_uti_tx_v1.h index ac337da09..20e3994f6 100644 --- a/bcos-c-sdk/bcos_sdk_c_uti_tx_v2.h +++ b/bcos-c-sdk/bcos_sdk_c_uti_tx_v1.h @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @file bcos_sdk_c_uti_tx_v2.h + * @file bcos_sdk_c_uti_tx_v1.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 +#ifndef BCOS_C_SDK_BCOS_SDK_C_UTI_TX_V1_H +#define BCOS_C_SDK_BCOS_SDK_C_UTI_TX_V1_H #include "bcos_sdk_c_common.h" @@ -54,7 +54,7 @@ enum transaction_version * @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, +void* bcos_sdk_create_transaction_v1_data(const char* group_id, const char* chain_id, const char* to, const char* nonce, const unsigned char* input, long inputSize, const char* abi, int64_t block_limit, const char* value, const char* gas_price, int64_t gas_limit); @@ -211,4 +211,4 @@ void bcos_sdk_create_signed_eip1559_transaction_with_full_fields(void* key_pair, #ifdef __cplusplus } #endif -#endif // BCOS_C_SDK_BCOS_SDK_C_UTI_TX_V2_H +#endif // BCOS_C_SDK_BCOS_SDK_C_UTI_TX_V1_H diff --git a/bindings/java/jni/scripts/java2jni.sh b/bindings/java/jni/scripts/java2jni.sh index 35c0f91ec..55f7117f0 100644 --- a/bindings/java/jni/scripts/java2jni.sh +++ b/bindings/java/jni/scripts/java2jni.sh @@ -30,7 +30,7 @@ function convert_java_to_jni() { # convert_java_to_jni ${JAVA_SOURCE_PATH} # classes="rpc.RpcJniObj amop.AmopJniObj event.EventSubJniObj BcosSDKJniObj" -classes="BcosSDKJniObj utilities.keypair.KeyPairJniObj utilities.tx.TransactionBuilderJniObj utilities.tx.TransactionBuilderV2JniObj utilities.tx.TransactionStructBuilderJniObj utilities.receipt.ReceiptBuilderJniObj utilities.signature.SignatureJniObj" +classes="BcosSDKJniObj utilities.keypair.KeyPairJniObj utilities.tx.TransactionBuilderJniObj utilities.tx.TransactionBuilderV1JniObj utilities.tx.TransactionStructBuilderJniObj utilities.receipt.ReceiptBuilderJniObj utilities.signature.SignatureJniObj" for class in ${classes} do diff --git a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj.cpp b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj.cpp similarity index 96% rename from bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj.cpp rename to bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj.cpp index ab940033e..d8e9283ae 100644 --- a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj.cpp +++ b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj.cpp @@ -13,26 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @file org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj.cpp + * @file org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj.cpp * @author: kyonGuo * @date 2023/11/29 */ -#include "org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj.h" +#include "org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj.h" +#include "bcos-c-sdk/bcos_sdk_c_uti_tx_v1.h" #include "bcos-c-sdk/bcos_sdk_c_error.h" #include "bcos-c-sdk/bcos_sdk_c_uti_keypair.h" -#include "bcos-c-sdk/bcos_sdk_c_uti_tx_v2.h" #include "org_fisco_bcos_sdk_common.h" #include /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: createTransactionData * Signature: * (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;JLjava/lang/String;Ljava/lang/String;J)J */ JNIEXPORT jlong JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createTransactionData( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_createTransactionData( JNIEnv* env, jclass, jstring j_group_id, jstring j_chain_id, jstring j_to, jstring j_nonce, jbyteArray j_input, jstring j_abi, jlong j_block_limit, jstring j_value, jstring j_gas_price, jlong j_gas_limit) @@ -54,7 +54,7 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createTransa jbyte* inputBuffer = env->GetByteArrayElements(j_input, NULL); jsize inputSize = env->GetArrayLength(j_input); - void* transaction_data = bcos_sdk_create_transaction_v2_data(group_id, chain_id, to, nonce, + void* transaction_data = bcos_sdk_create_transaction_v1_data(group_id, chain_id, to, nonce, reinterpret_cast(inputBuffer), inputSize, abi, block_limit, value, gas_price, gas_limit); @@ -77,13 +77,13 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createTransa } /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: createEIP1559TransactionData * Signature: * (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;JLjava/lang/String;JLjava/lang/String;Ljava/lang/String;)J */ JNIEXPORT jlong JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createEIP1559TransactionData( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_createEIP1559TransactionData( JNIEnv* env, jclass, jstring j_group_id, jstring j_chain_id, jstring j_to, jstring j_nonce, jbyteArray j_input, jstring j_abi, jlong j_block_limit, jstring j_value, jlong j_gas_limit, jstring j_max_fee_per_gas, jstring j_max_priority_fee_per_gas) @@ -130,13 +130,13 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createEIP155 } /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: calcTransactionDataHashWithFullFields * Signature: * (ILorg/fisco/bcos/sdk/jni/utilities/tx/TransactionVersion;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;JLjava/lang/String;Ljava/lang/String;JLjava/lang/String;Ljava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_calcTransactionDataHashWithFullFields( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_calcTransactionDataHashWithFullFields( JNIEnv* env, jclass, jint j_crypto_type, jobject j_tx_version, jstring j_group_id, jstring j_chain_id, jstring j_to, jstring j_nonce, jbyteArray j_input, jstring j_abi, jlong j_block_limit, jstring j_value, jstring j_gasPrice, jlong j_gas_limit, @@ -202,12 +202,12 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_calcTransact } /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: calcTransactionDataHashWithJson * Signature: (ILjava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_calcTransactionDataHashWithJson( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_calcTransactionDataHashWithJson( JNIEnv* env, jclass, jint j_crypto_type, jstring j_json) { CHECK_OBJECT_NOT_NULL(env, j_json, NULL); @@ -236,13 +236,13 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_calcTransact } /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: createSignedTransactionWithSignature * Signature: * ([BLjava/lang/String;Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionVersion;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;JLjava/lang/String;Ljava/lang/String;JLjava/lang/String;Ljava/lang/String;ILjava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createSignedTransactionWithSignature( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_createSignedTransactionWithSignature( JNIEnv* env, jclass, jbyteArray j_signature, jstring j_tx_hash, jobject j_tx_version, jstring j_group_id, jstring j_chain_id, jstring j_to, jstring j_nonce, jbyteArray j_input, jstring j_abi, jlong j_block_limit, jstring j_value, jstring j_gas_price, jlong j_gas_limit, @@ -318,13 +318,13 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createSigned } /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: createSignedTransactionWithFullFields * Signature: * (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;JLjava/lang/String;Ljava/lang/String;JILjava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/TxPair; */ JNIEXPORT jobject JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createSignedTransactionWithFullFields( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_createSignedTransactionWithFullFields( JNIEnv* env, jclass, jlong j_key_pair, jstring j_group_id, jstring j_chain_id, jstring j_to, jstring j_nonce, jbyteArray j_input, jstring j_abi, jlong j_block_limit, jstring j_value, jstring j_gas_price, jlong j_gas_limit, jint j_attribute, jstring j_extra_data) @@ -408,13 +408,13 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createSigned } /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: createSignedEIP1559TransactionWithFullFields * Signature: * (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;JILjava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/TxPair; */ JNIEXPORT jobject JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createSignedEIP1559TransactionWithFullFields( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_createSignedEIP1559TransactionWithFullFields( JNIEnv* env, jclass, jlong j_key_pair, jstring j_group_id, jstring j_chain_id, jstring j_to, jstring j_nonce, jbyteArray j_input, jstring j_abi, jlong j_block_limit, jstring j_value, jstring j_max_fee_per_gas, jstring j_max_priority_fee_per_gas, jlong j_gas_limit, diff --git a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj.h b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj.h similarity index 86% rename from bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj.h rename to bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj.h index 4fd67599c..bd74d5402 100644 --- a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj.h +++ b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj.h @@ -1,84 +1,84 @@ /* DO NOT EDIT THIS FILE - it is machine generated */ #include -/* Header for class org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj */ +/* Header for class org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj */ -#ifndef _Included_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj -#define _Included_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj +#ifndef _Included_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj +#define _Included_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj #ifdef __cplusplus extern "C" { #endif /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: createTransactionData * Signature: * (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;JLjava/lang/String;Ljava/lang/String;J)J */ JNIEXPORT jlong JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createTransactionData(JNIEnv*, +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_createTransactionData(JNIEnv*, jclass, jstring, jstring, jstring, jstring, jbyteArray, jstring, jlong, jstring, jstring, jlong); /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: createEIP1559TransactionData * Signature: * (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;JLjava/lang/String;JLjava/lang/String;Ljava/lang/String;)J */ JNIEXPORT jlong JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createEIP1559TransactionData( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_createEIP1559TransactionData( JNIEnv*, jclass, jstring, jstring, jstring, jstring, jbyteArray, jstring, jlong, jstring, jlong, jstring, jstring); /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: calcTransactionDataHashWithFullFields * Signature: * (ILorg/fisco/bcos/sdk/jni/utilities/tx/TransactionVersion;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;JLjava/lang/String;Ljava/lang/String;JLjava/lang/String;Ljava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_calcTransactionDataHashWithFullFields( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_calcTransactionDataHashWithFullFields( JNIEnv*, jclass, jint, jobject, jstring, jstring, jstring, jstring, jbyteArray, jstring, jlong, jstring, jstring, jlong, jstring, jstring); /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: calcTransactionDataHashWithJson * Signature: (ILjava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_calcTransactionDataHashWithJson( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_calcTransactionDataHashWithJson( JNIEnv*, jclass, jint, jstring); /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: createSignedTransactionWithSignature * Signature: * ([BLjava/lang/String;Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionVersion;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;JLjava/lang/String;Ljava/lang/String;JLjava/lang/String;Ljava/lang/String;ILjava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createSignedTransactionWithSignature( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_createSignedTransactionWithSignature( JNIEnv*, jclass, jbyteArray, jstring, jobject, jstring, jstring, jstring, jstring, jbyteArray, jstring, jlong, jstring, jstring, jlong, jstring, jstring, jint, jstring); /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: createSignedTransactionWithFullFields * Signature: * (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;JLjava/lang/String;Ljava/lang/String;JILjava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/TxPair; */ JNIEXPORT jobject JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createSignedTransactionWithFullFields( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_createSignedTransactionWithFullFields( JNIEnv*, jclass, jlong, jstring, jstring, jstring, jstring, jbyteArray, jstring, jlong, jstring, jstring, jlong, jint, jstring); /* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj + * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj * Method: createSignedEIP1559TransactionWithFullFields * Signature: * (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;JILjava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/TxPair; */ JNIEXPORT jobject JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV2JniObj_createSignedEIP1559TransactionWithFullFields( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionBuilderV1JniObj_createSignedEIP1559TransactionWithFullFields( JNIEnv*, jclass, jlong, jstring, jstring, jstring, jstring, jbyteArray, jstring, jlong, jstring, jstring, jstring, jlong, jint, jstring); diff --git a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj.cpp b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj.cpp index 12f34235b..ed5582b4e 100644 --- a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj.cpp +++ b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj.cpp @@ -6,8 +6,8 @@ #include "org_fisco_bcos_sdk_exception.h" -// tx data v2: java obj => c struct -struct bcos_sdk_c_transaction_data_v2* convert_to_tx_v2_data_struct( +// tx data v1: java obj => c struct +struct bcos_sdk_c_transaction_data_v1* convert_to_tx_v1_data_struct( JNIEnv* env, jobject transactionObject) { if (transactionObject == NULL) @@ -19,8 +19,8 @@ struct bcos_sdk_c_transaction_data_v2* convert_to_tx_v2_data_struct( jclass txDataClass = env->GetObjectClass(transactionObject); - bcos_sdk_c_transaction_data_v2* tx_data_struct = (struct bcos_sdk_c_transaction_data_v2*)malloc( - sizeof(struct bcos_sdk_c_transaction_data_v2)); + bcos_sdk_c_transaction_data_v1* tx_data_struct = (struct bcos_sdk_c_transaction_data_v1*)malloc( + sizeof(struct bcos_sdk_c_transaction_data_v1)); // version jfieldID versionField = env->GetFieldID(txDataClass, "version", "I"); tx_data_struct->version = env->GetIntField(transactionObject, versionField); @@ -281,9 +281,9 @@ jobject convert_to_tx_data_jobject( return jTxDataObj; } -// tx data v2: c struct => java obj -jobject convert_to_tx_v2_data_jobject( - JNIEnv* env, const struct bcos_sdk_c_transaction_data_v2* transactionData) +// tx data v1: c struct => java obj +jobject convert_to_tx_v1_data_jobject( + JNIEnv* env, const struct bcos_sdk_c_transaction_data_v1* transactionData) { if (transactionData == NULL) { @@ -292,12 +292,12 @@ jobject convert_to_tx_v2_data_jobject( return NULL; } - jclass txDataClass = env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2"); + jclass txDataClass = env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDatav1"); if (txDataClass == NULL) { env->FatalError( "No such class, className: " - "org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2"); + "org/fisco/bcos/sdk/jni/utilities/tx/TransactionDatav1"); } jmethodID txDataMtd = env->GetMethodID(txDataClass, "", "()V"); if (txDataMtd == NULL) @@ -446,8 +446,8 @@ jobject convert_to_tx_jobject(JNIEnv* env, const struct bcos_sdk_c_transaction* return javaTxObj; } -// tx v2: c struct => java obj -jobject convert_to_tx_v2_jobject(JNIEnv* env, const struct bcos_sdk_c_transaction_v2* tx_struct) +// tx v1: c struct => java obj +jobject convert_to_tx_v1_jobject(JNIEnv* env, const struct bcos_sdk_c_transaction_v1* tx_struct) { if (tx_struct == NULL) @@ -479,7 +479,7 @@ jobject convert_to_tx_v2_jobject(JNIEnv* env, const struct bcos_sdk_c_transactio jobject javaTxObj = env->NewObject(txClass, txMtd); // TransactionData - jobject javaTxDataObj = convert_to_tx_v2_data_jobject(env, tx_struct->transaction_data); + jobject javaTxDataObj = convert_to_tx_v1_data_jobject(env, tx_struct->transaction_data); if (javaTxDataObj == NULL) { THROW_JNI_EXCEPTION(env, "exception in TransactionData field."); @@ -643,8 +643,8 @@ struct bcos_sdk_c_transaction* convert_to_tx_struct(JNIEnv* env, jobject jTxObj) return txStruct; } -// tx v2: java obj => c struct -struct bcos_sdk_c_transaction_v2* convert_to_tx_v2_struct(JNIEnv* env, jobject jTxObj) +// tx v1: java obj => c struct +struct bcos_sdk_c_transaction_v1* convert_to_tx_v1_struct(JNIEnv* env, jobject jTxObj) { if (jTxObj == NULL) { @@ -662,12 +662,12 @@ struct bcos_sdk_c_transaction_v2* convert_to_tx_v2_struct(JNIEnv* env, jobject j jfieldID attributeField = env->GetFieldID(javaTxClass, "attribute", "I"); jfieldID extraDataField = env->GetFieldID(javaTxClass, "extraData", "Ljava/lang/String;"); - struct bcos_sdk_c_transaction_v2* txStruct = - (struct bcos_sdk_c_transaction_v2*)malloc(sizeof(struct bcos_sdk_c_transaction_v2)); + struct bcos_sdk_c_transaction_v1* txStruct = + (struct bcos_sdk_c_transaction_v1*)malloc(sizeof(struct bcos_sdk_c_transaction_v1)); // TransactionData jobject javaTxDataObj = env->GetObjectField(jTxObj, transactionDataField); - struct bcos_sdk_c_transaction_data_v2* txDataStruct = - convert_to_tx_v2_data_struct(env, javaTxDataObj); + struct bcos_sdk_c_transaction_data_v1* txDataStruct = + convert_to_tx_v1_data_struct(env, javaTxDataObj); if (txDataStruct == NULL) { THROW_JNI_EXCEPTION(env, "exception in txDataStruct field."); @@ -769,19 +769,19 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_encodeTr } const char* tx_data_hex = nullptr; if (env->IsInstanceOf(jTransactionDataObj, - env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2")) == JNI_TRUE) + env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDatav1")) == JNI_TRUE) { - bcos_sdk_c_transaction_data_v2* tx_data_struct = - convert_to_tx_v2_data_struct(env, jTransactionDataObj); + bcos_sdk_c_transaction_data_v1* tx_data_struct = + convert_to_tx_v1_data_struct(env, jTransactionDataObj); if (tx_data_struct == NULL) { THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_data_struct"); return nullptr; } - tx_data_hex = bcos_sdk_encode_transaction_data_struct_to_hex_v2(tx_data_struct); + tx_data_hex = bcos_sdk_encode_transaction_data_struct_to_hex_v1(tx_data_struct); if (tx_data_struct) { - bcos_sdk_destroy_transaction_data_struct_v2(tx_data_struct); + bcos_sdk_destroy_transaction_data_struct_v1(tx_data_struct); } } else @@ -833,19 +833,19 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_encodeTr } const char* tx_data_json = nullptr; if (env->IsInstanceOf(jTransactionDataObj, - env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2")) == JNI_TRUE) + env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDatav1")) == JNI_TRUE) { - bcos_sdk_c_transaction_data_v2* tx_data_struct = - convert_to_tx_v2_data_struct(env, jTransactionDataObj); + bcos_sdk_c_transaction_data_v1* tx_data_struct = + convert_to_tx_v1_data_struct(env, jTransactionDataObj); if (tx_data_struct == NULL) { THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_data_struct"); return nullptr; } - tx_data_json = bcos_sdk_encode_transaction_data_struct_to_json_v2(tx_data_struct); + tx_data_json = bcos_sdk_encode_transaction_data_struct_to_json_v1(tx_data_struct); if (tx_data_struct) { - bcos_sdk_destroy_transaction_data_struct_v2(tx_data_struct); + bcos_sdk_destroy_transaction_data_struct_v1(tx_data_struct); } } else @@ -918,35 +918,35 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_decodeTr /* * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj - * Method: decodeTransactionDataStructV2 - * Signature: (Ljava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2; + * Method: decodeTransactionDataStructv1 + * Signature: (Ljava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDatav1; */ JNIEXPORT jobject JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_decodeTransactionDataStructV2( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_decodeTransactionDataStructV1( JNIEnv* env, jclass, jstring jTxDataHexStr) { CHECK_OBJECT_NOT_NULL(env, jTxDataHexStr, nullptr); const char* tx_data_hex_str = env->GetStringUTFChars(jTxDataHexStr, nullptr); - struct bcos_sdk_c_transaction_data_v2* tx_data_struct_v2 = - bcos_sdk_decode_transaction_data_struct_from_hex_v2(tx_data_hex_str); + struct bcos_sdk_c_transaction_data_v1* tx_data_struct_v1 = + bcos_sdk_decode_transaction_data_struct_from_hex_v1(tx_data_hex_str); if (!bcos_sdk_is_last_opr_success()) { THROW_JNI_EXCEPTION(env, bcos_sdk_get_last_error_msg()); return nullptr; } - jobject jTxDataObj = convert_to_tx_v2_data_jobject(env, tx_data_struct_v2); + jobject jTxDataObj = convert_to_tx_v1_data_jobject(env, tx_data_struct_v1); if (jTxDataObj == NULL) { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_v2_data_jobject"); + THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_v1_data_jobject"); return nullptr; } // release source - if (tx_data_struct_v2) + if (tx_data_struct_v1) { - bcos_sdk_destroy_transaction_data_struct_v2(tx_data_struct_v2); + bcos_sdk_destroy_transaction_data_struct_v1(tx_data_struct_v1); } env->ReleaseStringUTFChars(jTxDataHexStr, tx_data_hex_str); @@ -970,19 +970,19 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_calcTran const char* tx_data_hash = nullptr; int crypto_type = jCrytpTyte; if (env->IsInstanceOf(jTransactionDataObj, - env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2")) == JNI_TRUE) + env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDatav1")) == JNI_TRUE) { - bcos_sdk_c_transaction_data_v2* tx_data_struct = - convert_to_tx_v2_data_struct(env, jTransactionDataObj); + bcos_sdk_c_transaction_data_v1* tx_data_struct = + convert_to_tx_v1_data_struct(env, jTransactionDataObj); if (tx_data_struct == NULL) { THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_data_struct"); return nullptr; } - tx_data_hash = bcos_sdk_calc_transaction_data_struct_hash_v2(crypto_type, tx_data_struct); + tx_data_hash = bcos_sdk_calc_transaction_data_struct_hash_v1(crypto_type, tx_data_struct); if (tx_data_struct) { - bcos_sdk_destroy_transaction_data_struct_v2(tx_data_struct); + bcos_sdk_destroy_transaction_data_struct_v1(tx_data_struct); } } else @@ -1040,20 +1040,20 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_createEn int attribute = jAttribute; const char* extra_data = env->GetStringUTFChars(jExtraData, NULL); if (env->IsInstanceOf(jTxDataObj, - env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2")) == JNI_TRUE) + env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDatav1")) == JNI_TRUE) { - bcos_sdk_c_transaction_data_v2* tx_data_struct = - convert_to_tx_v2_data_struct(env, jTxDataObj); + bcos_sdk_c_transaction_data_v1* tx_data_struct = + convert_to_tx_v1_data_struct(env, jTxDataObj); if (tx_data_struct == NULL) { THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_data_struct"); return nullptr; } - tx_str = bcos_sdk_create_encoded_transaction_v2( + tx_str = bcos_sdk_create_encoded_transaction_v1( tx_data_struct, signature, tx_data_hash, attribute, extra_data); if (tx_data_struct) { - bcos_sdk_destroy_transaction_data_struct_v2(tx_data_struct); + bcos_sdk_destroy_transaction_data_struct_v1(tx_data_struct); } } else @@ -1113,18 +1113,18 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_encodeTr CHECK_OBJECT_NOT_NULL(env, javaTxDataObj, nullptr); const char* tx_hex = nullptr; if (env->IsInstanceOf(javaTxDataObj, - env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2")) == JNI_TRUE) + env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDatav1")) == JNI_TRUE) { - bcos_sdk_c_transaction_v2* tx_struct = convert_to_tx_v2_struct(env, jTransactionObj); + bcos_sdk_c_transaction_v1* tx_struct = convert_to_tx_v1_struct(env, jTransactionObj); if (tx_struct == NULL) { THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_struct"); return nullptr; } - tx_hex = bcos_sdk_encode_transaction_struct_to_hex_v2(tx_struct); + tx_hex = bcos_sdk_encode_transaction_struct_to_hex_v1(tx_struct); if (tx_struct) { - bcos_sdk_destroy_transaction_struct_v2(tx_struct); + bcos_sdk_destroy_transaction_struct_v1(tx_struct); } } else @@ -1176,18 +1176,18 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_encodeTr CHECK_OBJECT_NOT_NULL(env, javaTxDataObj, nullptr); const char* tx_json = nullptr; if (env->IsInstanceOf(javaTxDataObj, - env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2")) == JNI_TRUE) + env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDatav1")) == JNI_TRUE) { - bcos_sdk_c_transaction_v2* tx_struct = convert_to_tx_v2_struct(env, jTransactionObj); + bcos_sdk_c_transaction_v1* tx_struct = convert_to_tx_v1_struct(env, jTransactionObj); if (tx_struct == NULL) { THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_struct"); return nullptr; } - tx_json = bcos_sdk_encode_transaction_struct_to_json_v2(tx_struct); + tx_json = bcos_sdk_encode_transaction_struct_to_json_v1(tx_struct); if (tx_struct) { - bcos_sdk_destroy_transaction_struct_v2(tx_struct); + bcos_sdk_destroy_transaction_struct_v1(tx_struct); } } else @@ -1260,35 +1260,35 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_decodeTr /* * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj - * Method: decodeTransactionStructV2 - * Signature: (Ljava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionV2; + * Method: decodeTransactionStructv1 + * Signature: (Ljava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/Transactionv1; */ JNIEXPORT jobject JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_decodeTransactionStructV2( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_decodeTransactionStructV1( JNIEnv* env, jclass, jstring jTxHexStr) { CHECK_OBJECT_NOT_NULL(env, jTxHexStr, nullptr); const char* tx_hex_str = env->GetStringUTFChars(jTxHexStr, nullptr); - struct bcos_sdk_c_transaction_v2* tx_struct_v2 = - bcos_sdk_decode_transaction_struct_from_hex_v2(tx_hex_str); + struct bcos_sdk_c_transaction_v1* tx_struct_v1 = + bcos_sdk_decode_transaction_struct_from_hex_v1(tx_hex_str); if (!bcos_sdk_is_last_opr_success()) { THROW_JNI_EXCEPTION(env, bcos_sdk_get_last_error_msg()); return nullptr; } - jobject jTxObj = convert_to_tx_v2_jobject(env, tx_struct_v2); + jobject jTxObj = convert_to_tx_v1_jobject(env, tx_struct_v1); if (jTxObj == NULL) { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_v2_jobject"); + THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_v1_jobject"); return nullptr; } // release source - if (tx_struct_v2) + if (tx_struct_v1) { - bcos_sdk_destroy_transaction_struct_v2(tx_struct_v2); + bcos_sdk_destroy_transaction_struct_v1(tx_struct_v1); } env->ReleaseStringUTFChars(jTxHexStr, tx_hex_str); diff --git a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj.h b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj.h index 82048c474..0ade4cbdc 100644 --- a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj.h +++ b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj.h @@ -36,11 +36,11 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_decodeTr /* * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj - * Method: decodeTransactionDataStructV2 - * Signature: (Ljava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2; + * Method: decodeTransactionDataStructV1 + * Signature: (Ljava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV1; */ JNIEXPORT jobject JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_decodeTransactionDataStructV2( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_decodeTransactionDataStructV1( JNIEnv*, jclass, jstring); /* @@ -91,11 +91,11 @@ Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_decodeTr /* * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj - * Method: decodeTransactionStructV2 + * Method: decodeTransactionStructV1 * Signature: (Ljava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/Transaction; */ JNIEXPORT jobject JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_decodeTransactionStructV2( +Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderJniObj_decodeTransactionStructV1( JNIEnv*, jclass, jstring); #ifdef __cplusplus diff --git a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj.cpp b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj.cpp deleted file mode 100644 index c5a168c81..000000000 --- a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj.cpp +++ /dev/null @@ -1,724 +0,0 @@ -#include "org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj.h" -#include "bcos-c-sdk/bcos_sdk_c_error.h" -#include "bcos-c-sdk/bcos_sdk_c_uti_keypair.h" -#include "bcos-c-sdk/bcos_sdk_c_uti_tx_struct.h" -#include "org_fisco_bcos_sdk_common.h" -#include "org_fisco_bcos_sdk_exception.h" - - -struct bcos_sdk_c_bytes* convert_to_bytes_struct_v2(JNIEnv* env, jobject bytesObj) -{ - if (bytesObj == NULL) - { - return NULL; - } - - struct bcos_sdk_c_bytes* bytes = - (struct bcos_sdk_c_bytes*)malloc(sizeof(struct bcos_sdk_c_bytes)); - jclass bytesClass = env->GetObjectClass(bytesObj); - jfieldID bufferField = env->GetFieldID(bytesClass, "buffer", "[B"); - jfieldID lengthField = env->GetFieldID(bytesClass, "length", "I"); - - jbyteArray bufferArray = (jbyteArray)env->GetObjectField(bytesObj, bufferField); - jbyte* bufferData = env->GetByteArrayElements(bufferArray, nullptr); - jsize bufferLength = env->GetArrayLength(bufferArray); - bytes->length = (uint32_t)env->GetIntField(bytesObj, lengthField); - bytes->buffer = (uint8_t*)malloc(bufferLength * sizeof(uint8_t)); - memcpy(bytes->buffer, bufferData, bufferLength); - - env->ReleaseByteArrayElements(bufferArray, bufferData, 0); - - return bytes; -} - -jobject convert_to_bytes_jobject_v2(JNIEnv* env, const struct bcos_sdk_c_bytes* bytes_struct) -{ - if (bytes_struct == NULL) - { - return NULL; - } - - jclass txBytesClass = env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionBytes"); - if (txBytesClass == NULL) - { - env->FatalError( - "No such class, className: " - "org/fisco/bcos/sdk/jni/utilities/tx/TransactionBytes"); - } - jmethodID txBytesMtd = env->GetMethodID(txBytesClass, "", "()V"); - if (txBytesMtd == NULL) - { - env->FatalError("No such constructor in TransactionBytes, constructor()"); - } - jfieldID bufferField = env->GetFieldID(txBytesClass, "buffer", "[B"); - jfieldID lengthField = env->GetFieldID(txBytesClass, "length", "I"); - - jobject jTxBytesObj = env->NewObject(txBytesClass, txBytesMtd); - // buffer - jbyteArray bufferArray = env->NewByteArray(bytes_struct->length); - env->SetByteArrayRegion( - bufferArray, 0, bytes_struct->length, reinterpret_cast(bytes_struct->buffer)); - env->SetObjectField(jTxBytesObj, bufferField, bufferArray); - // length - env->SetIntField(jTxBytesObj, lengthField, bytes_struct->length); - - env->DeleteLocalRef(bufferArray); - - return jTxBytesObj; -} - -struct bcos_sdk_c_transaction_data_v2* convert_to_tx_data_struct_v2( - JNIEnv* env, jobject transactionObject) -{ - if (transactionObject == NULL) - { - THROW_JNI_EXCEPTION( - env, "exception in convert_to_tx_data_struct_v2, transactionObject is nullptr"); - return NULL; - } - - bcos_sdk_c_transaction_data_v2* tx_data_struct_v2 = - (struct bcos_sdk_c_transaction_data_v2*)malloc( - sizeof(struct bcos_sdk_c_transaction_data_v2)); - jclass txDataClass = env->GetObjectClass(transactionObject); - - // version - jfieldID versionField = env->GetFieldID(txDataClass, "version", "I"); - tx_data_struct_v2->version = env->GetIntField(transactionObject, versionField); - - // blockLimit - jfieldID blockLimitField = env->GetFieldID(txDataClass, "blockLimit", "J"); - tx_data_struct_v2->block_limit = env->GetLongField(transactionObject, blockLimitField); - - // chainId - jfieldID chainIdField = env->GetFieldID(txDataClass, "chainId", "Ljava/lang/String;"); - jstring chainIdString = (jstring)env->GetObjectField(transactionObject, chainIdField); - const char* chainIdValue = env->GetStringUTFChars(chainIdString, nullptr); - tx_data_struct_v2->chain_id = strdup(chainIdValue); - - // groupId - jfieldID groupIdField = env->GetFieldID(txDataClass, "groupId", "Ljava/lang/String;"); - jstring groupIdString = (jstring)env->GetObjectField(transactionObject, groupIdField); - const char* groupIdValue = env->GetStringUTFChars(groupIdString, nullptr); - tx_data_struct_v2->group_id = strdup(groupIdValue); - - // nonce - jfieldID nonceField = env->GetFieldID(txDataClass, "nonce", "Ljava/lang/String;"); - jstring nonceString = (jstring)env->GetObjectField(transactionObject, nonceField); - const char* nonceValue = env->GetStringUTFChars(nonceString, nullptr); - tx_data_struct_v2->nonce = strdup(nonceValue); - - // to - jfieldID toField = env->GetFieldID(txDataClass, "to", "Ljava/lang/String;"); - jstring toString = (jstring)env->GetObjectField(transactionObject, toField); - const char* toValue = env->GetStringUTFChars(toString, nullptr); - tx_data_struct_v2->to = strdup(toValue); - - // abi - jfieldID abiField = env->GetFieldID(txDataClass, "abi", "Ljava/lang/String;"); - jstring abiString = (jstring)env->GetObjectField(transactionObject, abiField); - const char* abiValue = env->GetStringUTFChars(abiString, nullptr); - tx_data_struct_v2->abi = strdup(abiValue); - - // input - jfieldID inputField = env->GetFieldID( - txDataClass, "input", "Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionBytes;"); - jobject inputObject = env->GetObjectField(transactionObject, inputField); - struct bcos_sdk_c_bytes* inputStruct = convert_to_bytes_struct_v2(env, inputObject); - if (inputStruct == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_bytes_struct_v2"); - return NULL; - } - tx_data_struct_v2->input = inputStruct; - - // value - jfieldID valueField = env->GetFieldID(txDataClass, "value", "Ljava/lang/String;"); - jstring valueString = (jstring)env->GetObjectField(transactionObject, valueField); - const char* valueChar = env->GetStringUTFChars(valueString, nullptr); - tx_data_struct_v2->value = strdup(valueChar); - - // gas_price - jfieldID gasPriceField = env->GetFieldID(txDataClass, "gasPrice", "Ljava/lang/String;"); - jstring gasPriceString = (jstring)env->GetObjectField(transactionObject, gasPriceField); - const char* gasPriceChar = env->GetStringUTFChars(gasPriceString, nullptr); - tx_data_struct_v2->gas_price = strdup(gasPriceChar); - - // gas_limit - jfieldID gasLimitField = env->GetFieldID(txDataClass, "gasLimit", "J"); - tx_data_struct_v2->gas_limit = env->GetLongField(transactionObject, gasLimitField); - - // max_fee_per_gas - jfieldID maxFeePerGasField = env->GetFieldID(txDataClass, "maxFeePerGas", "Ljava/lang/String;"); - jstring maxFeePerGasString = (jstring)env->GetObjectField(transactionObject, maxFeePerGasField); - const char* maxFeePerGasChar = env->GetStringUTFChars(maxFeePerGasString, nullptr); - tx_data_struct_v2->max_fee_per_gas = strdup(maxFeePerGasChar); - - // max_priority_fee_per_gas - jfieldID maxPriorityFeePerGasField = - env->GetFieldID(txDataClass, "maxPriorityFeePerGas", "Ljava/lang/String;"); - jstring maxPriorityFeePerGasString = - (jstring)env->GetObjectField(transactionObject, maxPriorityFeePerGasField); - const char* maxPriorityFeePerGasChar = - env->GetStringUTFChars(maxPriorityFeePerGasString, nullptr); - tx_data_struct_v2->max_priority_fee_per_gas = strdup(maxPriorityFeePerGasChar); - - // release source - env->ReleaseStringUTFChars(chainIdString, chainIdValue); - env->ReleaseStringUTFChars(groupIdString, groupIdValue); - env->ReleaseStringUTFChars(nonceString, nonceValue); - env->ReleaseStringUTFChars(toString, toValue); - env->ReleaseStringUTFChars(abiString, abiValue); - env->ReleaseStringUTFChars(valueString, valueChar); - env->ReleaseStringUTFChars(gasPriceString, gasPriceChar); - env->ReleaseStringUTFChars(maxFeePerGasString, maxFeePerGasChar); - env->ReleaseStringUTFChars(maxPriorityFeePerGasString, maxPriorityFeePerGasChar); - - return tx_data_struct_v2; -} - -jobject convert_to_tx_data_jobject_v2( - JNIEnv* env, const struct bcos_sdk_c_transaction_data_v2* transactionDataV2) -{ - if (transactionDataV2 == nullptr) - { - THROW_JNI_EXCEPTION( - env, "exception in convert_to_tx_data_jobject_v2, transactionDataV2 is nullptr"); - return NULL; - } - - jclass txDataClass = env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2"); - if (txDataClass == NULL) - { - env->FatalError( - "No such class, className: " - "org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2"); - } - jmethodID txDataMtd = env->GetMethodID(txDataClass, "", "()V"); - if (txDataMtd == NULL) - { - env->FatalError("No such constructor in TransactionDataV2, constructor()"); - } - jobject jTxDataObj = env->NewObject(txDataClass, txDataMtd); - - // version - jfieldID versionField = env->GetFieldID(txDataClass, "version", "I"); - env->SetIntField(jTxDataObj, versionField, transactionDataV2->version); - // block_limit - jfieldID blockLimitField = env->GetFieldID(txDataClass, "blockLimit", "J"); - env->SetLongField(jTxDataObj, blockLimitField, transactionDataV2->block_limit); - // chain_id - jfieldID chainIdField = env->GetFieldID(txDataClass, "chainId", "Ljava/lang/String;"); - env->SetObjectField(jTxDataObj, chainIdField, env->NewStringUTF(transactionDataV2->chain_id)); - // group_id - jfieldID groupIdField = env->GetFieldID(txDataClass, "groupId", "Ljava/lang/String;"); - env->SetObjectField(jTxDataObj, groupIdField, env->NewStringUTF(transactionDataV2->group_id)); - // nonce - jfieldID nonceField = env->GetFieldID(txDataClass, "nonce", "Ljava/lang/String;"); - env->SetObjectField(jTxDataObj, nonceField, env->NewStringUTF(transactionDataV2->nonce)); - // to - jfieldID toField = env->GetFieldID(txDataClass, "to", "Ljava/lang/String;"); - env->SetObjectField(jTxDataObj, toField, env->NewStringUTF(transactionDataV2->to)); - // abi - jfieldID abiField = env->GetFieldID(txDataClass, "abi", "Ljava/lang/String;"); - env->SetObjectField(jTxDataObj, abiField, env->NewStringUTF(transactionDataV2->abi)); - // input - jobject jInput = convert_to_bytes_jobject_v2(env, transactionDataV2->input); - if (jInput == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_bytes_jobject_v2"); - return NULL; - } - jfieldID inputField = env->GetFieldID( - txDataClass, "input", "Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionBytes;"); - env->SetObjectField(jTxDataObj, inputField, jInput); - // value - jfieldID valueField = env->GetFieldID(txDataClass, "value", "Ljava/lang/String;"); - env->SetObjectField(jTxDataObj, valueField, env->NewStringUTF(transactionDataV2->value)); - // gas_price - jfieldID gasPriceField = env->GetFieldID(txDataClass, "gasPrice", "Ljava/lang/String;"); - env->SetObjectField(jTxDataObj, gasPriceField, env->NewStringUTF(transactionDataV2->gas_price)); - // gas_limit - jfieldID gasLimitField = env->GetFieldID(txDataClass, "gasLimit", "J"); - env->SetLongField(jTxDataObj, gasLimitField, transactionDataV2->gas_limit); - // max_fee_per_gas - jfieldID maxFeePerGasField = env->GetFieldID(txDataClass, "maxFeePerGas", "Ljava/lang/String;"); - env->SetObjectField( - jTxDataObj, maxFeePerGasField, env->NewStringUTF(transactionDataV2->max_fee_per_gas)); - // max_priority_fee_per_gas - jfieldID maxPriorityFeePerGasField = - env->GetFieldID(txDataClass, "maxPriorityFeePerGas", "Ljava/lang/String;"); - env->SetObjectField(jTxDataObj, maxPriorityFeePerGasField, - env->NewStringUTF(transactionDataV2->max_priority_fee_per_gas)); - - // release - env->DeleteLocalRef(jInput); - - return jTxDataObj; -} - -jobject convert_to_tx_jobject_v2(JNIEnv* env, const struct bcos_sdk_c_transaction_v2* tx_struct_v2) -{ - if (tx_struct_v2 == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_jobject_v2, tx_struct_v2 is nullptr"); - return NULL; - } - - jclass txClass = env->FindClass("org/fisco/bcos/sdk/jni/utilities/tx/TransactionV2"); - if (txClass == NULL) - { - env->FatalError( - "No such class, className: " - "org/fisco/bcos/sdk/jni/utilities/tx/TransactionV2"); - } - jmethodID txMtd = env->GetMethodID(txClass, "", "()V"); - if (txMtd == NULL) - { - env->FatalError("No such constructor in TransactionV2, constructor()"); - } - - jfieldID txDataField = env->GetFieldID( - txClass, "transactionData", "Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2;"); - jfieldID dataHashField = env->GetFieldID( - txClass, "dataHash", "Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionBytes;"); - jfieldID signatureField = env->GetFieldID( - txClass, "signature", "Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionBytes;"); - jfieldID senderField = env->GetFieldID( - txClass, "sender", "Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionBytes;"); - jfieldID importTimeField = env->GetFieldID(txClass, "importTime", "J"); - jfieldID attributeField = env->GetFieldID(txClass, "attribute", "I"); - jfieldID extraDataField = env->GetFieldID(txClass, "extraData", "Ljava/lang/String;"); - - jobject javaTxObj = env->NewObject(txClass, txMtd); - // TransactionData - jobject javaTxDataObj = convert_to_tx_data_jobject_v2(env, tx_struct_v2->transaction_data); - if (javaTxDataObj == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_data_jobject_v2"); - return NULL; - } - env->SetObjectField(javaTxObj, txDataField, javaTxDataObj); - // DataHash - jobject javaDataHashObj = convert_to_bytes_jobject_v2(env, tx_struct_v2->data_hash); - if (javaDataHashObj == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_bytes_jobject_v2"); - return NULL; - } - env->SetObjectField(javaTxObj, dataHashField, javaDataHashObj); - // Signature - jobject javaSignatureObj = convert_to_bytes_jobject_v2(env, tx_struct_v2->signature); - if (javaSignatureObj == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_bytes_jobject_v2"); - return NULL; - } - env->SetObjectField(javaTxObj, signatureField, javaSignatureObj); - // Sender - jobject javaSenderObj = convert_to_bytes_jobject_v2(env, tx_struct_v2->sender); - env->SetObjectField(javaTxObj, senderField, javaSenderObj); - // ImportTime - env->SetLongField(javaTxObj, importTimeField, tx_struct_v2->import_time); - // Attribute - env->SetIntField(javaTxObj, attributeField, tx_struct_v2->attribute); - // ExtraData - jstring javaExtraData = env->NewStringUTF(tx_struct_v2->extra_data); - env->SetObjectField(javaTxObj, extraDataField, javaExtraData); - - return javaTxObj; -} - -struct bcos_sdk_c_transaction_v2* convert_to_tx_struct_v2(JNIEnv* env, jobject jTxObj) -{ - if (jTxObj == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_struct_v2, jTxObj is nullptr"); - return NULL; - } - - jclass javaTxClass = env->GetObjectClass(jTxObj); - jfieldID transactionDataField = env->GetFieldID( - javaTxClass, "transactionData", "Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2;"); - jfieldID dataHashField = env->GetFieldID( - javaTxClass, "dataHash", "Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionBytes;"); - jfieldID signatureField = env->GetFieldID( - javaTxClass, "signature", "Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionBytes;"); - jfieldID senderField = env->GetFieldID( - javaTxClass, "sender", "Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionBytes;"); - jfieldID importTimeField = env->GetFieldID(javaTxClass, "importTime", "J"); - jfieldID attributeField = env->GetFieldID(javaTxClass, "attribute", "I"); - jfieldID extraDataField = env->GetFieldID(javaTxClass, "extraData", "Ljava/lang/String;"); - - struct bcos_sdk_c_transaction_v2* txStruct = - (struct bcos_sdk_c_transaction_v2*)malloc(sizeof(struct bcos_sdk_c_transaction_v2)); - // TransactionData - jobject javaTxDataObj = env->GetObjectField(jTxObj, transactionDataField); - struct bcos_sdk_c_transaction_data_v2* txDataStruct = - convert_to_tx_data_struct_v2(env, javaTxDataObj); - if (txDataStruct == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_data_struct_v2"); - return NULL; - } - txStruct->transaction_data = txDataStruct; - // DataHash - jobject javaDataHashObj = env->GetObjectField(jTxObj, dataHashField); - struct bcos_sdk_c_bytes* dataHashStruct = convert_to_bytes_struct_v2(env, javaDataHashObj); - if (dataHashStruct == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_bytes_struct_v2"); - return NULL; - } - txStruct->data_hash = dataHashStruct; - // Signature - jobject javaSignatureObj = env->GetObjectField(jTxObj, signatureField); - struct bcos_sdk_c_bytes* signatureStruct = convert_to_bytes_struct_v2(env, javaSignatureObj); - if (signatureStruct == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_bytes_struct_v2"); - return NULL; - } - txStruct->signature = signatureStruct; - // Sender - jobject javaSenderObj = env->GetObjectField(jTxObj, senderField); - struct bcos_sdk_c_bytes* senderStruct = convert_to_bytes_struct_v2(env, javaSenderObj); - txStruct->sender = senderStruct; - // ImportTime - jlong importTimeValue = env->GetLongField(jTxObj, importTimeField); - txStruct->import_time = (int64_t)importTimeValue; - // Attribute - jint attributeValue = env->GetIntField(jTxObj, attributeField); - txStruct->attribute = (int32_t)attributeValue; - // ExtraData - jstring javaExtraData = (jstring)env->GetObjectField(jTxObj, extraDataField); - const char* extraDataValue = env->GetStringUTFChars(javaExtraData, NULL); - txStruct->extra_data = strdup(extraDataValue); - - env->ReleaseStringUTFChars(javaExtraData, extraDataValue); - - return txStruct; -} - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: encodeTransactionDataStructV2 - * Signature: (Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_encodeTransactionDataStructV2( - JNIEnv* env, jclass, jobject jTransactionDataObj) -{ - struct bcos_sdk_c_transaction_data_v2* tx_data_struct_v2 = - convert_to_tx_data_struct_v2(env, jTransactionDataObj); - if (tx_data_struct_v2 == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_data_struct_v2"); - return nullptr; - } - const char* tx_data_hex = bcos_sdk_encode_transaction_data_struct_to_hex_v2(tx_data_struct_v2); - if (!bcos_sdk_is_last_opr_success()) - { - THROW_JNI_EXCEPTION(env, bcos_sdk_get_last_error_msg()); - return nullptr; - } - - jstring jTxDataHex = env->NewStringUTF(tx_data_hex); - - if (tx_data_hex) - { - free((void*)tx_data_hex); - tx_data_hex = NULL; - } - if (tx_data_struct_v2) - { - bcos_sdk_destroy_transaction_data_struct_v2(tx_data_struct_v2); - } - - return jTxDataHex; -} - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: encodeTransactionDataStructToJsonV2 - * Signature: (Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_encodeTransactionDataStructToJsonV2( - JNIEnv* env, jclass, jobject jTransactionDataObj) -{ - struct bcos_sdk_c_transaction_data_v2* tx_data_struct_v2 = - convert_to_tx_data_struct_v2(env, jTransactionDataObj); - if (tx_data_struct_v2 == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_data_struct_v2"); - return nullptr; - } - const char* tx_data_json = - bcos_sdk_encode_transaction_data_struct_to_json_v2(tx_data_struct_v2); - if (!bcos_sdk_is_last_opr_success()) - { - THROW_JNI_EXCEPTION(env, bcos_sdk_get_last_error_msg()); - return nullptr; - } - - jstring jTxDataJson = env->NewStringUTF(tx_data_json); - - if (tx_data_json) - { - free((void*)tx_data_json); - tx_data_json = NULL; - } - if (tx_data_struct_v2) - { - bcos_sdk_destroy_transaction_data_struct_v2(tx_data_struct_v2); - } - - return jTxDataJson; -} - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: decodeTransactionDataStructV2 - * Signature: (Ljava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2; - */ -JNIEXPORT jobject JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_decodeTransactionDataStructV2( - JNIEnv* env, jclass, jstring jTxDataHexStr) -{ - checkJString(env, jTxDataHexStr); - - const char* tx_data_hex_str = env->GetStringUTFChars(jTxDataHexStr, nullptr); - struct bcos_sdk_c_transaction_data_v2* tx_data_struct_v2 = - bcos_sdk_decode_transaction_data_struct_from_hex_v2(tx_data_hex_str); - if (!bcos_sdk_is_last_opr_success()) - { - THROW_JNI_EXCEPTION(env, bcos_sdk_get_last_error_msg()); - return nullptr; - } - - jobject jTxDataObj = convert_to_tx_data_jobject_v2(env, tx_data_struct_v2); - if (jTxDataObj == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_data_jobject_v2"); - return nullptr; - } - - // release source - if (tx_data_struct_v2) - { - bcos_sdk_destroy_transaction_data_struct_v2(tx_data_struct_v2); - } - env->ReleaseStringUTFChars(jTxDataHexStr, tx_data_hex_str); - - return jTxDataObj; -} - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: calcTransactionDataStructHashV2 - * Signature: (ILorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_calcTransactionDataStructHashV2( - JNIEnv* env, jclass, jint jCrytpTyte, jobject jTransactionDataObj) -{ - struct bcos_sdk_c_transaction_data_v2* tx_data_struct_v2 = - convert_to_tx_data_struct_v2(env, jTransactionDataObj); - if (tx_data_struct_v2 == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_data_struct_v2"); - return nullptr; - } - int crypto_type = jCrytpTyte; - const char* tx_data_hash = - bcos_sdk_calc_transaction_data_struct_hash_v2(crypto_type, tx_data_struct_v2); - if (!bcos_sdk_is_last_opr_success()) - { - THROW_JNI_EXCEPTION(env, bcos_sdk_get_last_error_msg()); - return nullptr; - } - - jstring jTxDataHash = env->NewStringUTF(tx_data_hash); - - // release source - if (tx_data_struct_v2) - { - bcos_sdk_destroy_transaction_data_struct_v2(tx_data_struct_v2); - } - if (tx_data_hash) - { - free((void*)tx_data_hash); - tx_data_hash = NULL; - } - - return jTxDataHash; -} - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: createEncodedTransactionV2 - * Signature: - * (Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_createEncodedTransactionV2( - JNIEnv* env, jclass, jobject jTxDataObj, jstring jSignature, jstring jTxDataHash, - jint jAttribute, jstring jExtraData) -{ - checkJString(env, jSignature); - checkJString(env, jTxDataHash); - checkJString(env, jExtraData); - - struct bcos_sdk_c_transaction_data_v2* tx_data_struct_v2 = - convert_to_tx_data_struct_v2(env, jTxDataObj); - if (tx_data_struct_v2 == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_data_struct_v2"); - return nullptr; - } - const char* signature = env->GetStringUTFChars(jSignature, NULL); - const char* tx_data_hash = env->GetStringUTFChars(jTxDataHash, NULL); - int attribute = jAttribute; - const char* extra_data = env->GetStringUTFChars(jExtraData, NULL); - - const char* tx_str = bcos_sdk_create_encoded_transaction_v2( - tx_data_struct_v2, signature, tx_data_hash, attribute, extra_data); - if (!bcos_sdk_is_last_opr_success()) - { - THROW_JNI_EXCEPTION(env, bcos_sdk_get_last_error_msg()); - return nullptr; - } - - jstring jTxStr = env->NewStringUTF(tx_str); - - // release resource - env->ReleaseStringUTFChars(jSignature, signature); - env->ReleaseStringUTFChars(jTxDataHash, tx_data_hash); - env->ReleaseStringUTFChars(jExtraData, extra_data); - if (tx_data_struct_v2) - { - bcos_sdk_destroy_transaction_data_struct_v2(tx_data_struct_v2); - } - if (tx_str) - { - free((void*)tx_str); - tx_str = NULL; - } - - return jTxStr; -} - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: encodeTransactionStructV2 - * Signature: (Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionV2;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_encodeTransactionStructV2( - JNIEnv* env, jclass, jobject jTransactionObj) -{ - struct bcos_sdk_c_transaction_v2* tx_struct_v2 = convert_to_tx_struct_v2(env, jTransactionObj); - if (tx_struct_v2 == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_struct_v2"); - return nullptr; - } - - const char* tx_hex = bcos_sdk_encode_transaction_struct_to_hex_v2(tx_struct_v2); - if (!bcos_sdk_is_last_opr_success()) - { - THROW_JNI_EXCEPTION(env, bcos_sdk_get_last_error_msg()); - return nullptr; - } - - jstring jTxHex = env->NewStringUTF(tx_hex); - - // release source - if (tx_hex) - { - free((void*)tx_hex); - tx_hex = NULL; - } - if (tx_struct_v2) - { - bcos_sdk_destroy_transaction_struct_v2(tx_struct_v2); - } - - return jTxHex; -} - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: encodeTransactionStructToJsonV2 - * Signature: (Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionV2;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_encodeTransactionStructToJsonV2( - JNIEnv* env, jclass, jobject jTransactionObj) -{ - struct bcos_sdk_c_transaction_v2* tx_struct_v2 = convert_to_tx_struct_v2(env, jTransactionObj); - if (tx_struct_v2 == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_struct_v2"); - return nullptr; - } - - const char* tx_json = bcos_sdk_encode_transaction_struct_to_json_v2(tx_struct_v2); - if (!bcos_sdk_is_last_opr_success()) - { - THROW_JNI_EXCEPTION(env, bcos_sdk_get_last_error_msg()); - return nullptr; - } - - jstring jTxJson = env->NewStringUTF(tx_json); - - if (tx_json) - { - free((void*)tx_json); - tx_json = NULL; - } - if (tx_struct_v2) - { - bcos_sdk_destroy_transaction_struct_v2(tx_struct_v2); - } - - return jTxJson; -} - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: decodeTransactionStructV2 - * Signature: (Ljava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionV2; - */ -JNIEXPORT jobject JNICALL -Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_decodeTransactionStructV2( - JNIEnv* env, jclass, jstring jTxHexStr) -{ - checkJString(env, jTxHexStr); - - const char* tx_hex_str = env->GetStringUTFChars(jTxHexStr, nullptr); - struct bcos_sdk_c_transaction_v2* tx_struct_v2 = - bcos_sdk_decode_transaction_struct_from_hex_v2(tx_hex_str); - if (!bcos_sdk_is_last_opr_success()) - { - THROW_JNI_EXCEPTION(env, bcos_sdk_get_last_error_msg()); - return nullptr; - } - - jobject jTxObj = convert_to_tx_jobject_v2(env, tx_struct_v2); - if (jTxObj == NULL) - { - THROW_JNI_EXCEPTION(env, "exception in convert_to_tx_jobject_v2"); - return nullptr; - } - - // release source - if (tx_struct_v2) - { - bcos_sdk_destroy_transaction_struct_v2(tx_struct_v2); - } - env->ReleaseStringUTFChars(jTxHexStr, tx_hex_str); - - return jTxObj; -} diff --git a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj.h b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj.h deleted file mode 100644 index 425cda94e..000000000 --- a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj.h +++ /dev/null @@ -1,77 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj */ - -#ifndef _Included_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj -#define _Included_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: encodeTransactionDataStructV2 - * Signature: (Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_encodeTransactionDataStructV2 - (JNIEnv *, jclass, jobject); - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: encodeTransactionDataStructToJsonV2 - * Signature: (Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_encodeTransactionDataStructToJsonV2 - (JNIEnv *, jclass, jobject); - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: decodeTransactionDataStructV2 - * Signature: (Ljava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2; - */ -JNIEXPORT jobject JNICALL Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_decodeTransactionDataStructV2 - (JNIEnv *, jclass, jstring); - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: calcTransactionDataStructHashV2 - * Signature: (ILorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_calcTransactionDataStructHashV2 - (JNIEnv *, jclass, jint, jobject); - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: createEncodedTransactionV2 - * Signature: (Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_createEncodedTransactionV2 - (JNIEnv *, jclass, jobject, jstring, jstring, jint, jstring); - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: encodeTransactionStructV2 - * Signature: (Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionV2;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_encodeTransactionStructV2 - (JNIEnv *, jclass, jobject); - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: encodeTransactionStructToJsonV2 - * Signature: (Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionV2;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_encodeTransactionStructToJsonV2 - (JNIEnv *, jclass, jobject); - -/* - * Class: org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj - * Method: decodeTransactionStructV2 - * Signature: (Ljava/lang/String;)Lorg/fisco/bcos/sdk/jni/utilities/tx/TransactionV2; - */ -JNIEXPORT jobject JNICALL Java_org_fisco_bcos_sdk_jni_utilities_tx_TransactionStructBuilderV2JniObj_decodeTransactionStructV2 - (JNIEnv *, jclass, jstring); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/Transaction.java b/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/Transaction.java index c5a8adbf7..a0ad0c9e2 100644 --- a/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/Transaction.java +++ b/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/Transaction.java @@ -4,7 +4,7 @@ public class Transaction { private TransactionData transactionData; private byte[] dataHash; private byte[] signature; - private byte[] sender; + private byte[] sender; private long importTime; private int attribute; private String extraData; diff --git a/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionBuilderV2JniObj.java b/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionBuilderV1JniObj.java similarity index 99% rename from bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionBuilderV2JniObj.java rename to bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionBuilderV1JniObj.java index f2cbfff21..88e0499c0 100644 --- a/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionBuilderV2JniObj.java +++ b/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionBuilderV1JniObj.java @@ -3,7 +3,7 @@ import org.fisco.bcos.sdk.jni.common.JniException; import org.fisco.bcos.sdk.jni.common.JniLibLoader; -public class TransactionBuilderV2JniObj extends TransactionBuilderJniObj { +public class TransactionBuilderV1JniObj extends TransactionBuilderJniObj { static { JniLibLoader.loadJniLibrary(); diff --git a/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2.java b/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV1.java similarity index 94% rename from bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2.java rename to bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV1.java index e83bb4796..7d3d5b55f 100644 --- a/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV2.java +++ b/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionDataV1.java @@ -1,6 +1,6 @@ package org.fisco.bcos.sdk.jni.utilities.tx; -public class TransactionDataV2 extends TransactionData { +public class TransactionDataV1 extends TransactionData { protected String value; protected String gasPrice; protected long gasLimit; diff --git a/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionStructBuilderJniObj.java b/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionStructBuilderJniObj.java index dfe34ac0e..400320b61 100644 --- a/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionStructBuilderJniObj.java +++ b/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionStructBuilderJniObj.java @@ -34,8 +34,8 @@ public static native TransactionData decodeTransactionDataStruct(String transact * @param transactionDataHex transactionData hex string * @return TxData */ - public static native TransactionDataV2 decodeTransactionDataStructV2(String transactionDataHex) - throws JniException; + public static native TransactionDataV1 decodeTransactionDataStructV1(String transactionDataHex) + throws JniException; /** * @param cryptoType crypto type @@ -85,6 +85,6 @@ public static native Transaction decodeTransactionStruct(String transactionHex) * @param transactionHex transaction hex string * @return Tx */ - public static native Transaction decodeTransactionStructV2(String transactionHex) - throws JniException; + public static native Transaction decodeTransactionStructV1(String transactionHex) + throws JniException; } diff --git a/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionVersion.java b/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionVersion.java index 79d1d0a0b..ba96756f3 100644 --- a/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionVersion.java +++ b/bindings/java/jni/src/main/java/org/fisco/bcos/sdk/jni/utilities/tx/TransactionVersion.java @@ -1,27 +1,27 @@ package org.fisco.bcos.sdk.jni.utilities.tx; public enum TransactionVersion { - V0(0), - V1(1); + V0(0), + V1(1); - private int value; + private int value; - TransactionVersion(int value) { - this.value = value; - } + TransactionVersion(int value) { + this.value = value; + } - public int getValue() { - return value; - } + public int getValue() { + return value; + } - public static TransactionVersion fromInt(int value) { - switch (value) { - case 0: - return V0; - case 1: - return V1; - default: - return V0; - } + public static TransactionVersion fromInt(int value) { + switch (value) { + case 0: + return V0; + case 1: + return V1; + default: + return V0; } + } } diff --git a/bindings/java/jni/src/test/java/org/fisco/bcos/sdk/jni/test/tx/TestTxStruct.java b/bindings/java/jni/src/test/java/org/fisco/bcos/sdk/jni/test/tx/TestTxStruct.java index e4fbf7120..78b605c5a 100644 --- a/bindings/java/jni/src/test/java/org/fisco/bcos/sdk/jni/test/tx/TestTxStruct.java +++ b/bindings/java/jni/src/test/java/org/fisco/bcos/sdk/jni/test/tx/TestTxStruct.java @@ -4,12 +4,10 @@ import java.util.Arrays; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; - import org.fisco.bcos.sdk.jni.BcosSDKJniObj; import org.fisco.bcos.sdk.jni.common.JniConfig; import org.fisco.bcos.sdk.jni.common.JniException; import org.fisco.bcos.sdk.jni.common.Response; -import org.fisco.bcos.sdk.jni.rpc.RpcCallback; import org.fisco.bcos.sdk.jni.rpc.RpcJniObj; import org.fisco.bcos.sdk.jni.test.Utility; import org.fisco.bcos.sdk.jni.utilities.keypair.KeyPairJniObj; @@ -18,28 +16,28 @@ public class TestTxStruct { - // ------------------------------------------------------------------------------ - // ------------------------------------------------------------------------------ - - // HelloWorld Source Code: - - // HelloWorld Source Code: - /** - * pragma solidity>=0.4.24 <0.6.11; - * - *

contract HelloWorld { string name; - * - *

constructor() public { name = "Hello, World!"; } - * - *

function get() public view returns (string memory) { return name; } - * - *

function set(string memory n) public { name = n; } } - */ - private static final String hwBIN = - "608060405234801561001057600080fd5b506040518060400160405280600d81526020017f48656c6c6f2c20576f726c6421000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b610310806101166000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80634ed3885e1461003b5780636d4ce63c146100f6575b600080fd5b6100f46004803603602081101561005157600080fd5b810190808035906020019064010000000081111561006e57600080fd5b82018360208201111561008057600080fd5b803590602001918460018302840111640100000000831117156100a257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610179565b005b6100fe610193565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013e578082015181840152602081019050610123565b50505050905090810190601f16801561016b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b806000908051906020019061018f929190610235565b5050565b606060008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561022b5780601f106102005761010080835404028352916020019161022b565b820191906000526020600020905b81548152906001019060200180831161020e57829003601f168201915b5050505050905090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061027657805160ff19168380011785556102a4565b828001600101855582156102a4579182015b828111156102a3578251825591602001919060010190610288565b5b5090506102b191906102b5565b5090565b6102d791905b808211156102d35760008160009055506001016102bb565b5090565b9056fea2646970667358221220b5943f43c48cc93c6d71cdcf27aee5072566c88755ce9186e32ce83b24e8dc6c64736f6c634300060a0033"; - - private static final String hwSmBIN = - "608060405234801561001057600080fd5b506040518060400160405280600d81526020017f48656c6c6f2c20576f726c6421000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b610310806101166000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063299f7f9d1461003b5780633590b49f146100be575b600080fd5b610043610179565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610083578082015181840152602081019050610068565b50505050905090810190601f1680156100b05780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610177600480360360208110156100d457600080fd5b81019080803590602001906401000000008111156100f157600080fd5b82018360208201111561010357600080fd5b8035906020019184600183028401116401000000008311171561012557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061021b565b005b606060008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102115780601f106101e657610100808354040283529160200191610211565b820191906000526020600020905b8154815290600101906020018083116101f457829003601f168201915b5050505050905090565b8060009080519060200190610231929190610235565b5050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061027657805160ff19168380011785556102a4565b828001600101855582156102a4579182015b828111156102a3578251825591602001919060010190610288565b5b5090506102b191906102b5565b5090565b6102d791905b808211156102d35760008160009055506001016102bb565b5090565b9056fea26469706673582212209871cb2bcf390d53645807cbaedfe052d739ef9cff9d84787f74c4f379e1854664736f6c634300060a0033"; + // ------------------------------------------------------------------------------ + // ------------------------------------------------------------------------------ + + // HelloWorld Source Code: + + // HelloWorld Source Code: + /** + * pragma solidity>=0.4.24 <0.6.11; + * + *

contract HelloWorld { string name; + * + *

constructor() public { name = "Hello, World!"; } + * + *

function get() public view returns (string memory) { return name; } + * + *

function set(string memory n) public { name = n; } } + */ + private static final String hwBIN = + "608060405234801561001057600080fd5b506040518060400160405280600d81526020017f48656c6c6f2c20576f726c6421000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b610310806101166000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80634ed3885e1461003b5780636d4ce63c146100f6575b600080fd5b6100f46004803603602081101561005157600080fd5b810190808035906020019064010000000081111561006e57600080fd5b82018360208201111561008057600080fd5b803590602001918460018302840111640100000000831117156100a257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610179565b005b6100fe610193565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013e578082015181840152602081019050610123565b50505050905090810190601f16801561016b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b806000908051906020019061018f929190610235565b5050565b606060008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561022b5780601f106102005761010080835404028352916020019161022b565b820191906000526020600020905b81548152906001019060200180831161020e57829003601f168201915b5050505050905090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061027657805160ff19168380011785556102a4565b828001600101855582156102a4579182015b828111156102a3578251825591602001919060010190610288565b5b5090506102b191906102b5565b5090565b6102d791905b808211156102d35760008160009055506001016102bb565b5090565b9056fea2646970667358221220b5943f43c48cc93c6d71cdcf27aee5072566c88755ce9186e32ce83b24e8dc6c64736f6c634300060a0033"; + + private static final String hwSmBIN = + "608060405234801561001057600080fd5b506040518060400160405280600d81526020017f48656c6c6f2c20576f726c6421000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b610310806101166000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063299f7f9d1461003b5780633590b49f146100be575b600080fd5b610043610179565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610083578082015181840152602081019050610068565b50505050905090810190601f1680156100b05780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610177600480360360208110156100d457600080fd5b81019080803590602001906401000000008111156100f157600080fd5b82018360208201111561010357600080fd5b8035906020019184600183028401116401000000008311171561012557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061021b565b005b606060008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102115780601f106101e657610100808354040283529160200191610211565b820191906000526020600020905b8154815290600101906020018083116101f457829003601f168201915b5050505050905090565b8060009080519060200190610231929190610235565b5050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061027657805160ff19168380011785556102a4565b828001600101855582156102a4579182015b828111156102a3578251825591602001919060010190610288565b5b5090506102b191906102b5565b5090565b6102d791905b808211156102d35760008160009055506001016102bb565b5090565b9056fea26469706673582212209871cb2bcf390d53645807cbaedfe052d739ef9cff9d84787f74c4f379e1854664736f6c634300060a0033"; /* { @@ -53,188 +51,182 @@ public class TestTxStruct { } */ - public static byte[] fromHex(String hexString) { - if (hexString.startsWith("0x")) { - hexString = hexString.substring(2); - } - - if (hexString.length() % 2 != 0) { - throw new IllegalArgumentException("Invalid hex string: " + hexString); - } + public static byte[] fromHex(String hexString) { + if (hexString.startsWith("0x")) { + hexString = hexString.substring(2); + } - int length = hexString.length() / 2; - byte[] bytes = new byte[length]; + if (hexString.length() % 2 != 0) { + throw new IllegalArgumentException("Invalid hex string: " + hexString); + } - for (int i = 0; i < length; i++) { - String twoChars = hexString.substring(i * 2, i * 2 + 2); - bytes[i] = (byte) Integer.parseInt(twoChars, 16); - } + int length = hexString.length() / 2; + byte[] bytes = new byte[length]; - return bytes; + for (int i = 0; i < length; i++) { + String twoChars = hexString.substring(i * 2, i * 2 + 2); + bytes[i] = (byte) Integer.parseInt(twoChars, 16); } - public static String generateNonce() { - byte[] nonceBytes = new byte[16]; - SecureRandom secureRandom = new SecureRandom(); - secureRandom.nextBytes(nonceBytes); - StringBuilder hex = new StringBuilder(); - for (byte b : nonceBytes) { - hex.append(String.format("%02x", b)); - } - return hex.toString(); - } + return bytes; + } - public static String getBinary(boolean isSM) { - return isSM ? hwSmBIN : hwBIN; + public static String generateNonce() { + byte[] nonceBytes = new byte[16]; + SecureRandom secureRandom = new SecureRandom(); + secureRandom.nextBytes(nonceBytes); + StringBuilder hex = new StringBuilder(); + for (byte b : nonceBytes) { + hex.append(String.format("%02x", b)); } + return hex.toString(); + } - public static void Usage() { - System.out.println("Desc: test transaction struct [HelloWorld set]"); - System.out.println( - "Usage: java -cp 'conf/:lib/*:apps/*' org.fisco.bcos.sdk.jni.test.tx.TestTxStruct"); - System.exit(0); - } + public static String getBinary(boolean isSM) { + return isSM ? hwSmBIN : hwBIN; + } + + public static void Usage() { + System.out.println("Desc: test transaction struct [HelloWorld set]"); + System.out.println( + "Usage: java -cp 'conf/:lib/*:apps/*' org.fisco.bcos.sdk.jni.test.tx.TestTxStruct"); + System.exit(0); + } - public static void main(String[] args) throws JniException, InterruptedException, ExecutionException { - if (args.length > 1) { - Usage(); - } - - String endpoint = "127.0.0.1:20200"; - String group = "group0"; - String node = ""; - JniConfig jniConfig = Utility.newJniConfig(Arrays.asList(endpoint)); - jniConfig.setDisableSsl(true); - BcosSDKJniObj bcosSDKJni = BcosSDKJniObj.build(jniConfig); - RpcJniObj rpcJniObj = RpcJniObj.build(bcosSDKJni.getNativePointer()); - System.out.println("build Rpc"); - rpcJniObj.start(); - - boolean smCrypto = false; - - long keyPair = KeyPairJniObj.createJniKeyPair(smCrypto ? 1 : 0); - String jniKeyPairAddress = KeyPairJniObj.getJniKeyPairAddress(keyPair); - - long blockLimit = 1111; - String groupID = "group0"; - String chainID = "chain0"; - String data = getBinary(smCrypto); - System.out.printf(" [test Tx Struct] new account, address: %s\n", jniKeyPairAddress); - - // construct TransactionData - TransactionData transactionDataStruct = new TransactionData(); - transactionDataStruct.setGroupId(groupID); - transactionDataStruct.setChainId(chainID); - transactionDataStruct.setTo(""); - transactionDataStruct.setAbi(""); - transactionDataStruct.setVersion(0); - transactionDataStruct.setNonce(generateNonce()); - transactionDataStruct.setBlockLimit(blockLimit); - // input - byte[] bytesInput = fromHex(data); - transactionDataStruct.setInput(bytesInput); - - // encode TxData to hex tx data - String txDataHex = - TransactionStructBuilderJniObj.encodeTransactionDataStruct(transactionDataStruct); - // decode hex tx data to TxData - TransactionData decodeTransactionDataStructHex = - TransactionStructBuilderJniObj.decodeTransactionDataStruct(txDataHex); - // assert - Assert.assertEquals( - transactionDataStruct.getChainId(), decodeTransactionDataStructHex.getChainId()); - Assert.assertEquals( - transactionDataStruct.getGroupId(), decodeTransactionDataStructHex.getGroupId()); - Assert.assertEquals(transactionDataStruct.getAbi(), decodeTransactionDataStructHex.getAbi()); - Assert.assertEquals( - transactionDataStruct.getBlockLimit(), decodeTransactionDataStructHex.getBlockLimit()); - - // encode TxData to json tx data - String txDataJson = - TransactionStructBuilderJniObj.encodeTransactionDataStructToJson(transactionDataStruct); - System.out.printf(" [test Tx Struct] txDataJson: %s\n", txDataJson); - - // calc tx data hash - String txDataHash = - TransactionStructBuilderJniObj.calcTransactionDataStructHash( - smCrypto ? 1 : 0, decodeTransactionDataStructHex); - System.out.printf(" [test Tx Struct] txDataHash: %s\n", txDataHash); - // signature tx data hash - String signature = TransactionBuilderJniObj.signTransactionDataHash(keyPair, txDataHash); - System.out.printf(" [test Tx Struct] signature: %s\n", signature); - - // construct tx - Transaction transactionStruct = new Transaction(); - transactionStruct.setTransactionData(decodeTransactionDataStructHex); - transactionStruct.setDataHash(fromHex(txDataHash)); - transactionStruct.setSignature(fromHex(signature)); - transactionStruct.setSender(null); - transactionStruct.setImportTime(0); - transactionStruct.setAttribute(0); - transactionStruct.setExtraData(""); - // assert - Assert.assertEquals( - transactionStruct.getTransactionData().getBlockLimit(), - decodeTransactionDataStructHex.getBlockLimit()); - Assert.assertEquals( - transactionStruct.getTransactionData().getGroupId(), - decodeTransactionDataStructHex.getGroupId()); - Assert.assertEquals( - transactionStruct.getTransactionData().getChainId(), - decodeTransactionDataStructHex.getChainId()); - Assert.assertEquals( - transactionStruct.getTransactionData().getAbi(), decodeTransactionDataStructHex.getAbi()); - Assert.assertArrayEquals(transactionStruct.getDataHash(), fromHex(txDataHash)); - Assert.assertArrayEquals(transactionStruct.getSignature(), fromHex(signature)); - - // encode Tx to hex tx - String txHex = TransactionStructBuilderJniObj.encodeTransactionStruct(transactionStruct); - // decode hex tx to Tx - Transaction decodeTransactionStructHex = - TransactionStructBuilderJniObj.decodeTransactionStruct(txHex); - // assert - Assert.assertEquals( - transactionStruct.getTransactionData().getBlockLimit(), - decodeTransactionStructHex.getTransactionData().getBlockLimit()); - Assert.assertEquals( - transactionStruct.getTransactionData().getGroupId(), - decodeTransactionStructHex.getTransactionData().getGroupId()); - Assert.assertEquals( - transactionStruct.getTransactionData().getChainId(), - decodeTransactionStructHex.getTransactionData().getChainId()); - Assert.assertEquals( - transactionStruct.getTransactionData().getAbi(), - decodeTransactionStructHex.getTransactionData().getAbi()); - Assert.assertArrayEquals( - transactionStruct.getDataHash(), - decodeTransactionStructHex.getDataHash()); - Assert.assertArrayEquals( - transactionStruct.getSignature(), - decodeTransactionStructHex.getSignature()); - - // encode Tx to json tx - String txJson = TransactionStructBuilderJniObj.encodeTransactionStructToJson(transactionStruct); - System.out.printf(" [test Tx Struct] txJson: %s\n", txJson); - // create tx string - String txString = - TransactionStructBuilderJniObj.createEncodedTransaction( - decodeTransactionDataStructHex, signature, txDataHash, 0, ""); - // System.out.printf(" [test Tx Struct] txString: %s\n", txString); - - CompletableFuture future = new CompletableFuture<>(); - // rpc send tx - rpcJniObj.sendTransaction( - group, - node, - txString, - false, - future::complete); - - Response response = future.get(); - System.out.println("response error code: ==>>> " + response.getErrorCode()); - String dataStr = new String(response.getData()); - System.out.println("response data: ==>>> " + dataStr); - rpcJniObj.stop(); - System.out.println(" [test Tx Struct] finish !!"); + public static void main(String[] args) + throws JniException, InterruptedException, ExecutionException { + if (args.length > 1) { + Usage(); } + + String endpoint = "127.0.0.1:20200"; + String group = "group0"; + String node = ""; + JniConfig jniConfig = Utility.newJniConfig(Arrays.asList(endpoint)); + jniConfig.setDisableSsl(true); + BcosSDKJniObj bcosSDKJni = BcosSDKJniObj.build(jniConfig); + RpcJniObj rpcJniObj = RpcJniObj.build(bcosSDKJni.getNativePointer()); + System.out.println("build Rpc"); + rpcJniObj.start(); + + boolean smCrypto = false; + + long keyPair = KeyPairJniObj.createJniKeyPair(smCrypto ? 1 : 0); + String jniKeyPairAddress = KeyPairJniObj.getJniKeyPairAddress(keyPair); + + long blockLimit = 1111; + String groupID = "group0"; + String chainID = "chain0"; + String data = getBinary(smCrypto); + System.out.printf(" [test Tx Struct] new account, address: %s\n", jniKeyPairAddress); + + // construct TransactionData + TransactionData transactionDataStruct = new TransactionData(); + transactionDataStruct.setGroupId(groupID); + transactionDataStruct.setChainId(chainID); + transactionDataStruct.setTo(""); + transactionDataStruct.setAbi(""); + transactionDataStruct.setVersion(0); + transactionDataStruct.setNonce(generateNonce()); + transactionDataStruct.setBlockLimit(blockLimit); + // input + byte[] bytesInput = fromHex(data); + transactionDataStruct.setInput(bytesInput); + + // encode TxData to hex tx data + String txDataHex = + TransactionStructBuilderJniObj.encodeTransactionDataStruct(transactionDataStruct); + // decode hex tx data to TxData + TransactionData decodeTransactionDataStructHex = + TransactionStructBuilderJniObj.decodeTransactionDataStruct(txDataHex); + // assert + Assert.assertEquals( + transactionDataStruct.getChainId(), decodeTransactionDataStructHex.getChainId()); + Assert.assertEquals( + transactionDataStruct.getGroupId(), decodeTransactionDataStructHex.getGroupId()); + Assert.assertEquals(transactionDataStruct.getAbi(), decodeTransactionDataStructHex.getAbi()); + Assert.assertEquals( + transactionDataStruct.getBlockLimit(), decodeTransactionDataStructHex.getBlockLimit()); + + // encode TxData to json tx data + String txDataJson = + TransactionStructBuilderJniObj.encodeTransactionDataStructToJson(transactionDataStruct); + System.out.printf(" [test Tx Struct] txDataJson: %s\n", txDataJson); + + // calc tx data hash + String txDataHash = + TransactionStructBuilderJniObj.calcTransactionDataStructHash( + smCrypto ? 1 : 0, decodeTransactionDataStructHex); + System.out.printf(" [test Tx Struct] txDataHash: %s\n", txDataHash); + // signature tx data hash + String signature = TransactionBuilderJniObj.signTransactionDataHash(keyPair, txDataHash); + System.out.printf(" [test Tx Struct] signature: %s\n", signature); + + // construct tx + Transaction transactionStruct = new Transaction(); + transactionStruct.setTransactionData(decodeTransactionDataStructHex); + transactionStruct.setDataHash(fromHex(txDataHash)); + transactionStruct.setSignature(fromHex(signature)); + transactionStruct.setSender(null); + transactionStruct.setImportTime(0); + transactionStruct.setAttribute(0); + transactionStruct.setExtraData(""); + // assert + Assert.assertEquals( + transactionStruct.getTransactionData().getBlockLimit(), + decodeTransactionDataStructHex.getBlockLimit()); + Assert.assertEquals( + transactionStruct.getTransactionData().getGroupId(), + decodeTransactionDataStructHex.getGroupId()); + Assert.assertEquals( + transactionStruct.getTransactionData().getChainId(), + decodeTransactionDataStructHex.getChainId()); + Assert.assertEquals( + transactionStruct.getTransactionData().getAbi(), decodeTransactionDataStructHex.getAbi()); + Assert.assertArrayEquals(transactionStruct.getDataHash(), fromHex(txDataHash)); + Assert.assertArrayEquals(transactionStruct.getSignature(), fromHex(signature)); + + // encode Tx to hex tx + String txHex = TransactionStructBuilderJniObj.encodeTransactionStruct(transactionStruct); + // decode hex tx to Tx + Transaction decodeTransactionStructHex = + TransactionStructBuilderJniObj.decodeTransactionStruct(txHex); + // assert + Assert.assertEquals( + transactionStruct.getTransactionData().getBlockLimit(), + decodeTransactionStructHex.getTransactionData().getBlockLimit()); + Assert.assertEquals( + transactionStruct.getTransactionData().getGroupId(), + decodeTransactionStructHex.getTransactionData().getGroupId()); + Assert.assertEquals( + transactionStruct.getTransactionData().getChainId(), + decodeTransactionStructHex.getTransactionData().getChainId()); + Assert.assertEquals( + transactionStruct.getTransactionData().getAbi(), + decodeTransactionStructHex.getTransactionData().getAbi()); + Assert.assertArrayEquals( + transactionStruct.getDataHash(), decodeTransactionStructHex.getDataHash()); + Assert.assertArrayEquals( + transactionStruct.getSignature(), decodeTransactionStructHex.getSignature()); + + // encode Tx to json tx + String txJson = TransactionStructBuilderJniObj.encodeTransactionStructToJson(transactionStruct); + System.out.printf(" [test Tx Struct] txJson: %s\n", txJson); + // create tx string + String txString = + TransactionStructBuilderJniObj.createEncodedTransaction( + decodeTransactionDataStructHex, signature, txDataHash, 0, ""); + // System.out.printf(" [test Tx Struct] txString: %s\n", txString); + + CompletableFuture future = new CompletableFuture<>(); + // rpc send tx + rpcJniObj.sendTransaction(group, node, txString, false, future::complete); + + Response response = future.get(); + System.out.println("response error code: ==>>> " + response.getErrorCode()); + String dataStr = new String(response.getData()); + System.out.println("response data: ==>>> " + dataStr); + rpcJniObj.stop(); + System.out.println(" [test Tx Struct] finish !!"); + } } diff --git a/bindings/java/jni/src/test/java/org/fisco/bcos/sdk/jni/test/tx/TestTxStructV1.java b/bindings/java/jni/src/test/java/org/fisco/bcos/sdk/jni/test/tx/TestTxStructV1.java new file mode 100644 index 000000000..5a09b7854 --- /dev/null +++ b/bindings/java/jni/src/test/java/org/fisco/bcos/sdk/jni/test/tx/TestTxStructV1.java @@ -0,0 +1,272 @@ +package org.fisco.bcos.sdk.jni.test.tx; + +import java.security.SecureRandom; +import java.util.Arrays; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import org.fisco.bcos.sdk.jni.BcosSDKJniObj; +import org.fisco.bcos.sdk.jni.common.JniConfig; +import org.fisco.bcos.sdk.jni.common.JniException; +import org.fisco.bcos.sdk.jni.common.Response; +import org.fisco.bcos.sdk.jni.rpc.RpcJniObj; +import org.fisco.bcos.sdk.jni.test.Utility; +import org.fisco.bcos.sdk.jni.utilities.keypair.KeyPairJniObj; +import org.fisco.bcos.sdk.jni.utilities.tx.*; +import org.junit.Assert; + +public class TestTxStructV1 { + + // ------------------------------------------------------------------------------ + // ------------------------------------------------------------------------------ + + // HelloWorld Source Code: + /** + * pragma solidity>=0.4.24 <0.6.11; + * + *

contract HelloWorld { string name; + * + *

constructor() public { name = "Hello, World!"; } + * + *

function get() public view returns (string memory) { return name; } + * + *

function set(string memory n) public { name = n; } } + */ + private static final String hwBIN = + "608060405234801561001057600080fd5b506040518060400160405280600d81526020017f48656c6c6f2c20576f726c6421000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b610310806101166000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80634ed3885e1461003b5780636d4ce63c146100f6575b600080fd5b6100f46004803603602081101561005157600080fd5b810190808035906020019064010000000081111561006e57600080fd5b82018360208201111561008057600080fd5b803590602001918460018302840111640100000000831117156100a257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610179565b005b6100fe610193565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013e578082015181840152602081019050610123565b50505050905090810190601f16801561016b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b806000908051906020019061018f929190610235565b5050565b606060008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561022b5780601f106102005761010080835404028352916020019161022b565b820191906000526020600020905b81548152906001019060200180831161020e57829003601f168201915b5050505050905090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061027657805160ff19168380011785556102a4565b828001600101855582156102a4579182015b828111156102a3578251825591602001919060010190610288565b5b5090506102b191906102b5565b5090565b6102d791905b808211156102d35760008160009055506001016102bb565b5090565b9056fea2646970667358221220b5943f43c48cc93c6d71cdcf27aee5072566c88755ce9186e32ce83b24e8dc6c64736f6c634300060a0033"; + + private static final String hwSmBIN = + "608060405234801561001057600080fd5b506040518060400160405280600d81526020017f48656c6c6f2c20576f726c6421000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b610310806101166000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063299f7f9d1461003b5780633590b49f146100be575b600080fd5b610043610179565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610083578082015181840152602081019050610068565b50505050905090810190601f1680156100b05780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610177600480360360208110156100d457600080fd5b81019080803590602001906401000000008111156100f157600080fd5b82018360208201111561010357600080fd5b8035906020019184600183028401116401000000008311171561012557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061021b565b005b606060008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102115780601f106101e657610100808354040283529160200191610211565b820191906000526020600020905b8154815290600101906020018083116101f457829003601f168201915b5050505050905090565b8060009080519060200190610231929190610235565b5050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061027657805160ff19168380011785556102a4565b828001600101855582156102a4579182015b828111156102a3578251825591602001919060010190610288565b5b5090506102b191906102b5565b5090565b6102d791905b808211156102d35760008160009055506001016102bb565b5090565b9056fea26469706673582212209871cb2bcf390d53645807cbaedfe052d739ef9cff9d84787f74c4f379e1854664736f6c634300060a0033"; + + /* + { + "6d4ce63c": "get()", + "4ed3885e": "set(string)" + } + + { + "299f7f9d": "get()", + "3590b49f": "set(string)" + } + */ + + public static byte[] fromHex(String hexString) { + if (hexString.startsWith("0x")) { + hexString = hexString.substring(2); + } + + if (hexString.length() % 2 != 0) { + throw new IllegalArgumentException("Invalid hex string: " + hexString); + } + + int length = hexString.length() / 2; + byte[] bytes = new byte[length]; + + for (int i = 0; i < length; i++) { + String twoChars = hexString.substring(i * 2, i * 2 + 2); + bytes[i] = (byte) Integer.parseInt(twoChars, 16); + } + + return bytes; + } + + public static String generateNonce() { + byte[] nonceBytes = new byte[16]; + SecureRandom secureRandom = new SecureRandom(); + secureRandom.nextBytes(nonceBytes); + StringBuilder hex = new StringBuilder(); + for (byte b : nonceBytes) { + hex.append(String.format("%02x", b)); + } + return hex.toString(); + } + + public static String getBinary(boolean isSM) { + return isSM ? hwSmBIN : hwBIN; + } + + public static void Usage() { + System.out.println("Desc: test transaction struct V1 [HelloWorld set]"); + System.out.println( + "Usage: java -cp 'conf/:lib/*:apps/*' org.fisco.bcos.sdk.jni.test.tx.TestTxStructV1"); + System.exit(0); + } + + public static void main(String[] args) + throws JniException, InterruptedException, ExecutionException { + if (args.length > 1) { + Usage(); + } + + String endpoint = "127.0.0.1:20200"; + String group = "group0"; + String node = ""; + JniConfig jniConfig = Utility.newJniConfig(Arrays.asList(endpoint)); + jniConfig.setDisableSsl(true); + BcosSDKJniObj bcosSDKJni = BcosSDKJniObj.build(jniConfig); + RpcJniObj rpcJniObj = RpcJniObj.build(bcosSDKJni.getNativePointer()); + System.out.println("build Rpc"); + rpcJniObj.start(); + long blockLimit = rpcJniObj.getBlockLimit(group); + + boolean smCrypto = false; + + long keyPair = KeyPairJniObj.createJniKeyPair(smCrypto ? 1 : 0); + String jniKeyPairAddress = KeyPairJniObj.getJniKeyPairAddress(keyPair); + System.out.printf(" [test Tx Struct V1] new account, address: %s\n", jniKeyPairAddress); + + String groupID = "group0"; + String chainID = "chain0"; + String data = getBinary(smCrypto); + String value = "0x11"; + String gasPrice = "0x10"; + long gasLimit = 0; + String maxFeePerGas = "0x11"; + String maxPriorityFeePerGas = "0x22"; + + // construct TransactionDataV1 + TransactionDataV1 transactionDataStructV1 = new TransactionDataV1(); + transactionDataStructV1.setGroupId(groupID); + transactionDataStructV1.setChainId(chainID); + transactionDataStructV1.setTo(""); + transactionDataStructV1.setAbi(""); + transactionDataStructV1.setVersion(1); + transactionDataStructV1.setNonce(generateNonce()); + transactionDataStructV1.setBlockLimit(blockLimit); + transactionDataStructV1.setValue(value); + transactionDataStructV1.setGasPrice(gasPrice); + transactionDataStructV1.setGasLimit(gasLimit); + transactionDataStructV1.setMaxFeePerGas(maxFeePerGas); + transactionDataStructV1.setMaxPriorityFeePerGas(maxPriorityFeePerGas); + // input + byte[] bytesInput = fromHex(data); + transactionDataStructV1.setInput(bytesInput); + + // encode TxData to hex tx data + String txDataHex = + TransactionStructBuilderJniObj.encodeTransactionDataStruct(transactionDataStructV1); + // decode hex tx data to TxData + TransactionDataV1 decodeTransactionDataStructHex = + TransactionStructBuilderJniObj.decodeTransactionDataStructV1(txDataHex); + // TransactionDataV1 decodeTransactionDataStructHex2 = + // TransactionStructBuilderV1JniObj.decodeTransactionDataStructV1(null); + // TransactionDataV1 decodeTransactionDataStructHex3 = + // TransactionStructBuilderV1JniObj.decodeTransactionDataStructV1(""); + + // assert + Assert.assertEquals( + transactionDataStructV1.getChainId(), decodeTransactionDataStructHex.getChainId()); + Assert.assertEquals( + transactionDataStructV1.getGroupId(), decodeTransactionDataStructHex.getGroupId()); + Assert.assertEquals(transactionDataStructV1.getAbi(), decodeTransactionDataStructHex.getAbi()); + Assert.assertEquals( + transactionDataStructV1.getBlockLimit(), decodeTransactionDataStructHex.getBlockLimit()); + Assert.assertEquals( + transactionDataStructV1.getValue(), decodeTransactionDataStructHex.getValue()); + Assert.assertEquals( + transactionDataStructV1.getGasPrice(), decodeTransactionDataStructHex.getGasPrice()); + Assert.assertEquals( + transactionDataStructV1.getGasLimit(), decodeTransactionDataStructHex.getGasLimit()); + Assert.assertEquals( + transactionDataStructV1.getMaxFeePerGas(), + decodeTransactionDataStructHex.getMaxFeePerGas()); + Assert.assertEquals( + transactionDataStructV1.getMaxPriorityFeePerGas(), + decodeTransactionDataStructHex.getMaxPriorityFeePerGas()); + + // encode TxData to json tx data + String txDataJson = + TransactionStructBuilderJniObj.encodeTransactionDataStructToJson(transactionDataStructV1); + System.out.printf(" [test Tx Struct V1] txDataJson: %s\n", txDataJson); + + // calc tx data hash + String txDataHash = + TransactionStructBuilderJniObj.calcTransactionDataStructHash( + smCrypto ? 1 : 0, decodeTransactionDataStructHex); + System.out.printf(" [test Tx Struct V1] txDataHash: %s\n", txDataHash); + // signature tx data hash + String signature = TransactionBuilderJniObj.signTransactionDataHash(keyPair, txDataHash); + System.out.printf(" [test Tx Struct V1] signature: %s\n", signature); + + // construct tx + Transaction transactionStructV1 = new Transaction(); + transactionStructV1.setTransactionData(decodeTransactionDataStructHex); + transactionStructV1.setDataHash(fromHex(txDataHash)); + transactionStructV1.setSignature(fromHex(signature)); + transactionStructV1.setSender(null); + transactionStructV1.setImportTime(0); + transactionStructV1.setAttribute(0); + transactionStructV1.setExtraData(""); + // assert + Assert.assertEquals( + transactionStructV1.getTransactionData().getBlockLimit(), + decodeTransactionDataStructHex.getBlockLimit()); + Assert.assertEquals( + transactionStructV1.getTransactionData().getGroupId(), + decodeTransactionDataStructHex.getGroupId()); + Assert.assertEquals( + transactionStructV1.getTransactionData().getChainId(), + decodeTransactionDataStructHex.getChainId()); + Assert.assertEquals( + transactionStructV1.getTransactionData().getChainId(), + decodeTransactionDataStructHex.getChainId()); + Assert.assertEquals( + transactionStructV1.getTransactionData().getAbi(), decodeTransactionDataStructHex.getAbi()); + Assert.assertArrayEquals(transactionStructV1.getDataHash(), fromHex(txDataHash)); + Assert.assertArrayEquals(transactionStructV1.getSignature(), fromHex(signature)); + + // encode Tx to hex tx + String txHex = TransactionStructBuilderJniObj.encodeTransactionStruct(transactionStructV1); + // decode hex tx to Tx + Transaction decodeTransactionStructHex = + TransactionStructBuilderJniObj.decodeTransactionStructV1(txHex); + + // assert + Assert.assertEquals( + transactionStructV1.getTransactionData().getBlockLimit(), + decodeTransactionStructHex.getTransactionData().getBlockLimit()); + Assert.assertEquals( + transactionStructV1.getTransactionData().getGroupId(), + decodeTransactionStructHex.getTransactionData().getGroupId()); + Assert.assertEquals( + transactionStructV1.getTransactionData().getChainId(), + decodeTransactionStructHex.getTransactionData().getChainId()); + Assert.assertEquals( + transactionStructV1.getTransactionData().getAbi(), + decodeTransactionStructHex.getTransactionData().getAbi()); + TransactionDataV1 transactionData = + (TransactionDataV1) transactionStructV1.getTransactionData(); + TransactionDataV1 decodeTransactionData = + (TransactionDataV1) decodeTransactionStructHex.getTransactionData(); + Assert.assertEquals(transactionData.getValue(), decodeTransactionData.getValue()); + Assert.assertEquals(transactionData.getGasLimit(), decodeTransactionData.getGasLimit()); + Assert.assertEquals(transactionData.getGasPrice(), decodeTransactionData.getGasPrice()); + Assert.assertEquals(transactionData.getMaxFeePerGas(), decodeTransactionData.getMaxFeePerGas()); + Assert.assertEquals( + transactionData.getMaxPriorityFeePerGas(), decodeTransactionData.getMaxPriorityFeePerGas()); + Assert.assertArrayEquals( + transactionStructV1.getDataHash(), decodeTransactionStructHex.getDataHash()); + Assert.assertArrayEquals( + transactionStructV1.getSignature(), decodeTransactionStructHex.getSignature()); + + // encode Tx to json tx + String txJson = + TransactionStructBuilderJniObj.encodeTransactionStructToJson(transactionStructV1); + System.out.printf(" [test Tx Struct V1] txJson: %s\n", txJson); + // create tx string + String txString = + TransactionStructBuilderJniObj.createEncodedTransaction( + decodeTransactionDataStructHex, signature, txDataHash, 0, ""); + // System.out.printf(" [test Tx Struct V1] txString: %s\n", txString); + CompletableFuture future = new CompletableFuture<>(); + + // rpc send tx + rpcJniObj.sendTransaction(group, node, txString, false, future::complete); + + Response response = future.get(); + System.out.println("response error code: ==>>> " + response.getErrorCode()); + String dataStr = new String(response.getData()); + System.out.println("response data: ==>>> " + dataStr); + rpcJniObj.stop(); + System.out.println(" [test Tx Struct V1] finish !! "); + } +} diff --git a/bindings/java/jni/src/test/java/org/fisco/bcos/sdk/jni/test/tx/TestTxStructV2.java b/bindings/java/jni/src/test/java/org/fisco/bcos/sdk/jni/test/tx/TestTxStructV2.java deleted file mode 100644 index 16db16885..000000000 --- a/bindings/java/jni/src/test/java/org/fisco/bcos/sdk/jni/test/tx/TestTxStructV2.java +++ /dev/null @@ -1,293 +0,0 @@ -package org.fisco.bcos.sdk.jni.test.tx; - -import java.security.SecureRandom; -import java.util.Arrays; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -import org.fisco.bcos.sdk.jni.BcosSDKJniObj; -import org.fisco.bcos.sdk.jni.common.JniConfig; -import org.fisco.bcos.sdk.jni.common.JniException; -import org.fisco.bcos.sdk.jni.common.Response; -import org.fisco.bcos.sdk.jni.rpc.RpcCallback; -import org.fisco.bcos.sdk.jni.rpc.RpcJniObj; -import org.fisco.bcos.sdk.jni.test.Utility; -import org.fisco.bcos.sdk.jni.utilities.keypair.KeyPairJniObj; -import org.fisco.bcos.sdk.jni.utilities.tx.*; -import org.junit.Assert; - -public class TestTxStructV2 { - - // ------------------------------------------------------------------------------ - // ------------------------------------------------------------------------------ - - // HelloWorld Source Code: - /** - * pragma solidity>=0.4.24 <0.6.11; - * - *

contract HelloWorld { string name; - * - *

constructor() public { name = "Hello, World!"; } - * - *

function get() public view returns (string memory) { return name; } - * - *

function set(string memory n) public { name = n; } } - */ - private static final String hwBIN = - "608060405234801561001057600080fd5b506040518060400160405280600d81526020017f48656c6c6f2c20576f726c6421000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b610310806101166000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80634ed3885e1461003b5780636d4ce63c146100f6575b600080fd5b6100f46004803603602081101561005157600080fd5b810190808035906020019064010000000081111561006e57600080fd5b82018360208201111561008057600080fd5b803590602001918460018302840111640100000000831117156100a257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610179565b005b6100fe610193565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013e578082015181840152602081019050610123565b50505050905090810190601f16801561016b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b806000908051906020019061018f929190610235565b5050565b606060008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561022b5780601f106102005761010080835404028352916020019161022b565b820191906000526020600020905b81548152906001019060200180831161020e57829003601f168201915b5050505050905090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061027657805160ff19168380011785556102a4565b828001600101855582156102a4579182015b828111156102a3578251825591602001919060010190610288565b5b5090506102b191906102b5565b5090565b6102d791905b808211156102d35760008160009055506001016102bb565b5090565b9056fea2646970667358221220b5943f43c48cc93c6d71cdcf27aee5072566c88755ce9186e32ce83b24e8dc6c64736f6c634300060a0033"; - - private static final String hwSmBIN = - "608060405234801561001057600080fd5b506040518060400160405280600d81526020017f48656c6c6f2c20576f726c6421000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b610310806101166000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063299f7f9d1461003b5780633590b49f146100be575b600080fd5b610043610179565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610083578082015181840152602081019050610068565b50505050905090810190601f1680156100b05780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610177600480360360208110156100d457600080fd5b81019080803590602001906401000000008111156100f157600080fd5b82018360208201111561010357600080fd5b8035906020019184600183028401116401000000008311171561012557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061021b565b005b606060008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102115780601f106101e657610100808354040283529160200191610211565b820191906000526020600020905b8154815290600101906020018083116101f457829003601f168201915b5050505050905090565b8060009080519060200190610231929190610235565b5050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061027657805160ff19168380011785556102a4565b828001600101855582156102a4579182015b828111156102a3578251825591602001919060010190610288565b5b5090506102b191906102b5565b5090565b6102d791905b808211156102d35760008160009055506001016102bb565b5090565b9056fea26469706673582212209871cb2bcf390d53645807cbaedfe052d739ef9cff9d84787f74c4f379e1854664736f6c634300060a0033"; - - /* - { - "6d4ce63c": "get()", - "4ed3885e": "set(string)" - } - - { - "299f7f9d": "get()", - "3590b49f": "set(string)" - } - */ - - public static byte[] fromHex(String hexString) { - if (hexString.startsWith("0x")) { - hexString = hexString.substring(2); - } - - if (hexString.length() % 2 != 0) { - throw new IllegalArgumentException("Invalid hex string: " + hexString); - } - - int length = hexString.length() / 2; - byte[] bytes = new byte[length]; - - for (int i = 0; i < length; i++) { - String twoChars = hexString.substring(i * 2, i * 2 + 2); - bytes[i] = (byte) Integer.parseInt(twoChars, 16); - } - - return bytes; - } - - public static String generateNonce() { - byte[] nonceBytes = new byte[16]; - SecureRandom secureRandom = new SecureRandom(); - secureRandom.nextBytes(nonceBytes); - StringBuilder hex = new StringBuilder(); - for (byte b : nonceBytes) { - hex.append(String.format("%02x", b)); - } - return hex.toString(); - } - - public static String getBinary(boolean isSM) { - return isSM ? hwSmBIN : hwBIN; - } - - public static void Usage() { - System.out.println("Desc: test transaction struct V2 [HelloWorld set]"); - System.out.println( - "Usage: java -cp 'conf/:lib/*:apps/*' org.fisco.bcos.sdk.jni.test.tx.TestTxStructV2"); - System.exit(0); - } - - public static void main(String[] args) throws JniException, InterruptedException, ExecutionException { - if (args.length > 1) { - Usage(); - } - - String endpoint = "127.0.0.1:20200"; - String group = "group0"; - String node = ""; - JniConfig jniConfig = Utility.newJniConfig(Arrays.asList(endpoint)); - jniConfig.setDisableSsl(true); - BcosSDKJniObj bcosSDKJni = BcosSDKJniObj.build(jniConfig); - RpcJniObj rpcJniObj = RpcJniObj.build(bcosSDKJni.getNativePointer()); - System.out.println("build Rpc"); - rpcJniObj.start(); - long blockLimit = rpcJniObj.getBlockLimit(group); - - boolean smCrypto = false; - - long keyPair = KeyPairJniObj.createJniKeyPair(smCrypto ? 1 : 0); - String jniKeyPairAddress = KeyPairJniObj.getJniKeyPairAddress(keyPair); - System.out.printf(" [test Tx Struct V2] new account, address: %s\n", jniKeyPairAddress); - - String groupID = "group0"; - String chainID = "chain0"; - String data = getBinary(smCrypto); - String value = "0x11"; - String gasPrice = "0x10"; - long gasLimit = 0; - String maxFeePerGas = "0x11"; - String maxPriorityFeePerGas = "0x22"; - - // construct TransactionDataV2 - TransactionDataV2 transactionDataStructV2 = new TransactionDataV2(); - transactionDataStructV2.setGroupId(groupID); - transactionDataStructV2.setChainId(chainID); - transactionDataStructV2.setTo(""); - transactionDataStructV2.setAbi(""); - transactionDataStructV2.setVersion(1); - transactionDataStructV2.setNonce(generateNonce()); - transactionDataStructV2.setBlockLimit(blockLimit); - transactionDataStructV2.setValue(value); - transactionDataStructV2.setGasPrice(gasPrice); - transactionDataStructV2.setGasLimit(gasLimit); - transactionDataStructV2.setMaxFeePerGas(maxFeePerGas); - transactionDataStructV2.setMaxPriorityFeePerGas(maxPriorityFeePerGas); - // input - byte[] bytesInput = fromHex(data); - transactionDataStructV2.setInput(bytesInput); - - // encode TxData to hex tx data - String txDataHex = - TransactionStructBuilderJniObj.encodeTransactionDataStruct(transactionDataStructV2); - // decode hex tx data to TxData - TransactionDataV2 decodeTransactionDataStructHex = - TransactionStructBuilderJniObj.decodeTransactionDataStructV2(txDataHex); - // TransactionDataV2 decodeTransactionDataStructHex2 = - // TransactionStructBuilderV2JniObj.decodeTransactionDataStructV2(null); - // TransactionDataV2 decodeTransactionDataStructHex3 = - // TransactionStructBuilderV2JniObj.decodeTransactionDataStructV2(""); - - // assert - Assert.assertEquals( - transactionDataStructV2.getChainId(), decodeTransactionDataStructHex.getChainId()); - Assert.assertEquals( - transactionDataStructV2.getGroupId(), decodeTransactionDataStructHex.getGroupId()); - Assert.assertEquals( - transactionDataStructV2.getAbi(), decodeTransactionDataStructHex.getAbi()); - Assert.assertEquals( - transactionDataStructV2.getBlockLimit(), decodeTransactionDataStructHex.getBlockLimit()); - Assert.assertEquals( - transactionDataStructV2.getValue(), decodeTransactionDataStructHex.getValue()); - Assert.assertEquals( - transactionDataStructV2.getGasPrice(), decodeTransactionDataStructHex.getGasPrice()); - Assert.assertEquals( - transactionDataStructV2.getGasLimit(), decodeTransactionDataStructHex.getGasLimit()); - Assert.assertEquals( - transactionDataStructV2.getMaxFeePerGas(), - decodeTransactionDataStructHex.getMaxFeePerGas()); - Assert.assertEquals( - transactionDataStructV2.getMaxPriorityFeePerGas(), - decodeTransactionDataStructHex.getMaxPriorityFeePerGas()); - - // encode TxData to json tx data - String txDataJson = - TransactionStructBuilderJniObj.encodeTransactionDataStructToJson( - transactionDataStructV2); - System.out.printf(" [test Tx Struct V2] txDataJson: %s\n", txDataJson); - - // calc tx data hash - String txDataHash = - TransactionStructBuilderJniObj.calcTransactionDataStructHash( - smCrypto ? 1 : 0, decodeTransactionDataStructHex); - System.out.printf(" [test Tx Struct V2] txDataHash: %s\n", txDataHash); - // signature tx data hash - String signature = TransactionBuilderJniObj.signTransactionDataHash(keyPair, txDataHash); - System.out.printf(" [test Tx Struct V2] signature: %s\n", signature); - - // construct tx - Transaction transactionStructV2 = new Transaction(); - transactionStructV2.setTransactionData(decodeTransactionDataStructHex); - transactionStructV2.setDataHash(fromHex(txDataHash)); - transactionStructV2.setSignature(fromHex(signature)); - transactionStructV2.setSender(null); - transactionStructV2.setImportTime(0); - transactionStructV2.setAttribute(0); - transactionStructV2.setExtraData(""); - // assert - Assert.assertEquals( - transactionStructV2.getTransactionData().getBlockLimit(), - decodeTransactionDataStructHex.getBlockLimit()); - Assert.assertEquals( - transactionStructV2.getTransactionData().getGroupId(), - decodeTransactionDataStructHex.getGroupId()); - Assert.assertEquals( - transactionStructV2.getTransactionData().getChainId(), - decodeTransactionDataStructHex.getChainId()); - Assert.assertEquals( - transactionStructV2.getTransactionData().getChainId(), - decodeTransactionDataStructHex.getChainId()); - Assert.assertEquals( - transactionStructV2.getTransactionData().getAbi(), - decodeTransactionDataStructHex.getAbi()); - Assert.assertArrayEquals( - transactionStructV2.getDataHash(), fromHex(txDataHash)); - Assert.assertArrayEquals( - transactionStructV2.getSignature(), fromHex(signature)); - - // encode Tx to hex tx - String txHex = - TransactionStructBuilderJniObj.encodeTransactionStruct(transactionStructV2); - // decode hex tx to Tx - Transaction decodeTransactionStructHex = - TransactionStructBuilderJniObj.decodeTransactionStructV2(txHex); - - // assert - Assert.assertEquals( - transactionStructV2.getTransactionData().getBlockLimit(), - decodeTransactionStructHex.getTransactionData().getBlockLimit()); - Assert.assertEquals( - transactionStructV2.getTransactionData().getGroupId(), - decodeTransactionStructHex.getTransactionData().getGroupId()); - Assert.assertEquals( - transactionStructV2.getTransactionData().getChainId(), - decodeTransactionStructHex.getTransactionData().getChainId()); - Assert.assertEquals( - transactionStructV2.getTransactionData().getAbi(), - decodeTransactionStructHex.getTransactionData().getAbi()); - TransactionDataV2 transactionData = (TransactionDataV2) transactionStructV2.getTransactionData(); - TransactionDataV2 decodeTransactionData = (TransactionDataV2) decodeTransactionStructHex.getTransactionData(); - Assert.assertEquals( - transactionData.getValue(), - decodeTransactionData.getValue()); - Assert.assertEquals( - transactionData.getGasLimit(), - decodeTransactionData.getGasLimit()); - Assert.assertEquals( - transactionData.getGasPrice(), - decodeTransactionData.getGasPrice()); - Assert.assertEquals( - transactionData.getMaxFeePerGas(), - decodeTransactionData.getMaxFeePerGas()); - Assert.assertEquals( - transactionData.getMaxPriorityFeePerGas(), - decodeTransactionData.getMaxPriorityFeePerGas()); - Assert.assertArrayEquals( - transactionStructV2.getDataHash(), - decodeTransactionStructHex.getDataHash()); - Assert.assertArrayEquals( - transactionStructV2.getSignature(), - decodeTransactionStructHex.getSignature()); - - // encode Tx to json tx - String txJson = - TransactionStructBuilderJniObj.encodeTransactionStructToJson(transactionStructV2); - System.out.printf(" [test Tx Struct V2] txJson: %s\n", txJson); - // create tx string - String txString = - TransactionStructBuilderJniObj.createEncodedTransaction( - decodeTransactionDataStructHex, signature, txDataHash, 0, ""); - // System.out.printf(" [test Tx Struct V2] txString: %s\n", txString); - CompletableFuture future = new CompletableFuture<>(); - - // rpc send tx - rpcJniObj.sendTransaction( - group, - node, - txString, - false, - future::complete); - - Response response = future.get(); - System.out.println("response error code: ==>>> " + response.getErrorCode()); - String dataStr = new String(response.getData()); - System.out.println("response data: ==>>> " + dataStr); - rpcJniObj.stop(); - System.out.println(" [test Tx Struct V2] finish !! "); - } -} diff --git a/sample/tx/CMakeLists.txt b/sample/tx/CMakeLists.txt index f6a8783e0..5776ef247 100644 --- a/sample/tx/CMakeLists.txt +++ b/sample/tx/CMakeLists.txt @@ -7,8 +7,8 @@ target_link_libraries(hello_sample_hsm PUBLIC ${BCOS_C_SDK_STATIC_TARGET}) add_executable(tx_struct_test tx_struct_test.c) target_link_libraries(tx_struct_test PUBLIC ${BCOS_C_SDK_STATIC_TARGET}) -add_executable(tx_struct_v2_test tx_struct_v2_test.c) -target_link_libraries(tx_struct_v2_test PUBLIC ${BCOS_C_SDK_STATIC_TARGET}) +add_executable(tx_struct_v1_test tx_struct_v1_test.c) +target_link_libraries(tx_struct_v1_test PUBLIC ${BCOS_C_SDK_STATIC_TARGET}) # add_executable(tx_sign_perf tx_sign_perf.cpp) # target_link_libraries(tx_sign_perf PUBLIC ${BCOS_C_SDK_STATIC_TARGET}) \ No newline at end of file diff --git a/sample/tx/tx_struct_v2_test.c b/sample/tx/tx_struct_v1_test.c similarity index 74% rename from sample/tx/tx_struct_v2_test.c rename to sample/tx/tx_struct_v1_test.c index d22a5fbc9..869f85bf0 100644 --- a/sample/tx/tx_struct_v2_test.c +++ b/sample/tx/tx_struct_v1_test.c @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @file tx_struct_v2_test.c + * @file tx_struct_v1_test.c * @author: lucasli * @date 2023-11-29 */ @@ -131,14 +131,15 @@ const char* g_hw_abi = void usage(void) { - printf("Desc: tx struct v2 test sample\n"); - printf("Usage: tx_struct_v2_test \n"); + printf("Desc: tx struct v1 test sample\n"); + printf("Usage: tx_struct_v1_test \n"); printf("Example:\n"); - printf(" ./tx_struct_v2_test ./config.ini group0\n"); + printf(" ./tx_struct_v1_test ./config.ini group0\n"); exit(0); } -int convertCharToHexNumber(char hexChar) { +int convertCharToHexNumber(char hexChar) +{ if (hexChar >= '0' && hexChar <= '9') return hexChar - '0'; if (hexChar >= 'a' && hexChar <= 'f') @@ -148,15 +149,20 @@ int convertCharToHexNumber(char hexChar) { return -1; } -struct bcos_sdk_c_bytes* fromHexString(const char* hexedString) { - unsigned startIndex = (strlen(hexedString) >= 2 && hexedString[0] == '0' && hexedString[1] == 'x') ? 2 : 0; - struct bcos_sdk_c_bytes* bytesData = (struct bcos_sdk_c_bytes*)malloc(sizeof(struct bcos_sdk_c_bytes)); +struct bcos_sdk_c_bytes* fromHexString(const char* hexedString) +{ + unsigned startIndex = + (strlen(hexedString) >= 2 && hexedString[0] == '0' && hexedString[1] == 'x') ? 2 : 0; + struct bcos_sdk_c_bytes* bytesData = + (struct bcos_sdk_c_bytes*)malloc(sizeof(struct bcos_sdk_c_bytes)); bytesData->buffer = (uint8_t*)malloc((strlen(hexedString) - startIndex + 1) / 2); bytesData->length = 0; - if (strlen(hexedString) % 2) { + if (strlen(hexedString) % 2) + { int h = convertCharToHexNumber(hexedString[startIndex++]); - if (h == -1) { + if (h == -1) + { // Handle error free(bytesData->buffer); free(bytesData); @@ -164,10 +170,12 @@ struct bcos_sdk_c_bytes* fromHexString(const char* hexedString) { } bytesData->buffer[bytesData->length++] = (uint8_t)h; } - for (unsigned i = startIndex; i < strlen(hexedString); i += 2) { + for (unsigned i = startIndex; i < strlen(hexedString); i += 2) + { int highValue = convertCharToHexNumber(hexedString[i]); int lowValue = convertCharToHexNumber(hexedString[i + 1]); - if (highValue == -1 || lowValue == -1) { + if (highValue == -1 || lowValue == -1) + { // Handle error free(bytesData->buffer); free(bytesData); @@ -212,15 +220,15 @@ void on_deploy_resp_callback(struct bcos_sdk_c_struct_response* resp) memcpy(contract_address, p1, p2 - p1); contract_address[p2 - p1] = '\0'; - printf(" [TxStructV2Test] contractAddress ===>>>>: %s\n", contract_address); - printf(" [TxStructV2Test] transaction receipt ===>>>>: %s\n", (char*)resp->data); + printf(" [TxStructv1Test] contractAddress ===>>>>: %s\n", contract_address); + printf(" [TxStructv1Test] transaction receipt ===>>>>: %s\n", (char*)resp->data); } /* resp->data 的数据结构 { "id" : 2, "jsonrpc" : "2.0", - "result" : + "result" : { "blockNumber" : 113, "checksumContractAddress" : "", @@ -229,7 +237,8 @@ void on_deploy_resp_callback(struct bcos_sdk_c_struct_response* resp) "from" : "0x69df04bec1c36551be6298f7e4c2f867592a4b37", "gasUsed" : "13063", "hash" : "0x7d816bbde4aef3bd4c084b0887982f2c50cb9a50975a4d07328ec5fd5dd4e6e6", - "input" : "0x3590b49f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001748656c6c6f20464953434f2d42434f5320332e30212121000000000000000000", + "input" : +"0x3590b49f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001748656c6c6f20464953434f2d42434f5320332e30212121000000000000000000", "logEntries" : [], "message" : "", "output" : "0x", @@ -272,7 +281,7 @@ int main(int argc, char** argv) const char* config = argv[1]; const char* group_id = argv[2]; - printf("[TxStructV2Test] params ===>>>> \n"); + printf("[TxStructv1Test] params ===>>>> \n"); printf("\t # config: %s\n", config); printf("\t # group_id: %s\n", group_id); @@ -290,13 +299,14 @@ int main(int argc, char** argv) exit(-1); } - printf(" [TxStructV2Test] start sdk ... \n"); + printf(" [TxStructv1Test] start sdk ... \n"); // 2. start bcos c sdk bcos_sdk_start(sdk); if (!bcos_sdk_is_last_opr_success()) { - printf(" [TxStructV2Test] bcos_sdk_start failed, error: %s\n", bcos_sdk_get_last_error_msg()); + printf( + " [TxStructv1Test] bcos_sdk_start failed, error: %s\n", bcos_sdk_get_last_error_msg()); exit(-1); } @@ -312,40 +322,41 @@ int main(int argc, char** argv) exit(-1); } - printf(" [TxStructV2Test] sm crypto: %d\n", sm_crypto); + printf(" [TxStructv1Test] sm crypto: %d\n", sm_crypto); // 4. get chain_id of the group_id const char* chain_id = bcos_sdk_get_group_chain_id(sdk, group_id); if (!bcos_sdk_is_last_opr_success()) { - printf(" [TxStructV2Test] bcos_sdk_get_group_chain_id failed, error: %s\n", + printf(" [TxStructv1Test] bcos_sdk_get_group_chain_id failed, error: %s\n", bcos_sdk_get_last_error_msg()); exit(-1); } - printf(" [TxStructV2Test] chain id: %s\n", chain_id); + printf(" [TxStructv1Test] chain id: %s\n", chain_id); // 5. get blocklimit of the group_id int64_t block_limit = bcos_rpc_get_block_limit(sdk, group_id); if (block_limit < 0) { - printf(" [TxStructV2Test] group not exist, group: %s\n", group_id); + printf(" [TxStructv1Test] group not exist, group: %s\n", group_id); exit(-1); } - printf(" [TxStructV2Test] block limit: %d\n", (int32_t)block_limit); + printf(" [TxStructv1Test] block limit: %d\n", (int32_t)block_limit); // 6. load or create keypair for transaction sign void* key_pair = bcos_sdk_create_keypair(sm_crypto); if (!key_pair) { - printf(" [TxStructV2Test] create keypair failed, error: %s\n", bcos_sdk_get_last_error_msg()); + printf( + " [TxStructv1Test] create keypair failed, error: %s\n", bcos_sdk_get_last_error_msg()); exit(-1); } - // printf(" [TxStructV2Test] bcos_sdk_get_keypair_type: %d\n", + // printf(" [TxStructv1Test] bcos_sdk_get_keypair_type: %d\n", // bcos_sdk_get_keypair_type(key_pair)); // 7. get account address of the keypair const char* address = bcos_sdk_get_keypair_address(key_pair); - printf(" [TxStructV2Test] new account, address: %s\n", address); + printf(" [TxStructv1Test] new account, address: %s\n", address); const char* extra_data = "ExtraData"; const char* value = "33"; @@ -354,25 +365,32 @@ int main(int argc, char** argv) const char* maxFeePerGas = "11"; const char* maxPriorityFeePerGas = "22"; - // printf(" [TxStructV2Test] extra_data: %s, value: %s, gasPrice: %s, gasLimit: %ld, maxFeePerGas: %s, maxPriorityFeePerGas: %s\n", extra_data, value, gasPrice, gasLimit, maxFeePerGas, maxPriorityFeePerGas); - + // printf(" [TxStructv1Test] extra_data: %s, value: %s, gasPrice: %s, gasLimit: %ld, + // maxFeePerGas: %s, maxPriorityFeePerGas: %s\n", extra_data, value, gasPrice, gasLimit, + // maxFeePerGas, maxPriorityFeePerGas); + // 8. deploy HelloWorld contract - struct bcos_sdk_c_transaction_data_v2* transaction_data_v2_deploy = bcos_sdk_create_transaction_data_struct_with_hex_input_v2( - group_id, chain_id, "", sm_crypto ? g_hw_sm_bin : g_hw_bin, "", block_limit, value, gasPrice, gasLimit, maxFeePerGas, maxPriorityFeePerGas); + struct bcos_sdk_c_transaction_data_v1* transaction_data_v1_deploy = + bcos_sdk_create_transaction_data_struct_with_hex_input_v1(group_id, chain_id, "", + sm_crypto ? g_hw_sm_bin : g_hw_bin, "", block_limit, value, gasPrice, gasLimit, + maxFeePerGas, maxPriorityFeePerGas); const char* transaction_data_hash_deploy = - bcos_sdk_calc_transaction_data_struct_hash_v2(sm_crypto, transaction_data_v2_deploy); + bcos_sdk_calc_transaction_data_struct_hash_v1(sm_crypto, transaction_data_v1_deploy); const char* signed_hash_deploy = bcos_sdk_sign_transaction_data_hash(key_pair, transaction_data_hash_deploy); - const char* signed_tx_deploy = bcos_sdk_create_encoded_transaction_v2( - transaction_data_v2_deploy, signed_hash_deploy, transaction_data_hash_deploy, 0, extra_data); - printf(" [TxStructV2Test] create deploy contract transaction success, signed_tx_deploy: %s\n", signed_tx_deploy); - + const char* signed_tx_deploy = + bcos_sdk_create_encoded_transaction_v1(transaction_data_v1_deploy, signed_hash_deploy, + transaction_data_hash_deploy, 0, extra_data); + printf(" [TxStructv1Test] create deploy contract transaction success, signed_tx_deploy: %s\n", + signed_tx_deploy); + // call rpc interface, send transaction - bcos_rpc_send_transaction(sdk, group_id, "", signed_tx_deploy, 0, on_deploy_resp_callback, NULL); + bcos_rpc_send_transaction( + sdk, group_id, "", signed_tx_deploy, 0, on_deploy_resp_callback, NULL); // wait for async operation done, just for sample sleep(5); - printf(" [TxStructV2Test] set operation\n"); + printf(" [TxStructv1Test] set operation\n"); // 9. HelloWorld set // 9.1 abi encode params const char* set_data = @@ -380,57 +398,65 @@ int main(int argc, char** argv) // 9.2 create signed transaction { // 9.2.1 create transaction data with hex input - struct bcos_sdk_c_transaction_data_v2* transaction_data_v2 = bcos_sdk_create_transaction_data_struct_with_hex_input_v2( - group_id, chain_id, contract_address, set_data, g_hw_abi, block_limit, value, gasPrice, gasLimit, maxFeePerGas, maxPriorityFeePerGas); + struct bcos_sdk_c_transaction_data_v1* transaction_data_v1 = + bcos_sdk_create_transaction_data_struct_with_hex_input_v1(group_id, chain_id, + contract_address, set_data, g_hw_abi, block_limit, value, gasPrice, gasLimit, + maxFeePerGas, maxPriorityFeePerGas); // create transaction data with bytes input struct bcos_sdk_c_bytes* input_bytes = fromHexString(set_data); - transaction_data_v2 = bcos_sdk_create_transaction_data_struct_with_bytes_v2( - group_id, chain_id, contract_address, input_bytes->buffer, input_bytes->length, g_hw_abi, block_limit, value, gasPrice, gasLimit, maxFeePerGas, maxPriorityFeePerGas); + transaction_data_v1 = bcos_sdk_create_transaction_data_struct_with_bytes_v1(group_id, + chain_id, contract_address, input_bytes->buffer, input_bytes->length, g_hw_abi, + block_limit, value, gasPrice, gasLimit, maxFeePerGas, maxPriorityFeePerGas); // 9.2.1.1 encode tx data to hex - const char* hex_tx_data = bcos_sdk_encode_transaction_data_struct_to_hex_v2(transaction_data_v2); - printf(" [TxStructV2Test] tx_data_hex: %s\n", hex_tx_data); + const char* hex_tx_data = + bcos_sdk_encode_transaction_data_struct_to_hex_v1(transaction_data_v1); + printf(" [TxStructv1Test] tx_data_hex: %s\n", hex_tx_data); // 9.2.1.2 decode hex tx data - struct bcos_sdk_c_transaction_data_v2* decode_tx_data = bcos_sdk_decode_transaction_data_struct_from_hex_v2(hex_tx_data); + struct bcos_sdk_c_transaction_data_v1* decode_tx_data = + bcos_sdk_decode_transaction_data_struct_from_hex_v1(hex_tx_data); // 9.2.1.3 encode tx data to json - const char* json_tx_data = bcos_sdk_encode_transaction_data_struct_to_json_v2(decode_tx_data); - printf(" [TxStructV2Test] tx_data_json: %s\n", json_tx_data); + const char* json_tx_data = + bcos_sdk_encode_transaction_data_struct_to_json_v1(decode_tx_data); + printf(" [TxStructv1Test] tx_data_json: %s\n", json_tx_data); // 9.2.1.4 decode json to tx data struct - decode_tx_data = bcos_sdk_decode_transaction_data_struct_from_json_v2(json_tx_data); + decode_tx_data = bcos_sdk_decode_transaction_data_struct_from_json_v1(json_tx_data); // 9.2.2 calc transaction data hash const char* transaction_data_hash = - bcos_sdk_calc_transaction_data_struct_hash_v2(sm_crypto, decode_tx_data); - printf(" [TxStructV2Test] set tx hash: %s\n", transaction_data_hash); - transaction_data_hash = bcos_sdk_calc_transaction_data_struct_hash_with_hex_v2(sm_crypto, hex_tx_data); - printf(" [TxStructV2Test] set tx hash with tx_data_hex: %s\n", transaction_data_hash); + bcos_sdk_calc_transaction_data_struct_hash_v1(sm_crypto, decode_tx_data); + printf(" [TxStructv1Test] set tx hash: %s\n", transaction_data_hash); + transaction_data_hash = + bcos_sdk_calc_transaction_data_struct_hash_with_hex_v1(sm_crypto, hex_tx_data); + printf(" [TxStructv1Test] set tx hash with tx_data_hex: %s\n", transaction_data_hash); // 9.2.3 sign transaction hash const char* signed_hash = bcos_sdk_sign_transaction_data_hash(key_pair, transaction_data_hash); - + // 9.2.4 create signed transaction - const char* signed_tx = bcos_sdk_create_encoded_transaction_v2( + const char* signed_tx = bcos_sdk_create_encoded_transaction_v1( decode_tx_data, signed_hash, transaction_data_hash, 0, extra_data); - + // 9.2.4.1 create transaction struct - struct bcos_sdk_c_transaction_v2* transaction = bcos_sdk_create_transaction_struct_v2(decode_tx_data, - signed_hash, transaction_data_hash, 0, extra_data); + struct bcos_sdk_c_transaction_v1* transaction = bcos_sdk_create_transaction_struct_v1( + decode_tx_data, signed_hash, transaction_data_hash, 0, extra_data); // 9.2.4.2 encode tx to hex - const char* hex_tx = bcos_sdk_encode_transaction_struct_to_hex_v2(transaction); - printf(" [TxStructV2Test] tx_hex: %s\n", hex_tx); + const char* hex_tx = bcos_sdk_encode_transaction_struct_to_hex_v1(transaction); + printf(" [TxStructv1Test] tx_hex: %s\n", hex_tx); // 9.2.4.3 decode hex to tx - struct bcos_sdk_c_transaction_v2* decode_tx = bcos_sdk_decode_transaction_struct_from_hex_v2(hex_tx); + struct bcos_sdk_c_transaction_v1* decode_tx = + bcos_sdk_decode_transaction_struct_from_hex_v1(hex_tx); // 9.2.4.4 encode tx to json - const char* json_tx = bcos_sdk_encode_transaction_struct_to_json_v2(decode_tx); - printf(" [TxStructV2Test] tx_json: %s\n", json_tx); + const char* json_tx = bcos_sdk_encode_transaction_struct_to_json_v1(decode_tx); + printf(" [TxStructv1Test] tx_json: %s\n", json_tx); // 9.2.4.5 decode json to tx - decode_tx = bcos_sdk_decode_transaction_struct_from_json_v2(json_tx); - const char* hex_tx2 = bcos_sdk_encode_transaction_struct_to_hex_v2(decode_tx); + decode_tx = bcos_sdk_decode_transaction_struct_from_json_v1(json_tx); + const char* hex_tx2 = bcos_sdk_encode_transaction_struct_to_hex_v1(decode_tx); - printf(" [TxStructV2Test] signed_tx: %s\n", signed_tx); - printf(" [TxStructV2Test] hex_tx: %s\n", hex_tx); - printf(" [TxStructV2Test] hex_tx2: %s\n", hex_tx2); + printf(" [TxStructv1Test] signed_tx: %s\n", signed_tx); + printf(" [TxStructv1Test] hex_tx: %s\n", hex_tx); + printf(" [TxStructv1Test] hex_tx2: %s\n", hex_tx2); // 9.3 call rpc interface, sendTransaction bcos_rpc_send_transaction(sdk, group_id, "", signed_tx, 0, on_send_tx_resp_callback, NULL); @@ -443,10 +469,10 @@ int main(int argc, char** argv) { bcos_sdk_c_free(input_bytes->buffer); } - bcos_sdk_destroy_transaction_data_struct_v2(transaction_data_v2); - bcos_sdk_destroy_transaction_data_struct_v2(decode_tx_data); - bcos_sdk_destroy_transaction_struct_v2(transaction); - bcos_sdk_destroy_transaction_struct_v2(decode_tx); + bcos_sdk_destroy_transaction_data_struct_v1(transaction_data_v1); + bcos_sdk_destroy_transaction_data_struct_v1(decode_tx_data); + bcos_sdk_destroy_transaction_struct_v1(transaction); + bcos_sdk_destroy_transaction_struct_v1(decode_tx); bcos_sdk_c_free((void*)transaction_data_hash); bcos_sdk_c_free((void*)signed_hash); bcos_sdk_c_free((void*)signed_tx); diff --git a/test/testTransactionStructV2.cpp b/test/testTransactionStructV1.cpp similarity index 85% rename from test/testTransactionStructV2.cpp rename to test/testTransactionStructV1.cpp index 283825ba5..c059bc7f6 100644 --- a/test/testTransactionStructV2.cpp +++ b/test/testTransactionStructV1.cpp @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @file testTransactionStructV2.cpp + * @file testTransactionStructv1.cpp * @author: lucasli * @date 2023-12-13 */ @@ -31,11 +31,11 @@ using namespace bcos; -struct TestTxStructV2Fixture +struct TestTxStructv1Fixture { }; -BOOST_FIXTURE_TEST_SUITE(TransactionStructV2Test, TestTxStructV2Fixture) +BOOST_FIXTURE_TEST_SUITE(TransactionStructv1Test, TestTxStructv1Fixture) const auto input = "0x3590b49f00000000000000000000000000000000000000000000000000000000000000200000000000000000" @@ -50,7 +50,7 @@ const char* abi_with_chinese = "\"string\",\"name\":\"n\",\"type\":\"string\"}],\"name\":\"set\",\"outputs\":[]," "\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"; -struct bcos_sdk_c_transaction_data_v2* createTxDataStructWithHexInputV2() +struct bcos_sdk_c_transaction_data_v1* createTxDataStructWithHexInputv1() { auto group_id = ""; auto chain_id = ""; @@ -62,14 +62,14 @@ struct bcos_sdk_c_transaction_data_v2* createTxDataStructWithHexInputV2() int64_t gas_limit = 0; auto max_fee_per_gas = "1"; auto max_priority_fee_per_gas = "1"; - auto txDataWithHex = bcos_sdk_create_transaction_data_struct_with_hex_input_v2(group_id, + auto txDataWithHex = bcos_sdk_create_transaction_data_struct_with_hex_input_v1(group_id, chain_id, to, input, abi, block_limit, value, gas_price, gas_limit, max_fee_per_gas, max_priority_fee_per_gas); return txDataWithHex; } -struct bcos_sdk_c_transaction_data_v2* createTxDataStructWithByteInputV2() +struct bcos_sdk_c_transaction_data_v1* createTxDataStructWithByteInputv1() { auto group_id = ""; auto chain_id = ""; @@ -83,15 +83,15 @@ struct bcos_sdk_c_transaction_data_v2* createTxDataStructWithByteInputV2() auto max_priority_fee_per_gas = "1"; auto bytesInput = fromHexString(input); - auto txDataWithBytes = bcos_sdk_create_transaction_data_struct_with_bytes_v2(group_id, chain_id, + auto txDataWithBytes = bcos_sdk_create_transaction_data_struct_with_bytes_v1(group_id, chain_id, to, bytesInput->data(), bytesInput->size(), abi, block_limit, value, gas_price, gas_limit, max_fee_per_gas, max_priority_fee_per_gas); return txDataWithBytes; } -void compareTxStruct(struct bcos_sdk_c_transaction_v2* txStruct, - struct bcos_sdk_c_transaction_data_v2* txDataStruct, const char* signature, +void compareTxStruct(struct bcos_sdk_c_transaction_v1* txStruct, + struct bcos_sdk_c_transaction_data_v1* txDataStruct, const char* signature, const char* extraData, int64_t attribute) { // transaction_data @@ -130,7 +130,7 @@ void compareTxStruct(struct bcos_sdk_c_transaction_v2* txStruct, BOOST_TEST(txStruct->extra_data == extraData); } -BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithHexInputV2) +BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithHexInputv1) { auto group_id = ""; auto chain_id = ""; @@ -143,8 +143,8 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithHexInputV2) auto max_fee_per_gas = "1"; auto max_priority_fee_per_gas = "1"; - // create transaction_data_struct_v2 failed (block_limit = 0) - auto txData = bcos_sdk_create_transaction_data_struct_with_hex_input_v2(group_id, chain_id, to, + // create transaction_data_struct_v1 failed (block_limit = 0) + auto txData = bcos_sdk_create_transaction_data_struct_with_hex_input_v1(group_id, chain_id, to, input, abi, block_limit, value, gas_price, gas_limit, max_fee_per_gas, max_priority_fee_per_gas); auto success = bcos_sdk_is_last_opr_success(); @@ -153,9 +153,9 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithHexInputV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); BOOST_TEST(bcos_sdk_get_last_error_msg() == std::string("block limit must > 0")); - // create transaction_data_struct_v2 failed (input = "") + // create transaction_data_struct_v1 failed (input = "") block_limit = 1; - txData = bcos_sdk_create_transaction_data_struct_with_hex_input_v2(group_id, chain_id, to, "", + txData = bcos_sdk_create_transaction_data_struct_with_hex_input_v1(group_id, chain_id, to, "", abi, block_limit, value, gas_price, gas_limit, max_fee_per_gas, max_priority_fee_per_gas); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); @@ -163,8 +163,8 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithHexInputV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); BOOST_TEST(bcos_sdk_get_last_error_msg() == std::string("input can not be empty string")); - // create transaction_data_struct_v2 failed (gas_limit <0) - txData = bcos_sdk_create_transaction_data_struct_with_hex_input_v2(group_id, chain_id, to, + // create transaction_data_struct_v1 failed (gas_limit <0) + txData = bcos_sdk_create_transaction_data_struct_with_hex_input_v1(group_id, chain_id, to, input, abi, block_limit, value, gas_price, -1, max_fee_per_gas, max_priority_fee_per_gas); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); @@ -172,8 +172,8 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithHexInputV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); BOOST_TEST(bcos_sdk_get_last_error_msg() == std::string("gas limit must >= 0")); - // create transaction_data_struct_v2 success - txData = bcos_sdk_create_transaction_data_struct_with_hex_input_v2(group_id, chain_id, to, + // create transaction_data_struct_v1 success + txData = bcos_sdk_create_transaction_data_struct_with_hex_input_v1(group_id, chain_id, to, input, abi, block_limit, value, gas_price, gas_limit, max_fee_per_gas, max_priority_fee_per_gas); success = bcos_sdk_is_last_opr_success(); @@ -195,10 +195,10 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithHexInputV2) reinterpret_cast(txData->input->buffer), txData->input->length); BOOST_TEST(txDataInputString == fromInputHexString); - bcos_sdk_destroy_transaction_data_struct_v2(txData); + bcos_sdk_destroy_transaction_data_struct_v1(txData); } -BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithByteInputV2) +BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithByteInputv1) { auto bytesInput = fromHexString(input); auto group_id = ""; @@ -213,8 +213,8 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithByteInputV2) auto max_fee_per_gas = "1"; auto max_priority_fee_per_gas = "1"; - // create transaction_data_struct_v2 failed (block_limit = 0) - auto txData = bcos_sdk_create_transaction_data_struct_with_bytes_v2(group_id, chain_id, to, + // create transaction_data_struct_v1 failed (block_limit = 0) + auto txData = bcos_sdk_create_transaction_data_struct_with_bytes_v1(group_id, chain_id, to, bytesInput->data(), bytes_input_length, abi, block_limit, value, gas_price, gas_limit, max_fee_per_gas, max_priority_fee_per_gas); auto success = bcos_sdk_is_last_opr_success(); @@ -224,10 +224,10 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithByteInputV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); BOOST_TEST(bcos_sdk_get_last_error_msg() == std::string("block limit must > 0")); - // create transaction_data_struct_v2 failed (bytes_input_length = 0) + // create transaction_data_struct_v1 failed (bytes_input_length = 0) bytes_input_length = 0; block_limit = 1; - txData = bcos_sdk_create_transaction_data_struct_with_bytes_v2(group_id, chain_id, to, + txData = bcos_sdk_create_transaction_data_struct_with_bytes_v1(group_id, chain_id, to, bytesInput->data(), bytes_input_length, abi, block_limit, value, gas_price, gas_limit, max_fee_per_gas, max_priority_fee_per_gas); success = bcos_sdk_is_last_opr_success(); @@ -237,9 +237,9 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithByteInputV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); BOOST_TEST(bcos_sdk_get_last_error_msg() == std::string("bytes input length must > 0")); - // create transaction_data_struct_v2 failed (group_id = NULL) + // create transaction_data_struct_v1 failed (group_id = NULL) group_id = nullptr; - txData = bcos_sdk_create_transaction_data_struct_with_bytes_v2(group_id, chain_id, to, + txData = bcos_sdk_create_transaction_data_struct_with_bytes_v1(group_id, chain_id, to, bytesInput->data(), bytesInput->size(), abi, block_limit, value, gas_price, gas_limit, max_fee_per_gas, max_priority_fee_per_gas); success = bcos_sdk_is_last_opr_success(); @@ -248,9 +248,9 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithByteInputV2) BOOST_TEST(txData == nullptr); BOOST_TEST(bcos_sdk_get_last_error() == -1); - // create transaction_data_struct_v2 success (group_id has Chinese characters) + // create transaction_data_struct_v1 success (group_id has Chinese characters) group_id = "区块链群组1"; - txData = bcos_sdk_create_transaction_data_struct_with_bytes_v2(group_id, chain_id, to, + txData = bcos_sdk_create_transaction_data_struct_with_bytes_v1(group_id, chain_id, to, bytesInput->data(), bytesInput->size(), abi, block_limit, value, gas_price, gas_limit, max_fee_per_gas, max_priority_fee_per_gas); success = bcos_sdk_is_last_opr_success(); @@ -272,9 +272,9 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithByteInputV2) reinterpret_cast(txData->input->buffer), txData->input->length); BOOST_TEST(txDataInputString1 == fromInputHexString1); - // create transaction_data_struct_v2 failed (chain_id = NULL) + // create transaction_data_struct_v1 failed (chain_id = NULL) chain_id = nullptr; - txData = bcos_sdk_create_transaction_data_struct_with_bytes_v2(group_id, chain_id, to, + txData = bcos_sdk_create_transaction_data_struct_with_bytes_v1(group_id, chain_id, to, bytesInput->data(), bytesInput->size(), abi, block_limit, value, gas_price, gas_limit, max_fee_per_gas, max_priority_fee_per_gas); success = bcos_sdk_is_last_opr_success(); @@ -283,9 +283,9 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithByteInputV2) BOOST_TEST(txData == nullptr); BOOST_TEST(bcos_sdk_get_last_error() == -1); - // create transaction_data_struct_v2 success (chain_id has Chinese characters) + // create transaction_data_struct_v1 success (chain_id has Chinese characters) chain_id = "区块链1"; - txData = bcos_sdk_create_transaction_data_struct_with_bytes_v2(group_id, chain_id, to, + txData = bcos_sdk_create_transaction_data_struct_with_bytes_v1(group_id, chain_id, to, bytesInput->data(), bytesInput->size(), abi, block_limit, value, gas_price, gas_limit, max_fee_per_gas, max_priority_fee_per_gas); success = bcos_sdk_is_last_opr_success(); @@ -307,9 +307,9 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithByteInputV2) reinterpret_cast(txData->input->buffer), txData->input->length); BOOST_TEST(txDataInputString2 == fromInputHexString2); - // create transaction_data_struct_v2 success (abi has Chinese characters) + // create transaction_data_struct_v1 success (abi has Chinese characters) chain_id = ""; - txData = bcos_sdk_create_transaction_data_struct_with_bytes_v2(group_id, chain_id, to, + txData = bcos_sdk_create_transaction_data_struct_with_bytes_v1(group_id, chain_id, to, bytesInput->data(), bytesInput->size(), abi_with_chinese, block_limit, value, gas_price, gas_limit, max_fee_per_gas, max_priority_fee_per_gas); success = bcos_sdk_is_last_opr_success(); @@ -331,8 +331,8 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithByteInputV2) reinterpret_cast(txData->input->buffer), txData->input->length); BOOST_TEST(txDataInputString3 == fromInputHexString3); - // create transaction_data_struct_v2 failed (gas_limit <0) - txData = bcos_sdk_create_transaction_data_struct_with_bytes_v2(group_id, chain_id, to, + // create transaction_data_struct_v1 failed (gas_limit <0) + txData = bcos_sdk_create_transaction_data_struct_with_bytes_v1(group_id, chain_id, to, bytesInput->data(), bytesInput->size(), abi, block_limit, value, gas_price, -1, max_fee_per_gas, max_priority_fee_per_gas); success = bcos_sdk_is_last_opr_success(); @@ -341,9 +341,9 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithByteInputV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); BOOST_TEST(bcos_sdk_get_last_error_msg() == std::string("gas limit must >= 0")); - // create transaction_data_struct_v2 success + // create transaction_data_struct_v1 success group_id = ""; - txData = bcos_sdk_create_transaction_data_struct_with_bytes_v2(group_id, chain_id, to, + txData = bcos_sdk_create_transaction_data_struct_with_bytes_v1(group_id, chain_id, to, bytesInput->data(), bytesInput->size(), abi, block_limit, value, gas_price, gas_limit, max_fee_per_gas, max_priority_fee_per_gas); success = bcos_sdk_is_last_opr_success(); @@ -365,17 +365,17 @@ BOOST_AUTO_TEST_CASE(testCreateTxDataStructWithByteInputV2) reinterpret_cast(txData->input->buffer), txData->input->length); BOOST_TEST(txDataInputString == fromInputHexString); - bcos_sdk_destroy_transaction_data_struct_v2(txData); + bcos_sdk_destroy_transaction_data_struct_v1(txData); } -BOOST_AUTO_TEST_CASE(testEncodeDecodeTxDataStructV2) +BOOST_AUTO_TEST_CASE(testEncodeDecodeTxDataStructv1) { - auto txDataWithHex = createTxDataStructWithHexInputV2(); - auto txDataWithBytes = createTxDataStructWithByteInputV2(); + auto txDataWithHex = createTxDataStructWithHexInputv1(); + auto txDataWithBytes = createTxDataStructWithByteInputv1(); // 1. test tx data encode decode hex // encode to hex failed (transaction_data == NULL) - auto encodedTxDataHex = bcos_sdk_encode_transaction_data_struct_to_hex_v2(nullptr); + auto encodedTxDataHex = bcos_sdk_encode_transaction_data_struct_to_hex_v1(nullptr); auto hexSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(hexSuccess == false); @@ -383,14 +383,14 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxDataStructV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); // encode to hex success - encodedTxDataHex = bcos_sdk_encode_transaction_data_struct_to_hex_v2(txDataWithHex); + encodedTxDataHex = bcos_sdk_encode_transaction_data_struct_to_hex_v1(txDataWithHex); hexSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(hexSuccess == true); BOOST_TEST(encodedTxDataHex != nullptr); BOOST_TEST(bcos_sdk_get_last_error() == 0); - encodedTxDataHex = bcos_sdk_encode_transaction_data_struct_to_hex_v2(txDataWithBytes); + encodedTxDataHex = bcos_sdk_encode_transaction_data_struct_to_hex_v1(txDataWithBytes); hexSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(hexSuccess == true); @@ -398,7 +398,7 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxDataStructV2) BOOST_TEST(bcos_sdk_get_last_error() == 0); // decode hex failed (transaction_data_hex_str == NULL) - auto decodedTxDataHex = bcos_sdk_decode_transaction_data_struct_from_hex_v2(nullptr); + auto decodedTxDataHex = bcos_sdk_decode_transaction_data_struct_from_hex_v1(nullptr); hexSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(hexSuccess == false); @@ -406,7 +406,7 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxDataStructV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); // decode hex failed (transaction_data_hex_str == "") - decodedTxDataHex = bcos_sdk_decode_transaction_data_struct_from_hex_v2(""); + decodedTxDataHex = bcos_sdk_decode_transaction_data_struct_from_hex_v1(""); hexSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(hexSuccess == false); @@ -416,7 +416,7 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxDataStructV2) std::string("transaction_data_hex_str can not be empty string")); // decode hex failed (the length of transaction_data_hex_str is not even number) - decodedTxDataHex = bcos_sdk_decode_transaction_data_struct_from_hex_v2("0xabc"); + decodedTxDataHex = bcos_sdk_decode_transaction_data_struct_from_hex_v1("0xabc"); hexSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(hexSuccess == false); @@ -426,7 +426,7 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxDataStructV2) std::string("the length of transaction_data_hex_str must be an even number")); // decode hex success - decodedTxDataHex = bcos_sdk_decode_transaction_data_struct_from_hex_v2(encodedTxDataHex); + decodedTxDataHex = bcos_sdk_decode_transaction_data_struct_from_hex_v1(encodedTxDataHex); hexSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(hexSuccess == true); @@ -453,7 +453,7 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxDataStructV2) // 2. test tx data encode decode json // encode to json failed (transaction_data == NULL) - auto encodedTxDataJson = bcos_sdk_encode_transaction_data_struct_to_json_v2(nullptr); + auto encodedTxDataJson = bcos_sdk_encode_transaction_data_struct_to_json_v1(nullptr); auto jsonSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(jsonSuccess == false); @@ -461,14 +461,14 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxDataStructV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); // encode to json success - encodedTxDataJson = bcos_sdk_encode_transaction_data_struct_to_json_v2(txDataWithHex); + encodedTxDataJson = bcos_sdk_encode_transaction_data_struct_to_json_v1(txDataWithHex); jsonSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(jsonSuccess == true); BOOST_TEST(encodedTxDataJson != nullptr); BOOST_TEST(bcos_sdk_get_last_error() == 0); - encodedTxDataJson = bcos_sdk_encode_transaction_data_struct_to_json_v2(txDataWithBytes); + encodedTxDataJson = bcos_sdk_encode_transaction_data_struct_to_json_v1(txDataWithBytes); jsonSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(jsonSuccess == true); @@ -476,7 +476,7 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxDataStructV2) BOOST_TEST(bcos_sdk_get_last_error() == 0); // decode json failed (transaction_data_json_str == NULL) - auto decodedTxDataJson = bcos_sdk_decode_transaction_data_struct_from_json_v2(nullptr); + auto decodedTxDataJson = bcos_sdk_decode_transaction_data_struct_from_json_v1(nullptr); jsonSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(jsonSuccess == false); @@ -484,7 +484,7 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxDataStructV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); // decode json failed (transaction_data_json_str == "") - decodedTxDataJson = bcos_sdk_decode_transaction_data_struct_from_json_v2(""); + decodedTxDataJson = bcos_sdk_decode_transaction_data_struct_from_json_v1(""); jsonSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(jsonSuccess == false); @@ -494,7 +494,7 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxDataStructV2) std::string("transaction_data_json_str can not be empty string")); // decode json success - decodedTxDataJson = bcos_sdk_decode_transaction_data_struct_from_json_v2(encodedTxDataJson); + decodedTxDataJson = bcos_sdk_decode_transaction_data_struct_from_json_v1(encodedTxDataJson); jsonSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(jsonSuccess == true); @@ -518,23 +518,23 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxDataStructV2) decodedTxDataJson->input->length); BOOST_TEST(txDataInputString == decodedJsonTxDataInputJson); - bcos_sdk_destroy_transaction_data_struct_v2(txDataWithHex); - bcos_sdk_destroy_transaction_data_struct_v2(txDataWithBytes); - bcos_sdk_destroy_transaction_data_struct_v2(decodedTxDataHex); - bcos_sdk_destroy_transaction_data_struct_v2(decodedTxDataJson); + bcos_sdk_destroy_transaction_data_struct_v1(txDataWithHex); + bcos_sdk_destroy_transaction_data_struct_v1(txDataWithBytes); + bcos_sdk_destroy_transaction_data_struct_v1(decodedTxDataHex); + bcos_sdk_destroy_transaction_data_struct_v1(decodedTxDataJson); } -BOOST_AUTO_TEST_CASE(testCalculateTxDataHashV2) +BOOST_AUTO_TEST_CASE(testCalculateTxDataHashv1) { - auto txDataWithHex = createTxDataStructWithHexInputV2(); - auto txDataWithByte = createTxDataStructWithByteInputV2(); - auto encodedtxDataWithHex = bcos_sdk_encode_transaction_data_struct_to_hex_v2(txDataWithHex); - auto encodedtxDataWithByte = bcos_sdk_encode_transaction_data_struct_to_hex_v2(txDataWithByte); + auto txDataWithHex = createTxDataStructWithHexInputv1(); + auto txDataWithByte = createTxDataStructWithByteInputv1(); + auto encodedtxDataWithHex = bcos_sdk_encode_transaction_data_struct_to_hex_v1(txDataWithHex); + auto encodedtxDataWithByte = bcos_sdk_encode_transaction_data_struct_to_hex_v1(txDataWithByte); // 1. test cal tx data hash with struct // calculate tx data hash failed (cryptoType not in 0,1) auto cryptoType = 2; - auto txDataHash = bcos_sdk_calc_transaction_data_struct_hash_v2(cryptoType, txDataWithHex); + auto txDataHash = bcos_sdk_calc_transaction_data_struct_hash_v1(cryptoType, txDataWithHex); auto success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); BOOST_TEST(txDataHash == nullptr); @@ -545,7 +545,7 @@ BOOST_AUTO_TEST_CASE(testCalculateTxDataHashV2) // calculate tx data hash failed (cryptoType is negative number) cryptoType = -11; - txDataHash = bcos_sdk_calc_transaction_data_struct_hash_v2(cryptoType, txDataWithHex); + txDataHash = bcos_sdk_calc_transaction_data_struct_hash_v1(cryptoType, txDataWithHex); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); BOOST_TEST(txDataHash == nullptr); @@ -556,7 +556,7 @@ BOOST_AUTO_TEST_CASE(testCalculateTxDataHashV2) // calculate tx data hash failed (transaction_data == NULL) cryptoType = 1; - txDataHash = bcos_sdk_calc_transaction_data_struct_hash_v2(cryptoType, nullptr); + txDataHash = bcos_sdk_calc_transaction_data_struct_hash_v1(cryptoType, nullptr); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); BOOST_TEST(txDataHash == nullptr); @@ -564,14 +564,14 @@ BOOST_AUTO_TEST_CASE(testCalculateTxDataHashV2) // calculate tx data hash success (txDataWithHex) cryptoType = 1; - txDataHash = bcos_sdk_calc_transaction_data_struct_hash_v2(cryptoType, txDataWithHex); + txDataHash = bcos_sdk_calc_transaction_data_struct_hash_v1(cryptoType, txDataWithHex); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == true); BOOST_TEST(txDataHash != nullptr); BOOST_TEST(bcos_sdk_get_last_error() == 0); // calculate tx data hash success (txDataWithByte) - txDataHash = bcos_sdk_calc_transaction_data_struct_hash_v2(cryptoType, txDataWithByte); + txDataHash = bcos_sdk_calc_transaction_data_struct_hash_v1(cryptoType, txDataWithByte); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == true); BOOST_TEST(txDataHash != nullptr); @@ -581,7 +581,7 @@ BOOST_AUTO_TEST_CASE(testCalculateTxDataHashV2) // calculate tx data hash with hex failed (cryptoType not in 0,1) cryptoType = 2; auto txDataHashWithHex = - bcos_sdk_calc_transaction_data_struct_hash_with_hex_v2(cryptoType, encodedtxDataWithHex); + bcos_sdk_calc_transaction_data_struct_hash_with_hex_v1(cryptoType, encodedtxDataWithHex); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); BOOST_TEST(txDataHashWithHex == nullptr); @@ -593,7 +593,7 @@ BOOST_AUTO_TEST_CASE(testCalculateTxDataHashV2) // calculate tx data hash failed (cryptoType is negative number) cryptoType = -11; txDataHashWithHex = - bcos_sdk_calc_transaction_data_struct_hash_with_hex_v2(cryptoType, encodedtxDataWithHex); + bcos_sdk_calc_transaction_data_struct_hash_with_hex_v1(cryptoType, encodedtxDataWithHex); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); BOOST_TEST(txDataHashWithHex == nullptr); @@ -604,14 +604,14 @@ BOOST_AUTO_TEST_CASE(testCalculateTxDataHashV2) // calculate tx data hash with hex failed (transaction_data_hex == NULL) cryptoType = 1; - txDataHashWithHex = bcos_sdk_calc_transaction_data_struct_hash_with_hex_v2(cryptoType, nullptr); + txDataHashWithHex = bcos_sdk_calc_transaction_data_struct_hash_with_hex_v1(cryptoType, nullptr); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); BOOST_TEST(txDataHashWithHex == nullptr); BOOST_TEST(bcos_sdk_get_last_error() == -1); // calculate tx data hash with hex failed (transaction_data_hex == "") - txDataHashWithHex = bcos_sdk_calc_transaction_data_struct_hash_with_hex_v2(cryptoType, ""); + txDataHashWithHex = bcos_sdk_calc_transaction_data_struct_hash_with_hex_v1(cryptoType, ""); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); BOOST_TEST(txDataHashWithHex == nullptr); @@ -622,7 +622,7 @@ BOOST_AUTO_TEST_CASE(testCalculateTxDataHashV2) // calculate tx data hash with hex success (encodedtxDataWithHex) cryptoType = 1; txDataHashWithHex = - bcos_sdk_calc_transaction_data_struct_hash_with_hex_v2(cryptoType, encodedtxDataWithHex); + bcos_sdk_calc_transaction_data_struct_hash_with_hex_v1(cryptoType, encodedtxDataWithHex); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == true); BOOST_TEST(txDataHashWithHex != nullptr); @@ -630,7 +630,7 @@ BOOST_AUTO_TEST_CASE(testCalculateTxDataHashV2) // calculate tx data hash with hex success (encodedtxDataWithByte) txDataHashWithHex = - bcos_sdk_calc_transaction_data_struct_hash_with_hex_v2(cryptoType, encodedtxDataWithByte); + bcos_sdk_calc_transaction_data_struct_hash_with_hex_v1(cryptoType, encodedtxDataWithByte); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == true); BOOST_TEST(txDataHashWithHex != nullptr); @@ -639,21 +639,21 @@ BOOST_AUTO_TEST_CASE(testCalculateTxDataHashV2) // 3. compare hash BOOST_TEST(txDataHash == txDataHashWithHex); - bcos_sdk_destroy_transaction_data_struct_v2(txDataWithHex); - bcos_sdk_destroy_transaction_data_struct_v2(txDataWithByte); + bcos_sdk_destroy_transaction_data_struct_v1(txDataWithHex); + bcos_sdk_destroy_transaction_data_struct_v1(txDataWithByte); } -BOOST_AUTO_TEST_CASE(testCreateTxStructV2) +BOOST_AUTO_TEST_CASE(testCreateTxStructv1) { - auto txDataStruct = createTxDataStructWithHexInputV2(); - auto transactionDataHash = bcos_sdk_calc_transaction_data_struct_hash_v2(1, txDataStruct); + auto txDataStruct = createTxDataStructWithHexInputv1(); + auto transactionDataHash = bcos_sdk_calc_transaction_data_struct_hash_v1(1, txDataStruct); void* key_pair = bcos_sdk_create_keypair(1); auto signature = bcos_sdk_sign_transaction_data_hash(key_pair, transactionDataHash); auto extraData = ""; int64_t attribute = 0; - // create transaction_struct failed (transaction_data_struct_v2 = NULL) - auto txStruct = bcos_sdk_create_transaction_struct_v2( + // create transaction_struct failed (transaction_data_struct_v1 = NULL) + auto txStruct = bcos_sdk_create_transaction_struct_v1( nullptr, signature, transactionDataHash, attribute, extraData); auto success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); @@ -661,7 +661,7 @@ BOOST_AUTO_TEST_CASE(testCreateTxStructV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); // create transaction_struct failed (transaction_data_hash = NULL) - txStruct = bcos_sdk_create_transaction_struct_v2( + txStruct = bcos_sdk_create_transaction_struct_v1( txDataStruct, signature, nullptr, attribute, extraData); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); @@ -669,7 +669,7 @@ BOOST_AUTO_TEST_CASE(testCreateTxStructV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); // create transaction_struct failed (signature = NULL) - txStruct = bcos_sdk_create_transaction_struct_v2( + txStruct = bcos_sdk_create_transaction_struct_v1( txDataStruct, nullptr, transactionDataHash, attribute, extraData); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); @@ -678,7 +678,7 @@ BOOST_AUTO_TEST_CASE(testCreateTxStructV2) // create transaction_struct failed (transaction_data_hash = "") txStruct = - bcos_sdk_create_transaction_struct_v2(txDataStruct, signature, "", attribute, extraData); + bcos_sdk_create_transaction_struct_v1(txDataStruct, signature, "", attribute, extraData); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); BOOST_TEST(txStruct == nullptr); @@ -687,7 +687,7 @@ BOOST_AUTO_TEST_CASE(testCreateTxStructV2) std::string("transaction_data_hash can not be empty string")); // create transaction_struct failed (signature = "") - txStruct = bcos_sdk_create_transaction_struct_v2( + txStruct = bcos_sdk_create_transaction_struct_v1( txDataStruct, "", transactionDataHash, attribute, extraData); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); @@ -696,38 +696,38 @@ BOOST_AUTO_TEST_CASE(testCreateTxStructV2) BOOST_TEST(bcos_sdk_get_last_error_msg() == std::string("signature can not be empty string")); // create transaction_struct success (extraData = NULL) - txStruct = bcos_sdk_create_transaction_struct_v2( + txStruct = bcos_sdk_create_transaction_struct_v1( txDataStruct, signature, transactionDataHash, attribute, nullptr); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == true); compareTxStruct(txStruct, txDataStruct, signature, "", attribute); // create transaction_struct success - txStruct = bcos_sdk_create_transaction_struct_v2( + txStruct = bcos_sdk_create_transaction_struct_v1( txDataStruct, signature, transactionDataHash, attribute, extraData); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == true); compareTxStruct(txStruct, txDataStruct, signature, extraData, attribute); - bcos_sdk_destroy_transaction_data_struct_v2(txDataStruct); - bcos_sdk_destroy_transaction_struct_v2(txStruct); + bcos_sdk_destroy_transaction_data_struct_v1(txDataStruct); + bcos_sdk_destroy_transaction_struct_v1(txStruct); } -BOOST_AUTO_TEST_CASE(testCreateEncodedTxV2) +BOOST_AUTO_TEST_CASE(testCreateEncodedTxv1) { - auto txDataStruct = createTxDataStructWithHexInputV2(); - auto transactionDataHash = bcos_sdk_calc_transaction_data_struct_hash_v2(1, txDataStruct); + auto txDataStruct = createTxDataStructWithHexInputv1(); + auto transactionDataHash = bcos_sdk_calc_transaction_data_struct_hash_v1(1, txDataStruct); void* key_pair = bcos_sdk_create_keypair(1); auto signature = bcos_sdk_sign_transaction_data_hash(key_pair, transactionDataHash); auto extraData = ""; int64_t attribute = 0; - auto txStruct = bcos_sdk_create_transaction_struct_v2( + auto txStruct = bcos_sdk_create_transaction_struct_v1( txDataStruct, signature, transactionDataHash, attribute, extraData); - // 1. test bcos_sdk_create_encoded_transaction_v2 - // create encoded tx failed (transaction_data_struct_v2 = NULL) - auto encodedTx = bcos_sdk_create_encoded_transaction_v2( + // 1. test bcos_sdk_create_encoded_transaction_v1 + // create encoded tx failed (transaction_data_struct_v1 = NULL) + auto encodedTx = bcos_sdk_create_encoded_transaction_v1( nullptr, signature, transactionDataHash, attribute, extraData); auto success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); @@ -735,7 +735,7 @@ BOOST_AUTO_TEST_CASE(testCreateEncodedTxV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); // create encoded tx failed (transaction_data_hash = NULL) - encodedTx = bcos_sdk_create_encoded_transaction_v2( + encodedTx = bcos_sdk_create_encoded_transaction_v1( txDataStruct, signature, nullptr, attribute, extraData); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); @@ -743,7 +743,7 @@ BOOST_AUTO_TEST_CASE(testCreateEncodedTxV2) BOOST_TEST(bcos_sdk_get_last_error() == -1); // create encoded tx failed (signature = NULL) - encodedTx = bcos_sdk_create_encoded_transaction_v2( + encodedTx = bcos_sdk_create_encoded_transaction_v1( txDataStruct, nullptr, transactionDataHash, attribute, extraData); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); @@ -752,7 +752,7 @@ BOOST_AUTO_TEST_CASE(testCreateEncodedTxV2) // create encoded tx failed (transaction_data_hash = "") encodedTx = - bcos_sdk_create_encoded_transaction_v2(txDataStruct, signature, "", attribute, extraData); + bcos_sdk_create_encoded_transaction_v1(txDataStruct, signature, "", attribute, extraData); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); BOOST_TEST(encodedTx == nullptr); @@ -761,7 +761,7 @@ BOOST_AUTO_TEST_CASE(testCreateEncodedTxV2) std::string("transaction_data_hash can not be empty string")); // create encoded tx failed (signature = "") - encodedTx = bcos_sdk_create_encoded_transaction_v2( + encodedTx = bcos_sdk_create_encoded_transaction_v1( txDataStruct, "", transactionDataHash, attribute, extraData); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); @@ -770,23 +770,23 @@ BOOST_AUTO_TEST_CASE(testCreateEncodedTxV2) BOOST_TEST(bcos_sdk_get_last_error_msg() == std::string("signature can not be empty string")); // create encoded tx success - encodedTx = bcos_sdk_create_encoded_transaction_v2( + encodedTx = bcos_sdk_create_encoded_transaction_v1( txDataStruct, signature, transactionDataHash, attribute, extraData); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == true); BOOST_TEST(encodedTx != nullptr); BOOST_TEST(bcos_sdk_get_last_error() == 0); - // 2. test bcos_sdk_encode_transaction_struct_to_hex__v2 + // 2. test bcos_sdk_encode_transaction_struct_to_hex__v1 // create encoded tx with tx_struct failed (transaction_struct == "") - auto encodedTxWithTxStruct = bcos_sdk_encode_transaction_struct_to_hex_v2(nullptr); + auto encodedTxWithTxStruct = bcos_sdk_encode_transaction_struct_to_hex_v1(nullptr); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == false); BOOST_TEST(encodedTxWithTxStruct == nullptr); BOOST_TEST(bcos_sdk_get_last_error() == -1); // create encoded tx with tx_struct success - encodedTxWithTxStruct = bcos_sdk_encode_transaction_struct_to_hex_v2(txStruct); + encodedTxWithTxStruct = bcos_sdk_encode_transaction_struct_to_hex_v1(txStruct); success = bcos_sdk_is_last_opr_success(); BOOST_TEST(success == true); BOOST_TEST(encodedTxWithTxStruct != nullptr); @@ -795,46 +795,46 @@ BOOST_AUTO_TEST_CASE(testCreateEncodedTxV2) // 3. compare encodedTx encodedTxWithTxStruct BOOST_TEST(encodedTx == encodedTxWithTxStruct); - bcos_sdk_destroy_transaction_data_struct_v2(txDataStruct); - bcos_sdk_destroy_transaction_struct_v2(txStruct); + bcos_sdk_destroy_transaction_data_struct_v1(txDataStruct); + bcos_sdk_destroy_transaction_struct_v1(txStruct); } -BOOST_AUTO_TEST_CASE(testEncodeDecodeTxStructV2) +BOOST_AUTO_TEST_CASE(testEncodeDecodeTxStructv1) { - auto txDataStruct = createTxDataStructWithHexInputV2(); - auto transactionDataHash = bcos_sdk_calc_transaction_data_struct_hash_v2(1, txDataStruct); + auto txDataStruct = createTxDataStructWithHexInputv1(); + auto transactionDataHash = bcos_sdk_calc_transaction_data_struct_hash_v1(1, txDataStruct); void* key_pair = bcos_sdk_create_keypair(1); auto signature = bcos_sdk_sign_transaction_data_hash(key_pair, transactionDataHash); auto extraData = ""; int64_t attribute = 0; - auto txStruct = bcos_sdk_create_transaction_struct_v2( + auto txStruct = bcos_sdk_create_transaction_struct_v1( txDataStruct, signature, transactionDataHash, attribute, extraData); // 1. test tx encode decode hex // encode tx to hex failed (transaction == NULL) - auto encodedTxHex = bcos_sdk_encode_transaction_struct_to_hex_v2(nullptr); + auto encodedTxHex = bcos_sdk_encode_transaction_struct_to_hex_v1(nullptr); auto hexSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(hexSuccess == false); BOOST_TEST(encodedTxHex == nullptr); BOOST_TEST(bcos_sdk_get_last_error() == -1); // encode tx to hex success - encodedTxHex = bcos_sdk_encode_transaction_struct_to_hex_v2(txStruct); + encodedTxHex = bcos_sdk_encode_transaction_struct_to_hex_v1(txStruct); hexSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(hexSuccess == true); BOOST_TEST(encodedTxHex != nullptr); BOOST_TEST(bcos_sdk_get_last_error() == 0); // decode hex failed (transaction_hex_str == NULL) - auto decodedTxHex = bcos_sdk_decode_transaction_struct_from_hex_v2(nullptr); + auto decodedTxHex = bcos_sdk_decode_transaction_struct_from_hex_v1(nullptr); hexSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(hexSuccess == false); BOOST_TEST(decodedTxHex == nullptr); BOOST_TEST(bcos_sdk_get_last_error() == -1); // decode hex failed (transaction_hex_str == "") - decodedTxHex = bcos_sdk_decode_transaction_struct_from_hex_v2(""); + decodedTxHex = bcos_sdk_decode_transaction_struct_from_hex_v1(""); hexSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(hexSuccess == false); BOOST_TEST(decodedTxHex == nullptr); @@ -843,7 +843,7 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxStructV2) std::string("transaction_hex_str can not be empty string")); // decode hex failed (the length of transaction_hex_str is not even number) - decodedTxHex = bcos_sdk_decode_transaction_struct_from_hex_v2("0xabc"); + decodedTxHex = bcos_sdk_decode_transaction_struct_from_hex_v1("0xabc"); hexSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(hexSuccess == false); BOOST_TEST(decodedTxHex == nullptr); @@ -852,7 +852,7 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxStructV2) std::string("the length of transaction_hex_str must be an even number")); // decode hex success - decodedTxHex = bcos_sdk_decode_transaction_struct_from_hex_v2(encodedTxHex); + decodedTxHex = bcos_sdk_decode_transaction_struct_from_hex_v1(encodedTxHex); hexSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(hexSuccess == true); BOOST_TEST(decodedTxHex != nullptr); @@ -862,28 +862,28 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxStructV2) // 2. test tx encode decode json // encode tx to json failed (transaction == NULL) - auto encodedTxJson = bcos_sdk_encode_transaction_struct_to_json_v2(nullptr); + auto encodedTxJson = bcos_sdk_encode_transaction_struct_to_json_v1(nullptr); auto jsonSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(jsonSuccess == false); BOOST_TEST(encodedTxJson == nullptr); BOOST_TEST(bcos_sdk_get_last_error() == -1); // encode tx to json success - encodedTxJson = bcos_sdk_encode_transaction_struct_to_json_v2(txStruct); + encodedTxJson = bcos_sdk_encode_transaction_struct_to_json_v1(txStruct); jsonSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(jsonSuccess == true); BOOST_TEST(encodedTxJson != nullptr); BOOST_TEST(bcos_sdk_get_last_error() == 0); // decode json failed (transaction_json_str == NULL) - auto decodedTxJson = bcos_sdk_decode_transaction_struct_from_json_v2(nullptr); + auto decodedTxJson = bcos_sdk_decode_transaction_struct_from_json_v1(nullptr); jsonSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(jsonSuccess == false); BOOST_TEST(decodedTxJson == nullptr); BOOST_TEST(bcos_sdk_get_last_error() == -1); // decode json failed (transaction_json_str == "") - decodedTxJson = bcos_sdk_decode_transaction_struct_from_json_v2(""); + decodedTxJson = bcos_sdk_decode_transaction_struct_from_json_v1(""); jsonSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(jsonSuccess == false); BOOST_TEST(decodedTxJson == nullptr); @@ -892,7 +892,7 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxStructV2) std::string("transaction_json_str can not be empty string")); // decode json success - decodedTxJson = bcos_sdk_decode_transaction_struct_from_json_v2(encodedTxJson); + decodedTxJson = bcos_sdk_decode_transaction_struct_from_json_v1(encodedTxJson); jsonSuccess = bcos_sdk_is_last_opr_success(); BOOST_TEST(jsonSuccess == true); BOOST_TEST(decodedTxJson != nullptr); @@ -900,10 +900,10 @@ BOOST_AUTO_TEST_CASE(testEncodeDecodeTxStructV2) compareTxStruct(decodedTxJson, txDataStruct, signature, extraData, attribute); - bcos_sdk_destroy_transaction_data_struct_v2(txDataStruct); - bcos_sdk_destroy_transaction_struct_v2(txStruct); - bcos_sdk_destroy_transaction_struct_v2(decodedTxHex); - bcos_sdk_destroy_transaction_struct_v2(decodedTxJson); + bcos_sdk_destroy_transaction_data_struct_v1(txDataStruct); + bcos_sdk_destroy_transaction_struct_v1(txStruct); + bcos_sdk_destroy_transaction_struct_v1(decodedTxHex); + bcos_sdk_destroy_transaction_struct_v1(decodedTxJson); } BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json index 19978ab0c..f271077e4 100644 --- a/vcpkg-configuration.json +++ b/vcpkg-configuration.json @@ -3,7 +3,7 @@ { "kind": "git", "repository": "https://github.com/FISCO-BCOS/registry", - "baseline": "cf9b1d3f9133ac203abe2ae22a887f4efc2fdccb", + "baseline": "87805d2845731a26b5e9a80beff1cdf83331279e", "packages": [ "openssl", "hsm-crypto",