From 8052fcca3aec9bd396539e420a74aa2f3960d683 Mon Sep 17 00:00:00 2001 From: ghassmo Date: Tue, 26 Oct 2021 14:57:21 +0300 Subject: [PATCH] eth: impl base NetworkClient functions for EthClient --- src/service/eth.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/service/eth.rs b/src/service/eth.rs index 1c0df78e8..949106525 100644 --- a/src/service/eth.rs +++ b/src/service/eth.rs @@ -1,5 +1,8 @@ +use async_std::sync::{Arc, Mutex}; use std::convert::TryInto; +use async_executor::Executor; +use async_trait::async_trait; use hash_db::Hasher; use keccak_hasher::KeccakHasher; use lazy_static::lazy_static; @@ -8,6 +11,7 @@ use num_bigint::{BigUint, RandBigInt}; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; +use super::bridge::{NetworkClient, TokenNotification, TokenSubscribtion}; use crate::{rpc::jsonrpc, rpc::jsonrpc::JsonResult, Error, Result}; // An ERC-20 token transfer transaction's data is as follows: @@ -161,11 +165,22 @@ impl EthTx { // pub struct EthClient { socket_path: String, + _subscriptions: Arc>>>, + notify_channel: ( + async_channel::Sender, + async_channel::Receiver, + ), } impl EthClient { pub fn new(socket_path: String) -> Self { - Self { socket_path } + let notify_channel = async_channel::unbounded(); + let _subscriptions = Arc::new(Mutex::new(Vec::new())); + Self { + socket_path, + _subscriptions, + notify_channel, + } } async fn request(&self, r: jsonrpc::JsonRequest) -> Result { @@ -236,6 +251,48 @@ impl EthClient { } } +#[async_trait] +impl NetworkClient for EthClient { + async fn subscribe( + self: Arc, + _drk_pub_key: jubjub::SubgroupPoint, + _mint_address: Option, + _executor: Arc>, + ) -> Result { + let private_key: Vec = vec![]; + let public_key = String::from("addr"); + Ok(TokenSubscribtion { + private_key, + public_key, + }) + } + + async fn subscribe_with_keypair( + self: Arc, + _private_key: Vec, + _public_key: Vec, + _drk_pub_key: jubjub::SubgroupPoint, + _mint_address: Option, + _executor: Arc>, + ) -> Result { + let public_key = String::from("addr"); + Ok(public_key) + } + + async fn get_notifier(self: Arc) -> Result> { + Ok(self.notify_channel.1.clone()) + } + + async fn send( + self: Arc, + _address: Vec, + _mint: Option, + _amount: u64, + ) -> Result<()> { + Ok(()) + } +} + #[allow(unused_imports)] mod tests { use super::*;