Skip to content

Commit a20e889

Browse files
committed
Ledger/transaction_logic: extract valid module to separate file
Convert transaction_logic.rs into a directory with mod.rs and extract the valid module into valid.rs. This is the first step in splitting the large transaction_logic module into smaller, more manageable files. Changes: - Rename transaction_logic.rs to transaction_logic/mod.rs - Extract valid module to transaction_logic/valid.rs - Use explicit imports in valid.rs instead of 'use super::*'
1 parent 9e54a39 commit a20e889

File tree

2 files changed

+98
-92
lines changed

2 files changed

+98
-92
lines changed

ledger/src/scan_state/transaction_logic.rs renamed to ledger/src/scan_state/transaction_logic/mod.rs

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -253,98 +253,7 @@ where
253253
}
254254
}
255255

256-
pub mod valid {
257-
use super::*;
258-
259-
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
260-
pub struct VerificationKeyHash(pub Fp);
261-
262-
pub type SignedCommand = super::signed_command::SignedCommand;
263-
264-
use serde::{Deserialize, Serialize};
265-
266-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
267-
#[serde(into = "MinaBaseUserCommandStableV2")]
268-
#[serde(try_from = "MinaBaseUserCommandStableV2")]
269-
pub enum UserCommand {
270-
SignedCommand(Box<SignedCommand>),
271-
ZkAppCommand(Box<super::zkapp_command::valid::ZkAppCommand>),
272-
}
273-
274-
impl UserCommand {
275-
/// <https://github.com/MinaProtocol/mina/blob/05c2f73d0f6e4f1341286843814ce02dcb3919e0/src/lib/mina_base/user_command.ml#L277>
276-
pub fn forget_check(&self) -> super::UserCommand {
277-
match self {
278-
UserCommand::SignedCommand(cmd) => super::UserCommand::SignedCommand(cmd.clone()),
279-
UserCommand::ZkAppCommand(cmd) => {
280-
super::UserCommand::ZkAppCommand(Box::new(cmd.zkapp_command.clone()))
281-
}
282-
}
283-
}
284-
285-
pub fn fee_payer(&self) -> AccountId {
286-
match self {
287-
UserCommand::SignedCommand(cmd) => cmd.fee_payer(),
288-
UserCommand::ZkAppCommand(cmd) => cmd.zkapp_command.fee_payer(),
289-
}
290-
}
291-
292-
pub fn nonce(&self) -> Option<Nonce> {
293-
match self {
294-
UserCommand::SignedCommand(cmd) => Some(cmd.nonce()),
295-
UserCommand::ZkAppCommand(_) => None,
296-
}
297-
}
298-
}
299-
300-
impl GenericCommand for UserCommand {
301-
fn fee(&self) -> Fee {
302-
match self {
303-
UserCommand::SignedCommand(cmd) => cmd.fee(),
304-
UserCommand::ZkAppCommand(cmd) => cmd.zkapp_command.fee(),
305-
}
306-
}
307-
308-
fn forget(&self) -> super::UserCommand {
309-
match self {
310-
UserCommand::SignedCommand(cmd) => super::UserCommand::SignedCommand(cmd.clone()),
311-
UserCommand::ZkAppCommand(cmd) => {
312-
super::UserCommand::ZkAppCommand(Box::new(cmd.zkapp_command.clone()))
313-
}
314-
}
315-
}
316-
}
317-
318-
impl GenericTransaction for Transaction {
319-
fn is_fee_transfer(&self) -> bool {
320-
matches!(self, Transaction::FeeTransfer(_))
321-
}
322-
fn is_coinbase(&self) -> bool {
323-
matches!(self, Transaction::Coinbase(_))
324-
}
325-
fn is_command(&self) -> bool {
326-
matches!(self, Transaction::Command(_))
327-
}
328-
}
329-
330-
#[derive(Debug, derive_more::From)]
331-
pub enum Transaction {
332-
Command(UserCommand),
333-
FeeTransfer(super::FeeTransfer),
334-
Coinbase(super::Coinbase),
335-
}
336-
337-
impl Transaction {
338-
/// <https://github.com/MinaProtocol/mina/blob/05c2f73d0f6e4f1341286843814ce02dcb3919e0/src/lib/transaction/transaction.ml#L61>
339-
pub fn forget(&self) -> super::Transaction {
340-
match self {
341-
Transaction::Command(cmd) => super::Transaction::Command(cmd.forget_check()),
342-
Transaction::FeeTransfer(ft) => super::Transaction::FeeTransfer(ft.clone()),
343-
Transaction::Coinbase(cb) => super::Transaction::Coinbase(cb.clone()),
344-
}
345-
}
346-
}
347-
}
256+
pub mod valid;
348257

