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,20 +444,25 @@ 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(
&[&payer, &stake3_keypair], &Transaction::new(
Message::new_with_payer( &[&payer, &stake3_keypair],
&[stake_instruction::withdraw( Message::new_with_payer(
&stake3_keypair.pubkey(), &[stake_instruction::withdraw(
&stake3_keypair.pubkey(), &stake3_keypair.pubkey(),
&payer.pubkey(), &stake3_keypair.pubkey(),
one_sol, &payer.pubkey(),
None, one_sol,
)], None,
Some(&payer.pubkey()), )],
Some(&payer.pubkey()),
),
blockhash,
), ),
blockhash, RpcSendTransactionConfig {
)) skip_preflight: true,
},
)
.unwrap(); .unwrap();
rpc_client rpc_client
@ -492,19 +498,24 @@ 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(
&[&payer, &stake5_keypair], &Transaction::new(
Message::new_with_payer( &[&payer, &stake5_keypair],
&stake_instruction::split( Message::new_with_payer(
&stake4_keypair.pubkey(), &stake_instruction::split(
&payer.pubkey(), &stake4_keypair.pubkey(),
one_sol, &payer.pubkey(),
&stake5_keypair.pubkey(), one_sol,
&stake5_keypair.pubkey(),
),
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(
&system1_keypair, &system_transaction::transfer(
&payer.pubkey(), &system1_keypair,
one_sol, &payer.pubkey(),
blockhash, one_sol,
)) 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(
&system2_keypair, &system_transaction::transfer(
&payer.pubkey(), &system2_keypair,
one_sol - 1, &payer.pubkey(),
blockhash, one_sol - 1,
)) blockhash,
),
RpcSendTransactionConfig {
skip_preflight: true,
},
)
.unwrap(); .unwrap();
// Process all the transactions // Process all the transactions