aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--src/blockchain_db/blockchain_db.cpp8
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp19
-rw-r--r--src/wallet/wallet_rpc_server.cpp17
-rw-r--r--src/wallet/wallet_rpc_server.h2
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h17
6 files changed, 51 insertions, 13 deletions
diff --git a/.gitignore b/.gitignore
index 18653c238..622bbdb3a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -101,4 +101,5 @@ local.properties
# TeXlipse plugin
.texlipse
+.idea/
diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp
index 32e89e06a..4fa8cce26 100644
--- a/src/blockchain_db/blockchain_db.cpp
+++ b/src/blockchain_db/blockchain_db.cpp
@@ -26,6 +26,8 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#include <boost/range/adaptor/reversed.hpp>
+
#include "blockchain_db.h"
#include "cryptonote_core/cryptonote_format_utils.h"
#include "profile_tools.h"
@@ -133,13 +135,13 @@ void BlockchainDB::pop_block(block& blk, std::vector<transaction>& txs)
blk = get_top_block();
remove_block();
-
- remove_transaction(get_transaction_hash(blk.miner_tx));
- for (const auto& h : blk.tx_hashes)
+
+ for (const auto& h : boost::adaptors::reverse(blk.tx_hashes))
{
txs.push_back(get_tx(h));
remove_transaction(h);
}
+ remove_transaction(get_transaction_hash(blk.miner_tx));
}
bool BlockchainDB::is_open() const
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 4a4550179..f64cd75b1 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -722,15 +722,15 @@ void BlockchainLMDB::remove_tx_outputs(const crypto::hash& tx_hash, const transa
size_t num_elems = 0;
mdb_cursor_count(cur, &num_elems);
- mdb_cursor_get(cur, &k, &v, MDB_FIRST_DUP);
+ mdb_cursor_get(cur, &k, &v, MDB_LAST_DUP);
- for (uint64_t i = 0; i < num_elems; ++i)
+ for (uint64_t i = num_elems; i > 0; --i)
{
- const tx_out tx_output = tx.vout[i];
+ const tx_out tx_output = tx.vout[i-1];
remove_output(*(const uint64_t*)v.mv_data, tx_output.amount);
- if (i < num_elems - 1)
+ if (i > 1)
{
- mdb_cursor_get(cur, &k, &v, MDB_NEXT_DUP);
+ mdb_cursor_get(cur, &k, &v, MDB_PREV_DUP);
}
}
}
@@ -806,22 +806,23 @@ void BlockchainLMDB::remove_amount_output_index(const uint64_t amount, const uin
size_t num_elems = 0;
mdb_cursor_count(cur, &num_elems);
- mdb_cursor_get(cur, &k, &v, MDB_FIRST_DUP);
+ mdb_cursor_get(cur, &k, &v, MDB_LAST_DUP);
uint64_t amount_output_index = 0;
uint64_t goi = 0;
bool found_index = false;
- for (uint64_t i = 0; i < num_elems; ++i)
+ for (uint64_t i = num_elems; i > 0; --i)
{
mdb_cursor_get(cur, &k, &v, MDB_GET_CURRENT);
goi = *(const uint64_t *)v.mv_data;
if (goi == global_output_index)
{
- amount_output_index = i;
+ amount_output_index = i-1;
found_index = true;
break;
}
- mdb_cursor_get(cur, &k, &v, MDB_NEXT_DUP);
+ if (i > 1)
+ mdb_cursor_get(cur, &k, &v, MDB_PREV_DUP);
}
if (found_index)
{
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 026b78d2e..a1f48bd77 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -115,7 +115,21 @@ namespace tools
}
return true;
}
-
+ //------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_getheight(const wallet_rpc::COMMAND_RPC_GET_HEIGHT::request& req, wallet_rpc::COMMAND_RPC_GET_HEIGHT::response& res, epee::json_rpc::error& er)
+ {
+ try
+ {
+ res.height = m_wallet.get_blockchain_current_height();
+ }
+ catch (std::exception& e)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = e.what();
+ return false;
+ }
+ return true;
+ }
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::validate_transfer(const std::list<wallet_rpc::transfer_destination> destinations, std::string payment_id, std::vector<cryptonote::tx_destination_entry>& dsts, std::vector<uint8_t>& extra, epee::json_rpc::error& er)
{
@@ -652,3 +666,4 @@ namespace tools
}
//------------------------------------------------------------------------------------------------------------------------------
}
+
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index c81ab0141..a7c5077e9 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -63,6 +63,7 @@ namespace tools
BEGIN_JSON_RPC_MAP("/json_rpc")
MAP_JON_RPC_WE("getbalance", on_getbalance, wallet_rpc::COMMAND_RPC_GET_BALANCE)
MAP_JON_RPC_WE("getaddress", on_getaddress, wallet_rpc::COMMAND_RPC_GET_ADDRESS)
+ MAP_JON_RPC_WE("getheight", on_getheight, wallet_rpc::COMMAND_RPC_GET_HEIGHT)
MAP_JON_RPC_WE("transfer", on_transfer, wallet_rpc::COMMAND_RPC_TRANSFER)
MAP_JON_RPC_WE("transfer_split", on_transfer_split, wallet_rpc::COMMAND_RPC_TRANSFER_SPLIT)
MAP_JON_RPC_WE("sweep_dust", on_sweep_dust, wallet_rpc::COMMAND_RPC_SWEEP_DUST)
@@ -80,6 +81,7 @@ namespace tools
//json_rpc
bool on_getbalance(const wallet_rpc::COMMAND_RPC_GET_BALANCE::request& req, wallet_rpc::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er);
bool on_getaddress(const wallet_rpc::COMMAND_RPC_GET_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er);
+ bool on_getheight(const wallet_rpc::COMMAND_RPC_GET_HEIGHT::request& req, wallet_rpc::COMMAND_RPC_GET_HEIGHT::response& res, epee::json_rpc::error& er);
bool validate_transfer(const std::list<wallet_rpc::transfer_destination> destinations, const std::string payment_id, std::vector<cryptonote::tx_destination_entry>& dsts, std::vector<uint8_t>& extra, epee::json_rpc::error& er);
bool on_transfer(const wallet_rpc::COMMAND_RPC_TRANSFER::request& req, wallet_rpc::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er);
bool on_transfer_split(const wallet_rpc::COMMAND_RPC_TRANSFER_SPLIT::request& req, wallet_rpc::COMMAND_RPC_TRANSFER_SPLIT::response& res, epee::json_rpc::error& er);
diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h
index e12c4bfa8..a20c8b969 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -78,6 +78,23 @@ namespace wallet_rpc
};
};
+ struct COMMAND_RPC_GET_HEIGHT
+ {
+ struct request
+ {
+ BEGIN_KV_SERIALIZE_MAP()
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ uint64_t height;
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(height)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
struct transfer_destination
{
uint64_t amount;