From 4c3ffcfcb6243e706d76eb90057e98aae2663b75 Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Thu, 14 Dec 2023 13:36:29 +0100 Subject: [PATCH] WIP --- Cargo.lock | 3 ++- Cargo.toml | 1 + .../Cargo.toml | 2 +- .../src/data.rs | 0 .../src/data/decimal_u256.rs | 0 .../src/lib.rs | 0 src/ethereum/write_oz/mod.rs | 5 ++++- src/ethereum/write_oz/tx_sitter.rs | 22 ++++++++++++++++++- 8 files changed, 29 insertions(+), 4 deletions(-) rename crates/{tx-sitter => tx-sitter-client}/Cargo.toml (95%) rename crates/{tx-sitter => tx-sitter-client}/src/data.rs (100%) rename crates/{tx-sitter => tx-sitter-client}/src/data/decimal_u256.rs (100%) rename crates/{tx-sitter => tx-sitter-client}/src/lib.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index e3f758b9..910bd0d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5341,6 +5341,7 @@ dependencies = [ "tracing-futures", "tracing-subscriber 0.3.17", "tracing-test", + "tx-sitter-client", "url", "zeroize", ] @@ -6313,7 +6314,7 @@ dependencies = [ ] [[package]] -name = "tx-sitter" +name = "tx-sitter-client" version = "0.1.0" dependencies = [ "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 70f0ac7a..556c8080 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,6 +76,7 @@ tokio = { version = "1.17", features = [ ] } tracing = "0.1" tracing-futures = "0.2" +tx-sitter-client = { path = "crates/tx-sitter-client" } url = { version = "2.2", features = ["serde"] } # `ethers-rs` requires an older version of primitive-types. # But `ruint` supports the latest version. So we need to override it. diff --git a/crates/tx-sitter/Cargo.toml b/crates/tx-sitter-client/Cargo.toml similarity index 95% rename from crates/tx-sitter/Cargo.toml rename to crates/tx-sitter-client/Cargo.toml index c726e8bb..8536740d 100644 --- a/crates/tx-sitter/Cargo.toml +++ b/crates/tx-sitter-client/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "tx-sitter" +name = "tx-sitter-client" version = "0.1.0" edition = "2021" publish = false diff --git a/crates/tx-sitter/src/data.rs b/crates/tx-sitter-client/src/data.rs similarity index 100% rename from crates/tx-sitter/src/data.rs rename to crates/tx-sitter-client/src/data.rs diff --git a/crates/tx-sitter/src/data/decimal_u256.rs b/crates/tx-sitter-client/src/data/decimal_u256.rs similarity index 100% rename from crates/tx-sitter/src/data/decimal_u256.rs rename to crates/tx-sitter-client/src/data/decimal_u256.rs diff --git a/crates/tx-sitter/src/lib.rs b/crates/tx-sitter-client/src/lib.rs similarity index 100% rename from crates/tx-sitter/src/lib.rs rename to crates/tx-sitter-client/src/lib.rs diff --git a/src/ethereum/write_oz/mod.rs b/src/ethereum/write_oz/mod.rs index b0eff689..4d6d04ca 100644 --- a/src/ethereum/write_oz/mod.rs +++ b/src/ethereum/write_oz/mod.rs @@ -10,6 +10,7 @@ use tracing::{info, warn}; use self::inner::Inner; use self::openzeppelin::OzRelay; use self::options::ParsedOptions; +use self::tx_sitter::TxSitter; use super::write::TransactionId; use super::{ReadProvider, TxError}; @@ -44,7 +45,9 @@ impl WriteProvider { let inner: Arc = match options { ParsedOptions::Oz(oz_options) => Arc::new(OzRelay::new(&oz_options).await?), - ParsedOptions::TxSitter(tx_sitter_options) => todo!(), + ParsedOptions::TxSitter(tx_sitter_options) => { + Arc::new(TxSitter::new(&tx_sitter_options.tx_sitter_url)) + } }; Ok(Self { diff --git a/src/ethereum/write_oz/tx_sitter.rs b/src/ethereum/write_oz/tx_sitter.rs index 87af6106..307dd0fc 100644 --- a/src/ethereum/write_oz/tx_sitter.rs +++ b/src/ethereum/write_oz/tx_sitter.rs @@ -1,12 +1,23 @@ +use anyhow::Context; use async_trait::async_trait; use ethers::types::transaction::eip2718::TypedTransaction; +use tx_sitter_client::data::SendTxRequest; +use tx_sitter_client::TxSitterClient; use super::inner::{Inner, TransactionResult}; use crate::ethereum::write::TransactionId; use crate::ethereum::TxError; pub struct TxSitter { - url: String, + client: TxSitterClient, +} + +impl TxSitter { + pub fn new(url: impl ToString) -> Self { + Self { + client: TxSitterClient::new(url), + } + } } #[async_trait] @@ -16,6 +27,15 @@ impl Inner for TxSitter { tx: TypedTransaction, only_once: bool, ) -> Result { + let x = self.client.send_tx(&SendTxRequest { + to: *tx.to_addr().context("Tx receiver must be an address")?, + value: *tx.value().context("Missing tx value")?, + data: todo!(), + gas_limit: todo!(), + priority: todo!(), + tx_id: todo!(), + }).await.unwrap(); + todo!() }