Skip to content

Commit

Permalink
add RESTful api for withdraw status (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
zksemi authored May 17, 2024
1 parent 1997851 commit 187e9d8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bindings/wasm/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> Result<JsValue, JsValue> {
let hashes: Result<Vec<TxHash>, 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<StoredWithdrawalResp>
)
}
}
11 changes: 11 additions & 0 deletions provider/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TxHash>,
pub executed: bool,
pub success: bool,
pub block_number: BlockNumber,
pub block_index: i32,
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
6 changes: 6 additions & 0 deletions provider/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,10 @@ pub trait ZkLinkRpc {
tx: ZkLinkTx,
l1_signature: Option<TxLayer1Signature>,
) -> RpcResult<TxHash>;

#[method(name = "getWithdrawStatus")]
async fn get_withdraw_status(
&self,
hashes: Vec<TxHash>,
) -> RpcResult<Vec<StoredWithdrawalResp>>;
}

0 comments on commit 187e9d8

Please sign in to comment.