diff --git a/packages/tezos-contracts/vote.jsligo b/packages/tezos-contracts/vote.jsligo new file mode 100644 index 0000000..c2ccaba --- /dev/null +++ b/packages/tezos-contracts/vote.jsligo @@ -0,0 +1,43 @@ +type storage = { + yes: int, + no: int +}; + +type parameter = +| ["Vote", int] +| ["Access"] + +type return_ = [list , storage]; + +/* Two entrypoints */ +const voteProposal = ([store, vote] : [storage, int]) : storage => { + + let temp_store = store; + + if (vote == 1) { + temp_store.yes = store.yes + 1; + } + else if (vote == 2) { + temp_store.no = store.no + 1; + } + + const result = temp_store; + return result; +} + +const accessProposal = (store: storage) : storage => { + let result = store; + return result; +} + +/* Main access point that dispatches to the entrypoints according to + the smart contract parameter. */ +const main = ([action, store] : [parameter, storage]) : return_ => { + return [ + (list([]) as list ), // No operations + (match (action, { + Vote: (n: int) => voteProposal([store, n]), + Access: () => accessProposal(store), + })) + ] +}; diff --git a/packages/tezos-contracts/vote.tz b/packages/tezos-contracts/vote.tz new file mode 100644 index 0000000..3dd5e86 --- /dev/null +++ b/packages/tezos-contracts/vote.tz @@ -0,0 +1,19 @@ +{ parameter (or (unit %access) (int %vote)) ; + storage (pair (int %no) (int %yes)) ; + code { UNPAIR ; + IF_LEFT + { DROP } + { DUP 2 ; + PUSH int 1 ; + DUP 3 ; + COMPARE ; + EQ ; + IF { SWAP ; DROP ; PUSH int 1 ; DIG 2 ; CDR ; ADD ; UPDATE 2 } + { PUSH int 2 ; + DIG 2 ; + COMPARE ; + EQ ; + IF { PUSH int 1 ; DIG 2 ; CAR ; ADD ; UPDATE 1 } { SWAP ; DROP } } } ; + NIL operation ; + PAIR } } +