From 70306e90039f4a31d2ff86b1e4a6e7defbb8745e Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Wed, 24 Oct 2018 14:39:17 +0800 Subject: [PATCH] fix: expected number, got string --- html/js/controllers/send_coins.js | 10 +++++- src/TxSearch.cpp | 14 ++++---- src/YourMoneroRequests.cpp | 53 +++++++++++++++++-------------- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/html/js/controllers/send_coins.js b/html/js/controllers/send_coins.js index 172c922..df1b049 100644 --- a/html/js/controllers/send_coins.js +++ b/html/js/controllers/send_coins.js @@ -192,6 +192,14 @@ class HostedMoneroAPIClient self.$http.post(config.apiUrl + endpointPath, parameters).then( function(data) { + if (data.data.error) + { + const errStr = "Invalid mixin - must be >= 0"; + const err = new Error(data.data.error); + fn(err); + return; + } + __proceedTo_parseAndCallBack(data.data) } ).catch( @@ -302,7 +310,7 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS if (err) { console.error("Err:", err) $scope.status = ""; - $scope.error = "Something unexpected occurred when submitting your transaction: " + (err.Error || err); + $scope.error = "Error: " + (err.Error || err); $scope.submitting = false; return } diff --git a/src/TxSearch.cpp b/src/TxSearch.cpp index 7cd1652..4bb2e51 100755 --- a/src/TxSearch.cpp +++ b/src/TxSearch.cpp @@ -700,9 +700,9 @@ TxSearch::find_txs_in_mempool( j_tx["hash"] = oi_identification.get_tx_hash_str(); j_tx["tx_pub_key"] = oi_identification.get_tx_pub_key_str(); j_tx["timestamp"] = recieve_time*1e3; // when it got into mempool - j_tx["total_received"] = oi_identification.total_received; - j_tx["total_sent"] = 0; // to be set later when looking for key images - j_tx["unlock_time"] = 0; // for mempool we set it to zero + j_tx["total_received"] = std::to_string(oi_identification.total_received); + j_tx["total_sent"] = "0"; // to be set later when looking for key images + j_tx["unlock_time"] = "0"; // for mempool we set it to zero // since we dont have block_height to work with j_tx["height"] = current_height; // put current blockchain height, // just to indicate to frontend that this @@ -750,7 +750,7 @@ TxSearch::find_txs_in_mempool( spend_keys.push_back({ {"key_image" , in_info.key_img}, - {"amount" , out.amount}, + {"amount" , std::to_string(out.amount)}, {"tx_pub_key", out.tx_pub_key}, {"out_index" , out.out_index}, {"mixin" , out.mixin}, @@ -773,7 +773,7 @@ TxSearch::find_txs_in_mempool( json& j_tx = j_transactions->back(); - j_tx["total_sent"] = total_sent; + j_tx["total_sent"] = std::to_string(total_sent); j_tx["spent_outputs"] = spend_keys; } else @@ -793,8 +793,8 @@ TxSearch::find_txs_in_mempool( j_tx["hash"] = oi_identification.get_tx_hash_str(); j_tx["tx_pub_key"] = oi_identification.get_tx_pub_key_str(); j_tx["timestamp"] = recieve_time*1e3; // when it got into mempool - j_tx["total_received"] = 0; // we did not recive any outputs/xmr - j_tx["total_sent"] = total_sent; // to be set later when looking for key images + j_tx["total_received"] = "0"; // we did not recive any outputs/xmr + j_tx["total_sent"] = std::to_string(total_sent); // to be set later when looking for key images j_tx["unlock_time"] = 0; // for mempool we set it to zero // since we dont have block_height to work with j_tx["height"] = current_height; // put current blockchain height, diff --git a/src/YourMoneroRequests.cpp b/src/YourMoneroRequests.cpp index 92a1ce5..577f04b 100755 --- a/src/YourMoneroRequests.cpp +++ b/src/YourMoneroRequests.cpp @@ -346,6 +346,7 @@ YourMoneroRequests::get_address_txs( last_tx_id_db = j_response["transactions"].back()["id"]; } + for (json& j_tx: j_mempool_tx) { //cout << "mempool j_tx[\"total_received\"]: " @@ -353,14 +354,18 @@ YourMoneroRequests::get_address_txs( j_tx["id"] = ++last_tx_id_db; - total_received_mempool += j_tx["total_received"].get(); - total_sent_mempool += j_tx["total_sent"].get(); + total_received_mempool += boost::lexical_cast( + j_tx["total_received"].get()); + total_sent_mempool += boost::lexical_cast( + j_tx["total_sent"].get()); j_response["transactions"].push_back(j_tx); } j_response["total_received"] - = std::to_string(j_response["total_received"].get() + = std::to_string( + boost::lexical_cast( + j_response["total_received"].get()) + total_received_mempool); } @@ -409,9 +414,9 @@ YourMoneroRequests::get_address_info( string viewkey_hash = make_hash(view_key); j_response = json { - {"locked_funds" , 0}, // locked xmr (e.g., younger than 10 blocks) - {"total_received" , 0}, // calculated in this function - {"total_sent" , 0}, // calculated in this function + {"locked_funds" , "0"}, // locked xmr (e.g., younger than 10 blocks) + {"total_received" , "0"}, // calculated in this function + {"total_sent" , "0"}, // calculated in this function {"scanned_height" , 0}, // not used. it is here to match mymonero {"scanned_block_height" , 0}, // taken from Accounts table {"scanned_block_timestamp", 0}, // taken from Accounts table @@ -595,7 +600,7 @@ YourMoneroRequests::get_unspent_outs( string viewkey_hash = make_hash(view_key); j_response = json { - {"amount" , 0}, // total value of the outputs + {"amount" , "0"}, // total value of the outputs {"outputs", json::array()} // list of outputs // exclude those without require // no of confirmation @@ -823,7 +828,7 @@ YourMoneroRequests::get_random_outs( for (const auto& outs: found_outputs) { - json j_outs {{"amount", outs.amount}, + json j_outs {{"amount", std::to_string(outs.amount)}, {"outputs", json::array()}}; @@ -960,8 +965,9 @@ YourMoneroRequests::import_wallet_request( json j_response; j_response["request_fulfilled"] = false; - j_response["import_fee"] = current_bc_status->get_bc_setup() - .import_fee; + j_response["import_fee"] = std::to_string( + current_bc_status->get_bc_setup() + .import_fee); j_response["status"] = "error"; j_response["error"] = "Some error occured"; @@ -987,7 +993,7 @@ YourMoneroRequests::import_wallet_request( auto response_headers = make_headers({{ "Content-Length", - to_string(response_body.size())}}); + std::to_string(response_body.size())}}); session->close( OK, response_body, response_headers); @@ -1004,7 +1010,7 @@ YourMoneroRequests::import_wallet_request( string response_body = j_response.dump(); auto response_headers = make_headers({{ "Content-Length", - to_string(response_body.size())}}); + std::to_string(response_body.size())}}); session->close( OK, response_body, response_headers); return; @@ -1045,7 +1051,7 @@ YourMoneroRequests::import_wallet_request( xmr_payment.payment_id); j_response["payment_id"] = xmr_payment.payment_id; - j_response["import_fee"] = xmr_payment.import_fee; + j_response["import_fee"] = std::to_string(xmr_payment.import_fee); j_response["new_request"] = false; j_response["request_fulfilled"] = request_fulfilled; j_response["payment_address"] = integrated_address; @@ -1109,7 +1115,7 @@ YourMoneroRequests::import_wallet_request( else { cerr << "Updating accounts due to made " - "payment mysql failed! " << endl; + "payment mysql failed! \n"; j_response["error"] = "Updating accounts due to made " "payment mysql failed!"; @@ -1117,7 +1123,7 @@ YourMoneroRequests::import_wallet_request( } else { - cerr << "Updating payment mysql failed! " << endl; + cerr << "Updating payment mysql failed!\n"; j_response["error"] = "Updating payment mysql failed!"; } @@ -1167,10 +1173,11 @@ YourMoneroRequests::import_wallet_request( // payment entry created j_response["payment_id"] = payment_table_id; - j_response["import_fee"] = xmr_payment.import_fee; + j_response["import_fee"] = std::to_string( + xmr_payment.import_fee); j_response["new_request"] = true; j_response["request_fulfilled"] - = bool {xmr_payment.request_fulfilled}; + = bool {xmr_payment.request_fulfilled}; j_response["payment_address"] = xmr_payment.payment_address; j_response["status"] = "Payment not yet received"; j_response["error"] = ""; @@ -1180,7 +1187,7 @@ YourMoneroRequests::import_wallet_request( string response_body = j_response.dump(); auto response_headers = make_headers({{ "Content-Length", - to_string(response_body.size())}}); + std::to_string(response_body.size())}}); session->close( OK, response_body, response_headers); } @@ -1310,7 +1317,7 @@ YourMoneroRequests::import_recent_wallet_request( string response_body = j_response.dump(); auto response_headers = make_headers({{ "Content-Length", - to_string(response_body.size())}}); + std::to_string(response_body.size())}}); session->close( OK, response_body, response_headers); } @@ -1463,8 +1470,8 @@ YourMoneroRequests::get_tx( j_response["size"] = size; // to be field later on using data from OutputInputIdentification - j_response["total_sent"] = 0; - j_response["total_received"] = 0; + j_response["total_sent"] = "0"; + j_response["total_received"] = "0"; int64_t tx_height {-1}; @@ -1639,7 +1646,7 @@ YourMoneroRequests::get_tx( total_spent += out.amount; j_spent_outputs.push_back({ - {"amount" , in_info.amount}, + {"amount" , std::to_string(in_info.amount)}, {"key_image" , in_info.key_img}, {"tx_pub_key" , out.tx_pub_key}, {"out_index" , out.out_index}, @@ -1648,7 +1655,7 @@ YourMoneroRequests::get_tx( } // for (auto& in_info: oi_identification - j_response["total_sent"] = total_spent; + j_response["total_sent"] = std::to_string(total_spent); j_response["spent_outputs"] = j_spent_outputs;