From 2ea6dfa1deec21a9e98688ea2bfbab8dd788fa3a Mon Sep 17 00:00:00 2001 From: hanako mumei <81144685+2501babe@users.noreply.github.com> Date: Thu, 11 Aug 2022 12:40:31 -0700 Subject: [PATCH] token-cli: let clients return signature or txn --- token/client/src/client.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/token/client/src/client.rs b/token/client/src/client.rs index 195dfc2b..8a5ce84e 100644 --- a/token/client/src/client.rs +++ b/token/client/src/client.rs @@ -62,8 +62,14 @@ pub trait SendTransactionRpc: SendTransaction { #[derive(Debug, Clone, Copy, Default)] pub struct ProgramRpcClientSendTransaction; +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum RpcClientResponse { + Signature(Signature), + Transaction(Transaction), +} + impl SendTransaction for ProgramRpcClientSendTransaction { - type Output = Signature; + type Output = RpcClientResponse; } impl SendTransactionRpc for ProgramRpcClientSendTransaction { @@ -76,12 +82,12 @@ impl SendTransactionRpc for ProgramRpcClientSendTransaction { client .send_and_confirm_transaction(transaction) .await + .map(RpcClientResponse::Signature) .map_err(Into::into) }) } } -// pub type ProgramClientError = Box; pub type ProgramClientResult = Result; @@ -265,7 +271,7 @@ impl ProgramOfflineClient { #[async_trait] impl ProgramClient for ProgramOfflineClient where - ST: SendTransaction + Send + Sync, + ST: SendTransaction + Send + Sync, { async fn get_minimum_balance_for_rent_exemption( &self, @@ -279,7 +285,7 @@ where } async fn send_transaction(&self, transaction: &Transaction) -> ProgramClientResult { - Ok(*transaction.signatures.first().expect("need a signature")) + Ok(RpcClientResponse::Transaction(transaction.clone())) } async fn get_account(&self, _address: Pubkey) -> ProgramClientResult> {