diff options
Diffstat (limited to 'src/storagedb.erl')
-rw-r--r-- | src/storagedb.erl | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/storagedb.erl b/src/storagedb.erl index c94a13e..d781033 100644 --- a/src/storagedb.erl +++ b/src/storagedb.erl @@ -7,7 +7,7 @@ -behaviour(gen_server). %% API -export([start_link/0, stop/0]). --export([add/1, fetchnewhashes/1]). +-export([add/1, fetchnewhashes/1, lastverifiednewentry/0]). %% gen_server callbacks. -export([init/1, handle_call/3, terminate/2, handle_cast/2, handle_info/2, code_change/3]). @@ -23,6 +23,10 @@ start_link() -> stop() -> call(?MODULE, stop). +lastverifiednewentry_path() -> + {ok, Value} = application:get_env(plop, lastverifiednewentry_path), + Value. + %%%%%%%%%%%%%%%%%%%% %% Public API. @@ -34,6 +38,17 @@ fetchnewhashes(Index) -> index:getrange(newentries_path(), Index, Size - 1) end. +lastverifiednewentry() -> + case atomic:readfile(lastverifiednewentry_path()) of + noentry -> + {0, none}; + Contents -> + {struct, PropList} = mochijson2:decode(Contents), + Index = proplists:get_value(<<"index">>, PropList), + Hash = proplists:get_value(<<"hash">>, PropList), + {Index, mochihex:to_bin(binary_to_list(Hash))} + end. + -spec add(binary()) -> ok. add(LeafHash) -> ok = call(?MODULE, {add_nosync, LeafHash}), |