Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added high level call result #7

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ High level client library for transacting to the NEAR network.
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
base64 = "0.21"
serde = "1.0"
serde_json = "1.0"
thiserror = "1"
Expand Down
5 changes: 5 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use near_jsonrpc_primitives::types::blocks::RpcBlockError;
use near_jsonrpc_primitives::types::chunks::RpcChunkError;
use near_jsonrpc_primitives::types::query::RpcQueryError;
use near_jsonrpc_primitives::types::transactions::RpcTransactionError;
use near_primitives::errors::TxExecutionError;

pub type Result<T, E = Error> = core::result::Result<T, E>;

Expand All @@ -25,10 +26,14 @@ pub enum Error {
/// Catch all RPC error. This is usually resultant from query calls.
#[error("rpc: {0}")]
Rpc(Box<dyn std::error::Error + Send + Sync>),
#[error(transparent)]
TxExecution(Box<TxExecutionError>),

#[error(transparent)]
Serialization(#[from] serde_json::Error),
#[error(transparent)]
Base64(#[from] base64::DecodeError),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("invalid args were passed: {0}")]
InvalidArgs(&'static str),
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod error;
pub mod ops;
pub mod query;
pub mod signer;
pub mod result;

use crate::error::Result;
use crate::signer::ExposeAccountId;
Expand Down
14 changes: 13 additions & 1 deletion src/ops.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! All operation types that are generated/used when commiting transactions to the network.

use near_account_id::AccountId;
use near_crypto::{PublicKey, Signer};
use near_gas::NearGas;
Expand All @@ -11,11 +13,20 @@ use near_primitives::transaction::{
use near_primitives::views::FinalExecutionOutcomeView;
use near_token::NearToken;

use crate::result::ExecutionFinalResult;
use crate::signer::ExposeAccountId;
use crate::{Client, Error, Result};

/// Maximum amount of gas that can be used in a single transaction.
pub const MAX_GAS: NearGas = NearGas::from_tgas(300);

/// Default amount of gas to be used when calling into a function on a contract.
/// This is set to 10 TGas as a default for convenience.
pub const DEFAULT_CALL_FN_GAS: NearGas = NearGas::from_tgas(10);

/// Default amount of deposit to be used when calling into a function on a contract.
/// This is set to 0 NEAR as a default for convenience. Note, that some contracts
/// will require 1 yoctoNEAR to be deposited in order to perform a function.
pub const DEFAULT_CALL_DEPOSIT: NearToken = NearToken::from_near(0);

/// A set of arguments we can provide to a transaction, containing
Expand Down Expand Up @@ -155,14 +166,15 @@ where
S: Signer + ExposeAccountId + 'static,
{
/// Process the transaction, and return the result of the execution.
pub async fn transact(self) -> Result<FinalExecutionOutcomeView> {
pub async fn transact(self) -> Result<ExecutionFinalResult> {
self.client
.send_tx(
&self.signer,
&self.receiver_id,
vec![self.function.into_action()?.into()],
)
.await
.map(ExecutionFinalResult::from_view)
}

/// Send the transaction to the network to be processed. This will be done asynchronously
Expand Down
Loading