Client/Baking: use wallet lock
This commit is contained in:
parent
c0a47a5b6f
commit
c4549650b5
@ -10,7 +10,6 @@
|
||||
open Proto_alpha
|
||||
open Alpha_context
|
||||
|
||||
(* TODO locking... *)
|
||||
|
||||
type t = (Block_hash.t * Nonce.t) list
|
||||
|
||||
@ -28,29 +27,36 @@ let load (wallet : #Client_context.wallet) =
|
||||
wallet#load ~default:[] name encoding
|
||||
|
||||
let save (wallet : #Client_context.wallet) list =
|
||||
wallet#write name list encoding
|
||||
wallet#with_lock (fun () ->
|
||||
wallet#write name list encoding)
|
||||
|
||||
let mem (wallet : #Client_context.wallet) block_hash =
|
||||
load wallet >>|? fun data ->
|
||||
List.mem_assoc block_hash data
|
||||
wallet#with_lock (fun () ->
|
||||
load wallet >>|? fun data ->
|
||||
List.mem_assoc block_hash data)
|
||||
|
||||
let find wallet block_hash =
|
||||
load wallet >>|? fun data ->
|
||||
try Some (List.assoc block_hash data)
|
||||
with Not_found -> None
|
||||
let find (wallet : #Client_context.wallet) block_hash =
|
||||
wallet#with_lock ( fun () ->
|
||||
load wallet >>|? fun data ->
|
||||
try Some (List.assoc block_hash data)
|
||||
with Not_found -> None)
|
||||
|
||||
let add wallet block_hash nonce =
|
||||
|
||||
let add (wallet : #Client_context.wallet) block_hash nonce =
|
||||
wallet#with_lock ( fun () ->
|
||||
load wallet >>=? fun data ->
|
||||
save wallet ((block_hash, nonce) ::
|
||||
List.remove_assoc block_hash data)
|
||||
List.remove_assoc block_hash data))
|
||||
|
||||
let del wallet block_hash =
|
||||
load wallet >>=? fun data ->
|
||||
save wallet (List.remove_assoc block_hash data)
|
||||
let del (wallet : #Client_context.wallet) block_hash =
|
||||
wallet#with_lock ( fun () ->
|
||||
load wallet >>=? fun data ->
|
||||
save wallet (List.remove_assoc block_hash data))
|
||||
|
||||
let dels wallet hashes =
|
||||
let dels (wallet : #Client_context.wallet) hashes =
|
||||
wallet#with_lock ( fun () ->
|
||||
load wallet >>=? fun data ->
|
||||
save wallet @@
|
||||
List.fold_left
|
||||
(fun data hash -> List.remove_assoc hash data)
|
||||
data hashes
|
||||
data hashes)
|
||||
|
Loading…
Reference in New Issue
Block a user