sendTransaction rpc: expect transaction as base58 string (#7913)

This commit is contained in:
Tyera Eulberg
2020-01-21 22:16:07 -07:00
committed by GitHub
parent 7a132eabb4
commit 65f5885bce
4 changed files with 11 additions and 11 deletions

View File

@@ -532,7 +532,7 @@ pub trait RpcSol {
) -> Result<String>;
#[rpc(meta, name = "sendTransaction")]
fn send_transaction(&self, meta: Self::Metadata, data: Vec<u8>) -> Result<String>;
fn send_transaction(&self, meta: Self::Metadata, data: String) -> Result<String>;
#[rpc(meta, name = "getSlotLeader")]
fn get_slot_leader(
@@ -958,7 +958,8 @@ impl RpcSol for RpcSolImpl {
}
}
fn send_transaction(&self, meta: Self::Metadata, data: Vec<u8>) -> Result<String> {
fn send_transaction(&self, meta: Self::Metadata, data: String) -> Result<String> {
let data = bs58::decode(data).into_vec().unwrap();
if data.len() >= PACKET_DATA_SIZE {
info!(
"send_transaction: transaction too large: {} bytes (max: {} bytes)",
@@ -1833,8 +1834,7 @@ pub mod tests {
genesis_hash: Hash::default(),
};
let req =
r#"{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":[[0,0,0,0,0,0,0,0]]}"#;
let req = r#"{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":["37u9WtQpcm6ULa3Vmu7ySnANv"]}"#;
let res = io.handle_request_sync(req, meta.clone());
let expected =
r#"{"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid request"},"id":1}"#;

View File

@@ -42,14 +42,14 @@ fn test_rpc_send_tx() {
info!("blockhash: {:?}", blockhash);
let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash);
let serial_tx = serialize(&tx).unwrap();
let serialized_encoded_tx = bs58::encode(serialize(&tx).unwrap()).into_string();
let client = reqwest::blocking::Client::new();
let request = json!({
"jsonrpc": "2.0",
"id": 1,
"method": "sendTransaction",
"params": json!([serial_tx])
"params": json!([serialized_encoded_tx])
});
let rpc_addr = leader_data.rpc;
let rpc_string = get_rpc_request_str(rpc_addr, false);