Skip to main content
added 1 character in body
Source Link
TovarishFin
  • 438
  • 4
  • 12

I am trying to setup an account constraint as such:

#[account(
    init,
    payer = creator,
    space = WeddingStateObj::space(),
    seeds = [
        b"some-seed",
        user_partner0.key().as_ref(),
        user_partner1.key().as_ref(),
    ],
    bump,
)]

However, I realized that if you are doing this, you are going to need to know the order in which the seeds were used in order to get the correct address. I don't like this pattern and would prefer to have something like a hash of the two pubkeys and use it as a seed.

Ideally I would have a seeds function which could be called to easily do this:

#[account(
    init,
    payer = creator,
    space = StateObj::space(),
    seeds = [
        b"some-seed",
        StateObj::seeds(b"some-seed", user_partner0.key(), user_partner1.key()),
    ],
    bump,
)]

I was having some trouble with lifetimes as well since I needed to return a &[&[u8]] If someone knows how to handle the lifetime issue and how to hash these two pubkeys, I would be super grateful!

I am trying to setup an account constraint as such:

#[account(
    init,
    payer = creator,
    space = Wedding::space(),
    seeds = [
        b"some-seed",
        user_partner0.key().as_ref(),
        user_partner1.key().as_ref(),
    ],
    bump,
)]

However, I realized that if you are doing this, you are going to need to know the order in which the seeds were used in order to get the correct address. I don't like this pattern and would prefer to have something like a hash of the two pubkeys and use it as a seed.

Ideally I would have a seeds function which could be called to easily do this:

#[account(
    init,
    payer = creator,
    space = StateObj::space(),
    seeds = [
        b"some-seed",
        StateObj::seeds(b"some-seed", user_partner0.key(), user_partner1.key()),
    ],
    bump,
)]

I was having some trouble with lifetimes as well since I needed to return a &[&[u8]] If someone knows how to handle the lifetime issue and how to hash these two pubkeys, I would be super grateful!

I am trying to setup an account constraint as such:

#[account(
    init,
    payer = creator,
    space = StateObj::space(),
    seeds = [
        b"some-seed",
        user_partner0.key().as_ref(),
        user_partner1.key().as_ref(),
    ],
    bump,
)]

However, I realized that if you are doing this, you are going to need to know the order in which the seeds were used in order to get the correct address. I don't like this pattern and would prefer to have something like a hash of the two pubkeys and use it as a seed.

Ideally I would have a seeds function which could be called to easily do this:

#[account(
    init,
    payer = creator,
    space = StateObj::space(),
    seeds = [
        b"some-seed",
        StateObj::seeds(b"some-seed", user_partner0.key(), user_partner1.key()),
    ],
    bump,
)]

I was having some trouble with lifetimes as well since I needed to return a &[&[u8]] If someone knows how to handle the lifetime issue and how to hash these two pubkeys, I would be super grateful!

Source Link
TovarishFin
  • 438
  • 4
  • 12

How would one hash two different pubkeys inside an Anchor program?

I am trying to setup an account constraint as such:

#[account(
    init,
    payer = creator,
    space = Wedding::space(),
    seeds = [
        b"some-seed",
        user_partner0.key().as_ref(),
        user_partner1.key().as_ref(),
    ],
    bump,
)]

However, I realized that if you are doing this, you are going to need to know the order in which the seeds were used in order to get the correct address. I don't like this pattern and would prefer to have something like a hash of the two pubkeys and use it as a seed.

Ideally I would have a seeds function which could be called to easily do this:

#[account(
    init,
    payer = creator,
    space = StateObj::space(),
    seeds = [
        b"some-seed",
        StateObj::seeds(b"some-seed", user_partner0.key(), user_partner1.key()),
    ],
    bump,
)]

I was having some trouble with lifetimes as well since I needed to return a &[&[u8]] If someone knows how to handle the lifetime issue and how to hash these two pubkeys, I would be super grateful!