Skip to content

Commit cb9a15e

Browse files
authored
Merge pull request #5 from sigp/avoid-ownership-api-params
Updates to relay-api-types
2 parents e0a94a1 + e931db4 commit cb9a15e

File tree

4 files changed

+85
-46
lines changed

4 files changed

+85
-46
lines changed

builder-client/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,28 @@ impl BuilderClient {
5252

5353
pub async fn register_validators(
5454
&self,
55-
registrations: Vec<SignedValidatorRegistrationData>,
55+
registrations: &[SignedValidatorRegistrationData],
5656
) -> Result<(), Error> {
5757
let mut url = self.base_url.clone();
5858
url.path_segments_mut()
5959
.map_err(|_| Error::InvalidUrl(self.base_url.clone()))?
6060
.extend(&["eth", "v1", "builder", "validators"]);
6161

62-
let response = self.client.post(url).json(&registrations).send().await?;
62+
let response = self.client.post(url).json(registrations).send().await?;
6363

6464
self.build_response(response).await
6565
}
6666

6767
pub async fn submit_blinded_block<E: EthSpec>(
6868
&self,
69-
block: SignedBlindedBeaconBlock<E>,
69+
block: &SignedBlindedBeaconBlock<E>,
7070
) -> Result<ExecutionPayload<E>, Error> {
7171
let mut url = self.base_url.clone();
7272
url.path_segments_mut()
7373
.map_err(|_| Error::InvalidUrl(self.base_url.clone()))?
7474
.extend(&["eth", "v1", "builder", "blinded_blocks"]);
7575

76-
let response = self.client.post(url).json(&block).send().await?;
76+
let response = self.client.post(url).json(block).send().await?;
7777

7878
self.build_response(response).await
7979
}
@@ -82,7 +82,7 @@ impl BuilderClient {
8282
&self,
8383
slot: Slot,
8484
parent_hash: ExecutionBlockHash,
85-
pubkey: PublicKeyBytes,
85+
pubkey: &PublicKeyBytes,
8686
) -> Result<SignedBuilderBid<E>, Error> {
8787
let mut url = self.base_url.clone();
8888
url.path_segments_mut()

common/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ where
215215
}
216216

217217
// Headers
218-
#[derive(Default)]
218+
#[derive(Default, Clone, Copy)]
219219
pub enum ContentType {
220220
#[default]
221221
Json,
@@ -241,7 +241,7 @@ impl From<String> for ContentType {
241241
}
242242
}
243243

244-
#[derive(Default)]
244+
#[derive(Default, Clone, Copy)]
245245
pub enum ContentEncoding {
246246
Gzip,
247247
#[default]

relay-api-types/src/lib.rs

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pub struct SubmitBlockQueryParams {
2424
#[serde(bound = "E: EthSpec", untagged)]
2525
#[ssz(enum_behaviour = "transparent")]
2626
pub struct SubmitBlockRequest<E: EthSpec> {
27-
message: BidTraceV1,
27+
pub message: BidTraceV1,
2828
#[superstruct(flatten)]
29-
execution_payload: ExecutionPayload<E>,
30-
signature: Signature,
29+
pub execution_payload: ExecutionPayload<E>,
30+
pub signature: Signature,
3131
#[superstruct(only(Deneb))]
32-
blobs_bundle: BlobsBundle<E>,
32+
pub blobs_bundle: BlobsBundle<E>,
3333
}
3434

3535
impl<E: EthSpec> ssz::Decode for SubmitBlockRequest<E> {
@@ -116,11 +116,11 @@ pub struct GetValidatorRegistrationQueryParams {
116116
#[serde(bound = "E: EthSpec", untagged)]
117117
#[ssz(enum_behaviour = "transparent")]
118118
pub struct HeaderSubmission<E: EthSpec> {
119-
bid_trace: BidTraceV1,
119+
pub bid_trace: BidTraceV1,
120120
#[superstruct(flatten)]
121-
execution_payload_header: ExecutionPayloadHeader<E>,
121+
pub execution_payload_header: ExecutionPayloadHeader<E>,
122122
#[superstruct(only(Deneb))]
123-
blobs_bundle: BlobsBundle<E>,
123+
pub blobs_bundle: BlobsBundle<E>,
124124
}
125125

126126
#[superstruct(
@@ -137,8 +137,8 @@ pub struct HeaderSubmission<E: EthSpec> {
137137
#[ssz(enum_behaviour = "transparent")]
138138
pub struct SignedHeaderSubmission<E: EthSpec> {
139139
#[superstruct(flatten)]
140-
message: HeaderSubmission<E>,
141-
signature: Signature,
140+
pub message: HeaderSubmission<E>,
141+
pub signature: Signature,
142142
}
143143

144144
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
@@ -160,16 +160,16 @@ pub struct SignedCancellation {
160160
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
161161
pub struct TopBidUpdate {
162162
#[serde(with = "serde_utils::quoted_u64")]
163-
timestamp: u64,
164-
slot: Slot,
163+
pub timestamp: u64,
164+
pub slot: Slot,
165165
#[serde(with = "serde_utils::quoted_u64")]
166-
block_number: u64,
167-
block_hash: ExecutionBlockHash,
168-
parent_hash: ExecutionBlockHash,
169-
builder_pubkey: PublicKeyBytes,
170-
fee_recipient: Address,
166+
pub block_number: u64,
167+
pub block_hash: ExecutionBlockHash,
168+
pub parent_hash: ExecutionBlockHash,
169+
pub builder_pubkey: PublicKeyBytes,
170+
pub fee_recipient: Address,
171171
#[serde(with = "serde_utils::quoted_u256")]
172-
value: Uint256,
172+
pub value: Uint256,
173173
}
174174

175175
// Builder API responses
@@ -182,8 +182,8 @@ pub enum Filtering {
182182

183183
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
184184
pub struct ValidatorPreferences {
185-
filtering: Filtering,
186-
trusted_builders: Option<Vec<String>>,
185+
pub filtering: Filtering,
186+
pub trusted_builders: Option<Vec<String>>,
187187
}
188188

189189
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@@ -233,6 +233,45 @@ pub struct BidTraceV2WithTimestamp {
233233
pub timestamp_ms: i64,
234234
}
235235

236+
#[superstruct(
237+
variants(Bellatrix, Capella, Deneb, Electra),
238+
variant_attributes(
239+
derive(Debug, Clone, Serialize, Deserialize, Encode, Decode),
240+
serde(bound = "E: EthSpec", deny_unknown_fields),
241+
),
242+
map_into(ExecutionPayloadHeader),
243+
map_ref_into(ExecutionPayloadHeader)
244+
)]
245+
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
246+
#[serde(bound = "E: EthSpec", untagged)]
247+
#[ssz(enum_behaviour = "transparent")]
248+
pub struct SignedHeaderResponse<E: EthSpec> {
249+
#[superstruct(flatten)]
250+
pub message: HeaderResponse<E>,
251+
pub signature: Signature,
252+
}
253+
254+
#[superstruct(
255+
variants(Bellatrix, Capella, Deneb, Electra),
256+
variant_attributes(
257+
derive(Debug, Clone, Serialize, Deserialize, Encode, Decode),
258+
serde(bound = "E: EthSpec", deny_unknown_fields),
259+
),
260+
map_into(ExecutionPayloadHeader),
261+
map_ref_into(ExecutionPayloadHeader)
262+
)]
263+
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
264+
#[serde(bound = "E: EthSpec", untagged)]
265+
#[ssz(enum_behaviour = "transparent")]
266+
pub struct HeaderResponse<E: EthSpec> {
267+
#[superstruct(flatten)]
268+
pub execution_payload_header: ExecutionPayloadHeader<E>,
269+
#[superstruct(only(Deneb))]
270+
pub blobs_bundle: BlobsBundle<E>,
271+
pub value: Uint256,
272+
pub pubkey: PublicKeyBytes,
273+
}
274+
236275
// Builder API response types
237276
pub type GetValidatorsResponse = Vec<ValidatorsResponse>;
238277

relay-client/src/lib.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ impl RelayClient {
102102

103103
pub async fn submit_block<E>(
104104
&self,
105-
query_params: SubmitBlockQueryParams,
106-
body: SubmitBlockRequest<E>,
105+
query_params: &SubmitBlockQueryParams,
106+
body: &SubmitBlockRequest<E>,
107107
content_type: ContentType,
108108
content_encoding: ContentEncoding,
109109
) -> Result<(), Error>
@@ -117,8 +117,8 @@ impl RelayClient {
117117
let response = self
118118
.client
119119
.post(url)
120-
.query(&query_params)
121-
.json(&body)
120+
.query(query_params)
121+
.json(body)
122122
.send()
123123
.await?;
124124

@@ -141,7 +141,7 @@ impl RelayClient {
141141

142142
pub async fn get_delivered_payloads(
143143
&self,
144-
query_params: GetDeliveredPayloadsQueryParams,
144+
query_params: &GetDeliveredPayloadsQueryParams,
145145
) -> Result<GetDeliveredPayloadsResponse, Error> {
146146
let mut url = self.base_url.clone();
147147
url.path_segments_mut()
@@ -153,14 +153,14 @@ impl RelayClient {
153153
"bidtraces",
154154
"proposer_payload_delivered",
155155
]);
156-
let response = self.client.get(url).query(&query_params).send().await?;
156+
let response = self.client.get(url).query(query_params).send().await?;
157157

158158
self.build_response(response).await
159159
}
160160

161161
pub async fn get_received_bids(
162162
&self,
163-
query_params: GetReceivedBidsQueryParams,
163+
query_params: &GetReceivedBidsQueryParams,
164164
) -> Result<GetReceivedBidsResponse, Error> {
165165
let mut url = self.base_url.clone();
166166
url.path_segments_mut()
@@ -172,28 +172,28 @@ impl RelayClient {
172172
"bidtraces",
173173
"builder_blocks_received",
174174
]);
175-
let response = self.client.get(url).query(&query_params).send().await?;
175+
let response = self.client.get(url).query(query_params).send().await?;
176176

177177
self.build_response(response).await
178178
}
179179

180180
pub async fn get_validator_registration(
181181
&self,
182-
query_params: GetValidatorRegistrationQueryParams,
182+
query_params: &GetValidatorRegistrationQueryParams,
183183
) -> Result<GetValidatorRegistrationResponse, Error> {
184184
let mut url = self.base_url.clone();
185185
url.path_segments_mut()
186186
.map_err(|_| Error::InvalidUrl(self.base_url.clone()))?
187187
.extend(&["relay", "v1", "data", "validator_registration"]);
188-
let response = self.client.get(url).query(&query_params).send().await?;
188+
let response = self.client.get(url).query(query_params).send().await?;
189189

190190
self.build_response(response).await
191191
}
192192

193193
pub async fn submit_header<E>(
194194
&self,
195-
query_params: SubmitBlockQueryParams,
196-
body: SignedHeaderSubmission<E>,
195+
query_params: &SubmitBlockQueryParams,
196+
body: &SignedHeaderSubmission<E>,
197197
content_type: ContentType,
198198
content_encoding: ContentEncoding,
199199
) -> Result<(), Error>
@@ -207,8 +207,8 @@ impl RelayClient {
207207
let response = self
208208
.client
209209
.post(url)
210-
.query(&query_params)
211-
.json(&body)
210+
.query(query_params)
211+
.json(body)
212212
.send()
213213
.await?;
214214

@@ -218,8 +218,8 @@ impl RelayClient {
218218

219219
pub async fn submit_block_optimistic_v2<E>(
220220
&self,
221-
query_params: SubmitBlockQueryParams,
222-
body: SubmitBlockRequest<E>,
221+
query_params: &SubmitBlockQueryParams,
222+
body: &SubmitBlockRequest<E>,
223223
content_type: ContentType,
224224
content_encoding: ContentEncoding,
225225
) -> Result<(), Error>
@@ -233,8 +233,8 @@ impl RelayClient {
233233
let response = self
234234
.client
235235
.post(url)
236-
.query(&query_params)
237-
.json(&body)
236+
.query(query_params)
237+
.json(body)
238238
.send()
239239
.await?;
240240

@@ -244,15 +244,15 @@ impl RelayClient {
244244

245245
pub async fn submit_cancellation(
246246
&self,
247-
body: SignedCancellation,
247+
body: &SignedCancellation,
248248
content_type: ContentType,
249249
content_encoding: ContentEncoding,
250250
) -> Result<(), Error> {
251251
let mut url = self.base_url.clone();
252252
url.path_segments_mut()
253253
.map_err(|_| Error::InvalidUrl(self.base_url.clone()))?
254254
.extend(&["relay", "v1", "builder", "cancel_bid"]);
255-
let response = self.client.post(url).json(&body).send().await?;
255+
let response = self.client.post(url).json(body).send().await?;
256256

257257
self.build_response_with_headers(response, content_type, content_encoding)
258258
.await

0 commit comments

Comments
 (0)