automerge
This commit is contained in:
@ -697,11 +697,15 @@ fn get_tpu_addr(cluster_info: &ClusterInfo) -> Result<SocketAddr> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn verify_pubkey(input: String) -> Result<Pubkey> {
|
fn verify_pubkey(input: String) -> Result<Pubkey> {
|
||||||
input.parse().map_err(|_e| Error::invalid_request())
|
input
|
||||||
|
.parse()
|
||||||
|
.map_err(|e| Error::invalid_params(format!("{:?}", e)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_signature(input: &str) -> Result<Signature> {
|
fn verify_signature(input: &str) -> Result<Signature> {
|
||||||
input.parse().map_err(|_e| Error::invalid_request())
|
input
|
||||||
|
.parse()
|
||||||
|
.map_err(|e| Error::invalid_params(format!("{:?}", e)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -1617,21 +1621,24 @@ impl RpcSol for RpcSolImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_bs58_transaction(bs58_transaction: String) -> Result<(Vec<u8>, Transaction)> {
|
fn deserialize_bs58_transaction(bs58_transaction: String) -> Result<(Vec<u8>, Transaction)> {
|
||||||
let wire_transaction = bs58::decode(bs58_transaction).into_vec().unwrap();
|
let wire_transaction = bs58::decode(bs58_transaction)
|
||||||
|
.into_vec()
|
||||||
|
.map_err(|e| Error::invalid_params(format!("{:?}", e)))?;
|
||||||
if wire_transaction.len() >= PACKET_DATA_SIZE {
|
if wire_transaction.len() >= PACKET_DATA_SIZE {
|
||||||
info!(
|
let err = format!(
|
||||||
"transaction too large: {} bytes (max: {} bytes)",
|
"transaction too large: {} bytes (max: {} bytes)",
|
||||||
wire_transaction.len(),
|
wire_transaction.len(),
|
||||||
PACKET_DATA_SIZE
|
PACKET_DATA_SIZE
|
||||||
);
|
);
|
||||||
return Err(Error::invalid_request());
|
info!("{}", err);
|
||||||
|
return Err(Error::invalid_params(&err));
|
||||||
}
|
}
|
||||||
bincode::config()
|
bincode::config()
|
||||||
.limit(PACKET_DATA_SIZE as u64)
|
.limit(PACKET_DATA_SIZE as u64)
|
||||||
.deserialize(&wire_transaction)
|
.deserialize(&wire_transaction)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
info!("transaction deserialize error: {:?}", err);
|
info!("transaction deserialize error: {:?}", err);
|
||||||
Error::invalid_request()
|
Error::invalid_params(&err.to_string())
|
||||||
})
|
})
|
||||||
.map(|transaction| (wire_transaction, transaction))
|
.map(|transaction| (wire_transaction, transaction))
|
||||||
}
|
}
|
||||||
@ -1645,7 +1652,7 @@ pub mod tests {
|
|||||||
replay_stage::tests::create_test_transactions_and_populate_blockstore,
|
replay_stage::tests::create_test_transactions_and_populate_blockstore,
|
||||||
};
|
};
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
use jsonrpc_core::{MetaIoHandler, Output, Response, Value};
|
use jsonrpc_core::{ErrorCode, MetaIoHandler, Output, Response, Value};
|
||||||
use solana_ledger::{
|
use solana_ledger::{
|
||||||
blockstore::entries_to_test_shreds,
|
blockstore::entries_to_test_shreds,
|
||||||
blockstore_processor::fill_blockstore_slot_with_ticks,
|
blockstore_processor::fill_blockstore_slot_with_ticks,
|
||||||
@ -2736,14 +2743,10 @@ pub mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":["37u9WtQpcm6ULa3Vmu7ySnANv"]}"#;
|
let req = r#"{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":["37u9WtQpcm6ULa3Vmu7ySnANv"]}"#;
|
||||||
let res = io.handle_request_sync(req, meta.clone());
|
let res = io.handle_request_sync(req, meta);
|
||||||
let expected =
|
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
|
||||||
r#"{"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid request"},"id":1}"#;
|
let error = &json["error"];
|
||||||
let expected: Response =
|
assert_eq!(error["code"], ErrorCode::InvalidParams.code());
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -2764,7 +2767,7 @@ pub mod tests {
|
|||||||
let bad_pubkey = "a1b2c3d4";
|
let bad_pubkey = "a1b2c3d4";
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
verify_pubkey(bad_pubkey.to_string()),
|
verify_pubkey(bad_pubkey.to_string()),
|
||||||
Err(Error::invalid_request())
|
Err(Error::invalid_params("WrongSize"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2778,7 +2781,7 @@ pub mod tests {
|
|||||||
let bad_signature = "a1b2c3d4";
|
let bad_signature = "a1b2c3d4";
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
verify_signature(&bad_signature.to_string()),
|
verify_signature(&bad_signature.to_string()),
|
||||||
Err(Error::invalid_request())
|
Err(Error::invalid_params("WrongSize"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ fn test_rpc_invalid_requests() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap();
|
let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap();
|
||||||
let the_error = json["error"]["message"].as_str().unwrap();
|
let the_error = json["error"]["message"].as_str().unwrap();
|
||||||
assert_eq!(the_error, "Invalid request");
|
assert_eq!(the_error, "Invalid");
|
||||||
|
|
||||||
// test invalid get_account_info request
|
// test invalid get_account_info request
|
||||||
let client = reqwest::blocking::Client::new();
|
let client = reqwest::blocking::Client::new();
|
||||||
@ -167,7 +167,7 @@ fn test_rpc_invalid_requests() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap();
|
let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap();
|
||||||
let the_error = json["error"]["message"].as_str().unwrap();
|
let the_error = json["error"]["message"].as_str().unwrap();
|
||||||
assert_eq!(the_error, "Invalid request");
|
assert_eq!(the_error, "Invalid");
|
||||||
|
|
||||||
// test invalid get_account_info request
|
// test invalid get_account_info request
|
||||||
let client = reqwest::blocking::Client::new();
|
let client = reqwest::blocking::Client::new();
|
||||||
|
Reference in New Issue
Block a user