Add send_transaction_with_config
This commit is contained in:
parent
9158479dc4
commit
f1733ab125
|
@ -2,7 +2,7 @@ use crate::{
|
|||
client_error::{ClientError, ClientErrorKind, Result as ClientResult},
|
||||
http_sender::HttpSender,
|
||||
mock_sender::{MockSender, Mocks},
|
||||
rpc_config::RpcLargestAccountsConfig,
|
||||
rpc_config::{RpcLargestAccountsConfig, RpcSendTransactionConfig},
|
||||
rpc_request::{RpcError, RpcRequest},
|
||||
rpc_response::*,
|
||||
rpc_sender::RpcSender,
|
||||
|
@ -94,10 +94,20 @@ impl RpcClient {
|
|||
}
|
||||
|
||||
pub fn send_transaction(&self, transaction: &Transaction) -> ClientResult<Signature> {
|
||||
self.send_transaction_with_config(transaction, RpcSendTransactionConfig::default())
|
||||
}
|
||||
|
||||
pub fn send_transaction_with_config(
|
||||
&self,
|
||||
transaction: &Transaction,
|
||||
config: RpcSendTransactionConfig,
|
||||
) -> ClientResult<Signature> {
|
||||
let serialized_encoded = bs58::encode(serialize(transaction).unwrap()).into_string();
|
||||
|
||||
let signature_base58_str: String =
|
||||
self.send(RpcRequest::SendTransaction, json!([serialized_encoded]))?;
|
||||
let signature_base58_str: String = self.send(
|
||||
RpcRequest::SendTransaction,
|
||||
json!([serialized_encoded, config]),
|
||||
)?;
|
||||
|
||||
let signature = signature_base58_str
|
||||
.parse::<Signature>()
|
||||
|
|
|
@ -329,6 +329,7 @@ pub fn process_slots(rpc_client: &RpcClient, accounts_info: &mut AccountsInfo, b
|
|||
mod test {
|
||||
use super::*;
|
||||
use serial_test_derive::serial;
|
||||
use solana_client::rpc_config::RpcSendTransactionConfig;
|
||||
use solana_core::{rpc::JsonRpcConfig, validator::ValidatorConfig};
|
||||
use solana_local_cluster::local_cluster::{ClusterConfig, LocalCluster};
|
||||
use solana_sdk::{
|
||||
|
@ -443,20 +444,25 @@ mod test {
|
|||
|
||||
// Withdraw instruction causes non-compliance
|
||||
let stake3_withdraw_signature = rpc_client
|
||||
.send_transaction(&Transaction::new(
|
||||
&[&payer, &stake3_keypair],
|
||||
Message::new_with_payer(
|
||||
&[stake_instruction::withdraw(
|
||||
&stake3_keypair.pubkey(),
|
||||
&stake3_keypair.pubkey(),
|
||||
&payer.pubkey(),
|
||||
one_sol,
|
||||
None,
|
||||
)],
|
||||
Some(&payer.pubkey()),
|
||||
.send_transaction_with_config(
|
||||
&Transaction::new(
|
||||
&[&payer, &stake3_keypair],
|
||||
Message::new_with_payer(
|
||||
&[stake_instruction::withdraw(
|
||||
&stake3_keypair.pubkey(),
|
||||
&stake3_keypair.pubkey(),
|
||||
&payer.pubkey(),
|
||||
one_sol,
|
||||
None,
|
||||
)],
|
||||
Some(&payer.pubkey()),
|
||||
),
|
||||
blockhash,
|
||||
),
|
||||
blockhash,
|
||||
))
|
||||
RpcSendTransactionConfig {
|
||||
skip_preflight: true,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
rpc_client
|
||||
|
@ -492,19 +498,24 @@ mod test {
|
|||
// Split stake4 into stake5
|
||||
let stake5_keypair = Keypair::new();
|
||||
let stake45_split_signature = rpc_client
|
||||
.send_transaction(&Transaction::new(
|
||||
&[&payer, &stake5_keypair],
|
||||
Message::new_with_payer(
|
||||
&stake_instruction::split(
|
||||
&stake4_keypair.pubkey(),
|
||||
&payer.pubkey(),
|
||||
one_sol,
|
||||
&stake5_keypair.pubkey(),
|
||||
.send_transaction_with_config(
|
||||
&Transaction::new(
|
||||
&[&payer, &stake5_keypair],
|
||||
Message::new_with_payer(
|
||||
&stake_instruction::split(
|
||||
&stake4_keypair.pubkey(),
|
||||
&payer.pubkey(),
|
||||
one_sol,
|
||||
&stake5_keypair.pubkey(),
|
||||
),
|
||||
Some(&payer.pubkey()),
|
||||
),
|
||||
Some(&payer.pubkey()),
|
||||
blockhash,
|
||||
),
|
||||
blockhash,
|
||||
))
|
||||
RpcSendTransactionConfig {
|
||||
skip_preflight: true,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
rpc_client
|
||||
|
@ -539,12 +550,17 @@ mod test {
|
|||
|
||||
// Withdraw 1 sol from system 1 to make it non-compliant
|
||||
rpc_client
|
||||
.send_transaction(&system_transaction::transfer(
|
||||
&system1_keypair,
|
||||
&payer.pubkey(),
|
||||
one_sol,
|
||||
blockhash,
|
||||
))
|
||||
.send_transaction_with_config(
|
||||
&system_transaction::transfer(
|
||||
&system1_keypair,
|
||||
&payer.pubkey(),
|
||||
one_sol,
|
||||
blockhash,
|
||||
),
|
||||
RpcSendTransactionConfig {
|
||||
skip_preflight: true,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// System transfer 2
|
||||
|
@ -572,12 +588,17 @@ mod test {
|
|||
|
||||
// Withdraw 1 sol - 1 lamport from system 2, it's still compliant
|
||||
rpc_client
|
||||
.send_transaction(&system_transaction::transfer(
|
||||
&system2_keypair,
|
||||
&payer.pubkey(),
|
||||
one_sol - 1,
|
||||
blockhash,
|
||||
))
|
||||
.send_transaction_with_config(
|
||||
&system_transaction::transfer(
|
||||
&system2_keypair,
|
||||
&payer.pubkey(),
|
||||
one_sol - 1,
|
||||
blockhash,
|
||||
),
|
||||
RpcSendTransactionConfig {
|
||||
skip_preflight: true,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Process all the transactions
|
||||
|
|
Loading…
Reference in New Issue