Skip to content

Commit

Permalink
Fix compile errors in hello.py example (#47)
Browse files Browse the repository at this point in the history
I noticed this example had some errors, related to #39

- `hello` is re-assigned to the initialised account, so that it can be used as `authority`
- `bump` is stored at the start of the instruction, before this re-assign
- Similarly `hello.bump` is stored at the start of `say_hello`, doing `hello.bump` inside `mint.mint` was erroring

With these changes it compiles correctly: https://beta.solpg.io/636d27b177ea7f12846aef21
  • Loading branch information
mcintyre94 authored Nov 10, 2022
1 parent 8232459 commit 57053a7
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions examples/hello.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
# hello
# Built with Seahorse v0.1.0
# Built with Seahorse v0.2.3
#
# Greets users to Solana by printing a message and minting them a token!

from seahorse.prelude import *

declare_id('Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS')


class Hello(Account):
bump: u8


@instruction
def init(owner: Signer, hello: Empty[Hello], mint: Empty[TokenMint]):
init_hello = hello.init(
payer = owner,
seeds = ['hello']
bump = hello.bump()

hello = hello.init(
payer=owner,
seeds=['hello']
)

mint.init(
payer = owner,
seeds = ['hello-mint'],
decimals = 0,
authority = hello
)

init_hello.bump = hello.bump()
hello.bump = bump


@instruction
def say_hello(user_acc: TokenAccount, hello: Hello, mint: TokenMint):
bump = hello.bump
print(f'Hello {user_acc.authority()}, have a token!')
mint.mint(
authority = hello,
to = user_acc,
amount = u64(1),
signer = ['hello', hello.bump]
)
signer = ['hello', bump]
)

0 comments on commit 57053a7

Please sign in to comment.