pub struct HttpProvider { /* private fields */ }
Expand description
A low-level JSON-RPC Client over HTTP.
§Example
use neo3::neo_clients::{HttpProvider, RpcClient, APITrait};
use neo3::neo_config::NeoConstants;
use primitive_types::H256;
let provider = HttpProvider::new(NeoConstants::SEED_1)?;
let client = RpcClient::new(provider);
let block = client.get_block(H256::zero(), false).await?;
Implementations§
Source§impl HttpProvider
impl HttpProvider
Sourcepub fn new<T: TryInto<Url>>(url: T) -> Result<Self, T::Error>
pub fn new<T: TryInto<Url>>(url: T) -> Result<Self, T::Error>
Initializes a new HTTP Client
§Example
use neo3::neo_clients::HttpProvider;
use url::Url;
// Using a string
let provider = HttpProvider::new("http://localhost:8545")?;
// Using a &str
let provider = HttpProvider::new("http://localhost:8545")?;
// Using a Url
let url = Url::parse("http://localhost:8545").unwrap();
let provider = HttpProvider::new(url)?;
Sourcepub fn new_with_auth(
url: impl Into<Url>,
auth: Authorization,
) -> Result<Self, HttpClientError>
pub fn new_with_auth( url: impl Into<Url>, auth: Authorization, ) -> Result<Self, HttpClientError>
Initializes a new HTTP Client with authentication
§Example
use neo3::neo_clients::{HttpProvider, Authorization};
use url::Url;
let url = Url::parse("http://localhost:8545").unwrap();
let provider = HttpProvider::new_with_auth(url, Authorization::basic("admin", "good_password"))?;
Sourcepub fn new_with_client(url: impl Into<Url>, client: Client) -> Self
pub fn new_with_client(url: impl Into<Url>, client: Client) -> Self
Allows to customize the provider by providing your own http client
§Example
use neo3::neo_clients::HttpProvider;
use url::Url;
let url = Url::parse("http://localhost:8545").unwrap();
let client = reqwest::Client::builder().build().unwrap();
let provider = HttpProvider::new_with_client(url, client);
Trait Implementations§
Source§impl Clone for HttpProvider
impl Clone for HttpProvider
Source§impl Debug for HttpProvider
impl Debug for HttpProvider
Source§impl JsonRpcProvider for HttpProvider
impl JsonRpcProvider for HttpProvider
Source§type Error = ClientError
type Error = ClientError
A JSON-RPC Error
Source§fn fetch<'life0, 'life1, 'async_trait, T, R>(
&'life0 self,
method: &'life1 str,
params: T,
) -> Pin<Box<dyn Future<Output = Result<R, ClientError>> + Send + 'async_trait>>where
T: 'async_trait + Serialize + Send + Sync,
R: 'async_trait + DeserializeOwned,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn fetch<'life0, 'life1, 'async_trait, T, R>(
&'life0 self,
method: &'life1 str,
params: T,
) -> Pin<Box<dyn Future<Output = Result<R, ClientError>> + Send + 'async_trait>>where
T: 'async_trait + Serialize + Send + Sync,
R: 'async_trait + DeserializeOwned,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sends a request with the provided JSON-RPC and parameters serialized as JSON
Auto Trait Implementations§
impl !Freeze for HttpProvider
impl !RefUnwindSafe for HttpProvider
impl Send for HttpProvider
impl Sync for HttpProvider
impl Unpin for HttpProvider
impl !UnwindSafe for HttpProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more