Skip to content

Instantly share code, notes, and snippets.

@bhgames
Created March 22, 2021 18:02
Show Gist options
  • Save bhgames/230017d295131135a91eef5938f31d8f to your computer and use it in GitHub Desktop.
Save bhgames/230017d295131135a91eef5938f31d8f to your computer and use it in GitHub Desktop.
Escrow Update

There is an issue in the release_escrow command of V1 of escrow:

pub fn release_escrow(program_id: &Pubkey, accounts: &[AccountInfo], amount: u64) -> ProgramResult {
    let account_info_iter = &mut accounts.iter();
    let source = next_account_info(account_info_iter)?;
    let destination = next_account_info(account_info_iter)?;
    let authority = next_account_info(account_info_iter)?;
    let token_program = next_account_info(account_info_iter)?;

    let (authority_key, bump_seed) =
        Pubkey::find_program_address(&[source.key.as_ref()], program_id);
    if authority.key != &authority_key {
        return Err(HelloWorldError::InvalidAuthority.into());
    }
    let authority_signer_seeds = &[source.key.as_ref(), &[bump_seed]];

    spl_token_transfer(TokenTransferParams {
        source: source.clone(),
        destination: destination.clone(),
        amount: 0,
        authority: authority.clone(),
        authority_signer_seeds: authority_signer_seeds,
        token_program: token_program.clone(),
    })?;
    Ok(())
}

The amount is hardcoded to zero. The fix is to actually use amount. Suggested change:

pub fn release_escrow(program_id: &Pubkey, accounts: &[AccountInfo], amount: u64) -> ProgramResult {
    let account_info_iter = &mut accounts.iter();
    let source = next_account_info(account_info_iter)?;
    let destination = next_account_info(account_info_iter)?;
    let authority = next_account_info(account_info_iter)?;
    let token_program = next_account_info(account_info_iter)?;

    let (authority_key, bump_seed) =
        Pubkey::find_program_address(&[source.key.as_ref()], program_id);
    if authority.key != &authority_key {
        return Err(HelloWorldError::InvalidAuthority.into());
    }
    let authority_signer_seeds = &[source.key.as_ref(), &[bump_seed]];

    spl_token_transfer(TokenTransferParams {
        source: source.clone(),
        destination: destination.clone(),
        amount: amount,
        authority: authority.clone(),
        authority_signer_seeds: authority_signer_seeds,
        token_program: token_program.clone(),
    })?;
    Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment