Browse Source

client: Add documentation for `RequestBuilder.accounts` method (#2822)

acheron 1 year ago
parent
commit
6716c13b38
1 changed files with 30 additions and 0 deletions
  1. 30 0
      client/src/lib.rs

+ 30 - 0
client/src/lib.rs

@@ -541,6 +541,36 @@ impl<'a, C: Deref<Target = impl Signer> + Clone> RequestBuilder<'a, C> {
         self
         self
     }
     }
 
 
+    /// Set the accounts to pass to the instruction.
+    ///
+    /// `accounts` argument can be:
+    ///
+    /// - Any type that implements [`ToAccountMetas`] trait
+    /// - A vector of [`AccountMeta`]s (for remaining accounts)
+    ///
+    /// Note that the given accounts are appended to the previous list of accounts instead of
+    /// overriding the existing ones (if any).
+    ///
+    /// # Example
+    ///
+    /// ```ignore
+    /// program
+    ///     .request()
+    ///     // Regular accounts
+    ///     .accounts(accounts::Initialize {
+    ///         my_account: my_account_kp.pubkey(),
+    ///         payer: program.payer(),
+    ///         system_program: system_program::ID,
+    ///     })
+    ///     // Remaining accounts
+    ///     .accounts(vec![AccountMeta {
+    ///         pubkey: remaining,
+    ///         is_signer: true,
+    ///         is_writable: true,
+    ///     }])
+    ///     .args(instruction::Initialize { field: 42 })
+    ///     .send()?;
+    /// ```
     #[must_use]
     #[must_use]
     pub fn accounts(mut self, accounts: impl ToAccountMetas) -> Self {
     pub fn accounts(mut self, accounts: impl ToAccountMetas) -> Self {
         let mut metas = accounts.to_account_metas(None);
         let mut metas = accounts.to_account_metas(None);