Change the persistent data structure from a record to a proplist
This is done so that possible future updates to the data structure don't break existing code. With this change it will be possible to update the data structure and keep the same old persistent data file, which will still have the expected list format but with more properties
This commit is contained in:
parent
478a12637d
commit
9cf596c67b
|
@ -16,12 +16,6 @@
|
|||
pem :: binary()
|
||||
}).
|
||||
|
||||
-record(data, {
|
||||
account = none :: #data_acc{} | 'none',
|
||||
certs = [] :: [#data_cert{}]
|
||||
}).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -401,19 +401,19 @@ is_error(_) -> false.
|
|||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
data_empty() ->
|
||||
#data{}.
|
||||
[].
|
||||
|
||||
data_get_account(#data{account = Account}) ->
|
||||
case Account of
|
||||
#data_acc{id = AccId, key = PrivateKey} ->
|
||||
data_get_account(Data) ->
|
||||
case lists:keyfind(account, 1, Data) of
|
||||
{account, #data_acc{id = AccId, key = PrivateKey}} ->
|
||||
{ok, AccId, PrivateKey};
|
||||
none ->
|
||||
false ->
|
||||
none
|
||||
end.
|
||||
|
||||
data_set_account(Data = #data{}, {AccId, PrivateKey}) ->
|
||||
NewAcc = #data_acc{id = AccId, key = PrivateKey},
|
||||
Data#data{account = NewAcc}.
|
||||
data_set_account(Data, {AccId, PrivateKey}) ->
|
||||
NewAcc = {account, #data_acc{id = AccId, key = PrivateKey}},
|
||||
lists:keystore(account, 1, Data, NewAcc).
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
|
Loading…
Reference in New Issue