Crates.io | hub-rs |
lib.rs | hub-rs |
version | 0.1.3 |
source | src |
created_at | 2023-08-06 07:09:21.736806 |
updated_at | 2023-08-21 01:08:14.978892 |
description | A barebones Rust library to interact with Farcaster hubs |
homepage | |
repository | https://github.com/withportals/hub-rs |
max_upload_size | |
id | 936963 |
size | 56,750 |
hub-rs is a barebones Rust library for interacting with Farcaster hubs
All definitions and functions are auto-generated with tonic
Protobufs are provided from the Farcaster monorepo
First, install the crate:
hub-rs = { version = "0.1.3" }
OR cargo add hub-rs
Then, you can use it in your project. To create a client, and get info about the connected hub, you might write something like this:
use hub_rs::hub_service_client::HubServiceClient;
use hub_rs::HubInfoRequest;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Secure or insecure connections are defined by the protocol you provide, either http or https
let mut client = HubServiceClient::connect("https://mainnet.useportals.app:2283").await?;
let info = client.get_info(HubInfoRequest { db_stats: true }).await?;
println!("{:?}", info.into_inner());
Ok(())
}
Currently, writing to Hubs is not supported here. I have a messy start on the landon-write-operations branch if you'd like to take a look / build on it. (Under src/builders/make_cast_add.rs)
Currently, two extra functions are provided for QOL:
bytes_to_hex_string
- Converts Vec<u8>
or [u8; 32/64]
types to a hex stringhex_string_to_bytes
- Converts a hex string into Vec<u8>
Q: Why?
A: ๐ฆ๐ฆ๐ฆ ๐๐๐
Q: Is this faster than hub-nodejs?
A: Theoretically, yes, just due to the nature of Rust. However, the difference is probably minimal, since its majorly just requests, real bottleneck is I/O & internet speed.
If you're interested in doing some benchmarking, though, either open a PR or contact me on telegram: @landon_xyz