11use crate :: perms:: oauth:: SharedToken ;
2- use alloy:: { consensus :: BlobTransactionSidecarEip7594 , primitives :: B256 } ;
2+ use alloy:: eips :: eip2718 :: Eip2718Error ;
33use thiserror:: Error ;
44use tracing:: instrument;
55
@@ -10,7 +10,7 @@ pub enum PylonError {
1010 #[ error( "invalid sidecar: {0}" ) ]
1111 InvalidSidecar ( String ) ,
1212
13- /// Sidecar already exists for this transaction hash (409).
13+ /// Sidecar already exists for this transaction (409).
1414 #[ error( "sidecar already exists" ) ]
1515 SidecarAlreadyExists ,
1616
@@ -29,6 +29,10 @@ pub enum PylonError {
2929 /// Missing auth token.
3030 #[ error( "missing auth token" ) ]
3131 MissingAuthToken ( tokio:: sync:: watch:: error:: RecvError ) ,
32+
33+ /// Invalid transaction bytes.
34+ #[ error( "invalid transaction bytes: {0}" ) ]
35+ InvalidTransactionBytes ( Eip2718Error ) ,
3236}
3337
3438/// A client for interacting with the Pylon blob server API.
@@ -82,33 +86,28 @@ impl PylonClient {
8286 & self . token
8387 }
8488
85- /// Post a blob transaction sidecar to the Pylon server.
89+ /// Post a blob transaction to the Pylon server.
8690 ///
87- /// If the sidecar is in EIP-4844 format, it will be converted to EIP-7594
88- /// format before posting .
91+ /// The transaction must be an EIP-4844 blob transaction with an EIP-7594
92+ /// sidecar attached. Non-EIP-7594 sidecars will be rejected .
8993 ///
9094 /// # Arguments
9195 ///
92- /// * `tx_hash` - The transaction hash ([`B256`]).
93- /// * `sidecar` - The blob transaction sidecar ([`BlobTransactionSidecarEip7594`]).
96+ /// * `tx` - The raw EIP-2718 encoded transaction bytes ([`Bytes`]).
9497 ///
9598 /// # Errors
9699 ///
97100 /// Returns an error if:
98- /// - The sidecar format is invalid ([`PylonError::InvalidSidecar`])
101+ /// - The transaction bytes are invalid ([`PylonError::InvalidTransactionBytes`])
102+ /// - The sidecar is missing or not in EIP-7594 format ([`PylonError::InvalidSidecar`])
99103 /// - A sidecar already exists for this transaction hash ([`PylonError::SidecarAlreadyExists`])
100104 /// - An internal server error occurred ([`PylonError::InternalError`])
101105 /// - A network error occurred ([`PylonError::Request`])
102106 ///
103- /// [`B256`]: <https://docs.rs/alloy/latest/alloy/primitives/aliases/type.B256.html>
104- /// [`BlobTransactionSidecarEip7594`]: <https://docs.rs/alloy/latest/alloy/consensus/struct.BlobTransactionSidecarEip7594.html>
107+ /// [`Bytes`]: https://docs.rs/alloy/latest/alloy/primitives/struct.Bytes.html
105108 #[ instrument( skip_all) ]
106- pub async fn post_sidecar (
107- & self ,
108- tx_hash : B256 ,
109- sidecar : BlobTransactionSidecarEip7594 ,
110- ) -> Result < ( ) , PylonError > {
111- let url = self . url . join ( & format ! ( "v2/sidecar/{tx_hash}" ) ) ?;
109+ pub async fn post_blob_tx ( & self , raw_tx : alloy:: primitives:: Bytes ) -> Result < ( ) , PylonError > {
110+ let url = self . url . join ( "v2/sidecar" ) ?;
112111 let secret = self
113112 . token
114113 . secret ( )
@@ -118,13 +117,14 @@ impl PylonClient {
118117 let response = self
119118 . client
120119 . post ( url)
121- . json ( & sidecar)
120+ . header ( reqwest:: header:: CONTENT_TYPE , "application/octet-stream" )
121+ . body ( raw_tx. 0 )
122122 . bearer_auth ( secret)
123123 . send ( )
124124 . await ?;
125125
126126 match response. status ( ) {
127- reqwest:: StatusCode :: OK => Ok ( ( ) ) ,
127+ reqwest:: StatusCode :: CREATED => Ok ( ( ) ) ,
128128 reqwest:: StatusCode :: BAD_REQUEST => {
129129 let text = response. text ( ) . await . unwrap_or_default ( ) ;
130130 Err ( PylonError :: InvalidSidecar ( text) )
0 commit comments