-
Notifications
You must be signed in to change notification settings - Fork 20
Fix sophia-vote-contract #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
thepiwo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, added some comments
sophia-vote-contract.md
Outdated
| votes[candidate] = { voters = [] } }) | ||
| private function look_up_by_address(k : address, m, v) = | ||
| function lookup_by_address(k : address, m, v) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be replaced with Map.lookup_default(k : 'k, m : map('k, 'v), v : 'v) : 'v
sophia-vote-contract.md
Outdated
| We need to make use of a `size` function which we define as a helper function below. Here is the code: | ||
| ````` | ||
| private function size(l : list('a)) : int = size'(l, 0) | ||
| function size(l : list('a)) : int = size'(l, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The size function is now included with the standard library
include "List.aes"
https://github.com/aeternity/protocol/blob/master/contracts/sophia_stdlib.md#length
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. I tried a couple of syntaxes which returns unbound variable... error
Tried syntaxes
List.length(state.votes[candidate].voters)
length(state.votes[candidate].voters)
List.size(state.votes[candidate].voters)
size(state.votes[candidate].voters)
Kindly assist with this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I failed to `include "List.aes". It is working now.
sophia-vote-contract.md
Outdated
| let new_votes_state = Call.caller :: state.votes[candidate].voters | ||
| put(state{ | ||
| votes[candidate].voters = new_votes_state }) | ||
| true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guess there is no need to return true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. I have removed it. Kindly, resolve the conversation if you are satisfied with the new changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still seems to be there
|
maybe @DanielaIvanova can check as well :) |
sophia-vote-contract.md
Outdated
| votes: map(address, candidates) } | ||
| public stateful function init() : state = { | ||
| stateful entrypoint init() : state = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function does nothing stateful so the keyword can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I have implemented the requested changes. Can you resolve the conversation?
sophia-vote-contract.md
Outdated
| public stateful function vote(candidate: address) : bool = | ||
| stateful entrypoint vote(candidate: address) : bool = | ||
| is_candidate(candidate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is convoluted, you better use a default value when looking up the candidate and do away with the is_candidate function. I.e. something like this:
stateful vote(candidate: address) : unit =
let current_votes = state.votes[candidate = {voters = []}].voters
put(state{ votes[candidate] = {voters = Call.caller :: current_votes }})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a dilemma here. With this change, there will be no need for add_candidate function. Can you give me feedback on the new full contract? I will change the wordings in the tutorial when the contract is satisfactory.
cc: @thepiwo ,
sophia-vote-contract.md
Outdated
| _ :: l' => size'(l', x + 1) | ||
| public stateful function add_candidate(candidate: address) : bool = | ||
| stateful entrypoint add_candidate(candidate: address) : bool = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the point in always returning true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my first time using a language without a return statement. I think it's a reaction to the weird feeling 🙈. Thanks, I have removed them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have implemented the requested changes. Can you resolve the conversation?
sophia-vote-contract.md
Outdated
| switch(l) | ||
| [] => x | ||
| _ :: l' => size'(l', x + 1) | ||
| function size'(l : list('a), x : int) : int = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With compiler v4.2.0 this can be written more nicely as:
function
size' : (list('a), int) => int
size'([], x) = x
size'(_ :: l, x) = size'(l, x + 1)
But as @thepiwo mention it is a standard library function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have implemented the requested changes. Can you resolve the conversation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still seems to be there in the explaination
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I want the contract reviewed before I change the content of the tutorial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is any need to document size any more
sophia-vote-contract.md
Outdated
| First we have to initialize our project where we write our smart contract. In order to do this we are going to use `aeproject init`. | ||
|
|
||
| ## Smart contract | ||
| In Sophia ML we have a state which is the place to store data on-chain - and it is the only part in the smart contract that can be mutated (overwritten). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| In Sophia ML we have a state which is the place to store data on-chain - and it is the only part in the smart contract that can be mutated (overwritten). | |
| In Sophia we have a state which is the place to store data on-chain - and it is the only part in the smart contract that can be mutated (overwritten). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have implemented the requested changes. Can you resolve the conversation?
de88f12 to
630dab6
Compare
sophia-vote-contract.md
Outdated
| None => v | ||
| Some(x) => x | ||
| ````````` | ||
| Map.lookup_default(k, m, v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the whole function can be removed and replaced
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
ceb45b3 to
b2d508a
Compare
b2d508a to
a6f3c2e
Compare
a6f3c2e to
9d8af93
Compare
Description
It fixed the outdated contract in
sophia-vote-contract.md. It also replaces all references toforgaewithaeproject.Tasks completed
sophia-vote-contract.mdNotes