memo: moved to helper
This commit is contained in:
parent
533ce21d92
commit
55d1fd1dc8
|
@ -1,10 +1,11 @@
|
||||||
use std::{ops::Deref, sync::Arc};
|
use std::{ops::Deref, str::FromStr, sync::Arc};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
commitment_config::CommitmentConfig,
|
commitment_config::CommitmentConfig,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
|
instruction::Instruction,
|
||||||
message::Message,
|
message::Message,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signature},
|
signature::{Keypair, Signature},
|
||||||
|
@ -13,6 +14,8 @@ use solana_sdk::{
|
||||||
transaction::Transaction,
|
transaction::Transaction,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const MEMO_PROGRAM_ID: &str = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct BenchHelper {
|
pub struct BenchHelper {
|
||||||
pub rpc_client: Arc<RpcClient>,
|
pub rpc_client: Arc<RpcClient>,
|
||||||
|
@ -90,4 +93,19 @@ impl BenchHelper {
|
||||||
|
|
||||||
Ok(txs)
|
Ok(txs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn send_and_confirm_memo(
|
||||||
|
&self,
|
||||||
|
msg: &[u8],
|
||||||
|
payer: &Keypair,
|
||||||
|
blockhash: Hash,
|
||||||
|
) -> anyhow::Result<String> {
|
||||||
|
let memo = Pubkey::from_str(MEMO_PROGRAM_ID)?;
|
||||||
|
|
||||||
|
let instruction = Instruction::new_with_bytes(memo, msg, vec![]);
|
||||||
|
let message = Message::new(&[instruction], Some(&payer.pubkey()));
|
||||||
|
let tx = Transaction::new(&[payer], message, blockhash);
|
||||||
|
|
||||||
|
Ok(self.send_and_confirm_transaction(&tx).await?.to_string())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +1,20 @@
|
||||||
use std::str::FromStr;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use bench::helpers::BenchHelper;
|
use bench::helpers::BenchHelper;
|
||||||
use lite_rpc::DEFAULT_RPC_ADDR;
|
use lite_rpc::DEFAULT_LITE_RPC_ADDR;
|
||||||
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
||||||
use solana_sdk::{
|
|
||||||
instruction::Instruction, message::Message, pubkey::Pubkey, signer::Signer,
|
|
||||||
transaction::Transaction,
|
|
||||||
};
|
|
||||||
|
|
||||||
const MEMO_PROGRAM_ID: &str = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn memo() -> anyhow::Result<()> {
|
async fn memo() {
|
||||||
let rpc_client = Arc::new(RpcClient::new(DEFAULT_RPC_ADDR.to_owned()));
|
let rpc_client = Arc::new(RpcClient::new(DEFAULT_LITE_RPC_ADDR.to_owned()));
|
||||||
let blockhash = rpc_client.get_latest_blockhash().await.unwrap();
|
let helper = BenchHelper::new(rpc_client);
|
||||||
|
let payer = helper.get_payer().await.unwrap();
|
||||||
|
let blockhash = helper.get_latest_blockhash().await.unwrap();
|
||||||
|
|
||||||
let bench_helper = BenchHelper::new(rpc_client);
|
let sig = helper
|
||||||
let payer = bench_helper.get_payer().await.unwrap();
|
.send_and_confirm_memo(b"hello", &payer, blockhash)
|
||||||
|
|
||||||
let memo = Pubkey::from_str(MEMO_PROGRAM_ID).unwrap();
|
|
||||||
|
|
||||||
let instruction = Instruction::new_with_bytes(memo, b"Hello", vec![]);
|
|
||||||
let message = Message::new(&[instruction], Some(&payer.pubkey()));
|
|
||||||
let tx = Transaction::new(&[&payer], message, blockhash);
|
|
||||||
|
|
||||||
let sig = bench_helper
|
|
||||||
.send_and_confirm_transaction(&tx)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
println!("{sig}");
|
println!("{sig}");
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue