Skip to content

Commit

Permalink
result handlers for errors, v1
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Mar 26, 2024
1 parent 819c438 commit d28adf0
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
22 changes: 22 additions & 0 deletions framework/base/src/types/interaction/tx_rh_list/tx_rh_list_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ pub trait RHListItemExec<RawResult, Env, Original>: RHListItem<Env, Original>
where
Env: TxEnv,
{
fn is_error_handled(&self) -> bool {
false
}

fn item_process_result(self, raw_result: &RawResult) -> Self::Returns;
}

Expand All @@ -18,20 +22,30 @@ pub trait RHListExec<RawResult, Env>: RHList<Env>
where
Env: TxEnv,
{
fn is_error_handled(&self) -> bool;

fn list_process_result(self, raw_result: &RawResult) -> Self::ListReturns;
}

impl<RawResult, Env> RHListExec<RawResult, Env> for ()
where
Env: TxEnv,
{
fn is_error_handled(&self) -> bool {
false
}

fn list_process_result(self, _raw_result: &RawResult) -> Self::ListReturns {}
}

impl<RawResult, Env, O> RHListExec<RawResult, Env> for OriginalResultMarker<O>
where
Env: TxEnv,
{
fn is_error_handled(&self) -> bool {
false
}

fn list_process_result(self, _raw_result: &RawResult) -> Self::ListReturns {}
}

Expand All @@ -41,6 +55,10 @@ where
Head: RHListItemExec<RawResult, Env, Tail::OriginalResult>,
Tail: RHListExec<RawResult, Env>,
{
fn is_error_handled(&self) -> bool {
self.head.is_error_handled() || self.tail.is_error_handled()
}

fn list_process_result(self, raw_result: &RawResult) -> Self::ListReturns {
let head_result = self.head.item_process_result(raw_result);
let tail_result = self.tail.list_process_result(raw_result);
Expand All @@ -54,6 +72,10 @@ where
Head: RHListItemExec<RawResult, Env, Tail::OriginalResult, Returns = ()>,
Tail: RHListExec<RawResult, Env>,
{
fn is_error_handled(&self) -> bool {
self.head.is_error_handled() || self.tail.is_error_handled()
}

fn list_process_result(self, raw_result: &RawResult) -> Self::ListReturns {
self.head.item_process_result(raw_result);
self.tail.list_process_result(raw_result)
Expand Down
4 changes: 4 additions & 0 deletions framework/scenario/src/facade/result_handlers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
mod returns_message;
mod returns_status;
mod with_tx_raw_response;

pub use returns_message::ReturnsMessage;
pub use returns_status::ReturnsStatus;
pub use with_tx_raw_response::WithRawTxResponse;
26 changes: 26 additions & 0 deletions framework/scenario/src/facade/result_handlers/returns_message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use multiversx_sc::types::{RHListItem, RHListItemExec, TxEnv};

use crate::scenario_model::TxResponse;

/// Indicates that the error status will be returned.
pub struct ReturnsMessage;

impl<Env, Original> RHListItem<Env, Original> for ReturnsMessage
where
Env: TxEnv,
{
type Returns = String;
}

impl<Env, Original> RHListItemExec<TxResponse, Env, Original> for ReturnsMessage
where
Env: TxEnv,
{
fn is_error_handled(&self) -> bool {
true
}

fn item_process_result(self, raw_result: &TxResponse) -> Self::Returns {
raw_result.tx_error.message.clone()
}
}
26 changes: 26 additions & 0 deletions framework/scenario/src/facade/result_handlers/returns_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use multiversx_sc::types::{RHListItem, RHListItemExec, TxEnv};

use crate::scenario_model::TxResponse;

/// Indicates that the error status will be returned.
pub struct ReturnsStatus;

impl<Env, Original> RHListItem<Env, Original> for ReturnsStatus
where
Env: TxEnv,
{
type Returns = u64;
}

impl<Env, Original> RHListItemExec<TxResponse, Env, Original> for ReturnsStatus
where
Env: TxEnv,
{
fn is_error_handled(&self) -> bool {
true
}

fn item_process_result(self, raw_result: &TxResponse) -> Self::Returns {
raw_result.tx_error.status
}
}

0 comments on commit d28adf0

Please sign in to comment.