ligo/src/test/contracts/multisig-v2.ligo

46 lines
1.2 KiB
Plaintext
Raw Normal View History

2019-11-21 22:42:15 +04:00
// storage type
type threshold_t is nat
type addr_set_t is set(address)
2019-11-22 19:02:53 +04:00
type message_store_t is big_map(bytes,addr_set_t)
2019-11-21 22:42:15 +04:00
type storage_t is record
threshold : threshold_t ;
auth : addr_set_t ;
message_store : message_store_t ;
end
// I/O types
type message_t is (unit -> list(operation))
type send_pt is message_t
type contract_return_t is (list(operation) * storage_t)
type entry_point_t is
| Send of send_pt
function send (const param : send_pt; const s : storage_t) : contract_return_t is block {
2019-11-22 19:02:53 +04:00
if not set_mem(sender,s.auth) then failwith("Unauthorized address") else skip ;
2019-11-21 22:42:15 +04:00
var message : message_t := param ;
2019-11-22 19:02:53 +04:00
const packed_msg : bytes = bytes_pack(message) ;
2019-11-21 22:42:15 +04:00
var ret_ops : list(operation) := (nil : list(operation)) ;
2019-11-22 19:02:53 +04:00
var new_store : addr_set_t :=
2019-11-21 22:42:15 +04:00
case map_get(packed_msg, s.message_store) of
2019-11-22 19:02:53 +04:00
| Some(voters) -> set_add(sender,voters)
| None -> set sender end end
2019-11-22 19:02:53 +04:00
;
if size(new_store) >= s.threshold then block {
remove packed_msg from map s.message_store ;
ret_ops := message(unit) ;
} else
s.message_store[packed_msg] := new_store
2019-11-21 22:42:15 +04:00
} with ( ret_ops , s)
function main(const param : entry_point_t; const s : storage_t) : contract_return_t is
case param of
| Send (p) -> send(p,s)
end