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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use js_export_macro::js_export;
use miden_client::transaction::TransactionRecord as NativeTransactionRecord;
use super::account_id::AccountId;
use super::output_notes::OutputNotes;
use super::transaction_id::TransactionId;
use super::transaction_status::TransactionStatus;
use super::word::Word;
/// Describes a transaction that has been executed and is being tracked on the Client.
#[derive(Clone)]
#[js_export]
pub struct TransactionRecord(NativeTransactionRecord);
#[js_export]
impl TransactionRecord {
/// Returns the transaction ID.
pub fn id(&self) -> TransactionId {
self.0.id.into()
}
/// Returns the account this transaction was executed against.
#[js_export(js_name = "accountId")]
pub fn account_id(&self) -> AccountId {
self.0.details.account_id.into()
}
/// Returns the initial account state commitment before execution.
#[js_export(js_name = "initAccountState")]
pub fn init_account_state(&self) -> Word {
self.0.details.init_account_state.into()
}
/// Returns the final account state commitment after execution.
#[js_export(js_name = "finalAccountState")]
pub fn final_account_state(&self) -> Word {
self.0.details.final_account_state.into()
}
/// Returns the nullifiers of the consumed input notes.
#[js_export(js_name = "inputNoteNullifiers")]
pub fn input_note_nullifiers(&self) -> Vec<Word> {
self.0.details.input_note_nullifiers.iter().map(Into::into).collect()
}
/// Returns the output notes created by this transaction.
///
/// NOTE: this includes the kernel's `TX_FEE` note on any chain whose `verification_base_fee` is
/// non-zero, because the fee the account pays is itself an output note. Callers that index or
/// count this list should expect one more note than they created.
///
/// The split `ExecutedTransaction` offers through `feeNote` and `userOutputNotes` is not
/// available here: a record is read back from the store, and the fee script's root is not
/// exposed to JS, so there is nothing to compare against. `ExecutedTransaction` — returned at
/// execution time — is the only supported source of the split.
#[js_export(js_name = "outputNotes")]
pub fn output_notes(&self) -> OutputNotes {
self.0.details.output_notes.clone().into()
}
// pub fn transaction_script(&self) -> Option<TransactionScript> {
// self.0.transaction_script.map(|script| script.into())
// }
/// Returns the block height in which the transaction was included.
#[js_export(js_name = "blockNum")]
pub fn block_num(&self) -> u32 {
self.0.details.block_num.as_u32()
}
/// Returns the block height at which the transaction was submitted.
#[js_export(js_name = "submissionHeight")]
pub fn submission_height(&self) -> u32 {
self.0.details.submission_height.as_u32()
}
/// Returns the expiration block height for the transaction.
#[js_export(js_name = "expirationBlockNum")]
pub fn expiration_block_num(&self) -> u32 {
self.0.details.expiration_block_num.as_u32()
}
/// Returns the current status of the transaction.
#[js_export(js_name = "transactionStatus")]
pub fn transaction_status(&self) -> TransactionStatus {
self.0.status.clone().into()
}
/// Returns the timestamp when the record was created.
#[js_export(js_name = "creationTimestamp")]
pub fn creation_timestamp(&self) -> u64 {
self.0.details.creation_timestamp
}
}
// CONVERSIONS
// ================================================================================================
impl From<NativeTransactionRecord> for TransactionRecord {
fn from(native_record: NativeTransactionRecord) -> Self {
TransactionRecord(native_record)
}
}
impl From<&NativeTransactionRecord> for TransactionRecord {
fn from(native_record: &NativeTransactionRecord) -> Self {
TransactionRecord(native_record.clone())
}
}