-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rpc/v0.7):
get_block_with_receipts
stub
- Loading branch information
1 parent
7eddde0
commit 8a3c53a
Showing
5 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use pathfinder_common::{ | ||
receipt::Receipt, transaction::Transaction, BlockHeader, BlockId, PendingBlockHeader, | ||
}; | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub(crate) enum BlockWithReceipts { | ||
Full { | ||
header: BlockHeader, | ||
body: Vec<(Transaction, Receipt)>, | ||
is_l1_accepted: bool, | ||
}, | ||
Pending { | ||
header: PendingBlockHeader, | ||
body: Vec<(Transaction, Receipt)>, | ||
}, | ||
} | ||
|
||
impl super::RpcContext { | ||
pub(crate) async fn get_block_with_receipts( | ||
&self, | ||
block: BlockId, | ||
) -> anyhow::Result<Option<BlockWithReceipts>> { | ||
todo!(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod get_block_with_receipts; | ||
|
||
pub use get_block_with_receipts::get_block_with_receipts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use pathfinder_common::BlockId; | ||
use serde::Deserialize; | ||
|
||
use crate::v07::dto; | ||
|
||
use crate::context::{get_block_with_receipts::BlockWithReceipts, RpcContext}; | ||
use crate::v07::dto::transaction::TxnFinalityStatus; | ||
|
||
#[derive(Deserialize, Debug, PartialEq, Eq)] | ||
#[cfg_attr(test, derive(Copy, Clone))] | ||
#[serde(deny_unknown_fields)] | ||
pub struct Input { | ||
block_id: BlockId, | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct Output(BlockWithReceipts); | ||
|
||
crate::error::generate_rpc_error_subset!(Error: BlockNotFound); | ||
|
||
pub async fn get_block_with_receipts(context: RpcContext, input: Input) -> Result<Output, Error> { | ||
context | ||
.get_block_with_receipts(input.block_id) | ||
.await? | ||
.ok_or(Error::BlockNotFound) | ||
.map(Output) | ||
} | ||
|
||
impl serde::Serialize for Output { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
match &self.0 { | ||
BlockWithReceipts::Full { | ||
header, | ||
body, | ||
is_l1_accepted, | ||
} => { | ||
#[derive(serde::Serialize)] | ||
struct Dto<'a> { | ||
#[serde(flatten)] | ||
header: dto::header::Header<'a>, | ||
#[serde(flatten)] | ||
body: dto::transaction::BlockBodyWithReceipts<'a>, | ||
} | ||
|
||
let finality_status = if *is_l1_accepted { | ||
TxnFinalityStatus::AcceptedOnL1 | ||
} else { | ||
TxnFinalityStatus::AcceptedOnL2 | ||
}; | ||
|
||
let header = dto::header::Header(header); | ||
let body = dto::transaction::BlockBodyWithReceipts { | ||
transaction_data: body, | ||
finality_status, | ||
}; | ||
|
||
Dto { header, body }.serialize(serializer) | ||
} | ||
BlockWithReceipts::Pending { header, body } => { | ||
#[derive(serde::Serialize)] | ||
struct Dto<'a> { | ||
#[serde(flatten)] | ||
header: dto::header::PendingHeader<'a>, | ||
#[serde(flatten)] | ||
body: dto::transaction::BlockBodyWithReceipts<'a>, | ||
} | ||
|
||
let header = dto::header::PendingHeader(header); | ||
let body = dto::transaction::BlockBodyWithReceipts { | ||
transaction_data: body, | ||
finality_status: TxnFinalityStatus::AcceptedOnL2, | ||
}; | ||
|
||
Dto { header, body }.serialize(serializer) | ||
} | ||
} | ||
} | ||
} |