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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

#![forbid(unsafe_code)]

mod account_resource;
mod auto_validate;
pub mod command;
mod governance;
pub mod keys;
mod owner;
mod print;
pub mod rest_client;
mod validate_transaction;
mod validator_config;
mod validator_set;
mod validator_state;

mod network_checker;
#[cfg(any(test, feature = "testing"))]
pub mod test_helper;

use aptos_types::account_address::AccountAddress;
use serde::Serialize;

/// Information for validating a transaction after it's been submitted, or
/// retrieving the execution result.
#[derive(Debug, PartialEq, Serialize)]
pub struct TransactionContext {
    pub address: AccountAddress,
    pub sequence_number: u64,

    // The execution result of the transaction if it has already been validated
    // successfully.
    pub execution_result: Option<TransactionStatus>,
}

#[derive(Debug, PartialEq, Serialize)]
pub struct TransactionStatus {
    pub message: String,
    pub success: bool,
}

impl TransactionStatus {
    pub fn new(message: String, success: bool) -> Self {
        Self { message, success }
    }
}

impl TransactionContext {
    pub fn new(address: AccountAddress, sequence_number: u64) -> TransactionContext {
        TransactionContext::new_with_validation(address, sequence_number, None)
    }

    pub fn new_with_validation(
        address: AccountAddress,
        sequence_number: u64,
        execution_result: Option<TransactionStatus>,
    ) -> TransactionContext {
        TransactionContext {
            address,
            sequence_number,
            execution_result,
        }
    }
}