From 187e9d87888b65bb05194acd0533c0f899792563 Mon Sep 17 00:00:00 2001 From: zksemi <145792744+zksemi@users.noreply.github.com> Date: Fri, 17 May 2024 17:22:35 +0800 Subject: [PATCH] add RESTful api for withdraw status (#284) --- bindings/wasm/src/rpc_client.rs | 16 ++++++++++++++++ provider/src/response.rs | 11 +++++++++++ provider/src/rpc.rs | 6 ++++++ 3 files changed, 33 insertions(+) diff --git a/bindings/wasm/src/rpc_client.rs b/bindings/wasm/src/rpc_client.rs index ab069c35..2e08a5e5 100644 --- a/bindings/wasm/src/rpc_client.rs +++ b/bindings/wasm/src/rpc_client.rs @@ -322,4 +322,20 @@ impl RpcClient { let _ = builder.insert(client_offset); rpc_request!("getWebSocketEvents", builder, &self.server_url, bool) } + + #[wasm_bindgen(js_name=getWithdrawStatus)] + pub async fn get_withdraw_status(&self, hashes: Vec) -> Result { + let hashes: Result, RpcError> = hashes + .iter() + .map(|hash| TxHash::from_hex(&hash).map_err(|_e| RpcError::InvalidInputParameter)) + .collect(); + let mut builder = ArrayParams::new(); + let _ = builder.insert(hashes?); + rpc_request!( + "getWithdrawStatus", + builder, + &self.server_url, + Vec + ) + } } diff --git a/provider/src/response.rs b/provider/src/response.rs index 25d9aa55..9d1a0848 100644 --- a/provider/src/response.rs +++ b/provider/src/response.rs @@ -483,6 +483,17 @@ pub struct TokenInfo { pub fast_withdraw: bool, } +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] +pub struct StoredWithdrawalResp { + pub l2_tx_hash: TxHash, + pub l1_tx_hash: Option, + pub executed: bool, + pub success: bool, + pub block_number: BlockNumber, + pub block_index: i32, +} + #[cfg(test)] mod test { use super::*; diff --git a/provider/src/rpc.rs b/provider/src/rpc.rs index 621b1382..59dc56ca 100644 --- a/provider/src/rpc.rs +++ b/provider/src/rpc.rs @@ -125,4 +125,10 @@ pub trait ZkLinkRpc { tx: ZkLinkTx, l1_signature: Option, ) -> RpcResult; + + #[method(name = "getWithdrawStatus")] + async fn get_withdraw_status( + &self, + hashes: Vec, + ) -> RpcResult>; }