Skip to content

Commit

Permalink
support ETH query for RPC, add getway list query response and rpc int…
Browse files Browse the repository at this point in the history
…erface(fix #8)
  • Loading branch information
Fred0327 committed Oct 14, 2023
1 parent e046407 commit 0310f3e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
69 changes: 69 additions & 0 deletions provider/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,72 @@ pub struct ZkLinkTxHistory {
pub tx_receipt: TxReceiptResp,
pub created_at: DateTime<Utc>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct EthPropertyResp {
gateways: Vec<GetWayInfo>,
}

#[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<TokenInfo>,
}

#[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<EthPropertyResp, _> = serde_json::from_str(s);
println!("{:?}", resp);
assert!(resp.is_ok());
}
}
3 changes: 3 additions & 0 deletions provider/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ pub trait ZkLinkRpc {
max_txs: u32,
) -> RpcResult<Vec<FastWithdrawTxResp>>;

#[method(name = "getEthProperty")]
async fn query_getway_list(&self) -> RpcResult<EthPropertyResp>;

#[method(name = "pullForwardTxs")]
async fn pull_forward_txs(
&self,
Expand Down

0 comments on commit 0310f3e

Please sign in to comment.