Skip to content

Commit e140ab3

Browse files
authored
fix: FeePayment conversion (#389)
1 parent e0f0992 commit e140ab3

File tree

5 files changed

+74
-18
lines changed

5 files changed

+74
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Next release
44

5+
- fix: FeePayment conversion
56
- fix(block_production): get l2-to-l1 messages recursively from the call tree
67
- refactor: replace starknet-rs BlockId with types-rs BlockId and remove redundant mp_block::BlockId
78
- feat(fgw): added `add_transaction` for gateway client

crates/client/sync/test-data/block_724130.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

crates/primitives/gateway/src/receipt.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use mp_receipt::{Event, L1Gas, MsgToL1};
44
use serde::{Deserialize, Serialize};
55
use starknet_types_core::felt::Felt;
66

7-
use crate::transaction::{DeployAccountTransaction, DeployTransaction, L1HandlerTransaction, Transaction};
7+
use crate::transaction::{
8+
DeclareTransaction, DeployAccountTransaction, DeployTransaction, InvokeTransaction, L1HandlerTransaction,
9+
Transaction,
10+
};
811

912
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
1013
#[serde(deny_unknown_fields)]
@@ -49,20 +52,20 @@ impl ConfirmedReceipt {
4952

5053
pub fn into_mp(self, tx: &Transaction) -> mp_receipt::TransactionReceipt {
5154
match tx {
52-
Transaction::Invoke(_) => mp_receipt::TransactionReceipt::Invoke(self.into_mp_invoke()),
55+
Transaction::Invoke(tx) => mp_receipt::TransactionReceipt::Invoke(self.into_mp_invoke(tx)),
5356
Transaction::L1Handler(tx) => mp_receipt::TransactionReceipt::L1Handler(self.into_mp_l1_handler(tx)),
54-
Transaction::Declare(_) => mp_receipt::TransactionReceipt::Declare(self.into_mp_declare()),
57+
Transaction::Declare(tx) => mp_receipt::TransactionReceipt::Declare(self.into_mp_declare(tx)),
5558
Transaction::Deploy(tx) => mp_receipt::TransactionReceipt::Deploy(self.into_mp_deploy(tx)),
5659
Transaction::DeployAccount(tx) => {
5760
mp_receipt::TransactionReceipt::DeployAccount(self.into_mp_deploy_account(tx))
5861
}
5962
}
6063
}
6164

62-
fn into_mp_invoke(self) -> mp_receipt::InvokeTransactionReceipt {
65+
fn into_mp_invoke(self, tx: &InvokeTransaction) -> mp_receipt::InvokeTransactionReceipt {
6366
mp_receipt::InvokeTransactionReceipt {
6467
transaction_hash: self.transaction_hash,
65-
actual_fee: self.actual_fee.into(),
68+
actual_fee: fee_payment(self.actual_fee, tx.version()),
6669
messages_sent: self.l2_to_l1_messages,
6770
events: self.events,
6871
execution_resources: self.execution_resources.into(),
@@ -86,18 +89,18 @@ impl ConfirmedReceipt {
8689
mp_receipt::L1HandlerTransactionReceipt {
8790
message_hash: message_hash.try_into().unwrap_or_default(),
8891
transaction_hash: self.transaction_hash,
89-
actual_fee: self.actual_fee.into(),
92+
actual_fee: fee_payment(self.actual_fee, tx.version()),
9093
messages_sent: self.l2_to_l1_messages,
9194
events: self.events,
9295
execution_resources: self.execution_resources.into(),
9396
execution_result: execution_result(self.execution_status, self.revert_error),
9497
}
9598
}
9699

97-
fn into_mp_declare(self) -> mp_receipt::DeclareTransactionReceipt {
100+
fn into_mp_declare(self, tx: &DeclareTransaction) -> mp_receipt::DeclareTransactionReceipt {
98101
mp_receipt::DeclareTransactionReceipt {
99102
transaction_hash: self.transaction_hash,
100-
actual_fee: self.actual_fee.into(),
103+
actual_fee: fee_payment(self.actual_fee, tx.version()),
101104
messages_sent: self.l2_to_l1_messages,
102105
events: self.events,
103106
execution_resources: self.execution_resources.into(),
@@ -108,7 +111,7 @@ impl ConfirmedReceipt {
108111
fn into_mp_deploy(self, tx: &DeployTransaction) -> mp_receipt::DeployTransactionReceipt {
109112
mp_receipt::DeployTransactionReceipt {
110113
transaction_hash: self.transaction_hash,
111-
actual_fee: self.actual_fee.into(),
114+
actual_fee: fee_payment(self.actual_fee, tx.version()),
112115
messages_sent: self.l2_to_l1_messages,
113116
events: self.events,
114117
execution_resources: self.execution_resources.into(),
@@ -120,7 +123,7 @@ impl ConfirmedReceipt {
120123
fn into_mp_deploy_account(self, tx: &DeployAccountTransaction) -> mp_receipt::DeployAccountTransactionReceipt {
121124
mp_receipt::DeployAccountTransactionReceipt {
122125
transaction_hash: self.transaction_hash,
123-
actual_fee: self.actual_fee.into(),
126+
actual_fee: fee_payment(self.actual_fee, tx.version()),
124127
messages_sent: self.l2_to_l1_messages,
125128
events: self.events,
126129
execution_resources: self.execution_resources.into(),
@@ -290,3 +293,10 @@ pub enum ExecutionStatus {
290293
Succeeded,
291294
Reverted,
292295
}
296+
297+
fn fee_payment(fee: Felt, tx_version: u8) -> mp_receipt::FeePayment {
298+
mp_receipt::FeePayment {
299+
amount: fee,
300+
unit: if tx_version < 3 { mp_receipt::PriceUnit::Wei } else { mp_receipt::PriceUnit::Fri },
301+
}
302+
}

crates/primitives/gateway/src/transaction.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ impl Transaction {
8080
}
8181
}
8282
}
83+
84+
pub fn version(&self) -> u8 {
85+
match self {
86+
Transaction::Invoke(tx) => tx.version(),
87+
Transaction::L1Handler(tx) => tx.version(),
88+
Transaction::Declare(tx) => tx.version(),
89+
Transaction::Deploy(tx) => tx.version(),
90+
Transaction::DeployAccount(tx) => tx.version(),
91+
}
92+
}
8393
}
8494

8595
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@@ -94,6 +104,16 @@ pub enum InvokeTransaction {
94104
V3(InvokeTransactionV3),
95105
}
96106

107+
impl InvokeTransaction {
108+
pub fn version(&self) -> u8 {
109+
match self {
110+
InvokeTransaction::V0(_) => 0,
111+
InvokeTransaction::V1(_) => 1,
112+
InvokeTransaction::V3(_) => 3,
113+
}
114+
}
115+
}
116+
97117
impl From<InvokeTransaction> for mp_transactions::InvokeTransaction {
98118
fn from(tx: InvokeTransaction) -> Self {
99119
match tx {
@@ -242,6 +262,12 @@ pub struct L1HandlerTransaction {
242262
pub version: Felt,
243263
}
244264

265+
impl L1HandlerTransaction {
266+
pub fn version(&self) -> u8 {
267+
0
268+
}
269+
}
270+
245271
impl L1HandlerTransaction {
246272
pub fn new(transaction: mp_transactions::L1HandlerTransaction, hash: Felt) -> Self {
247273
Self {
@@ -281,6 +307,17 @@ pub enum DeclareTransaction {
281307
V3(DeclareTransactionV3),
282308
}
283309

310+
impl DeclareTransaction {
311+
pub fn version(&self) -> u8 {
312+
match self {
313+
DeclareTransaction::V0(_) => 0,
314+
DeclareTransaction::V1(_) => 1,
315+
DeclareTransaction::V2(_) => 2,
316+
DeclareTransaction::V3(_) => 3,
317+
}
318+
}
319+
}
320+
284321
impl From<DeclareTransaction> for mp_transactions::DeclareTransaction {
285322
fn from(tx: DeclareTransaction) -> Self {
286323
match tx {
@@ -474,6 +511,12 @@ pub struct DeployTransaction {
474511
pub version: Felt,
475512
}
476513

514+
impl DeployTransaction {
515+
pub fn version(&self) -> u8 {
516+
0
517+
}
518+
}
519+
477520
impl DeployTransaction {
478521
pub fn new(transaction: mp_transactions::DeployTransaction, hash: Felt, contract_address: Felt) -> Self {
479522
Self {
@@ -506,6 +549,15 @@ pub enum DeployAccountTransaction {
506549
V3(DeployAccountTransactionV3),
507550
}
508551

552+
impl DeployAccountTransaction {
553+
pub fn version(&self) -> u8 {
554+
match self {
555+
DeployAccountTransaction::V1(_) => 1,
556+
DeployAccountTransaction::V3(_) => 3,
557+
}
558+
}
559+
}
560+
509561
impl From<DeployAccountTransaction> for mp_transactions::DeployAccountTransaction {
510562
fn from(tx: DeployAccountTransaction) -> Self {
511563
match tx {

crates/primitives/receipt/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,6 @@ pub struct FeePayment {
226226
pub unit: PriceUnit,
227227
}
228228

229-
// FIXME: this conversion is outdated with transaction V3, see https://github.com/madara-alliance/madara/issues/385
230-
impl From<Felt> for FeePayment {
231-
fn from(fee: Felt) -> Self {
232-
Self { amount: fee, unit: PriceUnit::Wei }
233-
}
234-
}
235-
236229
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
237230
pub enum PriceUnit {
238231
#[default]

0 commit comments

Comments
 (0)