Skip to content

Commit

Permalink
fix: fix RPC get_transaction default param
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed Oct 19, 2021
1 parent c972c6b commit 1714f6d
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions crates/rpc-server/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ async fn ping() -> Result<String> {
Ok("pong".to_string())
}

#[derive(serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
enum GetTxParams {
Default((JsonH256,)),
WithVerbose((JsonH256, u8)),
}

enum GetTxVerbose {
TxWithStatus = 0,
OnlyStatus = 1,
Expand All @@ -283,18 +290,20 @@ impl TryFrom<u8> for GetTxVerbose {
}

async fn get_transaction(
Params((tx_hash, verbose)): Params<(JsonH256, Option<u8>)>,
Params(param): Params<GetTxParams>,
store: Data<Store>,
mem_pool: Data<MemPool>,
) -> Result<Option<L2TransactionWithStatus>, 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)? {
Expand Down

0 comments on commit 1714f6d

Please sign in to comment.