diff --git a/docs/introduction/calculator-your-first-seahorse-program.md b/docs/introduction/calculator-your-first-seahorse-program.md index 0fd7103..e32b3f9 100644 --- a/docs/introduction/calculator-your-first-seahorse-program.md +++ b/docs/introduction/calculator-your-first-seahorse-program.md @@ -149,10 +149,10 @@ The operation will be an enum (enumerated type), which is a type that can simply ``` class Operation(Enum): - ADD = 0 - SUB = 1 - MUL = 2 - DIV = 3 + Add = 0 + Sub = 1 + Mul = 2 + Div = 3 ``` For parsing purposes, each variant in the enum needs a unique number associated with it. These have no bearing on the generated code. @@ -168,13 +168,13 @@ def do_operation(owner: Signer, calculator: Calculator, op: Operation, num: i64) assert owner.key() == calculator.owner, 'This is not your calculator!' - if op == Operation.ADD: + if op == Operation.Add: calculator.display += num - elif op == Operation.SUB: + elif op == Operation.Sub: calculator.display -= num - elif op == Operation.MUL: + elif op == Operation.Mul: calculator.display *= num - elif op == Operation.DIV: + elif op == Operation.Div: calculator.display //= num ``` diff --git a/examples/calculator.py b/examples/calculator.py index 2a71614..2f8b9fa 100644 --- a/examples/calculator.py +++ b/examples/calculator.py @@ -12,10 +12,10 @@ class Calculator(Account): display: i64 class Operation(Enum): - ADD = 0 - SUB = 1 - MUL = 2 - DIV = 3 + Add = 0 + Sub = 1 + Mul = 2 + Div = 3 @instruction def init_calculator(owner: Signer, calculator: Empty[Calculator]): @@ -34,11 +34,11 @@ def reset_calculator(owner: Signer, calculator: Calculator): def do_operation(owner: Signer, calculator: Calculator, op: Operation, num: i64): assert owner.key() == calculator.owner, 'This is not your calculator!' - if op == Operation.ADD: + if op == Operation.Add: calculator.display += num - elif op == Operation.SUB: + elif op == Operation.Sub: calculator.display -= num - elif op == Operation.MUL: + elif op == Operation.Mul: calculator.display *= num - elif op == Operation.DIV: + elif op == Operation.Div: calculator.display //= num diff --git a/examples/hello.py b/examples/hello.py index 7a32c16..bbb1f87 100644 --- a/examples/hello.py +++ b/examples/hello.py @@ -1,5 +1,5 @@ # hello -# Built with Seahorse v0.2.3 +# Built with Seahorse v0.2.0 # # Greets users to Solana by printing a message and minting them a token! @@ -13,7 +13,8 @@ class Hello(Account): @instruction -def init(owner: Signer, hello: Empty[Hello], mint: Empty[TokenMint]): +def init_token(owner: Signer, hello: Empty[Hello], mint: Empty[TokenMint]): + bump = hello.bump() hello = hello.init( @@ -31,13 +32,27 @@ def init(owner: Signer, hello: Empty[Hello], mint: Empty[TokenMint]): hello.bump = bump +@instruction +def init_user_token_account(user: Signer, user_acc: Empty[TokenAccount], mint: TokenMint): + + user_acc.init( + payer = user, + seeds = ["hello-token", mint], + mint = mint, + authority = user + ) + + @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', bump] ) + + print(f'Hello {user_acc.authority()}, have a token!') \ No newline at end of file