gsdk 2.0.0-pre.1

Rust SDK of the Gear network
Documentation
// Copyright (C) Gear Technologies Inc.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

//! RPC calls with signer

use crate::{GasInfo, SignedApi, result::Result};
use gear_core::{
    ids::{ActorId, CodeId, MessageId},
    rpc::{CalculateReplyForHandleResult, ReplyInfo},
};
use gsdk_codegen::at_block;
use subxt::utils::H256;

impl SignedApi {
    /// Returns the signer's free balance.
    pub async fn free_balance(&self) -> Result<u128> {
        self.unsigned().free_balance(self.account_id()).await
    }

    /// Get self reserved balance.
    pub async fn reserved_balance(&self) -> Result<u128> {
        self.unsigned().reserved_balance(self.account_id()).await
    }

    /// Get self total balance.
    pub async fn total_balance(&self) -> Result<u128> {
        self.unsigned().total_balance(self.account_id()).await
    }

    /// Calls `gear_calculateInitCreateGas` RPC method at specified block.
    #[at_block]
    pub async fn calculate_create_gas_at(
        &self,
        code_id: CodeId,
        payload: impl AsRef<[u8]>,
        value: u128,
        allow_other_panics: bool,
        block_hash: Option<H256>,
    ) -> Result<GasInfo> {
        self.unsigned()
            .calculate_create_gas_at(
                self.account_id(),
                code_id,
                payload,
                value,
                allow_other_panics,
                block_hash,
            )
            .await
    }

    /// Calls `gear_calculateInitUploadGas` RPC method at specified block.
    #[at_block]
    pub async fn calculate_upload_gas_at(
        &self,
        code: impl AsRef<[u8]>,
        payload: impl AsRef<[u8]>,
        value: u128,
        allow_other_panics: bool,
        block_hash: Option<H256>,
    ) -> Result<GasInfo> {
        self.unsigned()
            .calculate_upload_gas_at(
                self.account_id(),
                code,
                payload,
                value,
                allow_other_panics,
                block_hash,
            )
            .await
    }

    /// Calls `gear_calculateHandleGas` RPC method at specified block at specified block.
    #[at_block]
    pub async fn calculate_handle_gas_at(
        &self,
        destination: ActorId,
        payload: impl AsRef<[u8]>,
        value: u128,
        allow_other_panics: bool,
        block_hash: Option<H256>,
    ) -> Result<GasInfo> {
        self.unsigned()
            .calculate_handle_gas_at(
                self.account_id(),
                destination,
                payload,
                value,
                allow_other_panics,
                block_hash,
            )
            .await
    }

    /// Calls `gear_calculateReplyGas` RPC method at specified block.
    #[at_block]
    pub async fn calculate_reply_gas_at(
        &self,
        message_id: MessageId,
        payload: impl AsRef<[u8]>,
        value: u128,
        allow_other_panics: bool,
        block_hash: Option<H256>,
    ) -> Result<GasInfo> {
        self.unsigned()
            .calculate_reply_gas_at(
                self.account_id(),
                message_id,
                payload,
                value,
                allow_other_panics,
                block_hash,
            )
            .await
    }

    /// Calls `gear_calculateReplyForHandle` RPC method at specified block.
    #[at_block]
    pub async fn calculate_reply_for_handle_at(
        &self,
        destination: ActorId,
        payload: impl AsRef<[u8]>,
        gas_limit: u64,
        value: u128,
        block_hash: Option<H256>,
    ) -> Result<ReplyInfo> {
        self.unsigned()
            .calculate_reply_for_handle_at(
                self.account_id(),
                destination,
                payload,
                gas_limit,
                value,
                block_hash,
            )
            .await
    }

    /// Calls `gear_calculateReplyForHandleResult` RPC method at specified block.
    #[at_block]
    pub async fn calculate_reply_for_handle_result_at(
        &self,
        destination: ActorId,
        payload: impl AsRef<[u8]>,
        gas_limit: u64,
        value: u128,
        block_hash: Option<H256>,
    ) -> Result<CalculateReplyForHandleResult> {
        self.unsigned()
            .calculate_reply_for_handle_result_at(
                self.account_id(),
                destination,
                payload,
                gas_limit,
                value,
                block_hash,
            )
            .await
    }
}