gmsol_solana_utils/
program.rs1use std::ops::Deref;
2
3use solana_sdk::{pubkey::Pubkey, signer::Signer};
4
5#[cfg(client)]
6use solana_client::nonblocking::rpc_client::RpcClient;
7
8use crate::transaction_builder::{Config, TransactionBuilder};
9
10pub struct Program<C> {
12 program_id: Pubkey,
13 cfg: Config<C>,
14}
15
16impl<C> Program<C> {
17 pub fn new(program_id: Pubkey, cfg: Config<C>) -> Self {
19 Self { program_id, cfg }
20 }
21
22 #[cfg(client)]
24 pub fn rpc(&self) -> RpcClient {
25 self.cfg.rpc()
26 }
27
28 pub fn id(&self) -> &Pubkey {
30 &self.program_id
31 }
32}
33
34impl<C: Deref<Target = impl Signer> + Clone> Program<C> {
35 pub fn transaction(&self) -> TransactionBuilder<C> {
37 TransactionBuilder::new(self.program_id, &self.cfg)
38 }
39}
40
41impl<C: Deref<Target = impl Signer>> Program<C> {
42 pub fn payer(&self) -> Pubkey {
44 self.cfg.payer()
45 }
46}