Class: Bitcoin::Store::DB::LevelDB
- Inherits:
-
Object
- Object
- Bitcoin::Store::DB::LevelDB
- Defined in:
- lib/bitcoin/store/db/level_db.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#best_hash ⇒ Object
get best block hash.
- #close ⇒ Object
-
#delete(key) ⇒ Object
delete specified key data.
-
#get(key) ⇒ Object
get value from specified key.
-
#get_entry_payload_from_hash(hash) ⇒ String
get entry payload.
-
#get_hash_from_height(height) ⇒ Object
get block hash specified
height
. -
#initialize(path = "#{Bitcoin.base_dir}/db/spv") ⇒ LevelDB
constructor
A new instance of LevelDB.
-
#next_hash(hash) ⇒ Object
get next block hash specified
hash
. -
#put(key, value) ⇒ Object
put data into LevelDB.
- #save_entry(entry) ⇒ Object
Constructor Details
#initialize(path = "#{Bitcoin.base_dir}/db/spv") ⇒ LevelDB
Returns a new instance of LevelDB.
12 13 14 15 16 17 |
# File 'lib/bitcoin/store/db/level_db.rb', line 12 def initialize(path = "#{Bitcoin.base_dir}/db/spv") # @logger = Bitcoin::Logger.create(:debug) FileUtils.mkdir_p(path) @db = ::LevelDBNative::DB.new(path) # logger.debug 'Opened LevelDB successfully.' end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
9 10 11 |
# File 'lib/bitcoin/store/db/level_db.rb', line 9 def db @db end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/bitcoin/store/db/level_db.rb', line 10 def logger @logger end |
Instance Method Details
#best_hash ⇒ Object
get best block hash.
35 36 37 |
# File 'lib/bitcoin/store/db/level_db.rb', line 35 def best_hash db.get(KEY_PREFIX[:best]) end |
#close ⇒ Object
69 70 71 |
# File 'lib/bitcoin/store/db/level_db.rb', line 69 def close db.close end |
#delete(key) ⇒ Object
delete specified key data.
40 41 42 |
# File 'lib/bitcoin/store/db/level_db.rb', line 40 def delete(key) db.delete(key) end |
#get(key) ⇒ Object
get value from specified key. @return the stored value.
30 31 32 |
# File 'lib/bitcoin/store/db/level_db.rb', line 30 def get(key) db.get(key) end |
#get_entry_payload_from_hash(hash) ⇒ String
get entry payload
57 58 59 |
# File 'lib/bitcoin/store/db/level_db.rb', line 57 def get_entry_payload_from_hash(hash) db.get(KEY_PREFIX[:entry] + hash) end |
#get_hash_from_height(height) ⇒ Object
get block hash specified height
45 46 47 |
# File 'lib/bitcoin/store/db/level_db.rb', line 45 def get_hash_from_height(height) db.get(height_key(height)) end |
#next_hash(hash) ⇒ Object
get next block hash specified hash
50 51 52 |
# File 'lib/bitcoin/store/db/level_db.rb', line 50 def next_hash(hash) db.get(KEY_PREFIX[:next] + hash) end |
#put(key, value) ⇒ Object
put data into LevelDB.
22 23 24 25 |
# File 'lib/bitcoin/store/db/level_db.rb', line 22 def put(key, value) # logger.debug "put #{key} data" db.put(key, value) end |
#save_entry(entry) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/bitcoin/store/db/level_db.rb', line 61 def save_entry(entry) db.batch do db.put(entry.key ,entry.to_payload) db.put(height_key(entry.height), entry.block_hash) connect_entry(entry) end end |