Skip to content

Commit

Permalink
support ETH property query for RPC, add getway list query response an…
Browse files Browse the repository at this point in the history
…d rpc interface(fix #8)
  • Loading branch information
Fred0327 committed Oct 16, 2023
1 parent cd98683 commit d16fc9f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
74 changes: 74 additions & 0 deletions provider/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,77 @@ 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<GeteWayInfo>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct GeteWayInfo {
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,
decimal: u8,
}

#[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",
"decimal": 6
},
{
"tokenId": 3,
"tokenAddress":"0xffffffffffffffffffffffffffffffffffffffff",
"decimal": 7
}
]
},
{
"chainId": 7,
"l1GatewayContract": "0xffffffffffffffffffffffffffffffffffffffff",
"l2GatewayContract": "0xffffffffffffffffffffffffffffffffffffffff",
"tokens": [
{
"tokenId": 1,
"tokenAddress":"0xffffffffffffffffffffffffffffffffffffffff",
"decimal": 6
},
{
"tokenId": 3,
"tokenAddress":"0xffffffffffffffffffffffffffffffffffffffff",
"decimal": 6
}
]
}
]
}
"#;
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 @@ -97,6 +97,9 @@ pub trait ZkLinkRpc {
#[method(name = "getChangePubkeyChainId")]
async fn get_change_pubkey_chain_id(&self) -> RpcResult<ChainId>;

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

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

0 comments on commit d16fc9f

Please sign in to comment.