use crate::{GasInfo, result::Result, signer::Inner};
use gear_core::{
ids::{ActorId, CodeId, MessageId},
rpc::ReplyInfo,
};
use subxt::utils::H256;
#[derive(Clone)]
pub struct SignerRpc<'a>(pub(crate) &'a Inner);
impl SignerRpc<'_> {
pub fn source(&self) -> H256 {
AsRef::<[u8; 32]>::as_ref(self.0.account_id()).into()
}
pub async fn get_balance(&self) -> Result<u128> {
self.0.api().get_balance(&self.0.address()).await
}
pub async fn calculate_create_gas(
&self,
origin: Option<H256>,
code_id: CodeId,
payload: Vec<u8>,
value: u128,
allow_other_panics: bool,
at: Option<H256>,
) -> Result<GasInfo> {
self.0
.api
.calculate_create_gas(
origin.unwrap_or_else(|| self.source()),
code_id,
payload,
value,
allow_other_panics,
at,
)
.await
}
pub async fn calculate_upload_gas(
&self,
origin: Option<H256>,
code: Vec<u8>,
payload: Vec<u8>,
value: u128,
allow_other_panics: bool,
at: Option<H256>,
) -> Result<GasInfo> {
self.0
.api
.calculate_upload_gas(
origin.unwrap_or_else(|| self.source()),
code,
payload,
value,
allow_other_panics,
at,
)
.await
}
pub async fn calculate_handle_gas(
&self,
origin: Option<H256>,
destination: ActorId,
payload: Vec<u8>,
value: u128,
allow_other_panics: bool,
at: Option<H256>,
) -> Result<GasInfo> {
self.0
.api
.calculate_handle_gas(
origin.unwrap_or_else(|| self.source()),
destination,
payload,
value,
allow_other_panics,
at,
)
.await
}
pub async fn calculate_reply_gas(
&self,
origin: Option<H256>,
message_id: MessageId,
payload: Vec<u8>,
value: u128,
allow_other_panics: bool,
at: Option<H256>,
) -> Result<GasInfo> {
self.0
.api
.calculate_reply_gas(
origin.unwrap_or_else(|| self.source()),
message_id,
payload,
value,
allow_other_panics,
at,
)
.await
}
pub async fn calculate_reply_for_handle(
&self,
origin: Option<H256>,
destination: ActorId,
payload: Vec<u8>,
gas_limit: u64,
value: u128,
at: Option<H256>,
) -> Result<ReplyInfo> {
self.0
.api
.calculate_reply_for_handle(
origin.unwrap_or_else(|| self.source()),
destination,
payload,
gas_limit,
value,
at,
)
.await
}
}