commit txn parsing error handling
diff --git a/service/http_server/BUILD b/service/http_server/BUILD
index 16909ba..5a444eb 100644
--- a/service/http_server/BUILD
+++ b/service/http_server/BUILD
@@ -1,20 +1,10 @@
package(default_visibility = ["//visibility:public"])
cc_library(
- name = "sdk_transaction",
- srcs = ["sdk_transaction.cpp"],
- hdrs = ["sdk_transaction.h"],
- deps = [
- "//third_party:rapidjson",
- ],
-)
-
-cc_library(
name = "crow_service",
srcs = ["crow_service.cpp"],
hdrs = ["crow_service.h"],
deps = [
- ":sdk_transaction",
"//service/kv_service:resdb_kv_client",
"@com_resdb_nexres//common:asio",
"@com_resdb_nexres//common:boost_comm",
diff --git a/service/http_server/crow_service.cpp b/service/http_server/crow_service.cpp
index ba680e6..0f70eeb 100644
--- a/service/http_server/crow_service.cpp
+++ b/service/http_server/crow_service.cpp
@@ -148,9 +148,17 @@
.methods("POST"_method)([this](const request& req) {
std::string body = req.body;
LOG(INFO) << "body: " << body;
- resdb::SDKTransaction transaction = resdb::ParseSDKTransaction(body);
- const std::string id = transaction.id;
- const std::string value = transaction.value;
+
+ // Parse transaction JSON
+ rapidjson::Document doc;
+ doc.Parse(body.c_str());
+ if (!doc.IsObject() || !doc.HasMember("id")) {
+ response res(400, "Invalid transaction format"); // Bad Request
+ res.set_header("Content-Type", "text/plain");
+ return res;
+ }
+ const std::string id = doc["id"].GetString();
+ const std::string value = body;
// Set key-value pair in kv server
int retval = kv_client_.Set(id, value);
@@ -344,7 +352,7 @@
+ ", \"transactionNum\" : " + std::to_string(num_transactions_)
+ ", \"blockNum\" : " + std::to_string(*block_num_resp)
+ ", \"chainAge\" : " + std::to_string(chain_age)
- + "}]");
+ + "}]");
LOG(INFO) << std::string(values.c_str());
res.set_header("Content-Type", "application/json");
res.end(std::string(values.c_str()));
@@ -385,8 +393,6 @@
KVRequest kv_request;
cur_size++;
if (request.ParseFromString(txn.second)) {
- LOG(INFO) << request.DebugString();
-
if (!first_batch_element) cur_batch_str.append(",");
first_batch_element = false;
diff --git a/service/http_server/crow_service.h b/service/http_server/crow_service.h
index 0dfa37c..7326164 100644
--- a/service/http_server/crow_service.h
+++ b/service/http_server/crow_service.h
@@ -34,7 +34,6 @@
#include "platform/config/resdb_config_utils.h"
#include "interface/common/resdb_state_accessor.h"
#include "interface/common/resdb_txn_accessor.h"
-#include "service/http_server/sdk_transaction.h"
#include "service/kv_service/proto/kv_server.pb.h"
namespace sdk {
diff --git a/service/http_server/sdk_transaction.cpp b/service/http_server/sdk_transaction.cpp
deleted file mode 100644
index dda4008..0000000
--- a/service/http_server/sdk_transaction.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "service/http_server/sdk_transaction.h"
-
-#include <rapidjson/document.h>
-#include <rapidjson/stringbuffer.h>
-#include <rapidjson/writer.h>
-
-namespace resdb {
-
-SDKTransaction ParseSDKTransaction(const std::string &json) {
- rapidjson::Document doc;
- doc.Parse(json.c_str());
- SDKTransaction transaction{};
- auto getString = [&doc](const char *id) { return doc[id].GetString(); };
- transaction.id = getString("id");
- transaction.value = json;
-
- return transaction;
-}
-
-} // namespace resdb
diff --git a/service/http_server/sdk_transaction.h b/service/http_server/sdk_transaction.h
deleted file mode 100644
index bb71a18..0000000
--- a/service/http_server/sdk_transaction.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
-#pragma once
-
-#include <string>
-namespace resdb {
-
-struct SDKTransaction {
- std::string id;
- std::string value;
-};
-
-SDKTransaction ParseSDKTransaction(const std::string &json);
-
-} // namespace resdb