[chainmaker][#547]add set chain id interface
@@ -187,10 +187,11 @@ BoatHlchainmakerWallet *BoatHlchainmakerWalletInit(const BoatHlchainmakerWalletC
wallet_ptr->http2Context_ptr = NULL;
wallet_ptr->node_info.node_url_info = NULL;
wallet_ptr->node_info.host_name_info = NULL;
+ wallet_ptr->node_info.chain_id_info = NULL;
+
BoatChainmakerWalletSetNodeUrl(wallet_ptr, config_ptr->node_url_cfg);
BoatChainmakerWalletSetHostName(wallet_ptr, config_ptr->host_name_cfg);
-
- wallet_ptr->node_info.chain_id_info = config_ptr->chain_id_cfg;
+ BoatChainmakerWalletSetChainId(wallet_ptr, config_ptr->chain_id_cfg);
wallet_ptr->node_info.org_id_info = config_ptr->org_id_cfg;
/* assignment */
@@ -650,3 +651,43 @@ BOAT_RESULT BoatChainmakerWalletSetHostName(BoatHlchainmakerWallet *wallet_ptr,
return result;
}
+
+BOAT_RESULT BoatChainmakerWalletSetChainId(BoatHlchainmakerWallet *wallet_ptr, const BCHAR *chain_id_ptr)
+{
+ BOAT_RESULT result;
+
+ if ((wallet_ptr == NULL) || (chain_id_ptr == NULL))
+ {
+ BoatLog(BOAT_LOG_CRITICAL, "wallet_ptr or node_url_ptr cannot be NULL.");
+ return BOAT_ERROR_COMMON_INVALID_ARGUMENT;
+ }
+
+ // string length check
+ if (BOAT_SUCCESS != UtilityStringLenCheck(chain_id_ptr))
+ {
+ BoatLog(BOAT_LOG_CRITICAL, "chain id length out of limit: %s.", chain_id_ptr);
+ return BOAT_ERROR_COMMON_INVALID_ARGUMENT;
+ }
+
+ // Set Node URL
+
+ if (wallet_ptr->node_info.chain_id_info != NULL)
+ {
+ BoatFree(wallet_ptr->node_info.chain_id_info);
+ }
+
+ // +1 for NULL Terminator
+ wallet_ptr->node_info.chain_id_info = BoatMalloc(strlen(chain_id_ptr) + 1);
+ if (wallet_ptr->node_info.chain_id_info == NULL)
+ {
+ BoatLog(BOAT_LOG_CRITICAL, "Fail to allocate memory for chain id string.");
+ result = BOAT_ERROR_COMMON_OUT_OF_MEMORY;
+ }
+ else
+ {
+ strcpy(wallet_ptr->node_info.chain_id_info, chain_id_ptr);
+ result = BOAT_SUCCESS;
+ }
+
+ return result;
+}
\ No newline at end of file
