tape_client/program/
initialize.rs1use anyhow::{anyhow, Result};
2use solana_sdk::{
3 compute_budget::ComputeBudgetInstruction,
4 signature::{Keypair, Signature, Signer},
5 transaction::Transaction,
6};
7use solana_client::nonblocking::rpc_client::RpcClient;
8
9use tape_api::prelude::*;
10use crate::utils::*;
11
12pub async fn initialize(client: &RpcClient, signer: &Keypair) -> Result<Signature> {
13 let compute_budget_ix = ComputeBudgetInstruction::set_compute_unit_limit(250_000);
14 let create_ix = build_initialize_ix(signer.pubkey());
15
16 let blockhash_bytes = get_latest_blockhash(client).await?;
17 let recent_blockhash = deserialize(&blockhash_bytes)?;
18 let tx = Transaction::new_signed_with_payer(
19 &[
20 compute_budget_ix,
21 create_ix
22 ],
23 Some(&signer.pubkey()),
24 &[signer],
25 recent_blockhash,
26 );
27
28 let signature_bytes = send_and_confirm_transaction(client, &tx)
29 .await
30 .map_err(|e| anyhow!("Failed to initialize program: {}", e))?;
31 let signature: Signature = deserialize(&signature_bytes)?;
32 Ok(signature)
33}