349258
/// <https://github.com/MinaProtocol/mina/blob/2ee6e004ba8c6a0541056076aab22ea162f7eb3a/src/lib/mina_base/fee_transfer.ml#L19>
350259
#[derive(Debug, Clone, PartialEq)]
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
use mina_hasher::Fp;
2+
use mina_p2p_messages::v2::MinaBaseUserCommandStableV2;
3+
use serde::{Deserialize, Serialize};
4+
5+
use crate::{
6+
scan_state::currency::{Fee, Nonce},
7+
AccountId,
8+
};
9+
10+
use super::{GenericCommand, GenericTransaction};
11+
12+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
13+
pub struct VerificationKeyHash(pub Fp);
14+
15+
pub type SignedCommand = super::signed_command::SignedCommand;
16+
17+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
18+
#[serde(into = "MinaBaseUserCommandStableV2")]
19+
#[serde(try_from = "MinaBaseUserCommandStableV2")]
20+
pub enum UserCommand {
21+
SignedCommand(Box<SignedCommand>),
22+
ZkAppCommand(Box<super::zkapp_command::valid::ZkAppCommand>),
23+
}
24+
25+
impl UserCommand {
26+
/// <https://github.com/MinaProtocol/mina/blob/05c2f73d0f6e4f1341286843814ce02dcb3919e0/src/lib/mina_base/user_command.ml#L277>
27+
pub fn forget_check(&self) -> super::UserCommand {
28+
match self {
29+
UserCommand::SignedCommand(cmd) => super::UserCommand::SignedCommand(cmd.clone()),
30+
UserCommand::ZkAppCommand(cmd) => {
31+
super::UserCommand::ZkAppCommand(Box::new(cmd.zkapp_command.clone()))
32+
}
33+
}
34+
}
35+
36+
pub fn fee_payer(&self) -> AccountId {
37+
match self {
38+
UserCommand::SignedCommand(cmd) => cmd.fee_payer(),
39+
UserCommand::ZkAppCommand(cmd) => cmd.zkapp_command.fee_payer(),
40+
}
41+
}
42+
43+
pub fn nonce(&self) -> Option<Nonce> {
44+
match self {
45+
UserCommand::SignedCommand(cmd) => Some(cmd.nonce()),
46+
UserCommand::ZkAppCommand(_) => None,
47+
}
48+
}
49+
}
50+
51+
impl GenericCommand for UserCommand {
52+
fn fee(&self) -> Fee {
53+
match self {
54+
UserCommand::SignedCommand(cmd) => cmd.fee(),
55+
UserCommand::ZkAppCommand(cmd) => cmd.zkapp_command.fee(),
56+
}
57+
}
58+
59+
fn forget(&self) -> super::UserCommand {
60+
match self {
61+
UserCommand::SignedCommand(cmd) => super::UserCommand::SignedCommand(cmd.clone()),
62+
UserCommand::ZkAppCommand(cmd) => {
63+
super::UserCommand::ZkAppCommand(Box::new(cmd.zkapp_command.clone()))
64+
}
65+
}
66+
}
67+
}
68+
69+
impl GenericTransaction for Transaction {
70+
fn is_fee_transfer(&self) -> bool {
71+
matches!(self, Transaction::FeeTransfer(_))
72+
}
73+
fn is_coinbase(&self) -> bool {
74+
matches!(self, Transaction::Coinbase(_))
75+
}
76+
fn is_command(&self) -> bool {
77+
matches!(self, Transaction::Command(_))
78+
}
79+
}
80+
81+
#[derive(Debug, derive_more::From)]
82+
pub enum Transaction {
83+
Command(UserCommand),
84+
FeeTransfer(super::FeeTransfer),
85+
Coinbase(super::Coinbase),
86+
}
87+
88+
impl Transaction {
89+
/// <https://github.com/MinaProtocol/mina/blob/05c2f73d0f6e4f1341286843814ce02dcb3919e0/src/lib/transaction/transaction.ml#L61>
90+
pub fn forget(&self) -> super::Transaction {
91+
match self {
92+
Transaction::Command(cmd) => super::Transaction::Command(cmd.forget_check()),
93+
Transaction::FeeTransfer(ft) => super::Transaction::FeeTransfer(ft.clone()),
94+
Transaction::Coinbase(cb) => super::Transaction::Coinbase(cb.clone()),
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)