Skip to content

Commit

Permalink
Merge pull request #12 from hollow-leaf/feat/tezosContract
Browse files Browse the repository at this point in the history
feat: add tezos jsligo contract
  • Loading branch information
Pianochicken authored Aug 23, 2023
2 parents 38dd97d + 9b69e99 commit d778c98
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
43 changes: 43 additions & 0 deletions packages/tezos-contracts/vote.jsligo
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
type storage = {
yes: int,
no: int
};

type parameter =
| ["Vote", int]
| ["Access"]

type return_ = [list <operation>, 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 <operation>), // No operations
(match (action, {
Vote: (n: int) => voteProposal([store, n]),
Access: () => accessProposal(store),
}))
]
};
19 changes: 19 additions & 0 deletions packages/tezos-contracts/vote.tz
Original file line number Diff line number Diff line change
@@ -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 } }

0 comments on commit d778c98

Please sign in to comment.