-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring of crate structure and execution of txns
- Loading branch information
Showing
16 changed files
with
206 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "dynsigner" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
solana-sdk = "1.14.18" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# DynSigner | ||
|
||
When using Solana labs CLI utilities | ||
(`solana-clap-utils`, https://github.com/solana-labs/solana/tree/master/clap-utils | ||
-> https://github.com/solana-labs/solana/blob/6b013f46ebd30c82f7fa9c50c5a0e9ae32df3c44/clap-utils/src/keypair.rs#L357) | ||
the loaded signer of type `Box<dyn Signer>` is not aligned to the expected `Client<C>` type of `<C: Clone + Deref<Target = impl Signer>>`. | ||
Using the dyn Signer fails with error: | ||
|
||
``` | ||
the size for values of type `dyn solana_sdk::signature::Signer` cannot be known at compilation time [E0277] doesn't have a size known at compile-time Help: the trait `Sized` is not implemented for `dyn solana_sdk::signature::Signer` Note: required by a bound in `anchor_client::Client::<C>::new_with_options` | ||
``` | ||
|
||
Adding the helper DynSigner makes possible to match those types and use the Signer loded from the Solana utils with the Anchor client. | ||
|
||
``` | ||
let fee_payer: Arc<dyn Signer> = ... | ||
let anchor_client: Client<Arc<DynSigner>> = Client::new_with_options( | ||
anchor_cluster, | ||
Arc::new(DynSigner(fee_payer.clone())), | ||
CommitmentConfig::confirmed(), | ||
); | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...de-common-rs/src/marinade/instructions.rs → libs/marinade-client-rs/src/instructions.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![cfg_attr(not(debug_assertions), deny(warnings))] | ||
|
||
pub mod builder; | ||
pub mod instructions; | ||
pub mod rpc_marinade; | ||
pub mod state; | ||
pub mod verifiers; | ||
pub mod transaction_executors; | ||
|
||
pub use solana_sdk; | ||
pub use spl_associated_token_account; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
.../marinade-common-rs/src/marinade/state.rs → libs/marinade-client-rs/src/state.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
use std::ops::Deref; | ||
use anchor_client::{RequestBuilder}; | ||
use anyhow::{anyhow}; | ||
use log::{debug, error, warn, info}; | ||
use solana_client::client_error::ClientErrorKind; | ||
use solana_client::rpc_client::RpcClient; | ||
use solana_client::rpc_config::RpcSendTransactionConfig; | ||
use solana_client::rpc_request::{RpcError, RpcResponseErrorData}; | ||
use solana_client::rpc_response::{RpcResult, RpcSimulateTransactionResult}; | ||
use solana_sdk::commitment_config::CommitmentLevel; | ||
use solana_sdk::signature::Signature; | ||
use solana_sdk::signer::Signer; | ||
|
||
pub trait TransactionExecutor { | ||
fn execute(self, commitment: CommitmentLevel) -> Result<Signature, anchor_client::ClientError>; | ||
} | ||
|
||
impl<'a, C: Deref<Target = impl Signer> + Clone> TransactionExecutor for RequestBuilder<'a, C> { | ||
fn execute(self, commitment: CommitmentLevel) -> Result<Signature, anchor_client::ClientError> { | ||
self.send_with_spinner_and_config(RpcSendTransactionConfig { | ||
skip_preflight: false, | ||
preflight_commitment: Some(commitment), | ||
..RpcSendTransactionConfig::default() | ||
}) | ||
} | ||
} | ||
|
||
pub fn log_execution(execution_result: Result<Signature, anchor_client::ClientError>) { | ||
match execution_result { | ||
Ok(signature) => debug!("Transaction {}", signature), | ||
Err(err) => { | ||
error!("Transaction error: {}", err); | ||
match &err { | ||
anchor_client::ClientError::SolanaClientError(ce) => { | ||
error!("Transaction error: {}", err); | ||
if let ClientErrorKind::RpcError(RpcError::RpcResponseError { | ||
data: | ||
RpcResponseErrorData::SendTransactionPreflightFailure( | ||
RpcSimulateTransactionResult { | ||
err: _, | ||
logs: Some(logs), | ||
accounts: _, | ||
return_data: _, | ||
units_consumed: _, | ||
}, | ||
), | ||
.. | ||
}) = ce.kind() | ||
{ | ||
for log in logs { | ||
error!("Log: {}", log); | ||
} | ||
error!("Transaction ERR {:?}", err); | ||
} | ||
} | ||
_ => { | ||
error!("Transaction ERR {:?}", err); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub trait TransactionSimulator { | ||
fn simulate(self, rpc_client: &RpcClient) -> RpcResult<RpcSimulateTransactionResult>; | ||
} | ||
|
||
impl<'a, C: Deref<Target = impl Signer> + Clone> TransactionSimulator for RequestBuilder<'a, C> { | ||
fn simulate(self, rpc_client: &RpcClient) -> RpcResult<RpcSimulateTransactionResult> { | ||
let tx = &self.transaction().map_err(|err| { | ||
RpcError::RpcRequestError(format!("Transaction error: {}", err)) | ||
})?; | ||
rpc_client.simulate_transaction(tx) | ||
} | ||
} | ||
|
||
pub fn log_simulation(simulation_result: RpcResult<RpcSimulateTransactionResult>) { | ||
match simulation_result { | ||
Ok(result) => { | ||
if let Some(logs) = &result.value.logs { | ||
for log in logs { | ||
debug!("Log: {}", log); | ||
} | ||
} | ||
if result.value.err.is_some() { | ||
error!("Transaction ERR {:?}", result); | ||
} else { | ||
info!("Transaction simulation Ok"); | ||
} | ||
} | ||
Err(err) => { | ||
error!("Transaction error: {}", err); | ||
if let ClientErrorKind::RpcError(RpcError::RpcResponseError { | ||
data: | ||
RpcResponseErrorData::SendTransactionPreflightFailure( | ||
RpcSimulateTransactionResult { | ||
err: _, | ||
logs: Some(logs), | ||
accounts: _, | ||
units_consumed: _, | ||
return_data: _, | ||
}, | ||
), | ||
.. | ||
}) = err.kind() | ||
{ | ||
for log in logs { | ||
error!("Log: {}", log); | ||
} | ||
error!("Transaction ERR {:?}", err); | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn execute<'a, I,C>(anchor_builders: I, rpc_client: &RpcClient, simulate: bool) -> anyhow::Result<()> | ||
where | ||
I: IntoIterator<Item = RequestBuilder<'a, C>>, | ||
C: Deref<Target = dynsigner::DynSigner> + Clone | ||
{ | ||
if !simulate { | ||
let commitment_level = rpc_client.commitment().commitment; | ||
anchor_builders.into_iter().for_each(|builder| log_execution(builder.execute(commitment_level))); | ||
} else { | ||
let mut builders_iterator = anchor_builders.into_iter(); | ||
log_simulation(builders_iterator.next().ok_or(anyhow!("No transactions to simulate"))?.simulate(rpc_client)); | ||
if builders_iterator.next().is_some() { | ||
warn!("Simulation mode: only the first transaction was simulated. The rest are ignored."); | ||
} | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#![cfg_attr(not(debug_assertions), deny(warnings))] | ||
|
||
pub mod config_args; | ||
pub mod processors; | ||
pub mod matchers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.