pub struct RpcBuilder<Query, Handler>where
Query: RpcType,
Query::Response: Debug + Send + Sync,
Query::Error: Debug + Send + Sync,
Handler: Send + Sync,{
reference: Query::RpcReference,
request: Arc<dyn RpcType<Response = Query::Response, RpcReference = Query::RpcReference, Error = Query::Error> + Send + Sync>,
handler: Handler,
}Fields§
§reference: Query::RpcReference§request: Arc<dyn RpcType<Response = Query::Response, RpcReference = Query::RpcReference, Error = Query::Error> + Send + Sync>§handler: HandlerImplementations§
Source§impl<Query, Handler> RpcBuilder<Query, Handler>
impl<Query, Handler> RpcBuilder<Query, Handler>
pub fn new( request: Query, reference: impl Into<Query::RpcReference>, handler: Handler, ) -> Self
Sourcepub fn at(self, reference: impl Into<Query::RpcReference>) -> Self
pub fn at(self, reference: impl Into<Query::RpcReference>) -> Self
Set the block reference for the query.
Sourcepub fn map<MappedType>(
self,
map: impl Fn(Handler::Response) -> MappedType + Send + Sync + 'static,
) -> RpcBuilder<Query, PostprocessHandler<MappedType, Handler>>
pub fn map<MappedType>( self, map: impl Fn(Handler::Response) -> MappedType + Send + Sync + 'static, ) -> RpcBuilder<Query, PostprocessHandler<MappedType, Handler>>
Post-process the response of the query.
This is useful if you want to convert one type to another.
§Example
use near_api::*;
let balance: NearToken = Contract("some_contract.testnet".parse()?)
.call_function("get_balance", ())?
.read_only()
.map(|balance: Data<u128>| NearToken::from_yoctonear(balance.data))
.fetch_from_testnet()
.await?;
println!("Balance: {}", balance);Sourcepub fn and_then<MappedType>(
self,
map: impl Fn(Handler::Response) -> Result<MappedType, Box<dyn Error + Send + Sync>> + Send + Sync + 'static,
) -> RpcBuilder<Query, AndThenHandler<MappedType, Handler>>
pub fn and_then<MappedType>( self, map: impl Fn(Handler::Response) -> Result<MappedType, Box<dyn Error + Send + Sync>> + Send + Sync + 'static, ) -> RpcBuilder<Query, AndThenHandler<MappedType, Handler>>
Post-process the response of the query with error handling
This is useful if you want to convert one type to another but your function might fail.
The error will be wrapped in a QueryError::ConversionError and returned to the caller.
§Example
use near_api::*;
let balance: NearToken = Contract("some_contract.testnet".parse()?)
.call_function("get_balance", ())?
.read_only()
.and_then(|balance: Data<String>| Ok(NearToken::from_yoctonear(balance.data.parse()?)))
.fetch_from_testnet()
.await?;
println!("Balance: {}", balance);Sourcepub async fn fetch_from(
self,
network: &NetworkConfig,
) -> Result<Handler::Response, QueryError<Query::Error>>
pub async fn fetch_from( self, network: &NetworkConfig, ) -> Result<Handler::Response, QueryError<Query::Error>>
Fetch the query from the provided network.
Sourcepub async fn fetch_from_mainnet(
self,
) -> Result<Handler::Response, QueryError<Query::Error>>
pub async fn fetch_from_mainnet( self, ) -> Result<Handler::Response, QueryError<Query::Error>>
Fetch the query from the default mainnet network configuration.
Sourcepub async fn fetch_from_testnet(
self,
) -> Result<Handler::Response, QueryError<Query::Error>>
pub async fn fetch_from_testnet( self, ) -> Result<Handler::Response, QueryError<Query::Error>>
Fetch the query from the default testnet network configuration.
Auto Trait Implementations§
impl<Query, Handler> Freeze for RpcBuilder<Query, Handler>
impl<Query, Handler> !RefUnwindSafe for RpcBuilder<Query, Handler>
impl<Query, Handler> Send for RpcBuilder<Query, Handler>
impl<Query, Handler> Sync for RpcBuilder<Query, Handler>
impl<Query, Handler> Unpin for RpcBuilder<Query, Handler>
impl<Query, Handler> !UnwindSafe for RpcBuilder<Query, Handler>
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