Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

Commit 9e9531f

Browse files
committed
Update jsonrpc.rs
1 parent e550f74 commit 9e9531f

1 file changed

Lines changed: 47 additions & 14 deletions

File tree

apps/dynode/src/proxy/jsonrpc.rs

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ impl JsonRpcHandler {
189189
Ok(client.execute(request).await?)
190190
}
191191

192+
// TODO: Temporary dynode override for older app versions. Remove after clients send matching preflightCommitment.
193+
fn override_solana_send_transaction(call: &JsonRpcCall) -> JsonRpcCall {
194+
let mut call = call.clone();
195+
if let serde_json::Value::Array(items) = &mut call.params
196+
&& let Some(serde_json::Value::Object(config)) = items.get_mut(1)
197+
{
198+
config.insert("preflightCommitment".to_string(), "confirmed".into());
199+
}
200+
call
201+
}
202+
192203
async fn fetch_single_response(
193204
call: &JsonRpcCall,
194205
request: &ProxyRequest,
@@ -198,20 +209,7 @@ impl JsonRpcHandler {
198209
forward_headers: &HeaderMap,
199210
) -> Result<(JsonRpcResult, u16, Vec<u8>), Box<dyn std::error::Error + Send + Sync>> {
200211
let upstream_call = if request.chain == Chain::Solana && call.method == "sendTransaction" {
201-
let mut call = call.clone();
202-
// TODO: Temporary dynode override for older app versions. Remove after clients send matching preflightCommitment.
203-
if let serde_json::Value::Array(items) = &mut call.params {
204-
if items.len() == 1 {
205-
items.push(serde_json::json!({
206-
"encoding": "base64",
207-
"preflightCommitment": "confirmed"
208-
}));
209-
} else if let Some(serde_json::Value::Object(config)) = items.get_mut(1) {
210-
config.entry("encoding".to_string()).or_insert_with(|| "base64".into());
211-
config.insert("preflightCommitment".to_string(), "confirmed".into());
212-
}
213-
}
214-
call
212+
Self::override_solana_send_transaction(call)
215213
} else {
216214
call.clone()
217215
};
@@ -308,6 +306,41 @@ mod tests {
308306
};
309307
}
310308

309+
#[test]
310+
fn test_override_solana_send_transaction() {
311+
let old_client = JsonRpcCall {
312+
jsonrpc: "2.0".into(),
313+
method: "sendTransaction".into(),
314+
params: json!(["tx", { "encoding": "base64", "skipPreflight": false }]),
315+
id: 1,
316+
};
317+
let result = JsonRpcHandler::override_solana_send_transaction(&old_client);
318+
assert_eq!(result.params[0], "tx");
319+
assert_eq!(result.params[1]["encoding"], "base64");
320+
assert_eq!(result.params[1]["skipPreflight"], false);
321+
assert_eq!(result.params[1]["preflightCommitment"], "confirmed");
322+
323+
let new_client = JsonRpcCall {
324+
jsonrpc: "2.0".into(),
325+
method: "sendTransaction".into(),
326+
params: json!(["tx", { "encoding": "base64", "skipPreflight": false, "preflightCommitment": "finalized" }]),
327+
id: 1,
328+
};
329+
let result = JsonRpcHandler::override_solana_send_transaction(&new_client);
330+
assert_eq!(result.params[1]["encoding"], "base64");
331+
assert_eq!(result.params[1]["skipPreflight"], false);
332+
assert_eq!(result.params[1]["preflightCommitment"], "confirmed");
333+
334+
let no_config = JsonRpcCall {
335+
jsonrpc: "2.0".into(),
336+
method: "sendTransaction".into(),
337+
params: json!(["tx"]),
338+
id: 1,
339+
};
340+
let result = JsonRpcHandler::override_solana_send_transaction(&no_config);
341+
assert_eq!(result.params, json!(["tx"]));
342+
}
343+
311344
#[test]
312345
fn test_format_parse_error() {
313346
let err = || serde_json::from_slice::<serde_json::Value>(b"x").unwrap_err();

0 commit comments

Comments
 (0)