Skip to content

Commit

Permalink
Merge pull request #29 from zkLinkProtocol/issue-8
Browse files Browse the repository at this point in the history
add getway list query response and rpc interface(fix #8)
  • Loading branch information
zkbenny authored Oct 16, 2023
2 parents cd98683 + f9f38ac commit 7049974
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<GateWayInfo>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct GateWayInfo {
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 7049974

Please sign in to comment.