Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking Change]: fix(client): Update signer method to accept a slice of signers #3116

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions client/example/src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ pub fn composite<C: Deref<Target = impl Signer> + Clone>(
let program = client.program(pid)?;

// `Initialize` parameters.
let dummy_a = Keypair::new();
let dummy_b = Keypair::new();
let dummy_a = Arc::new(Keypair::new());
let dummy_b = Arc::new(Keypair::new());

// Build and send a transaction.
program
Expand All @@ -122,8 +122,7 @@ pub fn composite<C: Deref<Target = impl Signer> + Clone>(
500,
&program.id(),
))
.signer(&dummy_a)
.signer(&dummy_b)
.signers(&[dummy_a.clone(), dummy_b.clone()])
.accounts(Initialize {
dummy_a: dummy_a.pubkey(),
dummy_b: dummy_b.pubkey(),
Expand Down Expand Up @@ -175,13 +174,13 @@ pub fn basic_2<C: Deref<Target = impl Signer> + Clone>(
let program = client.program(pid)?;

// `Create` parameters.
let counter = Keypair::new();
let counter = Arc::new(Keypair::new());
let authority = program.payer();

// Build and send a transaction.
program
.request()
.signer(&counter)
.signers(&[counter.clone()])
.accounts(basic_2_accounts::Create {
counter: counter.pubkey(),
user: authority,
Expand Down Expand Up @@ -278,13 +277,13 @@ pub fn optional<C: Deref<Target = impl Signer> + Clone>(
let program = client.program(pid)?;

// `Initialize` parameters.
let data_account_keypair = Keypair::new();
let data_account_keypair = Arc::new(Keypair::new());

let data_account_key = data_account_keypair.pubkey();

let data_pda_seeds = &[DataPda::PREFIX.as_ref(), data_account_key.as_ref()];
let data_pda_key = Pubkey::find_program_address(data_pda_seeds, &pid).0;
let required_keypair = Keypair::new();
let required_keypair = Arc::new(Keypair::new());
let value: u64 = 10;

// Build and send a transaction.
Expand All @@ -300,8 +299,7 @@ pub fn optional<C: Deref<Target = impl Signer> + Clone>(
DataAccount::LEN as u64,
&program.id(),
))
.signer(&data_account_keypair)
.signer(&required_keypair)
.signers(&[data_account_keypair.clone(), required_keypair.clone()])
.accounts(OptionalInitialize {
payer: Some(program.payer()),
required: required_keypair.pubkey(),
Expand Down
10 changes: 4 additions & 6 deletions client/example/src/nonblocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub async fn test_tokio(client: Client<Arc<Keypair>>, pid: Pubkey) -> Result<()>
// Build and send a transaction.
program
.request()
.signer(counter)
.signers(&[counter])
.accounts(basic_2_accounts::Create {
counter: counter_pubkey,
user: authority,
Expand Down Expand Up @@ -132,8 +132,7 @@ pub async fn composite<C: Deref<Target = impl Signer> + Clone>(
500,
&program.id(),
))
.signer(dummy_a.clone())
.signer(dummy_b.clone())
.signers(&[dummy_a.clone(), dummy_b.clone()])
.accounts(Initialize {
dummy_a: dummy_a.pubkey(),
dummy_b: dummy_b.pubkey(),
Expand Down Expand Up @@ -190,7 +189,7 @@ pub async fn basic_2<C: Deref<Target = impl Signer> + Clone>(
// Build and send a transaction.
program
.request()
.signer(counter.clone())
.signers(&[counter.clone()])
.accounts(basic_2_accounts::Create {
counter: counter.pubkey(),
user: authority,
Expand Down Expand Up @@ -313,8 +312,7 @@ pub async fn optional<C: Deref<Target = impl Signer> + Clone>(
DataAccount::LEN as u64,
&program.id(),
))
.signer(data_account_keypair.clone())
.signer(required_keypair.clone())
.signers(&[required_keypair.clone(), data_account_keypair.clone()])
.accounts(OptionalInitialize {
payer: Some(program.payer()),
required: required_keypair.pubkey(),
Expand Down
10 changes: 7 additions & 3 deletions client/src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ impl<'a, C: Deref<Target = impl Signer> + Clone> RequestBuilder<'a, C, Box<dyn S
}
}

#[must_use]
pub fn signer<T: Signer + 'a>(mut self, signer: T) -> Self {
self.signers.push(Box::new(signer));
#[must_use = "The signers must be provided to ensure the transaction is valid and authorized."]
pub fn signers<T: Signer + 'a>(mut self, signers: &'a [T]) -> Self {
self.signers.extend(
signers
.iter()
.map(|signer| Box::new(signer) as Box<dyn Signer>),
);
self
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//! system_program: system_program::ID,
//! })
//! .args(instruction::Initialize { field: 42 })
//! .signer(&my_account_kp)
//! .signers(&[my_account_kp])
//! .send()?;
//!
//! // Fetch an account
Expand Down
10 changes: 7 additions & 3 deletions client/src/nonblocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,13 @@ impl<'a, C: Deref<Target = impl Signer> + Clone> RequestBuilder<'a, C, Arc<dyn T
}
}

#[must_use]
pub fn signer<T: ThreadSafeSigner>(mut self, signer: T) -> Self {
self.signers.push(Arc::new(signer));
#[must_use = "The signers must be provided to ensure the transaction is valid and authorized."]
pub fn signers<'b, T: ThreadSafeSigner + Clone + 'static>(mut self, signers: &'b [T]) -> Self {
self.signers.extend(
signers
.iter()
.map(|signer| Arc::new(signer.clone()) as Arc<dyn ThreadSafeSigner>),
);
self
}

Expand Down