Add support for multiple params

This commit is contained in:
Michael Vines 2019-12-18 22:26:11 -07:00
parent 01f44f531e
commit fcda972cec
6 changed files with 69 additions and 109 deletions

View File

@ -1,12 +1,10 @@
use crate::{client_error::ClientError, rpc_request::RpcRequest}; use crate::{client_error::ClientError, rpc_request::RpcRequest};
use solana_sdk::commitment_config::CommitmentConfig;
pub(crate) trait GenericRpcClientRequest { pub(crate) trait GenericRpcClientRequest {
fn send( fn send(
&self, &self,
request: &RpcRequest, request: &RpcRequest,
params: Option<serde_json::Value>, params: serde_json::Value,
retries: usize, retries: usize,
commitment_config: Option<CommitmentConfig>,
) -> Result<serde_json::Value, ClientError>; ) -> Result<serde_json::Value, ClientError>;
} }

View File

@ -5,7 +5,6 @@ use crate::{
}; };
use serde_json::{Number, Value}; use serde_json::{Number, Value};
use solana_sdk::{ use solana_sdk::{
commitment_config::CommitmentConfig,
fee_calculator::FeeCalculator, fee_calculator::FeeCalculator,
instruction::InstructionError, instruction::InstructionError,
transaction::{self, TransactionError}, transaction::{self, TransactionError},
@ -29,17 +28,16 @@ impl GenericRpcClientRequest for MockRpcClientRequest {
fn send( fn send(
&self, &self,
request: &RpcRequest, request: &RpcRequest,
params: Option<serde_json::Value>, params: serde_json::Value,
_retries: usize, _retries: usize,
_commitment_config: Option<CommitmentConfig>,
) -> Result<serde_json::Value, ClientError> { ) -> Result<serde_json::Value, ClientError> {
if self.url == "fails" { if self.url == "fails" {
return Ok(Value::Null); return Ok(Value::Null);
} }
let val = match request { let val = match request {
RpcRequest::ConfirmTransaction => { RpcRequest::ConfirmTransaction => {
if let Some(Value::Array(param_array)) = params { if let Some(params_array) = params.as_array() {
if let Value::String(param_string) = &param_array[0] { if let Value::String(param_string) = &params_array[0] {
Value::Bool(param_string == SIGNATURE) Value::Bool(param_string == SIGNATURE)
} else { } else {
Value::Null Value::Null

View File

@ -70,14 +70,12 @@ impl RpcClient {
signature: &str, signature: &str,
commitment_config: CommitmentConfig, commitment_config: CommitmentConfig,
) -> RpcResponse<bool> { ) -> RpcResponse<bool> {
let params = json!(signature);
let response = self let response = self
.client .client
.send( .send(
&RpcRequest::ConfirmTransaction, &RpcRequest::ConfirmTransaction,
Some(params), json!([signature, commitment_config]),
0, 0,
Some(commitment_config),
) )
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
@ -96,10 +94,9 @@ impl RpcClient {
pub fn send_transaction(&self, transaction: &Transaction) -> Result<String, ClientError> { pub fn send_transaction(&self, transaction: &Transaction) -> Result<String, ClientError> {
let serialized = serialize(transaction).unwrap(); let serialized = serialize(transaction).unwrap();
let params = json!(serialized);
let signature = self let signature = self
.client .client
.send(&RpcRequest::SendTransaction, Some(params), 5, None)?; .send(&RpcRequest::SendTransaction, json!([serialized]), 5)?;
if signature.as_str().is_none() { if signature.as_str().is_none() {
Err(io::Error::new( Err(io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
@ -123,12 +120,10 @@ impl RpcClient {
signature: &str, signature: &str,
commitment_config: CommitmentConfig, commitment_config: CommitmentConfig,
) -> Result<Option<transaction::Result<()>>, ClientError> { ) -> Result<Option<transaction::Result<()>>, ClientError> {
let params = json!(signature.to_string());
let signature_status = self.client.send( let signature_status = self.client.send(
&RpcRequest::GetSignatureStatus, &RpcRequest::GetSignatureStatus,
Some(params), json!([signature.to_string(), commitment_config]),
5, 5,
commitment_config.ok(),
)?; )?;
let result: Option<transaction::Result<()>> = let result: Option<transaction::Result<()>> =
serde_json::from_value(signature_status).unwrap(); serde_json::from_value(signature_status).unwrap();
@ -145,7 +140,7 @@ impl RpcClient {
) -> io::Result<Slot> { ) -> io::Result<Slot> {
let response = self let response = self
.client .client
.send(&RpcRequest::GetSlot, None, 0, commitment_config.ok()) .send(&RpcRequest::GetSlot, json!([commitment_config]), 0)
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
@ -164,7 +159,7 @@ impl RpcClient {
pub fn get_vote_accounts(&self) -> io::Result<RpcVoteAccountStatus> { pub fn get_vote_accounts(&self) -> io::Result<RpcVoteAccountStatus> {
let response = self let response = self
.client .client
.send(&RpcRequest::GetVoteAccounts, None, 0, None) .send(&RpcRequest::GetVoteAccounts, Value::Null, 0)
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
@ -183,7 +178,7 @@ impl RpcClient {
pub fn get_cluster_nodes(&self) -> io::Result<Vec<RpcContactInfo>> { pub fn get_cluster_nodes(&self) -> io::Result<Vec<RpcContactInfo>> {
let response = self let response = self
.client .client
.send(&RpcRequest::GetClusterNodes, None, 0, None) .send(&RpcRequest::GetClusterNodes, Value::Null, 0)
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
@ -200,10 +195,9 @@ impl RpcClient {
} }
pub fn get_block_time(&self, slot: Slot) -> io::Result<UnixTimestamp> { pub fn get_block_time(&self, slot: Slot) -> io::Result<UnixTimestamp> {
let params = json!(slot);
let response = self let response = self
.client .client
.send(&RpcRequest::GetBlockTime, Some(params), 0, None); .send(&RpcRequest::GetBlockTime, json!([slot]), 0);
response response
.map(|result_json| { .map(|result_json| {
@ -235,7 +229,7 @@ impl RpcClient {
) -> io::Result<RpcEpochInfo> { ) -> io::Result<RpcEpochInfo> {
let response = self let response = self
.client .client
.send(&RpcRequest::GetEpochInfo, None, 0, commitment_config.ok()) .send(&RpcRequest::GetEpochInfo, json!([commitment_config]), 0)
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
@ -260,14 +254,12 @@ impl RpcClient {
slot: Option<Slot>, slot: Option<Slot>,
commitment_config: CommitmentConfig, commitment_config: CommitmentConfig,
) -> io::Result<Option<RpcLeaderSchedule>> { ) -> io::Result<Option<RpcLeaderSchedule>> {
let params = slot.map(|slot| json!(slot));
let response = self let response = self
.client .client
.send( .send(
&RpcRequest::GetLeaderSchedule, &RpcRequest::GetLeaderSchedule,
params, json!([slot, commitment_config]),
0, 0,
commitment_config.ok(),
) )
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
@ -287,7 +279,7 @@ impl RpcClient {
pub fn get_epoch_schedule(&self) -> io::Result<EpochSchedule> { pub fn get_epoch_schedule(&self) -> io::Result<EpochSchedule> {
let response = self let response = self
.client .client
.send(&RpcRequest::GetEpochSchedule, None, 0, None) .send(&RpcRequest::GetEpochSchedule, Value::Null, 0)
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
@ -306,7 +298,7 @@ impl RpcClient {
pub fn get_inflation(&self) -> io::Result<Inflation> { pub fn get_inflation(&self) -> io::Result<Inflation> {
let response = self let response = self
.client .client
.send(&RpcRequest::GetInflation, None, 0, None) .send(&RpcRequest::GetInflation, Value::Null, 0)
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
@ -325,7 +317,7 @@ impl RpcClient {
pub fn get_version(&self) -> io::Result<RpcVersionInfo> { pub fn get_version(&self) -> io::Result<RpcVersionInfo> {
let response = self let response = self
.client .client
.send(&RpcRequest::GetVersion, None, 0, None) .send(&RpcRequest::GetVersion, Value::Null, 0)
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
@ -478,10 +470,13 @@ impl RpcClient {
pubkey: &Pubkey, pubkey: &Pubkey,
retries: usize, retries: usize,
) -> Result<Option<u64>, Box<dyn error::Error>> { ) -> Result<Option<u64>, Box<dyn error::Error>> {
let params = json!(format!("{}", pubkey));
let balance_json = self let balance_json = self
.client .client
.send(&RpcRequest::GetBalance, Some(params), retries, None) .send(
&RpcRequest::GetBalance,
json!([pubkey.to_string()]),
retries,
)
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
@ -517,12 +512,10 @@ impl RpcClient {
pubkey: &Pubkey, pubkey: &Pubkey,
commitment_config: CommitmentConfig, commitment_config: CommitmentConfig,
) -> RpcResponse<Option<Account>> { ) -> RpcResponse<Option<Account>> {
let params = json!(format!("{}", pubkey));
let response = self.client.send( let response = self.client.send(
&RpcRequest::GetAccountInfo, &RpcRequest::GetAccountInfo,
Some(params), json!([pubkey.to_string(), commitment_config]),
0, 0,
Some(commitment_config),
); );
response response
@ -550,14 +543,12 @@ impl RpcClient {
} }
pub fn get_minimum_balance_for_rent_exemption(&self, data_len: usize) -> io::Result<u64> { pub fn get_minimum_balance_for_rent_exemption(&self, data_len: usize) -> io::Result<u64> {
let params = json!(data_len);
let minimum_balance_json = self let minimum_balance_json = self
.client .client
.send( .send(
&RpcRequest::GetMinimumBalanceForRentExemption, &RpcRequest::GetMinimumBalanceForRentExemption,
Some(params), json!([data_len]),
0, 0,
None,
) )
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
@ -595,14 +586,12 @@ impl RpcClient {
pubkey: &Pubkey, pubkey: &Pubkey,
commitment_config: CommitmentConfig, commitment_config: CommitmentConfig,
) -> RpcResponse<u64> { ) -> RpcResponse<u64> {
let params = json!(pubkey.to_string());
let balance_json = self let balance_json = self
.client .client
.send( .send(
&RpcRequest::GetBalance, &RpcRequest::GetBalance,
Some(params), json!([pubkey.to_string(), commitment_config]),
0, 0,
Some(commitment_config),
) )
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
@ -620,10 +609,13 @@ impl RpcClient {
} }
pub fn get_program_accounts(&self, pubkey: &Pubkey) -> io::Result<Vec<(Pubkey, Account)>> { pub fn get_program_accounts(&self, pubkey: &Pubkey) -> io::Result<Vec<(Pubkey, Account)>> {
let params = json!(format!("{}", pubkey));
let response = self let response = self
.client .client
.send(&RpcRequest::GetProgramAccounts, Some(params), 0, None) .send(
&RpcRequest::GetProgramAccounts,
json!([pubkey.to_string()]),
0,
)
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
@ -665,9 +657,8 @@ impl RpcClient {
.client .client
.send( .send(
&RpcRequest::GetTransactionCount, &RpcRequest::GetTransactionCount,
None, json!([commitment_config]),
0, 0,
commitment_config.ok(),
) )
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
@ -698,9 +689,8 @@ impl RpcClient {
.client .client
.send( .send(
&RpcRequest::GetRecentBlockhash, &RpcRequest::GetRecentBlockhash,
None, json!([commitment_config]),
0, 0,
commitment_config.ok(),
) )
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
@ -763,7 +753,7 @@ impl RpcClient {
pub fn get_genesis_hash(&self) -> io::Result<Hash> { pub fn get_genesis_hash(&self) -> io::Result<Hash> {
let response = self let response = self
.client .client
.send(&RpcRequest::GetGenesisHash, None, 0, None) .send(&RpcRequest::GetGenesisHash, Value::Null, 0)
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
@ -888,14 +878,12 @@ impl RpcClient {
/// Check a signature in the bank. /// Check a signature in the bank.
pub fn check_signature(&self, signature: &Signature) -> bool { pub fn check_signature(&self, signature: &Signature) -> bool {
trace!("check_signature: {:?}", signature); trace!("check_signature: {:?}", signature);
let params = json!(format!("{}", signature));
for _ in 0..30 { for _ in 0..30 {
let response = self.client.send( let response = self.client.send(
&RpcRequest::ConfirmTransaction, &RpcRequest::ConfirmTransaction,
Some(params.clone()), json!([signature.to_string(), CommitmentConfig::recent()]),
0, 0,
Some(CommitmentConfig::recent()),
); );
match response { match response {
@ -982,16 +970,14 @@ impl RpcClient {
pub fn get_num_blocks_since_signature_confirmation( pub fn get_num_blocks_since_signature_confirmation(
&self, &self,
sig: &Signature, signature: &Signature,
) -> io::Result<usize> { ) -> io::Result<usize> {
let params = json!(format!("{}", sig));
let response = self let response = self
.client .client
.send( .send(
&RpcRequest::GetNumBlocksSinceSignatureConfirmation, &RpcRequest::GetNumBlocksSinceSignatureConfirmation,
Some(params.clone()), json!([signature.to_string(), CommitmentConfig::recent().ok()]),
1, 1,
CommitmentConfig::recent().ok(),
) )
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
@ -1016,7 +1002,7 @@ impl RpcClient {
pub fn validator_exit(&self) -> io::Result<bool> { pub fn validator_exit(&self) -> io::Result<bool> {
let response = self let response = self
.client .client
.send(&RpcRequest::ValidatorExit, None, 0, None) .send(&RpcRequest::ValidatorExit, Value::Null, 0)
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
@ -1034,11 +1020,11 @@ impl RpcClient {
pub fn send( pub fn send(
&self, &self,
request: &RpcRequest, request: &RpcRequest,
params: Option<Value>, params: Value,
retries: usize, retries: usize,
commitment: Option<CommitmentConfig>,
) -> Result<Value, ClientError> { ) -> Result<Value, ClientError> {
self.client.send(request, params, retries, commitment) assert!(params.is_array() || params.is_null());
self.client.send(request, params, retries)
} }
} }
@ -1104,25 +1090,19 @@ mod tests {
let balance = rpc_client.send( let balance = rpc_client.send(
&RpcRequest::GetBalance, &RpcRequest::GetBalance,
Some(json!(["deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx"])), json!(["deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx"]),
0, 0,
None,
); );
assert_eq!(balance.unwrap().as_u64().unwrap(), 50); assert_eq!(balance.unwrap().as_u64().unwrap(), 50);
let blockhash = rpc_client.send(&RpcRequest::GetRecentBlockhash, None, 0, None); let blockhash = rpc_client.send(&RpcRequest::GetRecentBlockhash, Value::Null, 0);
assert_eq!( assert_eq!(
blockhash.unwrap().as_str().unwrap(), blockhash.unwrap().as_str().unwrap(),
"deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx" "deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx"
); );
// Send erroneous parameter // Send erroneous parameter
let blockhash = rpc_client.send( let blockhash = rpc_client.send(&RpcRequest::GetRecentBlockhash, json!(["parameter"]), 0);
&RpcRequest::GetRecentBlockhash,
Some(json!("parameter")),
0,
None,
);
assert_eq!(blockhash.is_err(), true); assert_eq!(blockhash.is_err(), true);
} }
@ -1158,9 +1138,8 @@ mod tests {
let balance = rpc_client.send( let balance = rpc_client.send(
&RpcRequest::GetBalance, &RpcRequest::GetBalance,
Some(json!(["deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhw"])), json!(["deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhw"]),
10, 10,
None,
); );
assert_eq!(balance.unwrap().as_u64().unwrap(), 5); assert_eq!(balance.unwrap().as_u64().unwrap(), 5);
} }

View File

@ -5,10 +5,7 @@ use crate::{
}; };
use log::*; use log::*;
use reqwest::{self, header::CONTENT_TYPE}; use reqwest::{self, header::CONTENT_TYPE};
use solana_sdk::{ use solana_sdk::clock::{DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT};
clock::{DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT},
commitment_config::CommitmentConfig,
};
use std::{thread::sleep, time::Duration}; use std::{thread::sleep, time::Duration};
pub struct RpcClientRequest { pub struct RpcClientRequest {
@ -38,14 +35,14 @@ impl GenericRpcClientRequest for RpcClientRequest {
fn send( fn send(
&self, &self,
request: &RpcRequest, request: &RpcRequest,
params: Option<serde_json::Value>, //params: Option<serde_json::Value>,
params: serde_json::Value,
mut retries: usize, mut retries: usize,
commitment_config: Option<CommitmentConfig>,
) -> Result<serde_json::Value, ClientError> { ) -> Result<serde_json::Value, ClientError> {
// Concurrent requests are not supported so reuse the same request id for all requests // Concurrent requests are not supported so reuse the same request id for all requests
let request_id = 1; let request_id = 1;
let request_json = request.build_request_json(request_id, params, commitment_config); let request_json = request.build_request_json(request_id, params);
loop { loop {
match self match self

View File

@ -2,7 +2,6 @@ use jsonrpc_core::Result as JsonResult;
use serde_json::{json, Value}; use serde_json::{json, Value};
use solana_sdk::{ use solana_sdk::{
clock::{Epoch, Slot}, clock::{Epoch, Slot},
commitment_config::CommitmentConfig,
hash::Hash, hash::Hash,
transaction::{Result, Transaction}, transaction::{Result, Transaction},
}; };
@ -149,12 +148,7 @@ pub enum RpcRequest {
} }
impl RpcRequest { impl RpcRequest {
pub(crate) fn build_request_json( pub(crate) fn build_request_json(&self, id: u64, params: Value) -> Value {
&self,
id: u64,
params: Option<Value>,
commitment_config: Option<CommitmentConfig>,
) -> Value {
let jsonrpc = "2.0"; let jsonrpc = "2.0";
let method = match self { let method = match self {
RpcRequest::ConfirmTransaction => "confirmTransaction", RpcRequest::ConfirmTransaction => "confirmTransaction",
@ -190,21 +184,12 @@ impl RpcRequest {
RpcRequest::SignVote => "signVote", RpcRequest::SignVote => "signVote",
RpcRequest::GetMinimumBalanceForRentExemption => "getMinimumBalanceForRentExemption", RpcRequest::GetMinimumBalanceForRentExemption => "getMinimumBalanceForRentExemption",
}; };
let mut request = json!({ json!({
"jsonrpc": jsonrpc, "jsonrpc": jsonrpc,
"id": id, "id": id,
"method": method, "method": method,
}); "params": params,
if let Some(param_string) = params { })
if let Some(config) = commitment_config {
request["params"] = json!([param_string, config]);
} else {
request["params"] = json!([param_string]);
}
} else if let Some(config) = commitment_config {
request["params"] = json!([config]);
}
request
} }
} }
@ -233,46 +218,46 @@ impl error::Error for RpcError {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use solana_sdk::commitment_config::CommitmentLevel; use solana_sdk::commitment_config::{CommitmentConfig, CommitmentLevel};
#[test] #[test]
fn test_build_request_json() { fn test_build_request_json() {
let test_request = RpcRequest::GetAccountInfo; let test_request = RpcRequest::GetAccountInfo;
let addr = json!("deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx"); let addr = json!("deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx");
let request = test_request.build_request_json(1, Some(addr.clone()), None); let request = test_request.build_request_json(1, json!([addr.clone()]));
assert_eq!(request["method"], "getAccountInfo"); assert_eq!(request["method"], "getAccountInfo");
assert_eq!(request["params"], json!([addr])); assert_eq!(request["params"], json!([addr]));
let test_request = RpcRequest::GetBalance; let test_request = RpcRequest::GetBalance;
let request = test_request.build_request_json(1, Some(addr), None); let request = test_request.build_request_json(1, json!([addr]));
assert_eq!(request["method"], "getBalance"); assert_eq!(request["method"], "getBalance");
let test_request = RpcRequest::GetEpochInfo; let test_request = RpcRequest::GetEpochInfo;
let request = test_request.build_request_json(1, None, None); let request = test_request.build_request_json(1, Value::Null);
assert_eq!(request["method"], "getEpochInfo"); assert_eq!(request["method"], "getEpochInfo");
let test_request = RpcRequest::GetInflation; let test_request = RpcRequest::GetInflation;
let request = test_request.build_request_json(1, None, None); let request = test_request.build_request_json(1, Value::Null);
assert_eq!(request["method"], "getInflation"); assert_eq!(request["method"], "getInflation");
let test_request = RpcRequest::GetRecentBlockhash; let test_request = RpcRequest::GetRecentBlockhash;
let request = test_request.build_request_json(1, None, None); let request = test_request.build_request_json(1, Value::Null);
assert_eq!(request["method"], "getRecentBlockhash"); assert_eq!(request["method"], "getRecentBlockhash");
let test_request = RpcRequest::GetSlot; let test_request = RpcRequest::GetSlot;
let request = test_request.build_request_json(1, None, None); let request = test_request.build_request_json(1, Value::Null);
assert_eq!(request["method"], "getSlot"); assert_eq!(request["method"], "getSlot");
let test_request = RpcRequest::GetTransactionCount; let test_request = RpcRequest::GetTransactionCount;
let request = test_request.build_request_json(1, None, None); let request = test_request.build_request_json(1, Value::Null);
assert_eq!(request["method"], "getTransactionCount"); assert_eq!(request["method"], "getTransactionCount");
let test_request = RpcRequest::RequestAirdrop; let test_request = RpcRequest::RequestAirdrop;
let request = test_request.build_request_json(1, None, None); let request = test_request.build_request_json(1, Value::Null);
assert_eq!(request["method"], "requestAirdrop"); assert_eq!(request["method"], "requestAirdrop");
let test_request = RpcRequest::SendTransaction; let test_request = RpcRequest::SendTransaction;
let request = test_request.build_request_json(1, None, None); let request = test_request.build_request_json(1, Value::Null);
assert_eq!(request["method"], "sendTransaction"); assert_eq!(request["method"], "sendTransaction");
} }
@ -285,13 +270,13 @@ mod tests {
// Test request with CommitmentConfig and no params // Test request with CommitmentConfig and no params
let test_request = RpcRequest::GetRecentBlockhash; let test_request = RpcRequest::GetRecentBlockhash;
let request = test_request.build_request_json(1, None, Some(commitment_config.clone())); let request = test_request.build_request_json(1, json!([commitment_config.clone()]));
assert_eq!(request["params"], json!([commitment_config.clone()])); assert_eq!(request["params"], json!([commitment_config.clone()]));
// Test request with CommitmentConfig and params // Test request with CommitmentConfig and params
let test_request = RpcRequest::GetBalance; let test_request = RpcRequest::GetBalance;
let request = let request =
test_request.build_request_json(1, Some(addr.clone()), Some(commitment_config.clone())); test_request.build_request_json(1, json!([addr.clone(), commitment_config.clone()]));
assert_eq!(request["params"], json!([addr, commitment_config])); assert_eq!(request["params"], json!([addr, commitment_config]));
} }
} }

View File

@ -748,9 +748,8 @@ impl Archiver {
Ok(rpc_client Ok(rpc_client
.send( .send(
&RpcRequest::GetSlotsPerSegment, &RpcRequest::GetSlotsPerSegment,
None, serde_json::json!([client_commitment]),
0, 0,
Some(client_commitment),
) )
.map_err(|err| { .map_err(|err| {
warn!("Error while making rpc request {:?}", err); warn!("Error while making rpc request {:?}", err);
@ -803,7 +802,11 @@ impl Archiver {
RpcClient::new_socket(rpc_peers[node_index].rpc) RpcClient::new_socket(rpc_peers[node_index].rpc)
}; };
let response = rpc_client let response = rpc_client
.send(&RpcRequest::GetStorageTurn, None, 0, None) .send(
&RpcRequest::GetStorageTurn,
serde_json::value::Value::Null,
0,
)
.map_err(|err| { .map_err(|err| {
warn!("Error while making rpc request {:?}", err); warn!("Error while making rpc request {:?}", err);
Error::IO(io::Error::new(ErrorKind::Other, "rpc error")) Error::IO(io::Error::new(ErrorKind::Other, "rpc error"))