solpayments / solana-payment-processor

Solana payment processor for e-commerce applications
18 stars 9 forks source link

Use Pubkey::find_program_address instead of hash functions for account addresses #26

Closed moshthepitt closed 3 years ago

moshthepitt commented 3 years ago
    let (associated_token_address, bump_seed) = Pubkey::find_program_address(
        &[
            &base_account_info.key.to_bytes(),
            &merchant_account_info.key.to_bytes(),
            "some string".as_bytes(),
        ],
        program_id,
    );

Would be nice if this works

moshthepitt commented 3 years ago

Looks like this is how to do this:

    // Fund the subscription account with the minimum balance to be rent exempt
    invoke(
        &system_instruction::transfer(
            &signer_info.key,
            subscription_info.key,
            Rent::default().minimum_balance(account_size),
        ),
        &[
            signer_info.clone(),
            subscription_info.clone(),
            system_program_info.clone(),
        ],
    )?;
    // Allocate space for the subscription account
    invoke_signed(
        &system_instruction::allocate(subscription_info.key, account_size as u64),
        &[subscription_info.clone(), system_program_info.clone()],
        &[&signer_seeds],
    )?;
    // Assign the subscription account to the SolPayments program
    invoke_signed(
        &system_instruction::assign(subscription_info.key, &program_id),
        &[subscription_info.clone(), system_program_info.clone()],
        &[&signer_seeds],
    )?;