diff --git a/crates/rpc-server/src/registry.rs b/crates/rpc-server/src/registry.rs index 9c0e36d2f..71950507a 100644 --- a/crates/rpc-server/src/registry.rs +++ b/crates/rpc-server/src/registry.rs @@ -263,6 +263,13 @@ async fn ping() -> Result { Ok("pong".to_string()) } +#[derive(serde::Serialize, serde::Deserialize)] +#[serde(untagged)] +enum GetTxParams { + Default((JsonH256,)), + WithVerbose((JsonH256, u8)), +} + enum GetTxVerbose { TxWithStatus = 0, OnlyStatus = 1, @@ -283,18 +290,20 @@ impl TryFrom for GetTxVerbose { } async fn get_transaction( - Params((tx_hash, verbose)): Params<(JsonH256, Option)>, + Params(param): Params, store: Data, mem_pool: Data, ) -> Result, RpcError> { - let tx_hash = to_h256(tx_hash); - let db = store.begin_transaction(); - let verbose: GetTxVerbose = match verbose { - None => GetTxVerbose::TxWithStatus, - Some(v) => v - .try_into() - .map_err(|_err| invalid_param_err("invalid verbose param"))?, + let (tx_hash, verbose) = match param { + GetTxParams::Default((tx_hash,)) => (to_h256(tx_hash), GetTxVerbose::TxWithStatus), + GetTxParams::WithVerbose((tx_hash, verbose)) => { + let verbose = verbose + .try_into() + .map_err(|_err| invalid_param_err("invalid verbose param"))?; + (to_h256(tx_hash), verbose) + } }; + let db = store.begin_transaction(); let tx_opt; let status; match db.get_transaction_info(&tx_hash)? {