Skip to content

Commit 2ec23e7

Browse files
Seulgi Kimjoojis
authored andcommitted
Remove TransactionOutcome
Since Invoice has TransactionOutcome only, there is no reason that TransactionOutcome exists.
1 parent d33f0b4 commit 2ec23e7

File tree

3 files changed

+20
-59
lines changed

3 files changed

+20
-59
lines changed

core/src/blockchain/extras.rs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -275,31 +275,18 @@ pub struct EpochTransitions {
275275

276276
#[cfg(test)]
277277
mod tests {
278-
use super::super::super::invoice::TransactionOutcome;
279278
use super::*;
280279
use rlp::{Encodable, UntrustedRlp};
281280

282281
#[test]
283282
fn rlp_encode_and_decode_parcel_invoices() {
284283
let invoices = vec![
285-
Invoice {
286-
outcome: TransactionOutcome::Success,
287-
},
288-
Invoice {
289-
outcome: TransactionOutcome::Success,
290-
},
291-
Invoice {
292-
outcome: TransactionOutcome::Failed,
293-
},
294-
Invoice {
295-
outcome: TransactionOutcome::Success,
296-
},
297-
Invoice {
298-
outcome: TransactionOutcome::Success,
299-
},
300-
Invoice {
301-
outcome: TransactionOutcome::Success,
302-
},
284+
Invoice::Success,
285+
Invoice::Success,
286+
Invoice::Failed,
287+
Invoice::Success,
288+
Invoice::Success,
289+
Invoice::Success,
303290
];
304291
let parcel_invoices = ParcelInvoices {
305292
invoices,
@@ -312,14 +299,7 @@ mod tests {
312299

313300
#[test]
314301
fn rlp_encode_and_decode_block_invoices() {
315-
let invoices = vec![
316-
Invoice {
317-
outcome: TransactionOutcome::Success,
318-
},
319-
Invoice {
320-
outcome: TransactionOutcome::Failed,
321-
},
322-
];
302+
let invoices = vec![Invoice::Success, Invoice::Failed];
323303
let parcel_invoices = ParcelInvoices {
324304
invoices,
325305
};

core/src/invoice.rs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,26 @@ use rlp::{Decodable, DecoderError, Encodable, RlpStream, UntrustedRlp};
1818

1919
/// Information describing execution of a parcel.
2020
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
21-
pub struct Invoice {
22-
/// Transaction outcome.
23-
pub outcome: TransactionOutcome,
24-
}
25-
26-
/// Transaction outcome store in the invoice.
27-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
28-
pub enum TransactionOutcome {
21+
pub enum Invoice {
2922
Success,
3023
Failed,
3124
}
3225

33-
impl Invoice {
34-
/// Create a new invocie.
35-
pub fn new(outcome: TransactionOutcome) -> Self {
36-
Self {
37-
outcome,
38-
}
39-
}
40-
}
41-
4226
impl Encodable for Invoice {
4327
fn rlp_append(&self, s: &mut RlpStream) {
44-
match self.outcome {
45-
TransactionOutcome::Success => s.append(&1u8),
46-
TransactionOutcome::Failed => s.append(&0u8),
28+
match self {
29+
Invoice::Success => s.append(&1u8),
30+
Invoice::Failed => s.append(&0u8),
4731
};
4832
}
4933
}
5034

5135
impl Decodable for Invoice {
5236
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
53-
let outcome = match rlp.as_val::<u8>()? {
54-
1 => TransactionOutcome::Success,
55-
0 => TransactionOutcome::Failed,
37+
Ok(match rlp.as_val::<u8>()? {
38+
1 => Invoice::Success,
39+
0 => Invoice::Failed,
5640
_ => return Err(DecoderError::Custom("Invalid parcel outcome")),
57-
};
58-
Ok(Self {
59-
outcome,
6041
})
6142
}
6243
}

core/src/state/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use trie::{self, Trie, TrieError, TrieFactory};
3232
use unexpected::Mismatch;
3333

3434
use self::cache::Cache;
35-
use super::invoice::{Invoice, TransactionOutcome};
35+
use super::invoice::Invoice;
3636
use super::parcel::ParcelError;
3737
use super::state_db::StateDB;
3838
use super::{Transaction, TransactionError};
@@ -535,7 +535,7 @@ impl<B: Backend> State<B> {
535535
Ok(_) => {
536536
cinfo!(TX, "Tx({}) is applied", t.hash());
537537
self.discard_checkpoint(TRANSACTION_CHECKPOINT);
538-
let invoice = Invoice::new(TransactionOutcome::Success);
538+
let invoice = Invoice::Success;
539539
let error = None;
540540
ApplyOutcome {
541541
invoice,
@@ -545,7 +545,7 @@ impl<B: Backend> State<B> {
545545
Err(Error::Transaction(err)) => {
546546
cinfo!(TX, "Cannot apply Tx({}): {:?}", t.hash(), err);
547547
self.revert_to_checkpoint(TRANSACTION_CHECKPOINT);
548-
let invoice = Invoice::new(TransactionOutcome::Failed);
548+
let invoice = Invoice::Failed;
549549
let error = Some(err);
550550
ApplyOutcome {
551551
invoice,
@@ -885,7 +885,7 @@ mod tests {
885885
let res = state.apply(&signed_parcel).unwrap();
886886
assert_eq!(1, res.len());
887887
let res = &res[0];
888-
assert_eq!(res.invoice.outcome, TransactionOutcome::Success);
888+
assert_eq!(res.invoice, Invoice::Success);
889889
assert!(res.error.is_none());
890890
assert_eq!(state.balance(&receiver).unwrap(), 10.into());
891891
assert_eq!(state.balance(&sender).unwrap(), 5.into());
@@ -918,7 +918,7 @@ mod tests {
918918
let res = state.apply(&signed_parcel).unwrap();
919919
assert_eq!(1, res.len());
920920
let res = &res[0];
921-
assert_eq!(res.invoice.outcome, TransactionOutcome::Success);
921+
assert_eq!(res.invoice, Invoice::Success);
922922
assert_eq!(state.regular_key(&sender).unwrap(), Some(key));
923923
}
924924

@@ -947,7 +947,7 @@ mod tests {
947947
let res = state.apply(&signed_parcel).unwrap();
948948
assert_eq!(1, res.len());
949949
let res = &res[0];
950-
assert_eq!(res.invoice.outcome, TransactionOutcome::Failed);
950+
assert_eq!(res.invoice, Invoice::Failed);
951951
assert_eq!(
952952
res.error.as_ref().unwrap(),
953953
&TransactionError::InsufficientBalance {

0 commit comments

Comments
 (0)