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

Can't use account fields in seed array #79

Open
firefly-sol opened this issue Dec 9, 2022 · 0 comments
Open

Can't use account fields in seed array #79

firefly-sol opened this issue Dec 9, 2022 · 0 comments

Comments

@firefly-sol
Copy link

Context

I wanted to have a tokenMint signed for by a program, so it uses a protocol as the mint and freeze authority

Issue

When trying to pass in the protocol and its bump as signer, I got an error message

# random
# Built with Seahorse v0.2.5

from seahorse.prelude import *

declare_id("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS")


class Protocol(Account):
    bump: u8


@instruction
def init_protocol(signer: Signer, protocol: Empty[Protocol]):
    protocol = protocol.init(payer=signer, seeds=["protocol"])
    bump = Pubkey.find_program_address(["protocol"])[1]

    protocol.bump = bump


@instruction
def init_mint(signer: Signer, mint: Empty[TokenMint], protocol: Protocol):
    mint = mint.init(payer=signer, authority=protocol, decimals=u8(6))


@instruction
def use_bump(
    signer: Signer,
    protocol: Protocol,
    mint: TokenMint,
    destination_token_account: TokenAccount,
):

    bump = protocol.bump
    mint.mint(
        authority=protocol,
        to=destination_token_account,
        amount=u64(100000),
        signer=["protocol", protocol.bump],
    )

output

Error: anchor build -p bugreport failed:

This is most likely a bug in the Seahorse compiler!

If you want to help the project, you can report this:
  - on the Seahorse Discord (http://discord.gg/4sFzH5pus8)
  - or as a Github issue (https://github.com/ameliatastic/seahorse-lang/issues).

Thanks!

   Compiling bugreport v0.1.0 (/Users/purpleparakeet/work/bugreport/programs/bugreport)
error[E0609]: no field `bump` on type `seahorse_util::Mutable<LoadedProtocol<'info, '_>>`
  --> programs/bugreport/src/dot/program.rs:84:26
   |
84 |                 protocol.bump.to_le_bytes().as_ref(),
   |                          ^^^^ unknown field

For more information about this error, try `rustc --explain E0609`.
error: could not compile `bugreport` due to previous error

but when I assign protocol.bump to a variable and pass it in the same way, I get no such message

# random
# Built with Seahorse v0.2.5

from seahorse.prelude import *

declare_id("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS")


class Protocol(Account):
    bump: u8


@instruction
def init_protocol(signer: Signer, protocol: Empty[Protocol]):
    protocol = protocol.init(payer=signer, seeds=["protocol"])
    bump = Pubkey.find_program_address(["protocol"])[1]

    protocol.bump = bump


@instruction
def init_mint(signer: Signer, mint: Empty[TokenMint], protocol: Protocol):
    mint = mint.init(payer=signer, authority=protocol, decimals=u8(6))


@instruction
def use_bump(
    signer: Signer,
    protocol: Protocol,
    mint: TokenMint,
    destination_token_account: TokenAccount,
):

    bump = protocol.bump
    mint.mint(
        authority=protocol,
        to=destination_token_account,
        amount=u64(100000),
        signer=["protocol", bump],
    )

I think this behavior is surprising, so I'm filing it as a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant