From 0310f3ee07e390a865c2c52373918c1f9b9f909a Mon Sep 17 00:00:00 2001 From: Fred Date: Fri, 13 Oct 2023 10:50:52 +0800 Subject: [PATCH] support ETH query for RPC, add getway list query response and rpc interface(fix #8) --- provider/src/response.rs | 69 ++++++++++++++++++++++++++++++++++++++++ provider/src/rpc.rs | 3 ++ 2 files changed, 72 insertions(+) diff --git a/provider/src/response.rs b/provider/src/response.rs index a339ca32..90e4726d 100644 --- a/provider/src/response.rs +++ b/provider/src/response.rs @@ -281,3 +281,72 @@ pub struct ZkLinkTxHistory { pub tx_receipt: TxReceiptResp, pub created_at: DateTime, } + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] +pub struct EthPropertyResp { + gateways: Vec, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] +pub struct GetWayInfo { + chain_id: ChainId, + l1_gateway_contract: ZkLinkAddress, + l2_gateway_contract: ZkLinkAddress, + tokens: Vec, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] +pub struct TokenInfo { + token_id: TokenId, + token_address: ZkLinkAddress, +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_rpc_response() { + let s = r#" { + "gateways": [ + { + "chainId": 5, + "l1GatewayContract": "0xffffffffffffffffffffffffffffffffffffffff", + "l2GatewayContract": "0xffffffffffffffffffffffffffffffffffffffff", + "tokens": [ + { + "tokenId": 1, + "tokenAddress":"0xffffffffffffffffffffffffffffffffffffffff" + }, + { + "tokenId": 3, + "tokenAddress":"0xffffffffffffffffffffffffffffffffffffffff" + } + ] + }, + { + "chainId": 7, + "l1GatewayContract": "0xffffffffffffffffffffffffffffffffffffffff", + "l2GatewayContract": "0xffffffffffffffffffffffffffffffffffffffff", + "tokens": [ + { + "tokenId": 1, + "tokenAddress":"0xffffffffffffffffffffffffffffffffffffffff" + }, + { + "tokenId": 3, + "tokenAddress":"0xffffffffffffffffffffffffffffffffffffffff" + } + ] + } + ] +} + "#; + let resp: Result = serde_json::from_str(s); + println!("{:?}", resp); + assert!(resp.is_ok()); + } +} diff --git a/provider/src/rpc.rs b/provider/src/rpc.rs index 6e723114..4e020cc8 100644 --- a/provider/src/rpc.rs +++ b/provider/src/rpc.rs @@ -94,6 +94,9 @@ pub trait ZkLinkRpc { max_txs: u32, ) -> RpcResult>; + #[method(name = "getEthProperty")] + async fn query_getway_list(&self) -> RpcResult; + #[method(name = "pullForwardTxs")] async fn pull_forward_txs( &self,