Add send_transaction_with_config

This commit is contained in:
Michael Vines 2020-05-31 21:54:12 -07:00
parent 9158479dc4
commit f1733ab125
2 changed files with 70 additions and 39 deletions

View File

@ -2,7 +2,7 @@ use crate::{
client_error::{ClientError, ClientErrorKind, Result as ClientResult}, client_error::{ClientError, ClientErrorKind, Result as ClientResult},
http_sender::HttpSender, http_sender::HttpSender,
mock_sender::{MockSender, Mocks}, mock_sender::{MockSender, Mocks},
rpc_config::RpcLargestAccountsConfig, rpc_config::{RpcLargestAccountsConfig, RpcSendTransactionConfig},
rpc_request::{RpcError, RpcRequest}, rpc_request::{RpcError, RpcRequest},
rpc_response::*, rpc_response::*,
rpc_sender::RpcSender, rpc_sender::RpcSender,
@ -94,10 +94,20 @@ impl RpcClient {
} }
pub fn send_transaction(&self, transaction: &Transaction) -> ClientResult<Signature> { 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 serialized_encoded = bs58::encode(serialize(transaction).unwrap()).into_string();
let signature_base58_str: String = let signature_base58_str: String = self.send(
self.send(RpcRequest::SendTransaction, json!([serialized_encoded]))?; RpcRequest::SendTransaction,
json!([serialized_encoded, config]),
)?;
let signature = signature_base58_str let signature = signature_base58_str
.parse::<Signature>() .parse::<Signature>()

View File

@ -329,6 +329,7 @@ pub fn process_slots(rpc_client: &RpcClient, accounts_info: &mut AccountsInfo, b
mod test { mod test {
use super::*; use super::*;
use serial_test_derive::serial; use serial_test_derive::serial;
use solana_client::rpc_config::RpcSendTransactionConfig;
use solana_core::{rpc::JsonRpcConfig, validator::ValidatorConfig}; use solana_core::{rpc::JsonRpcConfig, validator::ValidatorConfig};
use solana_local_cluster::local_cluster::{ClusterConfig, LocalCluster}; use solana_local_cluster::local_cluster::{ClusterConfig, LocalCluster};
use solana_sdk::{ use solana_sdk::{
@ -443,7 +444,8 @@ mod test {
// Withdraw instruction causes non-compliance // Withdraw instruction causes non-compliance
let stake3_withdraw_signature = rpc_client let stake3_withdraw_signature = rpc_client
.send_transaction(&Transaction::new( .send_transaction_with_config(
&Transaction::new(
&[&payer, &stake3_keypair], &[&payer, &stake3_keypair],
Message::new_with_payer( Message::new_with_payer(
&[stake_instruction::withdraw( &[stake_instruction::withdraw(
@ -456,7 +458,11 @@ mod test {
Some(&payer.pubkey()), Some(&payer.pubkey()),
), ),
blockhash, blockhash,
)) ),
RpcSendTransactionConfig {
skip_preflight: true,
},
)
.unwrap(); .unwrap();
rpc_client rpc_client
@ -492,7 +498,8 @@ mod test {
// Split stake4 into stake5 // Split stake4 into stake5
let stake5_keypair = Keypair::new(); let stake5_keypair = Keypair::new();
let stake45_split_signature = rpc_client let stake45_split_signature = rpc_client
.send_transaction(&Transaction::new( .send_transaction_with_config(
&Transaction::new(
&[&payer, &stake5_keypair], &[&payer, &stake5_keypair],
Message::new_with_payer( Message::new_with_payer(
&stake_instruction::split( &stake_instruction::split(
@ -504,7 +511,11 @@ mod test {
Some(&payer.pubkey()), Some(&payer.pubkey()),
), ),
blockhash, blockhash,
)) ),
RpcSendTransactionConfig {
skip_preflight: true,
},
)
.unwrap(); .unwrap();
rpc_client rpc_client
@ -539,12 +550,17 @@ mod test {
// Withdraw 1 sol from system 1 to make it non-compliant // Withdraw 1 sol from system 1 to make it non-compliant
rpc_client rpc_client
.send_transaction(&system_transaction::transfer( .send_transaction_with_config(
&system_transaction::transfer(
&system1_keypair, &system1_keypair,
&payer.pubkey(), &payer.pubkey(),
one_sol, one_sol,
blockhash, blockhash,
)) ),
RpcSendTransactionConfig {
skip_preflight: true,
},
)
.unwrap(); .unwrap();
// System transfer 2 // System transfer 2
@ -572,12 +588,17 @@ mod test {
// Withdraw 1 sol - 1 lamport from system 2, it's still compliant // Withdraw 1 sol - 1 lamport from system 2, it's still compliant
rpc_client rpc_client
.send_transaction(&system_transaction::transfer( .send_transaction_with_config(
&system_transaction::transfer(
&system2_keypair, &system2_keypair,
&payer.pubkey(), &payer.pubkey(),
one_sol - 1, one_sol - 1,
blockhash, blockhash,
)) ),
RpcSendTransactionConfig {
skip_preflight: true,
},
)
.unwrap(); .unwrap();
// Process all the transactions // Process all the transactions