Skip to content

Commit

Permalink
Merge pull request #4 from Into-the-Fathom/master
Browse files Browse the repository at this point in the history
Fathom update
  • Loading branch information
TonioMacaronio authored Sep 14, 2022
2 parents c593b72 + f344339 commit ab1961e
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ target
Cargo.lock
*.swp
.idea/
*.DS_Store
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "web3"
version = "0.19.0"
description = "Ethereum JSON-RPC client."
homepage = "https://github.com/tomusdrw/rust-web3"
repository = "https://github.com/tomusdrw/rust-web3"
documentation = "https://docs.rs/web3"
name = "web3_fe"
version = "0.1.0"
description = "Ethereum JSON-RPC client. Fathom Edition"
homepage = "https://github.com/Into-the-Fathom/rust-web3"
repository = "https://github.com/Into-the-Fathom/rust-web3"
documentation = "https://docs.rs/web3_fe"
license = "MIT"
keywords = ["jsonrpc", "web3", "ethereum", "rpc", "client"]
authors = ["Tomasz Drwięga <tomasz@parity.io>"]
authors = ["Tomasz Drwięga <tomasz@parity.io>", "Zachary Short <zachary.short@fathom.fi>", "Anton Grigorev <anton@fathom.fi>"]
readme = "README.md"
edition = "2018"

Expand Down
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2019 Tomasz Drwięga <tomasz@parity.io>
Original Copyright (c) 2019 Tomasz Drwięga <tomasz@parity.io>
Modified Copyright (c) 2022 Fathom

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# web3
# web3 FE

Ethereum JSON-RPC multi-transport client.
Rust implementation of Web3.js library.
Fathom Edition.

