chore: cargo +nightly clippy --fix -Z unstable-options
This commit is contained in:
committed by
Michael Vines
parent
3570b00560
commit
6514096a67
@ -20,7 +20,7 @@ pub fn get_parsed_token_account(
|
||||
pubkey: &Pubkey,
|
||||
account: AccountSharedData,
|
||||
) -> UiAccount {
|
||||
let additional_data = get_token_account_mint(&account.data())
|
||||
let additional_data = get_token_account_mint(account.data())
|
||||
.and_then(|mint_pubkey| get_mint_owner_and_decimals(&bank, &mint_pubkey).ok())
|
||||
.map(|(_, decimals)| AccountAdditionalData {
|
||||
spl_token_decimals: Some(decimals),
|
||||
@ -44,7 +44,7 @@ where
|
||||
{
|
||||
let mut mint_decimals: HashMap<Pubkey, u8> = HashMap::new();
|
||||
keyed_accounts.filter_map(move |(pubkey, account)| {
|
||||
let additional_data = get_token_account_mint(&account.data()).map(|mint_pubkey| {
|
||||
let additional_data = get_token_account_mint(account.data()).map(|mint_pubkey| {
|
||||
let spl_token_decimals = mint_decimals.get(&mint_pubkey).cloned().or_else(|| {
|
||||
let (_, decimals) = get_mint_owner_and_decimals(&bank, &mint_pubkey).ok()?;
|
||||
mint_decimals.insert(mint_pubkey, decimals);
|
||||
@ -80,7 +80,7 @@ pub fn get_mint_owner_and_decimals(bank: &Arc<Bank>, mint: &Pubkey) -> Result<(P
|
||||
let mint_account = bank.get_account(mint).ok_or_else(|| {
|
||||
Error::invalid_params("Invalid param: could not find mint".to_string())
|
||||
})?;
|
||||
let decimals = get_mint_decimals(&mint_account.data())?;
|
||||
let decimals = get_mint_decimals(mint_account.data())?;
|
||||
Ok((*mint_account.owner(), decimals))
|
||||
}
|
||||
}
|
||||
|
118
rpc/src/rpc.rs
118
rpc/src/rpc.rs
@ -1574,12 +1574,12 @@ impl JsonRpcRequestProcessor {
|
||||
"Invalid param: not a v2.0 Token account".to_string(),
|
||||
));
|
||||
}
|
||||
let token_account = TokenAccount::unpack(&account.data()).map_err(|_| {
|
||||
let token_account = TokenAccount::unpack(account.data()).map_err(|_| {
|
||||
Error::invalid_params("Invalid param: not a v2.0 Token account".to_string())
|
||||
})?;
|
||||
let mint = &Pubkey::from_str(&token_account.mint.to_string())
|
||||
.expect("Token account mint should be convertible to Pubkey");
|
||||
let (_, decimals) = get_mint_owner_and_decimals(&bank, &mint)?;
|
||||
let (_, decimals) = get_mint_owner_and_decimals(&bank, mint)?;
|
||||
let balance = token_amount_to_ui_amount(token_account.amount, decimals);
|
||||
Ok(new_response(&bank, balance))
|
||||
}
|
||||
@ -1598,7 +1598,7 @@ impl JsonRpcRequestProcessor {
|
||||
"Invalid param: not a v2.0 Token mint".to_string(),
|
||||
));
|
||||
}
|
||||
let mint = Mint::unpack(&mint_account.data()).map_err(|_| {
|
||||
let mint = Mint::unpack(mint_account.data()).map_err(|_| {
|
||||
Error::invalid_params("Invalid param: mint could not be unpacked".to_string())
|
||||
})?;
|
||||
|
||||
@ -1619,10 +1619,10 @@ impl JsonRpcRequestProcessor {
|
||||
));
|
||||
}
|
||||
let mut token_balances: Vec<RpcTokenAccountBalance> = self
|
||||
.get_filtered_spl_token_accounts_by_mint(&bank, &mint, vec![])?
|
||||
.get_filtered_spl_token_accounts_by_mint(&bank, mint, vec![])?
|
||||
.into_iter()
|
||||
.map(|(address, account)| {
|
||||
let amount = TokenAccount::unpack(&account.data())
|
||||
let amount = TokenAccount::unpack(account.data())
|
||||
.map(|account| account.amount)
|
||||
.unwrap_or(0);
|
||||
let amount = token_amount_to_ui_amount(amount, decimals);
|
||||
@ -1758,7 +1758,7 @@ impl JsonRpcRequestProcessor {
|
||||
let filter_closure = |account: &AccountSharedData| {
|
||||
filters.iter().all(|filter_type| match filter_type {
|
||||
RpcFilterType::DataSize(size) => account.data().len() as u64 == *size,
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data()),
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(account.data()),
|
||||
})
|
||||
};
|
||||
if self
|
||||
@ -1830,7 +1830,7 @@ impl JsonRpcRequestProcessor {
|
||||
account.owner() == &spl_token_id_v2_0()
|
||||
&& filters.iter().all(|filter_type| match filter_type {
|
||||
RpcFilterType::DataSize(size) => account.data().len() as u64 == *size,
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data()),
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(account.data()),
|
||||
})
|
||||
})
|
||||
.map_err(|e| RpcCustomError::ScanError {
|
||||
@ -1878,7 +1878,7 @@ impl JsonRpcRequestProcessor {
|
||||
account.owner() == &spl_token_id_v2_0()
|
||||
&& filters.iter().all(|filter_type| match filter_type {
|
||||
RpcFilterType::DataSize(size) => account.data().len() as u64 == *size,
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data()),
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(account.data()),
|
||||
})
|
||||
})
|
||||
.map_err(|e| RpcCustomError::ScanError {
|
||||
@ -2065,7 +2065,7 @@ fn get_token_program_id_and_mint(
|
||||
) -> Result<(Pubkey, Option<Pubkey>)> {
|
||||
match token_account_filter {
|
||||
TokenAccountsFilter::Mint(mint) => {
|
||||
let (mint_owner, _) = get_mint_owner_and_decimals(&bank, &mint)?;
|
||||
let (mint_owner, _) = get_mint_owner_and_decimals(bank, &mint)?;
|
||||
if mint_owner != spl_token_id_v2_0() {
|
||||
return Err(Error::invalid_params(
|
||||
"Invalid param: not a v2.0 Token mint".to_string(),
|
||||
@ -2973,7 +2973,7 @@ pub mod rpc_full {
|
||||
let durable_nonce_info = solana_sdk::transaction::uses_durable_nonce(&transaction)
|
||||
.and_then(|nonce_ix| {
|
||||
solana_sdk::transaction::get_nonce_pubkey_from_instruction(
|
||||
&nonce_ix,
|
||||
nonce_ix,
|
||||
&transaction,
|
||||
)
|
||||
})
|
||||
@ -3099,7 +3099,7 @@ pub mod rpc_full {
|
||||
};
|
||||
|
||||
Ok(new_response(
|
||||
&bank,
|
||||
bank,
|
||||
RpcSimulateTransactionResult {
|
||||
err: result.err(),
|
||||
logs: Some(logs),
|
||||
@ -3820,17 +3820,17 @@ pub fn create_test_transactions_and_populate_blockstore(
|
||||
// Generate transactions for processing
|
||||
// Successful transaction
|
||||
let success_tx =
|
||||
solana_sdk::system_transaction::transfer(&mint_keypair, &keypair1.pubkey(), 2, blockhash);
|
||||
solana_sdk::system_transaction::transfer(mint_keypair, &keypair1.pubkey(), 2, blockhash);
|
||||
let success_signature = success_tx.signatures[0];
|
||||
let entry_1 = solana_ledger::entry::next_entry(&blockhash, 1, vec![success_tx]);
|
||||
// Failed transaction, InstructionError
|
||||
let ix_error_tx =
|
||||
solana_sdk::system_transaction::transfer(&keypair2, &keypair3.pubkey(), 10, blockhash);
|
||||
solana_sdk::system_transaction::transfer(keypair2, &keypair3.pubkey(), 10, blockhash);
|
||||
let ix_error_signature = ix_error_tx.signatures[0];
|
||||
let entry_2 = solana_ledger::entry::next_entry(&entry_1.hash, 1, vec![ix_error_tx]);
|
||||
// Failed transaction
|
||||
let fail_tx = solana_sdk::system_transaction::transfer(
|
||||
&mint_keypair,
|
||||
mint_keypair,
|
||||
&keypair2.pubkey(),
|
||||
2,
|
||||
Hash::default(),
|
||||
@ -4203,7 +4203,7 @@ pub mod tests {
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getClusterNodes"}"#;
|
||||
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
|
||||
@ -4225,7 +4225,7 @@ pub mod tests {
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getRecentPerformanceSamples"}"#;
|
||||
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
|
||||
@ -4255,7 +4255,7 @@ pub mod tests {
|
||||
let req =
|
||||
r#"{"jsonrpc":"2.0","id":1,"method":"getRecentPerformanceSamples","params":[10000]}"#;
|
||||
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
|
||||
@ -4284,7 +4284,7 @@ pub mod tests {
|
||||
} = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getSlotLeader"}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let expected = format!(r#"{{"jsonrpc":"2.0","result":"{}","id":1}}"#, leader_pubkey);
|
||||
let expected: Response =
|
||||
serde_json::from_str(&expected).expect("expected response deserialization");
|
||||
@ -4314,10 +4314,10 @@ pub mod tests {
|
||||
io.extend_with(rpc_minimal::MinimalImpl.to_delegate());
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getTransactionCount"}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let expected = r#"{"jsonrpc":"2.0","result":4,"id":1}"#;
|
||||
let expected: Response =
|
||||
serde_json::from_str(&expected).expect("expected response deserialization");
|
||||
serde_json::from_str(expected).expect("expected response deserialization");
|
||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
assert_eq!(expected, result);
|
||||
@ -4329,10 +4329,10 @@ pub mod tests {
|
||||
let RpcHandler { io, meta, .. } = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"minimumLedgerSlot"}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let expected = r#"{"jsonrpc":"2.0","result":0,"id":1}"#;
|
||||
let expected: Response =
|
||||
serde_json::from_str(&expected).expect("expected response deserialization");
|
||||
serde_json::from_str(expected).expect("expected response deserialization");
|
||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
assert_eq!(expected, result);
|
||||
@ -4343,7 +4343,7 @@ pub mod tests {
|
||||
let bob_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let RpcHandler { io, meta, .. } = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getSupply"}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
|
||||
let supply: RpcSupply = serde_json::from_value(json["result"]["value"].clone())
|
||||
.expect("actual response deserialization");
|
||||
@ -4370,7 +4370,7 @@ pub mod tests {
|
||||
io, meta, alice, ..
|
||||
} = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getLargestAccounts"}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
|
||||
let largest_accounts: Vec<RpcAccountBalance> =
|
||||
serde_json::from_value(json["result"]["value"].clone())
|
||||
@ -4407,14 +4407,14 @@ pub mod tests {
|
||||
|
||||
// Test Circulating/NonCirculating Filter
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getLargestAccounts","params":[{"filter":"circulating"}]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
|
||||
let largest_accounts: Vec<RpcAccountBalance> =
|
||||
serde_json::from_value(json["result"]["value"].clone())
|
||||
.expect("actual response deserialization");
|
||||
assert_eq!(largest_accounts.len(), 20);
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getLargestAccounts","params":[{"filter":"nonCirculating"}]}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
|
||||
let largest_accounts: Vec<RpcAccountBalance> =
|
||||
serde_json::from_value(json["result"]["value"].clone())
|
||||
@ -4460,7 +4460,7 @@ pub mod tests {
|
||||
let RpcHandler { io, meta, bank, .. } = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getInflationGovernor"}"#;
|
||||
let rep = io.handle_request_sync(&req, meta.clone());
|
||||
let rep = io.handle_request_sync(req, meta.clone());
|
||||
let res: Response = serde_json::from_str(&rep.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let inflation_governor: RpcInflationGovernor = if let Response::Single(res) = res {
|
||||
@ -4476,7 +4476,7 @@ pub mod tests {
|
||||
assert_eq!(inflation_governor, expected_inflation_governor);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getInflationRate"}"#; // Queries current epoch
|
||||
let rep = io.handle_request_sync(&req, meta);
|
||||
let rep = io.handle_request_sync(req, meta);
|
||||
let res: Response = serde_json::from_str(&rep.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let inflation_rate: RpcInflationRate = if let Response::Single(res) = res {
|
||||
@ -4506,7 +4506,7 @@ pub mod tests {
|
||||
let RpcHandler { io, meta, bank, .. } = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getEpochSchedule"}"#;
|
||||
let rep = io.handle_request_sync(&req, meta);
|
||||
let rep = io.handle_request_sync(req, meta);
|
||||
let res: Response = serde_json::from_str(&rep.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
|
||||
@ -4541,7 +4541,7 @@ pub mod tests {
|
||||
]
|
||||
.iter()
|
||||
{
|
||||
let rep = io.handle_request_sync(&req, meta.clone());
|
||||
let rep = io.handle_request_sync(req, meta.clone());
|
||||
let res: Response = serde_json::from_str(&rep.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
|
||||
@ -4570,7 +4570,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getLeaderSchedule", "params": [42424242]}"#;
|
||||
let rep = io.handle_request_sync(&req, meta.clone());
|
||||
let rep = io.handle_request_sync(req, meta.clone());
|
||||
let res: Response = serde_json::from_str(&rep.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
|
||||
@ -5437,7 +5437,7 @@ pub mod tests {
|
||||
} = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getRecentBlockhash"}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let expected = json!({
|
||||
"jsonrpc": "2.0",
|
||||
"result": {
|
||||
@ -5468,7 +5468,7 @@ pub mod tests {
|
||||
} = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getFees"}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let expected = json!({
|
||||
"jsonrpc": "2.0",
|
||||
"result": {
|
||||
@ -5544,7 +5544,7 @@ pub mod tests {
|
||||
let RpcHandler { io, meta, .. } = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getFeeRateGovernor"}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let expected = json!({
|
||||
"jsonrpc": "2.0",
|
||||
"result": {
|
||||
@ -5818,7 +5818,7 @@ pub mod tests {
|
||||
let RpcHandler { io, meta, .. } = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getIdentity"}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let expected = json!({
|
||||
"jsonrpc": "2.0",
|
||||
"result": {
|
||||
@ -5857,7 +5857,7 @@ pub mod tests {
|
||||
let RpcHandler { io, meta, .. } = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getVersion"}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let version = solana_version::Version::default();
|
||||
let expected = json!({
|
||||
"jsonrpc": "2.0",
|
||||
@ -5952,7 +5952,7 @@ pub mod tests {
|
||||
} = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlockCommitment","params":[0]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let RpcBlockCommitment {
|
||||
@ -5978,7 +5978,7 @@ pub mod tests {
|
||||
assert_eq!(total_stake, 10);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlockCommitment","params":[2]}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let commitment_response: RpcBlockCommitment<BlockCommitmentArray> =
|
||||
@ -6007,7 +6007,7 @@ pub mod tests {
|
||||
} = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlock","params":[0]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let confirmed_block: Option<EncodedConfirmedBlock> =
|
||||
@ -6052,7 +6052,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlock","params":[0,"binary"]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let confirmed_block: Option<EncodedConfirmedBlock> =
|
||||
@ -6097,7 +6097,7 @@ pub mod tests {
|
||||
// disable rpc-tx-history
|
||||
meta.config.enable_rpc_transaction_history = false;
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlock","params":[0]}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
assert_eq!(
|
||||
res,
|
||||
Some(
|
||||
@ -6174,7 +6174,7 @@ pub mod tests {
|
||||
.set_highest_confirmed_root(8);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlockProduction","params":[]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let block_production: RpcBlockProduction =
|
||||
@ -6250,35 +6250,35 @@ pub mod tests {
|
||||
.set_highest_confirmed_root(8);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlocks","params":[0]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let confirmed_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
|
||||
assert_eq!(confirmed_blocks, roots[1..].to_vec());
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlocks","params":[2]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let confirmed_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
|
||||
assert_eq!(confirmed_blocks, vec![3, 4, 8]);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlocks","params":[0,4]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let confirmed_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
|
||||
assert_eq!(confirmed_blocks, vec![1, 3, 4]);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlocks","params":[0,7]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let confirmed_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
|
||||
assert_eq!(confirmed_blocks, vec![1, 3, 4]);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlocks","params":[9,11]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let confirmed_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
|
||||
@ -6327,7 +6327,7 @@ pub mod tests {
|
||||
.set_highest_confirmed_root(8);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlocksWithLimit","params":[0,500001]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
assert_eq!(
|
||||
res,
|
||||
Some(
|
||||
@ -6336,35 +6336,35 @@ pub mod tests {
|
||||
);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlocksWithLimit","params":[0,0]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let confirmed_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
|
||||
assert!(confirmed_blocks.is_empty());
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlocksWithLimit","params":[2,2]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let confirmed_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
|
||||
assert_eq!(confirmed_blocks, vec![3, 4]);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlocksWithLimit","params":[2,3]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let confirmed_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
|
||||
assert_eq!(confirmed_blocks, vec![3, 4, 8]);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlocksWithLimit","params":[2,500000]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let confirmed_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
|
||||
assert_eq!(confirmed_blocks, vec![3, 4, 8]);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlocksWithLimit","params":[9,500000]}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let confirmed_blocks: Vec<Slot> = serde_json::from_value(result["result"].clone()).unwrap();
|
||||
@ -6432,7 +6432,7 @@ pub mod tests {
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let expected = r#"{"jsonrpc":"2.0","error":{"code":-32004,"message":"Block not available for slot 12345"},"id":1}"#;
|
||||
let expected: Response =
|
||||
serde_json::from_str(&expected).expect("expected response deserialization");
|
||||
serde_json::from_str(expected).expect("expected response deserialization");
|
||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
assert_eq!(expected, result);
|
||||
@ -6494,7 +6494,7 @@ pub mod tests {
|
||||
// stake but has never voted, and the vote account with no stake should not be present.
|
||||
{
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getVoteAccounts"}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let result: Value = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
|
||||
@ -7360,7 +7360,7 @@ pub mod tests {
|
||||
);
|
||||
let req =
|
||||
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
|
||||
let slot: Slot = serde_json::from_value(json["result"].clone()).unwrap();
|
||||
assert_eq!(slot, 2);
|
||||
@ -7375,7 +7375,7 @@ pub mod tests {
|
||||
);
|
||||
let req =
|
||||
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
|
||||
let slot: Slot = serde_json::from_value(json["result"].clone()).unwrap();
|
||||
assert_eq!(slot, 2);
|
||||
@ -7390,7 +7390,7 @@ pub mod tests {
|
||||
);
|
||||
let req =
|
||||
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let res = io.handle_request_sync(req, meta.clone());
|
||||
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
|
||||
let slot: Slot = serde_json::from_value(json["result"].clone()).unwrap();
|
||||
assert_eq!(slot, 2);
|
||||
@ -7406,7 +7406,7 @@ pub mod tests {
|
||||
);
|
||||
let req =
|
||||
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let res = io.handle_request_sync(req, meta);
|
||||
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
|
||||
let slot: Slot = serde_json::from_value(json["result"].clone()).unwrap();
|
||||
assert_eq!(slot, 3);
|
||||
|
@ -65,7 +65,7 @@ impl RpcHealth {
|
||||
.iter()
|
||||
.filter_map(|trusted_validator| {
|
||||
self.cluster_info
|
||||
.get_accounts_hash_for_node(&trusted_validator, |hashes| {
|
||||
.get_accounts_hash_for_node(trusted_validator, |hashes| {
|
||||
hashes
|
||||
.iter()
|
||||
.max_by(|a, b| a.0.cmp(&b.0))
|
||||
|
@ -772,19 +772,19 @@ mod tests {
|
||||
let _res = io.handle_request_sync(&req, session.clone());
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"signatureUnsubscribe","params":[0]}"#;
|
||||
let res = io.handle_request_sync(&req, session.clone());
|
||||
let res = io.handle_request_sync(req, session.clone());
|
||||
|
||||
let expected = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
let expected: Response = serde_json::from_str(&expected).unwrap();
|
||||
let expected: Response = serde_json::from_str(expected).unwrap();
|
||||
|
||||
let result: Response = serde_json::from_str(&res.unwrap()).unwrap();
|
||||
assert_eq!(expected, result);
|
||||
|
||||
// Test bad parameter
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"signatureUnsubscribe","params":[1]}"#;
|
||||
let res = io.handle_request_sync(&req, session);
|
||||
let res = io.handle_request_sync(req, session);
|
||||
let expected = r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid subscription id."},"id":1}"#;
|
||||
let expected: Response = serde_json::from_str(&expected).unwrap();
|
||||
let expected: Response = serde_json::from_str(expected).unwrap();
|
||||
|
||||
let result: Response = serde_json::from_str(&res.unwrap()).unwrap();
|
||||
assert_eq!(expected, result);
|
||||
@ -1016,19 +1016,19 @@ mod tests {
|
||||
let _res = io.handle_request_sync(&req, session.clone());
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"accountUnsubscribe","params":[0]}"#;
|
||||
let res = io.handle_request_sync(&req, session.clone());
|
||||
let res = io.handle_request_sync(req, session.clone());
|
||||
|
||||
let expected = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
let expected: Response = serde_json::from_str(&expected).unwrap();
|
||||
let expected: Response = serde_json::from_str(expected).unwrap();
|
||||
|
||||
let result: Response = serde_json::from_str(&res.unwrap()).unwrap();
|
||||
assert_eq!(expected, result);
|
||||
|
||||
// Test bad parameter
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"accountUnsubscribe","params":[1]}"#;
|
||||
let res = io.handle_request_sync(&req, session);
|
||||
let res = io.handle_request_sync(req, session);
|
||||
let expected = r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid subscription id."},"id":1}"#;
|
||||
let expected: Response = serde_json::from_str(&expected).unwrap();
|
||||
let expected: Response = serde_json::from_str(expected).unwrap();
|
||||
|
||||
let result: Response = serde_json::from_str(&res.unwrap()).unwrap();
|
||||
assert_eq!(expected, result);
|
||||
|
@ -209,7 +209,7 @@ impl RequestMiddleware for RpcRequestMiddleware {
|
||||
.file_name()
|
||||
.unwrap_or_else(|| std::ffi::OsStr::new(""))
|
||||
.to_str()
|
||||
.unwrap_or(&"")
|
||||
.unwrap_or("")
|
||||
))
|
||||
} else {
|
||||
RpcRequestMiddleware::not_found()
|
||||
|
@ -335,7 +335,7 @@ fn filter_program_results(
|
||||
let keyed_accounts = accounts.into_iter().filter(move |(_, account)| {
|
||||
filters.iter().all(|filter_type| match filter_type {
|
||||
RpcFilterType::DataSize(size) => account.data().len() as u64 == *size,
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data()),
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(account.data()),
|
||||
})
|
||||
});
|
||||
let accounts: Box<dyn Iterator<Item = RpcKeyedAccount>> = if program_id == &spl_token_id_v2_0()
|
||||
@ -614,7 +614,7 @@ impl RpcSubscriptions {
|
||||
if let Some(subscription_ids) = subscriptions.get_mut(signature) {
|
||||
subscription_ids.retain(|k, _| !notified_ids.contains(k));
|
||||
if subscription_ids.is_empty() {
|
||||
subscriptions.remove(&signature);
|
||||
subscriptions.remove(signature);
|
||||
}
|
||||
}
|
||||
notified_ids
|
||||
@ -1156,7 +1156,7 @@ impl RpcSubscriptions {
|
||||
&subscriptions.gossip_signature_subscriptions,
|
||||
bank_forks,
|
||||
&commitment_slots,
|
||||
¬ifier,
|
||||
notifier,
|
||||
"gossip",
|
||||
);
|
||||
}
|
||||
@ -1182,8 +1182,8 @@ impl RpcSubscriptions {
|
||||
pubkey,
|
||||
bank_forks,
|
||||
account_subscriptions.clone(),
|
||||
¬ifier,
|
||||
&commitment_slots,
|
||||
notifier,
|
||||
commitment_slots,
|
||||
)
|
||||
.len();
|
||||
}
|
||||
@ -1200,8 +1200,8 @@ impl RpcSubscriptions {
|
||||
address,
|
||||
bank_forks,
|
||||
logs_subscriptions.clone(),
|
||||
¬ifier,
|
||||
&commitment_slots,
|
||||
notifier,
|
||||
commitment_slots,
|
||||
)
|
||||
.len();
|
||||
}
|
||||
@ -1218,8 +1218,8 @@ impl RpcSubscriptions {
|
||||
program_id,
|
||||
bank_forks,
|
||||
program_subscriptions.clone(),
|
||||
¬ifier,
|
||||
&commitment_slots,
|
||||
notifier,
|
||||
commitment_slots,
|
||||
)
|
||||
.len();
|
||||
}
|
||||
@ -1236,8 +1236,8 @@ impl RpcSubscriptions {
|
||||
signature,
|
||||
bank_forks,
|
||||
signature_subscriptions.clone(),
|
||||
¬ifier,
|
||||
&commitment_slots,
|
||||
notifier,
|
||||
commitment_slots,
|
||||
)
|
||||
.len();
|
||||
}
|
||||
@ -1304,7 +1304,7 @@ impl RpcSubscriptions {
|
||||
ReceivedSignatureResult::ReceivedSignature,
|
||||
),
|
||||
},
|
||||
&sink,
|
||||
sink,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -269,10 +269,10 @@ impl SendTransactionService {
|
||||
address_list
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| vec![&tpu_address]);
|
||||
.unwrap_or_else(|| vec![tpu_address]);
|
||||
for address in addresses {
|
||||
Self::send_transaction(
|
||||
&send_socket,
|
||||
send_socket,
|
||||
address,
|
||||
&transaction_info.wire_transaction,
|
||||
);
|
||||
|
Reference in New Issue
Block a user