From ecdaa0d65abdae158be9a30972da0dc85002b6fd Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Mon, 3 Jun 2024 21:22:02 +0000 Subject: [PATCH] update --- Cargo.lock | 176 +++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 2 +- src/erc165/mod.rs | 93 ++++-------------------- 3 files changed, 188 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4b3487e..5052ce7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,16 +47,38 @@ dependencies = [ "memchr", ] +[[package]] +name = "alloy-dyn-abi" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2919acdad13336bc5dc26b636cdd6892c2f27fb0d4a58320a00c2713cf6a4e9a" +dependencies = [ + "alloy-json-abi", + "alloy-primitives", + "alloy-sol-type-parser", + "alloy-sol-types", + "const-hex", + "itoa", + "serde", + "serde_json", + "winnow 0.6.8", +] + [[package]] name = "alloy-ethers-typecast" version = "0.2.0" -source = "git+https://github.com/rainlanguage/alloy-ethers-typecast?rev=a6bcb86b9b61a56d2440d33313f024297ce737bb#a6bcb86b9b61a56d2440d33313f024297ce737bb" +source = "git+https://github.com/rainlanguage/alloy-ethers-typecast?rev=3225b3aa057b24c1864be4b7748d22c0518c9d91#3225b3aa057b24c1864be4b7748d22c0518c9d91" dependencies = [ + "alloy-dyn-abi", + "alloy-json-abi", "alloy-primitives", "alloy-sol-types", "async-trait", "derive_builder", "ethers", + "once_cell", + "rain-error-decoding", + "reqwest", "serde", "serde_json", "thiserror", @@ -73,6 +95,7 @@ dependencies = [ "alloy-primitives", "alloy-sol-type-parser", "serde", + "serde_json", ] [[package]] @@ -1732,6 +1755,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -2153,6 +2191,19 @@ dependencies = [ "tokio-rustls", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -2515,6 +2566,23 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -2650,6 +2718,50 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "openssl" +version = "0.10.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "option-ext" version = "0.2.0" @@ -3095,6 +3207,23 @@ dependencies = [ "tokio", ] +[[package]] +name = "rain-error-decoding" +version = "0.1.0" +source = "git+https://github.com/rainlanguage/rain.error?rev=6763061d89cfc084c81e01f75f6118881fa5b77b#6763061d89cfc084c81e01f75f6118881fa5b77b" +dependencies = [ + "alloy-dyn-abi", + "alloy-json-abi", + "alloy-primitives", + "alloy-sol-types", + "ethers", + "once_cell", + "reqwest", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "rand" version = "0.8.5" @@ -3219,10 +3348,12 @@ dependencies = [ "http-body", "hyper", "hyper-rustls", + "hyper-tls", "ipnet", "js-sys", "log", "mime", + "native-tls", "once_cell", "percent-encoding", "pin-project-lite", @@ -3234,6 +3365,7 @@ dependencies = [ "sync_wrapper", "system-configuration", "tokio", + "tokio-native-tls", "tokio-rustls", "tower-service", "url", @@ -3509,6 +3641,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "schannel" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -3551,6 +3692,29 @@ dependencies = [ "zeroize", ] +[[package]] +name = "security-framework" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" +dependencies = [ + "bitflags 2.5.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "0.11.0" @@ -4095,6 +4259,16 @@ dependencies = [ "syn 2.0.66", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.24.1" diff --git a/Cargo.toml b/Cargo.toml index 4965d14..40c0a62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/rainlanguage/rain.erc" thiserror = "1.0.56" alloy-primitives = "0.6.3" alloy-sol-types = { version = "0.6.3", features = ["json"] } -alloy-ethers-typecast = { git = "https://github.com/rainlanguage/alloy-ethers-typecast", rev = "a6bcb86b9b61a56d2440d33313f024297ce737bb" } +alloy-ethers-typecast = { git = "https://github.com/rainlanguage/alloy-ethers-typecast", rev = "3225b3aa057b24c1864be4b7748d22c0518c9d91" } [dev-dependencies] tokio = { version = "1.28.0", features = ["full"] } diff --git a/src/erc165/mod.rs b/src/erc165/mod.rs index fc77a58..c8ee0cf 100644 --- a/src/erc165/mod.rs +++ b/src/erc165/mod.rs @@ -62,79 +62,18 @@ pub async fn supports_erc165(client: &ReadableClientHttp, contract_address: Addr mod tests { use super::*; use alloy_primitives::hex::decode; - use serde::{Deserialize, Serialize}; use httpmock::{Method::POST, MockServer}; - use serde_json::{from_str, value::RawValue, Value}; + use serde_json::{from_str, Value}; use alloy_ethers_typecast::{ request_shim::{AlloyTransactionRequest, TransactionRequestShim}, + rpc::{Request, Response}, transaction::ReadableClient, }; use ethers::{ - types::{transaction::eip2718::TypedTransaction, BlockId, BlockNumber, U256}, + types::{transaction::eip2718::TypedTransaction, BlockId, BlockNumber}, utils, }; - /// A JSON-RPC request, taken from ethers since it is private - /// https://github.com/gakonst/ethers-rs/blob/master/ethers-providers/src/rpc/transports/common.rs - #[derive(Serialize, Deserialize, Debug)] - pub struct Request<'a, T> { - id: u64, - jsonrpc: &'a str, - method: &'a str, - params: T, - } - impl<'a, T> Request<'a, T> { - /// Creates a new JSON RPC request - pub fn new(id: u64, method: &'a str, params: T) -> Self { - Self { - id, - jsonrpc: "2.0", - method, - params, - } - } - } - - /// A JSON-RPC response, taken from ethers since it is private - /// https://github.com/gakonst/ethers-rs/blob/master/ethers-providers/src/rpc/transports/common.rs - #[derive(Debug, Serialize)] - #[serde(untagged)] - pub enum Response<'a> { - Success { - jsonrpc: &'a str, - id: u64, - result: &'a RawValue, - }, - Error { - jsonrpc: &'a str, - id: u64, - error: JsonRpcError, - }, - #[allow(dead_code)] - Notification { method: &'a str, params: Params<'a> }, - } - - /// A JSON-RPC 2.0 error, taken from ethers since it is private - /// https://github.com/gakonst/ethers-rs/blob/master/ethers-providers/src/rpc/transports/common.rs - #[derive(Debug, Clone, Serialize)] - pub struct JsonRpcError { - /// The error code - pub code: i64, - /// The error message - pub message: String, - /// Additional data - pub data: Option, - } - - /// taken from ethers since it is private - /// https://github.com/gakonst/ethers-rs/blob/master/ethers-providers/src/rpc/transports/common.rs - #[derive(Deserialize, Debug, Serialize)] - pub struct Params<'a> { - pub subscription: U256, - #[serde(borrow)] - pub result: &'a RawValue, - } - // test contracts bindings sol! { interface ITest { @@ -151,16 +90,15 @@ mod tests { ) -> String { let tx = utils::serialize(&TypedTransaction::Eip1559(transaction.to_eip1559())); let block = utils::serialize::(&BlockNumber::Latest.into()); - serde_json::to_string(&Request::new(id, method, [tx, block])).unwrap() + Request::new(id, method, [tx, block]) + .to_json_string() + .unwrap() } fn get_rpc_success_response_body(id: u64, result_data: &str) -> String { - let res = Response::Success { - id, - jsonrpc: "2.0", - result: &RawValue::from_string(format!("\"{}\"", result_data)).unwrap(), - }; - serde_json::to_string(&res).unwrap() + Response::new_success(id, result_data) + .to_json_string() + .unwrap() } fn get_rpc_error_response_body( @@ -169,16 +107,9 @@ mod tests { message: &str, data: Option<&str>, ) -> String { - let res = Response::Error { - id, - jsonrpc: "2.0", - error: JsonRpcError { - code, - message: message.to_string(), - data: data.map(|v| serde_json::to_value(v).unwrap()), - }, - }; - serde_json::to_string(&res).unwrap() + Response::new_error(id, code, message, data) + .to_json_string() + .unwrap() } #[test]