[![Build Status][ci-image]][ci-url] [![Crates.io](https://img.shields.io/crates/v/web3)](https://crates.io/crates/web3)
[![Build Status][ci-image]][ci-url] [![Crates.io](https://img.shields.io/crates/v/web3_fe)](https://crates.io/crates/web3_fe)

[ci-image]: https://github.com/tomusdrw/rust-web3/workflows/Compilation%20and%20Testing%20Suite/badge.svg
[ci-url]: https://github.com/tomusdrw/rust-web3/actions?query=workflow%3A%22Compilation+and+Testing+Suite%22
[docs-rs-badge]: https://docs.rs/web3/badge.svg
[docs-rs-url]: https://docs.rs/web3
[ci-image]: https://github.com/Into-the-Fathom/rust-web3/workflows/Compilation%20and%20Testing%20Suite/badge.svg
[ci-url]: https://github.com/Into-the-Fathom/rust-web3/actions?query=workflow%3A%22Compilation+and+Testing+Suite%22
[docs-rs-badge]: https://docs.rs/web3_fe/badge.svg
[docs-rs-url]: https://docs.rs/web3_fe

Documentation: [crates.io][docs-rs-url]

Expand All @@ -18,15 +19,15 @@ First, add this to your `Cargo.toml`:

```toml
[dependencies]
web3 = "0.17.0"
web3_fe = "0.1.0"
```

## Example
```rust
#[tokio::main]
async fn main() -> web3::Result<()> {
let transport = web3::transports::Http::new("http://localhost:8545")?;
let web3 = web3::Web3::new(transport);
async fn main() -> web3_fe::Result<()> {
let transport = web3_fe::transports::Http::new("http://localhost:8545")?;
let web3 = web3_fe::Web3::new(transport);

println!("Calling accounts.");
let mut accounts = web3.eth().accounts().await?;
Expand Down Expand Up @@ -104,15 +105,15 @@ web3.api::<CustomNamespace>().custom_method().wait().unwrap()
Currently, Windows does not support IPC, which is enabled in the library by default.
To compile, you need to disable the IPC feature:
```
web3 = { version = "0.17.0", default-features = false, features = ["http"] }
web3_fe = { version = "0.1.0", default-features = false, features = ["http"] }
```

# Avoiding OpenSSL dependency

On Linux, `native-tls` is implemented using OpenSSL. To avoid that dependency
for HTTPS use the corresponding feature.
```
web3 = { version = "0.17.0", default-features = false, features = ["http-rustls-tls"] }
web3_fe = { version = "0.1.0", default-features = false, features = ["http-rustls-tls"] }
```

# Cargo Features
Expand Down
10 changes: 5 additions & 5 deletions examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ use std::{
};

#[tokio::main]
async fn main() -> web3::Result {
async fn main() -> web3_fe::Result {
let _ = env_logger::try_init();
let requests = 200_000;

let http = web3::transports::Http::new("http://localhost:8545/")?;
let http = web3_fe::transports::Http::new("http://localhost:8545/")?;
bench("http", http, requests);

let ipc = web3::transports::WebSocket::new("./jsonrpc.ipc").await?;
let ipc = web3_fe::transports::WebSocket::new("./jsonrpc.ipc").await?;
bench(" ipc", ipc, requests);

Ok(())
}

fn bench<T: web3::Transport>(id: &str, transport: T, max: usize)
fn bench<T: web3_fe::Transport>(id: &str, transport: T, max: usize)
where
T::Out: Send + 'static,
{
use futures::FutureExt;

let web3 = web3::Web3::new(transport);
let web3 = web3_fe::Web3::new(transport);
let ticker = Arc::new(Ticker::new(id));

for _ in 0..max {
Expand Down
8 changes: 4 additions & 4 deletions examples/contract.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use hex_literal::hex;
use web3::{
use web3_fe::{
contract::{Contract, Options},
types::U256,
};

#[tokio::main]
async fn main() -> web3::contract::Result<()> {
async fn main() -> web3_fe::contract::Result<()> {
let _ = env_logger::try_init();
let http = web3::transports::Http::new("http://localhost:8545")?;
let web3 = web3::Web3::new(http);
let http = web3_fe::transports::Http::new("http://localhost:8545")?;
let web3 = web3_fe::Web3::new(http);

let my_account = hex!("d028d24f16a8893bd078259d413372ac01580769").into();
// Get the contract bytecode for instance from Solidity compiler
Expand Down
6 changes: 3 additions & 3 deletions examples/contract_log_filter.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use hex_literal::hex;
use std::time;
use web3::{
use web3_fe::{
contract::{Contract, Options},
futures::StreamExt,
types::FilterBuilder,
};

#[tokio::main]
async fn main() -> web3::contract::Result<()> {
async fn main() -> web3_fe::contract::Result<()> {
let _ = env_logger::try_init();
let web3 = web3::Web3::new(web3::transports::Http::new("http://localhost:8545")?);
let web3 = web3_fe::Web3::new(web3_fe::transports::Http::new("http://localhost:8545")?);

// Get the contract bytecode for instance from Solidity compiler
let bytecode = include_str!("./res/SimpleEvent.bin");
Expand Down
6 changes: 3 additions & 3 deletions examples/contract_log_pubsub.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use hex_literal::hex;
use std::time;
use web3::{
use web3_fe::{
contract::{Contract, Options},
futures::{future, StreamExt},
types::FilterBuilder,
};

#[tokio::main]
async fn main() -> web3::contract::Result<()> {
async fn main() -> web3_fe::contract::Result<()> {
let _ = env_logger::try_init();
let web3 = web3::Web3::new(web3::transports::WebSocket::new("ws://localhost:8546").await?);
let web3 = web3_fe::Web3::new(web3_fe::transports::WebSocket::new("ws://localhost:8546").await?);

// Get the contract bytecode for instance from Solidity compiler
let bytecode = include_str!("./res/SimpleEvent.bin");
Expand Down
8 changes: 4 additions & 4 deletions examples/contract_storage.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//based on examples/contract.rs

use std::time;
use web3::{
use web3_fe::{
contract::{Contract, Options},
types::U256,
};

#[tokio::main]
async fn main() -> web3::contract::Result<()> {
async fn main() -> web3_fe::contract::Result<()> {
let _ = env_logger::try_init();
let transport = web3::transports::Http::new("http://localhost:8545")?;
let web3 = web3::Web3::new(transport);
let transport = web3_fe::transports::Http::new("http://localhost:8545")?;
let web3 = web3_fe::Web3::new(transport);
let accounts = web3.eth().accounts().await?;

// Get current balance
Expand Down
8 changes: 4 additions & 4 deletions examples/pubsub.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use web3::futures::{future, StreamExt};
use web3_fe::futures::{future, StreamExt};

#[tokio::main]
async fn main() -> web3::Result {
let ws = web3::transports::WebSocket::new("ws://localhost:8546").await?;
let web3 = web3::Web3::new(ws.clone());
async fn main() -> web3_fe::Result {
let ws = web3_fe::transports::WebSocket::new("ws://localhost:8546").await?;
let web3 = web3_fe::Web3::new(ws.clone());
let mut sub = web3.eth_subscribe().subscribe_new_heads().await?;

println!("Got subscription id: {:?}", sub.id());
Expand Down
8 changes: 4 additions & 4 deletions examples/transaction_private.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::str::FromStr;

use web3::{
use web3_fe::{
ethabi::ethereum_types::U256,
types::{Address, TransactionRequest},
};

/// Below sends a transaction to a local node that stores private keys (eg Ganache)
/// For generating and signing a transaction offline, before transmitting it to a public node (eg Infura) see transaction_public
#[tokio::main]
async fn main() -> web3::Result {
let transport = web3::transports::Http::new("http://localhost:7545")?;
let web3 = web3::Web3::new(transport);
async fn main() -> web3_fe::Result {
let transport = web3_fe::transports::Http::new("http://localhost:7545")?;
let web3 = web3_fe::Web3::new(transport);

// Insert the 20-byte "from" address in hex format (prefix with 0x)
let from = Address::from_str("0xC48ad5fd060e1400a41bcf51db755251AD5A2475").unwrap();
Expand Down
8 changes: 4 additions & 4 deletions examples/transaction_public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ use std::str::FromStr;

use secp256k1::SecretKey;

use web3::{
use web3_fe::{
ethabi::ethereum_types::U256,
types::{Address, TransactionParameters},
};

/// Below generates and signs a transaction offline, before transmitting it to a public node (eg Infura)
/// For sending a transaction to a local node that stores private keys (eg Ganache) see transaction_private
#[tokio::main]
async fn main() -> web3::Result {
async fn main() -> web3_fe::Result {
// Sign up at infura > choose the desired network (eg Rinkeby) > copy the endpoint url into the below
// If you need test ether use a faucet, eg https://faucet.rinkeby.io/
let transport = web3::transports::Http::new("https://rinkeby.infura.io/v3/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")?;
let web3 = web3::Web3::new(transport);
let transport = web3_fe::transports::Http::new("https://rinkeby.infura.io/v3/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")?;
let web3 = web3_fe::Web3::new(transport);

// Insert the 20-byte "to" address in hex format (prefix with 0x)
let to = Address::from_str("0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").unwrap();
Expand Down
6 changes: 3 additions & 3 deletions examples/transport_batch.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[tokio::main]
async fn main() -> web3::Result {
async fn main() -> web3_fe::Result {
let _ = env_logger::try_init();
let http = web3::transports::Http::new("http://localhost:8545")?;
let web3 = web3::Web3::new(web3::transports::Batch::new(http));
let http = web3_fe::transports::Http::new("http://localhost:8545")?;
let web3 = web3_fe::Web3::new(web3_fe::transports::Batch::new(http));

let accounts = web3.eth().accounts();
let block = web3.eth().block_number();
Expand Down
12 changes: 6 additions & 6 deletions examples/transport_either.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use hex_literal::hex;

pub type Transport = web3::transports::Either<web3::transports::WebSocket, web3::transports::Http>;
pub type Transport = web3_fe::transports::Either<web3_fe::transports::WebSocket, web3_fe::transports::Http>;

#[tokio::main]
async fn main() -> web3::Result {
async fn main() -> web3_fe::Result {
let _ = env_logger::try_init();
let transport = web3::transports::Http::new("http://localhost:8545")?;
let transport = web3_fe::transports::Http::new("http://localhost:8545")?;

run(web3::transports::Either::Right(transport)).await
run(web3_fe::transports::Either::Right(transport)).await
}

async fn run(transport: Transport) -> web3::Result {
let web3 = web3::Web3::new(transport);
async fn run(transport: Transport) -> web3_fe::Result {
let web3 = web3_fe::Web3::new(transport);

println!("Calling accounts.");
let mut accounts = web3.eth().accounts().await?;
Expand Down
6 changes: 3 additions & 3 deletions examples/transport_http.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use hex_literal::hex;

#[tokio::main]
async fn main() -> web3::Result<()> {
async fn main() -> web3_fe::Result<()> {
let _ = env_logger::try_init();
let transport = web3::transports::Http::new("http://localhost:8545")?;
let web3 = web3::Web3::new(transport);
let transport = web3_fe::transports::Http::new("http://localhost:8545")?;
let web3 = web3_fe::Web3::new(transport);

println!("Calling accounts.");
let mut accounts = web3.eth().accounts().await?;
Expand Down
6 changes: 3 additions & 3 deletions examples/transport_ws.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use hex_literal::hex;

#[tokio::main]
async fn main() -> web3::Result<()> {
async fn main() -> web3_fe::Result<()> {
let _ = env_logger::try_init();
let transport = web3::transports::WebSocket::new("ws://localhost:8546").await?;
let web3 = web3::Web3::new(transport);
let transport = web3_fe::transports::WebSocket::new("ws://localhost:8546").await?;
let web3 = web3_fe::Web3::new(transport);

println!("Calling accounts.");
let mut accounts = web3.eth().accounts().await?;
Expand Down
27 changes: 24 additions & 3 deletions src/types/block.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use std::{
fmt::{self, Debug},
str::FromStr,
};

use crate::types::{Bytes, H160, H2048, H256, H64, U256, U64};
use serde::{de::Error, ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};

Expand Down Expand Up @@ -118,11 +123,27 @@ pub struct Block<TX> {

fn null_to_default<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
T: Default + Deserialize<'de>,
T: Default + Deserialize<'de> + FromStr + Debug,
D: Deserializer<'de>,
<T as FromStr>::Err: fmt::Debug,
{
let option = Option::deserialize(deserializer)?;
Ok(option.unwrap_or_default())
let option = String::deserialize(deserializer);
match option {
Ok(string) => {
if string.len() > 40 {
// Remove address prefix
let len = string.len();
let author: &str = &string[len - 40..];
let author = author.clone().to_string();
let result: Option<T> = Some(author.parse().unwrap());
Ok(result.unwrap_or_default())
} else {
let result: Option<T> = Some(string.parse().unwrap());
Ok(result.unwrap_or_default())
}
}
Err(err) => Err(err),
}
}

/// Block Number
Expand Down
Loading

0 comments on commit ab1961e

Please sign in to comment.