From 401d5261509b5b273e1d58623743caf50edb430a Mon Sep 17 00:00:00 2001 From: chalda Date: Mon, 3 Jul 2023 22:56:58 +0200 Subject: [PATCH] client: Add `DynSigner` (#2550) --- CHANGELOG.md | 1 + client/src/lib.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5abe5166a9..205f7a4cb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The minor version will be incremented upon a breaking change and the patch versi ### Features - lang: Add `get_lamports`, `add_lamports` and `sub_lamports` methods for all account types ([#2552](https://github.com/coral-xyz/anchor/pull/2552)). +- client: Add a helper struct `DynSigner` to simplify use of `Client where >` with Solana clap CLI utils that loads `Signer` as `Box` ([#2550](https://github.com/coral-xyz/anchor/pull/2550)). ### Fixes diff --git a/client/src/lib.rs b/client/src/lib.rs index c25624a11c..2b8e52fb40 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -98,6 +98,36 @@ impl> Client { } } +/// Auxiliary data structure to align the types of the Solana CLI utils with Anchor client. +/// Client implementation requires > which does not comply with Box +/// that's used when loaded Signer from keypair file. This struct is used to wrap the usage. +pub struct DynSigner(pub Arc); + +impl Signer for DynSigner { + fn pubkey(&self) -> Pubkey { + self.0.pubkey() + } + + fn try_pubkey(&self) -> Result { + self.0.try_pubkey() + } + + fn sign_message(&self, message: &[u8]) -> solana_sdk::signature::Signature { + self.0.sign_message(message) + } + + fn try_sign_message( + &self, + message: &[u8], + ) -> Result { + self.0.try_sign_message(message) + } + + fn is_interactive(&self) -> bool { + self.0.is_interactive() + } +} + // Internal configuration for a client. #[derive(Debug)] pub struct Config {