Skip to content

Commit

Permalink
change operation's argument AccountIdentifier to &AccountIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-iohk committed Oct 8, 2024
1 parent 650b988 commit e2d59f8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
25 changes: 15 additions & 10 deletions src/api/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,16 @@ pub struct ZkappAccountUpdateMetadata {
}

fn user_command_metadata_to_operations(metadata: &UserCommandMetadata) -> Vec<Operation> {
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,
Expand All @@ -224,7 +228,7 @@ fn user_command_metadata_to_operations(metadata: &UserCommandMetadata) -> Vec<Op
operations.push(operation(
1,
Some(creation_fee),
AccountIdentifier::new(metadata.receiver.clone()),
receiver_account_id,
OperationType::AccountCreationFeeViaPayment,
Some(&metadata.status),
None,
Expand All @@ -236,7 +240,7 @@ fn user_command_metadata_to_operations(metadata: &UserCommandMetadata) -> Vec<Op
operations.push(operation(
2,
None,
AccountIdentifier::new(metadata.source.clone()),
source_account_id,
OperationType::DelegateChange,
Some(&metadata.status),
None,
Expand All @@ -248,7 +252,7 @@ fn user_command_metadata_to_operations(metadata: &UserCommandMetadata) -> Vec<Op
operation(
2,
metadata.amount.as_ref(),
AccountIdentifier::new(metadata.source.clone()),
source_account_id,
OperationType::PaymentSourceDec,
Some(&metadata.status),
None,
Expand All @@ -257,7 +261,7 @@ fn user_command_metadata_to_operations(metadata: &UserCommandMetadata) -> Vec<Op
operation(
3,
metadata.amount.as_ref(),
AccountIdentifier::new(metadata.receiver.clone()),
receiver_account_id,
OperationType::PaymentReceiverInc,
Some(&metadata.status),
None,
Expand All @@ -271,12 +275,13 @@ fn user_command_metadata_to_operations(metadata: &UserCommandMetadata) -> Vec<Op
}

fn internal_command_metadata_to_operation(metadata: &InternalCommandMetadata) -> Result<Vec<Operation>, 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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
47 changes: 21 additions & 26 deletions src/api/search_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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]),
Expand All @@ -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 })),
));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<i64>>,
Expand All @@ -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(),
),
Expand Down

0 comments on commit e2d59f8

Please sign in to comment.