Skip to content

Commit 30ad28a

Browse files
committed
Ledger/transaction_logic: extract signed_command module to separate file
Extract the signed_command module from transaction_logic/mod.rs into its own file. This module contains signed command types including payment and stake delegation. Changes: - Extract signed_command module to transaction_logic/signed_command.rs - Use explicit imports instead of 'use super::*' - Update mod.rs to reference the new module file
1 parent 499f29b commit 30ad28a

File tree

2 files changed

+216
-210
lines changed

2 files changed

+216
-210
lines changed

ledger/src/scan_state/transaction_logic/mod.rs

Lines changed: 1 addition & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -605,216 +605,7 @@ impl Memo {
605605
}
606606
}
607607

608-
pub mod signed_command {
609-
use mina_p2p_messages::v2::MinaBaseSignedCommandStableV2;
610-
use mina_signer::Signature;
611-
612-
use crate::decompress_pk;
613-
614-
use super::*;
615-
616-
/// <https://github.com/MinaProtocol/mina/blob/2ee6e004ba8c6a0541056076aab22ea162f7eb3a/src/lib/mina_base/signed_command_payload.ml#L75>
617-
#[derive(Debug, Clone, PartialEq)]
618-
pub struct Common {
619-
pub fee: Fee,
620-
pub fee_payer_pk: CompressedPubKey,
621-
pub nonce: Nonce,
622-
pub valid_until: Slot,
623-
pub memo: Memo,
624-
}
625-
626-
#[derive(Debug, Clone, PartialEq, Eq)]
627-
pub struct PaymentPayload {
628-
pub receiver_pk: CompressedPubKey,
629-
pub amount: Amount,
630-
}
631-
632-
/// <https://github.com/MinaProtocol/mina/blob/bfd1009abdbee78979ff0343cc73a3480e862f58/src/lib/mina_base/stake_delegation.ml#L11>
633-
#[derive(Debug, Clone, PartialEq, Eq)]
634-
pub enum StakeDelegationPayload {
635-
SetDelegate { new_delegate: CompressedPubKey },
636-
}
637-
638-
impl StakeDelegationPayload {
639-
/// <https://github.com/MinaProtocol/mina/blob/bfd1009abdbee78979ff0343cc73a3480e862f58/src/lib/mina_base/stake_delegation.ml#L35>
640-
pub fn receiver(&self) -> AccountId {
641-
let Self::SetDelegate { new_delegate } = self;
642-
AccountId::new(new_delegate.clone(), TokenId::default())
643-
}
644-
645-
/// <https://github.com/MinaProtocol/mina/blob/bfd1009abdbee78979ff0343cc73a3480e862f58/src/lib/mina_base/stake_delegation.ml#L33>
646-
pub fn receiver_pk(&self) -> &CompressedPubKey {
647-
let Self::SetDelegate { new_delegate } = self;
648-
new_delegate
649-
}
650-
}
651-
652-
/// <https://github.com/MinaProtocol/mina/blob/2ee6e004ba8c6a0541056076aab22ea162f7eb3a/src/lib/mina_base/signed_command_payload.mli#L24>
653-
#[derive(Debug, Clone, PartialEq, Eq)]
654-
pub enum Body {
655-
Payment(PaymentPayload),
656-
StakeDelegation(StakeDelegationPayload),
657-
}
658-
659-
/// <https://github.com/MinaProtocol/mina/blob/2ee6e004ba8c6a0541056076aab22ea162f7eb3a/src/lib/mina_base/signed_command_payload.mli#L165>
660-
#[derive(Debug, Clone, PartialEq)]
661-
pub struct SignedCommandPayload {
662-
pub common: Common,
663-
pub body: Body,
664-
}
665-
666-
impl SignedCommandPayload {
667-
pub fn create(
668-
fee: Fee,
669-
fee_payer_pk: CompressedPubKey,
670-
nonce: Nonce,
671-
valid_until: Option<Slot>,
672-
memo: Memo,
673-
body: Body,
674-
) -> Self {
675-
Self {
676-
common: Common {
677-
fee,
678-
fee_payer_pk,
679-
nonce,
680-
valid_until: valid_until.unwrap_or_else(Slot::max),
681-
memo,
682-
},
683-
body,
684-
}
685-
}
686-
}
687-
688-
/// <https://github.com/MinaProtocol/mina/blob/1551e2faaa246c01636908aabe5f7981715a10f4/src/lib/mina_base/signed_command_payload.ml#L362>
689-
mod weight {
690-
use super::*;
691-
692-
fn payment(_: &PaymentPayload) -> u64 {
693-
1
694-
}
695-
fn stake_delegation(_: &StakeDelegationPayload) -> u64 {
696-
1
697-
}
698-
pub fn of_body(body: &Body) -> u64 {
699-
match body {
700-
Body::Payment(p) => payment(p),
701-
Body::StakeDelegation(s) => stake_delegation(s),
702-
}
703-
}
704-
}
705-
706-
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
707-
#[serde(into = "MinaBaseSignedCommandStableV2")]
708-
#[serde(try_from = "MinaBaseSignedCommandStableV2")]
709-
pub struct SignedCommand {
710-
pub payload: SignedCommandPayload,
711-
pub signer: CompressedPubKey, // TODO: This should be a `mina_signer::PubKey`
712-
pub signature: Signature,
713-
}
714-
715-
impl SignedCommand {
716-
pub fn valid_until(&self) -> Slot {
717-
self.payload.common.valid_until
718-
}
719-
720-
/// <https://github.com/MinaProtocol/mina/blob/2ee6e004ba8c6a0541056076aab22ea162f7eb3a/src/lib/mina_base/signed_command_payload.ml#L322>
721-
pub fn fee_payer(&self) -> AccountId {
722-
let public_key = self.payload.common.fee_payer_pk.clone();
723-
AccountId::new(public_key, TokenId::default())
724-
}
725-
726-
/// <https://github.com/MinaProtocol/mina/blob/2ee6e004ba8c6a0541056076aab22ea162f7eb3a/src/lib/mina_base/signed_command_payload.ml#L320>
727-
pub fn fee_payer_pk(&self) -> &CompressedPubKey {
728-
&self.payload.common.fee_payer_pk
729-
}
730-
731-
pub fn weight(&self) -> u64 {
732-
let Self {
733-
payload: SignedCommandPayload { common: _, body },
734-
signer: _,
735-
signature: _,
736-
} = self;
737-
weight::of_body(body)
738-
}
739-
740-
/// <https://github.com/MinaProtocol/mina/blob/2ee6e004ba8c6a0541056076aab22ea162f7eb3a/src/lib/mina_base/signed_command_payload.ml#L318>
741-
pub fn fee_token(&self) -> TokenId {
742-
TokenId::default()
743-
}
744-
745-
pub fn fee(&self) -> Fee {
746-
self.payload.common.fee
747-
}
748-
749-
/// <https://github.com/MinaProtocol/mina/blob/05c2f73d0f6e4f1341286843814ce02dcb3919e0/src/lib/mina_base/signed_command_payload.ml#L250>
750-
pub fn receiver(&self) -> AccountId {
751-
match &self.payload.body {
752-
Body::Payment(payload) => {
753-
AccountId::new(payload.receiver_pk.clone(), TokenId::default())
754-
}
755-
Body::StakeDelegation(payload) => payload.receiver(),
756-
}
757-
}
758-
759-
/// <https://github.com/MinaProtocol/mina/blob/05c2f73d0f6e4f1341286843814ce02dcb3919e0/src/lib/mina_base/signed_command_payload.ml#L234>
760-
pub fn receiver_pk(&self) -> &CompressedPubKey {
761-
match &self.payload.body {
762-
Body::Payment(payload) => &payload.receiver_pk,
763-
Body::StakeDelegation(payload) => payload.receiver_pk(),
764-
}
765-
}
766-
767-
pub fn amount(&self) -> Option<Amount> {
768-
match &self.payload.body {
769-
Body::Payment(payload) => Some(payload.amount),
770-
Body::StakeDelegation(_) => None,
771-
}
772-
}
773-
774-
pub fn nonce(&self) -> Nonce {
775-
self.payload.common.nonce
776-
}
777-
778-
pub fn fee_excess(&self) -> FeeExcess {
779-
FeeExcess::of_single((self.fee_token(), Signed::<Fee>::of_unsigned(self.fee())))
780-
}
781-
782-
/// <https://github.com/MinaProtocol/mina/blob/802634fdda92f5cba106fd5f98bd0037c4ec14be/src/lib/mina_base/signed_command_payload.ml#L322>
783-
pub fn account_access_statuses(
784-
&self,
785-
status: &TransactionStatus,
786-
) -> Vec<(AccountId, AccessedOrNot)> {
787-
use AccessedOrNot::*;
788-
use TransactionStatus::*;
789-
790-
match status {
791-
Applied => vec![(self.fee_payer(), Accessed), (self.receiver(), Accessed)],
792-
// Note: The fee payer is always accessed, even if the transaction fails
793-
// <https://github.com/MinaProtocol/mina/blob/802634fdda92f5cba106fd5f98bd0037c4ec14be/src/lib/mina_base/signed_command_payload.mli#L205>
794-
Failed(_) => vec![(self.fee_payer(), Accessed), (self.receiver(), NotAccessed)],
795-
}
796-
}
797-
798-
pub fn accounts_referenced(&self) -> Vec<AccountId> {
799-
self.account_access_statuses(&TransactionStatus::Applied)
800-
.into_iter()
801-
.map(|(id, _status)| id)
802-
.collect()
803-
}
804-
805-
/// <https://github.com/MinaProtocol/mina/blob/05c2f73d0f6e4f1341286843814ce02dcb3919e0/src/lib/mina_base/signed_command.ml#L401>
806-
pub fn public_keys(&self) -> [&CompressedPubKey; 2] {
807-
[self.fee_payer_pk(), self.receiver_pk()]
808-
}
809-
810-
/// <https://github.com/MinaProtocol/mina/blob/05c2f73d0f6e4f1341286843814ce02dcb3919e0/src/lib/mina_base/signed_command.ml#L407>
811-
pub fn check_valid_keys(&self) -> bool {
812-
self.public_keys()
813-
.into_iter()
814-
.all(|pk| decompress_pk(pk).is_some())
815-
}
816-
}
817-
}
608+
pub mod signed_command;
818609

819610
pub mod zkapp_command {
820611
use std::sync::Arc;

0 commit comments

Comments
 (0)