Skip to content
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

Update add-instructions.md #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/poll-app/add-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ To make instances of polls, and write/modify the data stored in these polls, we

## Initialising Poll

Instructions in Seahorse are written using functions with the `@instruction` decorator. Let's add a `create_poll` instruction to our program:
Instructions in Seahorse are written using functions with the `@instruction` decorator. Let's add a `create` instruction to our program:

```py

Expand All @@ -22,15 +22,15 @@ class Poll(Account):
@instruction
def create(poll: Empty[Poll], user: Signer):
poll = poll.init(
payer=user
payer=user, seeds = ['poll', user]
)

```

From the first look, this may seem a little weird if you've never seen a statically typed language before like TypeScript.

```py
def create_poll(poll: Empty[Poll], user: Signer)
def create(poll: Empty[Poll], user: Signer)
```

- In Python, it is not necessary to declare the type of variables, but in Seahorse its necessary to do so to determine at compile time what account type does the variable belong to.
Expand All @@ -41,7 +41,7 @@ def create_poll(poll: Empty[Poll], user: Signer)

```py
poll = poll.init(
payer=user
payer=user, seeds = ['poll', user]
)
```

Expand Down Expand Up @@ -78,7 +78,7 @@ We add the following as instruction parameters:

> For the already-trained in Anchor, the above might look strange as we are essentially adding accounts and other data as instruction parameters together. This is way simpler than Anchor where data and accounts have to be handled differently.

- Like `Empty`, `Signer` is also an in-built account type available in Seahorse. In any blockchain, users need to sign the transactions to modify state of accounts (write/modify data). In our case as well, for a user to vote for their favorite chain and hence change the state of the account, they will have to sign a transaction. `Signer` represents the type of account `user` which will sign the transaction which will contain given intruction (`create_poll`).
- Like `Empty`, `Signer` is also an in-built account type available in Seahorse. In any blockchain, users need to sign the transactions to modify state of accounts (write/modify data). In our case as well, for a user to vote for their favorite chain and hence change the state of the account, they will have to sign a transaction. `Signer` represents the type of account `user` which will sign the transaction which will contain given instruction (`create`).

- The rest of the instruction is pretty straight-forward as we are simply incrementing the dedicated chain fields in the `poll` account depending on the type of `vote_op` provided.

Expand Down Expand Up @@ -107,7 +107,7 @@ class Poll(Account):
@instruction
def create(poll: Empty[Poll], user: Signer):
poll = poll.init(
payer=user
payer=user, seeds = ['poll', user]
)

@instruction
Expand All @@ -118,6 +118,8 @@ def vote(user: Signer, poll: Poll, vote_op: str):
poll.solana += 1
elif vote_op == "pol":
poll.polygon += 1
else:
print("Candidate does not exist")

```