From e2d59f83f11507781273c5ecf56f91fc4e9af56f Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Tue, 8 Oct 2024 12:24:12 +0200 Subject: [PATCH] change operation's argument AccountIdentifier to &AccountIdentifier --- src/api/block.rs | 25 ++++++++++-------- src/api/search_transactions.rs | 47 +++++++++++++++------------------- src/operation.rs | 4 +-- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/api/block.rs b/src/api/block.rs index 22f8ec5..9f7cd49 100644 --- a/src/api/block.rs +++ b/src/api/block.rs @@ -207,12 +207,16 @@ pub struct ZkappAccountUpdateMetadata { } fn user_command_metadata_to_operations(metadata: &UserCommandMetadata) -> Vec { + let fee_payer_account_id = &AccountIdentifier::new(metadata.fee_payer.clone()); + let receiver_account_id = &AccountIdentifier::new(metadata.receiver.clone()); + let source_account_id = &AccountIdentifier::new(metadata.source.clone()); + let mut operations = Vec::new(); if metadata.fee != "0" { operations.push(operation( 0, Some(&metadata.fee), - AccountIdentifier::new(metadata.fee_payer.clone()), + fee_payer_account_id, OperationType::FeePayment, None, None, @@ -224,7 +228,7 @@ fn user_command_metadata_to_operations(metadata: &UserCommandMetadata) -> Vec Vec Vec Vec Vec Result, MinaMeshError> { + let receiver_account_id = &AccountIdentifier::new(metadata.receiver.clone()); let mut operations = Vec::new(); if let Some(creation_fee) = &metadata.creation_fee { operations.push(operation( 0, Some(creation_fee), - AccountIdentifier::new(metadata.receiver.clone()), + receiver_account_id, OperationType::AccountCreationFeeViaFeeReceiver, None, None, @@ -288,7 +293,7 @@ fn internal_command_metadata_to_operation(metadata: &InternalCommandMetadata) -> operations.push(operation( 2, Some(&metadata.fee), - AccountIdentifier::new(metadata.receiver.clone()), + receiver_account_id, OperationType::CoinbaseInc, None, None, @@ -299,7 +304,7 @@ fn internal_command_metadata_to_operation(metadata: &InternalCommandMetadata) -> operations.push(operation( 2, Some(&metadata.fee), - AccountIdentifier::new(metadata.receiver.clone()), + receiver_account_id, OperationType::FeeReceiverInc, None, None, @@ -311,7 +316,7 @@ fn internal_command_metadata_to_operation(metadata: &InternalCommandMetadata) -> operations.push(operation( 2, Some(&metadata.fee), - AccountIdentifier::new(metadata.receiver.clone()), + receiver_account_id, OperationType::FeeReceiverInc, None, None, @@ -320,7 +325,7 @@ fn internal_command_metadata_to_operation(metadata: &InternalCommandMetadata) -> operations.push(operation( 3, Some(&metadata.fee), - AccountIdentifier::new(coinbase_receiver.to_string()), + &AccountIdentifier::new(coinbase_receiver.to_string()), OperationType::FeePayerDec, None, None, diff --git a/src/api/search_transactions.rs b/src/api/search_transactions.rs index db1eb85..d057c53 100644 --- a/src/api/search_transactions.rs +++ b/src/api/search_transactions.rs @@ -52,6 +52,21 @@ impl UserCommand { pub fn into_block_transaction(self) -> BlockTransaction { let decoded_memo = self.decoded_memo().unwrap_or_default(); let amt = self.amount.clone().unwrap_or_else(|| "0".to_string()); + let receiver_account_id = &AccountIdentifier { + address: self.receiver.clone(), + metadata: Some(json!({ "token_id": DEFAULT_TOKEN_ID })), + sub_account: None, + }; + let source_account_id = &AccountIdentifier { + address: self.source, + metadata: Some(json!({ "token_id": DEFAULT_TOKEN_ID })), + sub_account: None, + }; + let fee_payer_account_id = &AccountIdentifier { + address: self.fee_payer, + metadata: Some(json!({ "token_id": DEFAULT_TOKEN_ID })), + sub_account: None, + }; let mut operations = Vec::new(); let mut operation_index = 0; @@ -60,11 +75,7 @@ impl UserCommand { operations.push(operation( operation_index, Some(&format!("-{}", self.fee.unwrap_or_else(|| "0".to_string()))), - AccountIdentifier { - address: self.fee_payer.clone(), - metadata: Some(json!({ "token_id": DEFAULT_TOKEN_ID })), - sub_account: None, - }, + fee_payer_account_id, OperationType::FeePayment, Some(&self.status), None, @@ -78,11 +89,7 @@ impl UserCommand { operations.push(operation( operation_index, Some(&format!("-{}", creation_fee)), - AccountIdentifier { - address: self.receiver.clone(), - metadata: Some(json!({ "token_id": DEFAULT_TOKEN_ID })), - sub_account: None, - }, + receiver_account_id, OperationType::AccountCreationFeeViaPayment, Some(&self.status), None, @@ -99,11 +106,7 @@ impl UserCommand { operations.push(operation( operation_index, Some(&format!("-{}", amt)), - AccountIdentifier { - address: self.source.clone(), - metadata: Some(json!({ "token_id": DEFAULT_TOKEN_ID })), - sub_account: None, - }, + source_account_id, OperationType::PaymentSourceDec, Some(&self.status), None, @@ -116,11 +119,7 @@ impl UserCommand { operations.push(operation( operation_index, Some(&amt), - AccountIdentifier { - address: self.receiver.clone(), - metadata: Some(json!({ "token_id": DEFAULT_TOKEN_ID })), - sub_account: None, - }, + receiver_account_id, OperationType::PaymentReceiverInc, Some(&self.status), Some(vec![operation_index - 1]), @@ -133,15 +132,11 @@ impl UserCommand { operations.push(operation( operation_index, None, - AccountIdentifier { - address: self.source.clone(), - metadata: Some(json!({ "token_id": DEFAULT_TOKEN_ID })), - sub_account: None, - }, + source_account_id, OperationType::DelegateChange, Some(&self.status), None, - Some(json!({ "delegate_change_target": self.receiver.clone() })), + Some(json!({ "delegate_change_target": self.receiver })), )); } } diff --git a/src/operation.rs b/src/operation.rs index a21a428..d56999e 100644 --- a/src/operation.rs +++ b/src/operation.rs @@ -6,7 +6,7 @@ use crate::{OperationStatus, OperationType, TransactionStatus}; pub fn operation( ident: i64, amount: Option<&String>, - account: AccountIdentifier, + account: &AccountIdentifier, operation_type: OperationType, status: Option<&TransactionStatus>, related_operations: Option>, @@ -15,7 +15,7 @@ pub fn operation( Operation { operation_identifier: Box::new(OperationIdentifier::new(ident)), amount: amount.map(|value| Box::new(Amount::new(value.to_owned(), Currency::new("MINA".to_string(), 9)))), - account: Some(Box::new(account)), + account: Some(Box::new(account.to_owned())), status: Some( status.map(|item| OperationStatus::from(item.to_owned())).unwrap_or(OperationStatus::Success).to_string(), ),