Current section
Files
Jump to
Current section
Files
lib/store.ex
defmodule UltraDark.Store do
require Exleveldb
def initialize(store) do
{:ok, ref} = Exleveldb.open(store) # Generate a new leveldb instance if none exists
Exleveldb.close(ref) # Immediately close after ensuring creation, we don't need it constantly open
end
@doc """
We don't want to have to remember to open and keep a reference to the leveldb instance
each time we interact with the chain. Let's make a wrapper function that does this for us
"""
def transact(function, store) do
{:ok, ref} = Exleveldb.open(store)
result = function.(ref)
Exleveldb.close(ref)
result
end
def is_empty?(store) do
fn ref -> Exleveldb.is_empty? ref end
|> transact(store)
end
end