Skip to content

Commit a2a1e83

Browse files
authored
feat: interpret tx as pending conditionally (#425)
In the upcoming Starknet version 0.12.0, the `PENDING` transaction status will be removed. However, transactions can still live in a pending block, and hence not have a block hash. Per JSON-RPC specs transactions that do not have a block hash shall still be considered `PENDING`.
1 parent fad9f23 commit a2a1e83

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

starknet-providers/src/sequencer/models/conversions.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,20 @@ impl TryFrom<TransactionWithReceipt> for core::MaybePendingTransactionReceipt {
361361
// The caller should have directly returned a tx not found error instead in these cases
362362
TransactionStatus::NotReceived | TransactionStatus::Received => Err(ConversionError),
363363
TransactionStatus::Pending => Ok(Self::PendingReceipt(value.try_into()?)),
364-
TransactionStatus::Rejected
365-
| TransactionStatus::AcceptedOnL2
366-
| TransactionStatus::AcceptedOnL1 => Ok(Self::Receipt(value.try_into()?)),
364+
// Starting from Starknet v0.12.0 transactions no longer have a `PENDING` state.
365+
// Transactions with `AcceptedOnL2` can live in a pending block and thus not have block
366+
// hash. The JSON-RPC side requires `block_hash` to be present so we can only interpret
367+
// it as pending if `block_hash` is missing.
368+
TransactionStatus::AcceptedOnL2 => {
369+
if value.receipt.block_hash.is_some() {
370+
Ok(Self::Receipt(value.try_into()?))
371+
} else {
372+
Ok(Self::PendingReceipt(value.try_into()?))
373+
}
374+
}
375+
TransactionStatus::Rejected | TransactionStatus::AcceptedOnL1 => {
376+
Ok(Self::Receipt(value.try_into()?))
377+
}
367378
}
368379
}
369380
}

0 commit comments

Comments
 (0)