Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<feat>(sdk): impl transaction builder v2 in c sdk. #191

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
if: runner.os == 'macOS'
run: brew install ccache lcov
- name: fetch vcpkg
run: cd /usr/local/share/vcpkg/ && git fetch && git reset --hard && git pull && cd -
run: cd /usr/local/share/vcpkg/ && git status && git reset --hard && git stash && git fetch && git pull && cd -
- name: configure
if: runner.os == 'macOS'
run: |
Expand Down
14 changes: 14 additions & 0 deletions bcos-c-sdk/bcos_sdk_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,18 @@ const char* bcos_sdk_get_group_chain_id(void* sdk, const char* group)

auto chainID = groupInfo->chainID();
return strdup(chainID.c_str());
}

uint32_t bcos_sdk_get_local_protocol_info(void* sdk) {
bcos_sdk_clear_last_error();
BCOS_SDK_C_PARAMS_VERIFICATION(sdk, 0);

return ((bcos::cppsdk::Sdk*)sdk)->localProtocolInfo();
}

uint32_t bcos_sdk_get_negotiated_protocol_info(void* sdk) {
bcos_sdk_clear_last_error();
BCOS_SDK_C_PARAMS_VERIFICATION(sdk, 0);

return ((bcos::cppsdk::Sdk*)sdk)->negotiatedProtocolInfo();
}
4 changes: 4 additions & 0 deletions bcos-c-sdk/bcos_sdk_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ void bcos_sdk_get_group_wasm_and_crypto(void* sdk, const char* group, int* wasm,
* @return const char* : chain id
*/
const char* bcos_sdk_get_group_chain_id(void* sdk, const char* group);

uint32_t bcos_sdk_get_local_protocol_info(void* sdk);

uint32_t bcos_sdk_get_negotiated_protocol_info(void* sdk);
// --------------------------------------------------------------------

#ifdef __cplusplus
Expand Down
32 changes: 30 additions & 2 deletions bcos-c-sdk/bcos_sdk_c_uti_receipt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ void* bcos_sdk_create_receipt_data_with_json(const char* json)
{
std::string errorMsg = boost::diagnostic_information(e);
BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_create_receipt_data") << LOG_DESC("exception")
<< LOG_KV("json", json)
<< LOG_KV("error", errorMsg);
<< LOG_KV("json", json) << LOG_KV("error", errorMsg);
bcos_sdk_set_last_error_msg(-1, errorMsg.c_str());
}

Expand Down Expand Up @@ -167,4 +166,33 @@ const char* bcos_sdk_calc_receipt_data_hash(int crypto_type, void* _receiptData)
bcos_sdk_set_last_error_msg(-1, errorMsg.c_str());
}
return NULL;
}

const char* bcos_sdk_calc_receipt_data_hash_with_json(int crypto_type, const char* json)
{
bcos_sdk_clear_last_error();
BCOS_SDK_C_PARAMS_VERIFICATION(json, NULL);
BCOS_SDK_C_PARAMS_VERIFY_CONDITION(
(crypto_type == BCOS_C_SDK_ECDSA_TYPE || crypto_type == BCOS_C_SDK_SM_TYPE),
"invalid crypto type, it must be BCOS_C_SDK_ECDSA_TYPE(ecdsa crypto type) or "
"BCOS_C_SDK_SM_TYPE(sm crypto type)",
NULL);

try
{
ReceiptBuilder builder;
auto transactionDataHash = builder.calculateReceiptDataHashWithJson(
crypto_type == BCOS_C_SDK_ECDSA_TYPE ? CryptoType::Secp256K1 : CryptoType::SM2,
std::string(json));
return strdup(bcos::toHexStringWithPrefix(transactionDataHash).c_str());
}
catch (const std::exception& e)
{
std::string errorMsg = boost::diagnostic_information(e);
BCOS_LOG(WARNING) << LOG_BADGE("bcos_sdk_calc_transaction_data_hash_with_json")
<< LOG_DESC("exception") << LOG_KV("crypto_type", crypto_type)
<< LOG_KV("json", json) << LOG_KV("error", errorMsg);
bcos_sdk_set_last_error_msg(-1, errorMsg.c_str());
}
return NULL;
}
2 changes: 2 additions & 0 deletions bcos-c-sdk/bcos_sdk_c_uti_receipt.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ void bcos_sdk_destroy_receipt_data(void* transaction_data);

const char* bcos_sdk_calc_receipt_data_hash(int crypto_type, void* _receiptData);

const char* bcos_sdk_calc_receipt_data_hash_with_json(int crypto_type, const char* json);

const char* bcos_sdk_encode_receipt_data(void* receipt_data);

const char* bcos_sdk_decode_receipt_data(const char* receipt_bytes);
Expand Down
Loading
Loading