Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- storage (pair (pair (map string key) uint8) uint8) ;
- return unit ;
- parameter (pair (pair uint8 (pair (contract unit unit) tez)) (map string signature)) ;
- code
- {
- # storage is a pair of
- # pair of
- # map from names to public and
- # number of valid signatures required
- # and the last count value
- # parameter is a
- # pair
- # pair $newcount (pair $destination $amount)
- # (the new count value, where to send the funds and how much)
- # map from names to signature (the actual signatures)
- DUP ; DUP; CDR; SWAP; CADR; DIP { DUP; DUP } ; # $input : $storage : $storage : $storage
- DIP { CDR }; DIIP { CAAR }; DIIIP { CADR }; # $input : $count : $keys : $N : $storage
- DUP; CAAR; DIP { SWAP }; # $newcount : $count : $input : $keys : $N : $storage
- IFCMPGT {{ NOP }} {{ FAIL }} ;; # $input : $keys : $N : $storage
- DUP; CDR; SWAP; CAR ; # $action : $signatures : $keys : $N: $storage
- DUP; H ; # $hash : $action : $signatures : $keys : $N: $storage
- DUUUUUUP; CDAAR; PAIR ; # pair $keys $hash : $action : $signatures : $N: $storage
- PUSH uint8 0; SWAP; PAIR ; # pair (pair $keys $hash) 0 : $action : $signatures : $N : $storage
- DIP { SWAP }; SWAP ; # $signatures : pair (pair $keys $hash) 0 : $action : $N : $storage
- LAMBDA (pair (pair string signature) (pair (pair (map string key) string) uint8)) (pair (pair (map string key) string) uint8)
- {# S = pair (pair $name $signature) (pair (pair $keys $hash) $counter)
- DUP; CDR; SWAP; CAR ;
- # S = pair $name $signature : pair (pair $keys $hash) $counter
- DUP; CDR; SWAP; CAR ;
- # S = $name : $signature : pair (pair $keys $hash) $counter
- DIIP { DUP; CDR; SWAP; CAR } ;
- # S = $name : $signature : (pair $keys $hash) : $counter
- DIIP { DUP; CDR; SWAP; CAR }; SWAP ;
- # S = $signature : $name : $keys : $hash : $counter
- DIP
- { DIP { DUP }; GET ; # attempt to get the key for a given user
- IF_NONE { FAIL } { } # fail for unknown signer, otherwise key is pushed on the stack
- };
- # S = $signature : $key : $keys : $hash : $counter
- DIIP { SWAP ; DUP } ;
- # S = $signature : $key : $hash : $hash : $keys : $counter
- DIIIP { SWAP; PAIR; SWAP } ;
- # S = $signature : $key : $hash : $counter: pair $keys $hash
- SWAP ; DIP { PAIR } ;
- # S = $signature : pair $key $hash : $counter: pair $keys $hash
- CHECK_SIGNATURE ;
- # S = $sig_valid? : $counter : pair $keys $hash
- IF { PUSH uint8 1; CHECKED_ADD } { FAIL } ; # we don't *have* to fail on an invalid signature, but it is good hygiene
- # S = $counter : pair $keys $hash
- SWAP; PAIR ;
- # S = pair (pair $keys hash) $counter
- } ;
- # S = $reducer : $signatures : pair (pair $keys $hash) 0 : $action : $N : $storage
- REDUCE ; # this is where the counting happens
- # S = pair (pair $keys $hash) $counter : $action : $N : $storage
- CDR ; DIP { SWAP ; DROP ; SWAP } ;
- # S = $counter : $N : $action : $storage
- IFCMPGE
- { # if we have enough signatures
- DUP; DUP; CDDR; SWAP; CDAR; UNIT; DIP { SWAP }; DIIIIP { SWAP; CDR };
- # unit : $amount : $contract : $storage : $action
- TRANSFER_TOKENS; DROP; DIP { CAR } ; CAR;
- # $keys : $newcount
- PAIR; UNIT; PAIR
- }
- {
- FAIL
- } # not enough signatures, fail
- }
Advertisement
Add Comment
Please, Sign In to add comment