-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from hollow-leaf/feat/tezosContract
feat: add tezos jsligo contract
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
})) | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } } | ||
|