aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db/blockchain_db.cpp
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-02-21 11:27:15 +0200
committerRiccardo Spagni <ric@spagni.net>2017-02-21 11:27:15 +0200
commit49efd3add9f7b9bbcbd2526538846f6d8e58ac86 (patch)
treee3f1c97cd7dfb7a1c82927f3c2d483bfbe1afbe2 /src/blockchain_db/blockchain_db.cpp
parentMerge pull request #1725 (diff)
parentblockchain_db: add "raw" blobdata getters for block and transaction (diff)
downloadmonero-49efd3add9f7b9bbcbd2526538846f6d8e58ac86.tar.xz
Merge pull request #1727
0288310e blockchain_db: add "raw" blobdata getters for block and transaction (moneromooo-monero)
Diffstat (limited to 'src/blockchain_db/blockchain_db.cpp')
-rw-r--r--src/blockchain_db/blockchain_db.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp
index 7ac046bc9..c61a81379 100644
--- a/src/blockchain_db/blockchain_db.cpp
+++ b/src/blockchain_db/blockchain_db.cpp
@@ -200,6 +200,45 @@ void BlockchainDB::remove_transaction(const crypto::hash& tx_hash)
remove_transaction_data(tx_hash, tx);
}
+block BlockchainDB::get_block_from_height(const uint64_t& height) const
+{
+ blobdata bd = get_block_blob_from_height(height);
+ block b;
+ if (!parse_and_validate_block_from_blob(bd, b))
+ throw new DB_ERROR("Failed to parse block from blob retrieved from the db");
+
+ return b;
+}
+
+block BlockchainDB::get_block(const crypto::hash& h) const
+{
+ blobdata bd = get_block_blob(h);
+ block b;
+ if (!parse_and_validate_block_from_blob(bd, b))
+ throw new DB_ERROR("Failed to parse block from blob retrieved from the db");
+
+ return b;
+}
+
+bool BlockchainDB::get_tx(const crypto::hash& h, cryptonote::transaction &tx) const
+{
+ blobdata bd;
+ if (!get_tx_blob(h, bd))
+ return false;
+ if (!parse_and_validate_tx_from_blob(bd, tx))
+ throw new DB_ERROR("Failed to parse transaction from blob retrieved from the db");
+
+ return true;
+}
+
+transaction BlockchainDB::get_tx(const crypto::hash& h) const
+{
+ transaction tx;
+ if (!get_tx(h, tx))
+ throw new TX_DNE(std::string("tx with hash ").append(epee::string_tools::pod_to_hex(h)).append(" not found in db").c_str());
+ return tx;
+}
+
void BlockchainDB::reset_stats()
{
num_calls = 0;