-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathtxn_result.rs
34 lines (30 loc) · 951 Bytes
/
txn_result.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use crate::xdr::{Transaction, TransactionEnvelope, TransactionV1Envelope, VecM};
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum TxnResult<R> {
Txn(Box<Transaction>),
Res(R),
}
impl<R> TxnResult<R> {
pub fn into_result(self) -> Option<R> {
match self {
TxnResult::Res(res) => Some(res),
TxnResult::Txn(_) => None,
}
}
pub fn to_envelope(self) -> TxnEnvelopeResult<R> {
match self {
TxnResult::Txn(tx) => TxnEnvelopeResult::TxnEnvelope(Box::new(
TransactionEnvelope::Tx(TransactionV1Envelope {
tx: *tx,
signatures: VecM::default(),
}),
)),
TxnResult::Res(res) => TxnEnvelopeResult::Res(res),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum TxnEnvelopeResult<R> {
TxnEnvelope(Box<TransactionEnvelope>),
Res(R),
}