Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2017
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. storage (pair (pair (map string key) uint8) uint8) ;
  2. return unit ;
  3. parameter (pair (pair uint8 (pair (contract unit unit) tez)) (map string signature)) ;
  4. code
  5. {
  6. # storage is a pair of
  7. # pair of
  8. # map from names to public and
  9. # number of valid signatures required
  10. # and the last count value
  11. # parameter is a
  12. # pair
  13. # pair $newcount (pair $destination $amount)
  14. # (the new count value, where to send the funds and how much)
  15. # map from names to signature (the actual signatures)
  16. DUP ; DUP; CDR; SWAP; CADR; DIP { DUP; DUP } ; # $input : $storage : $storage : $storage
  17. DIP { CDR }; DIIP { CAAR }; DIIIP { CADR }; # $input : $count : $keys : $N : $storage
  18. DUP; CAAR; DIP { SWAP }; # $newcount : $count : $input : $keys : $N : $storage
  19. IFCMPGT {{ NOP }} {{ FAIL }} ;; # $input : $keys : $N : $storage
  20. DUP; CDR; SWAP; CAR ; # $action : $signatures : $keys : $N: $storage
  21. DUP; H ; # $hash : $action : $signatures : $keys : $N: $storage
  22. DUUUUUUP; CDAAR; PAIR ; # pair $keys $hash : $action : $signatures : $N: $storage
  23. PUSH uint8 0; SWAP; PAIR ; # pair (pair $keys $hash) 0 : $action : $signatures : $N : $storage
  24. DIP { SWAP }; SWAP ; # $signatures : pair (pair $keys $hash) 0 : $action : $N : $storage
  25. LAMBDA (pair (pair string signature) (pair (pair (map string key) string) uint8)) (pair (pair (map string key) string) uint8)
  26. {# S = pair (pair $name $signature) (pair (pair $keys $hash) $counter)
  27. DUP; CDR; SWAP; CAR ;
  28. # S = pair $name $signature : pair (pair $keys $hash) $counter
  29. DUP; CDR; SWAP; CAR ;
  30. # S = $name : $signature : pair (pair $keys $hash) $counter
  31. DIIP { DUP; CDR; SWAP; CAR } ;
  32. # S = $name : $signature : (pair $keys $hash) : $counter
  33. DIIP { DUP; CDR; SWAP; CAR }; SWAP ;
  34. # S = $signature : $name : $keys : $hash : $counter
  35. DIP
  36. { DIP { DUP }; GET ; # attempt to get the key for a given user
  37. IF_NONE { FAIL } { } # fail for unknown signer, otherwise key is pushed on the stack
  38. };
  39. # S = $signature : $key : $keys : $hash : $counter
  40. DIIP { SWAP ; DUP } ;
  41. # S = $signature : $key : $hash : $hash : $keys : $counter
  42. DIIIP { SWAP; PAIR; SWAP } ;
  43. # S = $signature : $key : $hash : $counter: pair $keys $hash
  44. SWAP ; DIP { PAIR } ;
  45. # S = $signature : pair $key $hash : $counter: pair $keys $hash
  46. CHECK_SIGNATURE ;
  47. # S = $sig_valid? : $counter : pair $keys $hash
  48. IF { PUSH uint8 1; CHECKED_ADD } { FAIL } ; # we don't *have* to fail on an invalid signature, but it is good hygiene
  49. # S = $counter : pair $keys $hash
  50. SWAP; PAIR ;
  51. # S = pair (pair $keys hash) $counter
  52. } ;
  53. # S = $reducer : $signatures : pair (pair $keys $hash) 0 : $action : $N : $storage
  54. REDUCE ; # this is where the counting happens
  55. # S = pair (pair $keys $hash) $counter : $action : $N : $storage
  56. CDR ; DIP { SWAP ; DROP ; SWAP } ;
  57. # S = $counter : $N : $action : $storage
  58. IFCMPGE
  59. { # if we have enough signatures
  60. DUP; DUP; CDDR; SWAP; CDAR; UNIT; DIP { SWAP }; DIIIIP { SWAP; CDR };
  61. # unit : $amount : $contract : $storage : $action
  62. TRANSFER_TOKENS; DROP; DIP { CAR } ; CAR;
  63. # $keys : $newcount
  64. PAIR; UNIT; PAIR
  65. }
  66. {
  67. FAIL
  68. } # not enough signatures, fail
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement