Source file contract_delegate_storage.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
let find = Storage.Contract.Delegate.find
let remove_contract_stake ctxt contract amount =
find ctxt contract >>=? function
| None -> return ctxt
| Some delegate -> Stake_storage.remove_stake ctxt delegate amount
let add_contract_stake ctxt contract amount =
find ctxt contract >>=? function
| None -> return ctxt
| Some delegate -> Stake_storage.add_stake ctxt delegate amount
let registered c delegate =
Storage.Contract.Delegate.find c (Contract_repr.implicit_contract delegate)
>|=? function
| Some current_delegate ->
Signature.Public_key_hash.equal delegate current_delegate
| None -> false
let link c contract delegate =
Storage.Contract.Balance.get c contract >>=? fun balance ->
Stake_storage.add_stake c delegate balance >>=? fun c ->
Storage.Contract.Delegated.add
(c, Contract_repr.implicit_contract delegate)
contract
>|= ok
let unlink c contract =
Storage.Contract.Delegate.find c contract >>=? function
| None -> return c
| Some delegate ->
Storage.Contract.Balance.get c contract >>=? fun balance ->
Stake_storage.remove_stake c delegate balance >>=? fun c ->
Storage.Contract.Delegated.remove
(c, Contract_repr.implicit_contract delegate)
contract
>|= ok
let init ctxt contract delegate =
Storage.Contract.Delegate.init ctxt contract delegate >>=? fun ctxt ->
link ctxt contract delegate
let delete ctxt contract =
unlink ctxt contract >>=? fun ctxt ->
Storage.Contract.Delegate.remove ctxt contract >|= ok
let remove ctxt contract = unlink ctxt contract
let set ctxt contract delegate =
unlink ctxt contract >>=? fun ctxt ->
Storage.Contract.Delegate.add ctxt contract delegate >>= fun ctxt ->
link ctxt contract delegate
let delegated_contracts ctxt delegate =
let contract = Contract_repr.implicit_contract delegate in
Storage.Contract.Delegated.elements (ctxt, contract)