1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2026 Regit
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
use std::time::{SystemTime, UNIX_EPOCH};
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use web_time::{SystemTime, UNIX_EPOCH};
use super::super::wire::{
RequestOptions, SlotValue, error_policy,
execution::{
HeightOptions, LatestWire, SimulationOptions, SimulationWire, StatusRequest, StatusWire,
SubmissionOptions, TransactionOptions, TransactionWire,
},
invalid_response,
};
use super::SolanaClient;
use crate::{
domain::{
Source, Timestamp,
solana::{
BlockHeight, BlockhashValidity, Commitment, ExecutionContext, ExecutionObservation,
ExecutionRequest, Hash, LatestBlockhash, MessageFee, ReadOptions, Signature,
SignedTransaction, Simulation, StatusLookup, StatusOptions, Submission, SubmitOptions,
TransactionLookup, TransactionReadOptions, UnsignedMessage, UnsignedTransaction,
},
},
error::Error,
transport::{OperationBudget, decode_response, encode_request, submission_unknown},
};
use base64::{Engine as _, engine::general_purpose::STANDARD};
impl SolanaClient {
/// Retrieves canonical legacy/v0/v1 source bytes and exact execution metadata.
/// Null means unknown at the selected confirmed/finalized state, not pending.
/// This RPC supplies inclusion slot, not evaluation slot or minimum-slot controls.
/// # Errors
/// Returns bounded source, identity, structural, deadline or unsupported failures.
/// # Panics
/// On native targets, Tokio may panic without caller-provided I/O and time drivers.
pub async fn get_transaction(
&self,
signature: Signature,
options: TransactionReadOptions,
) -> Result<ExecutionObservation<TransactionLookup>, Error> {
let budget = OperationBudget::new(self.config.http_config().limits())?;
budget
.run(async {
self.verify_genesis(&budget).await?;
let value: Option<TransactionWire> = self
.http
.read_rpc(
&budget,
"getTransaction",
&(signature, TransactionOptions::new(options)),
error_policy,
)
.await?;
let transaction = value.map(TransactionWire::into_transaction).transpose()?;
ExecutionObservation::transaction(
TransactionLookup {
signature,
transaction,
},
self.execution_context(
ExecutionRequest::Transaction { signature, options },
None,
"getTransaction",
)?,
)
.map_err(|_| invalid_response())
})
.await
}
/// Looks up one exact signature in the explicitly selected cache/history search.
/// Context evaluation slot and source inclusion/execution facts remain separate.
/// This RPC supports no requested commitment or minimum context slot.
/// # Errors
/// Returns fixed bounded-provider, correlation or deadline failures.
/// # Panics
/// On native targets, Tokio may panic without caller-provided I/O and time drivers.
pub async fn get_transaction_status(
&self,
signature: Signature,
options: StatusOptions,
) -> Result<ExecutionObservation<StatusLookup>, Error> {
let budget = OperationBudget::new(self.config.http_config().limits())?;
budget
.run(async {
self.verify_genesis(&budget).await?;
let value: SlotValue<[Option<StatusWire>; 1]> = self
.http
.read_rpc(
&budget,
"getSignatureStatuses",
&([signature], StatusRequest::from(options)),
error_policy,
)
.await?
.ok_or_else(invalid_response)?;
let [status] = value.value;
ExecutionObservation::status(
StatusLookup {
signature,
status: status.map(StatusWire::into_status).transpose()?,
},
self.execution_context(
ExecutionRequest::Status { signature, options },
Some(value.context.slot),
"getSignatureStatuses",
)?,
)
.map_err(|_| invalid_response())
})
.await
}
/// Reads a recent blockhash and last-valid BLOCK HEIGHT with actual context slot.
/// No implicit refresh, wall-clock expiry or hash-pinned history is claimed.
/// # Errors
/// Returns fixed provider, network, lower-bound or deadline failures.
/// # Panics
/// On native targets, Tokio may panic without caller-provided I/O and time drivers.
pub async fn get_latest_blockhash(
&self,
options: ReadOptions,
) -> Result<ExecutionObservation<LatestBlockhash>, Error> {
let budget = OperationBudget::new(self.config.http_config().limits())?;
budget
.run(async {
self.verify_genesis(&budget).await?;
let value: SlotValue<LatestWire> = self
.http
.read_rpc(
&budget,
"getLatestBlockhash",
&(RequestOptions::new(options, None),),
error_policy,
)
.await?
.ok_or_else(invalid_response)?;
ExecutionObservation::latest_blockhash(
LatestBlockhash {
lifetime: value.value.lifetime(),
},
self.execution_context(
ExecutionRequest::LatestBlockhash { options },
Some(value.context.slot),
"getLatestBlockhash",
)?,
)
.map_err(|_| invalid_response())
})
.await
}
/// Checks source validity of the exact frozen caller-supplied blockhash.
/// # Errors
/// Returns fixed provider, network, lower-bound or deadline failures.
/// # Panics
/// On native targets, Tokio may panic without caller-provided I/O and time drivers.
pub async fn is_blockhash_valid(
&self,
blockhash: Hash,
options: ReadOptions,
) -> Result<ExecutionObservation<BlockhashValidity>, Error> {
let budget = OperationBudget::new(self.config.http_config().limits())?;
budget
.run(async {
self.verify_genesis(&budget).await?;
let value: SlotValue<bool> = self
.http
.read_rpc(
&budget,
"isBlockhashValid",
&(blockhash, RequestOptions::new(options, None)),
error_policy,
)
.await?
.ok_or_else(invalid_response)?;
ExecutionObservation::blockhash_validity(
BlockhashValidity {
blockhash,
valid: value.value,
},
self.execution_context(
ExecutionRequest::BlockhashValidity { blockhash, options },
Some(value.context.slot),
"isBlockhashValid",
)?,
)
.map_err(|_| invalid_response())
})
.await
}
/// Reads exact source BLOCK HEIGHT for explicit commitment, without inventing a slot.
/// # Errors
/// Returns fixed provider, identity, width or deadline failures.
/// # Panics
/// On native targets, Tokio may panic without caller-provided I/O and time drivers.
pub async fn get_block_height(
&self,
commitment: Commitment,
) -> Result<ExecutionObservation<BlockHeight>, Error> {
let budget = OperationBudget::new(self.config.http_config().limits())?;
budget
.run(async {
self.verify_genesis(&budget).await?;
let height: u64 = self
.http
.read_rpc(
&budget,
"getBlockHeight",
&(HeightOptions { commitment },),
error_policy,
)
.await?
.ok_or_else(invalid_response)?;
ExecutionObservation::block_height(
BlockHeight { height },
self.execution_context(
ExecutionRequest::BlockHeight { commitment },
None,
"getBlockHeight",
)?,
)
.map_err(|_| invalid_response())
})
.await
}
/// Estimates exact lamport fees for immutable canonical message bytes.
/// Explicit null retains unavailable fee data; no zero fee or refreshed hash is invented.
/// # Errors
/// Returns fixed provider, identity, lower-bound or deadline failures.
/// # Panics
/// On native targets, Tokio may panic without caller-provided I/O and time drivers.
pub async fn get_fee_for_message(
&self,
message: UnsignedMessage,
options: ReadOptions,
) -> Result<ExecutionObservation<MessageFee>, Error> {
let budget = OperationBudget::new(self.config.http_config().limits())?;
budget
.run(async {
self.verify_genesis(&budget).await?;
let value: SlotValue<Option<u64>> = self
.http
.read_rpc(
&budget,
"getFeeForMessage",
&(
STANDARD.encode(message.bytes()),
RequestOptions::new(options, None),
),
error_policy,
)
.await?
.ok_or_else(invalid_response)?;
ExecutionObservation::message_fee(
MessageFee {
lamports: value.value,
},
self.execution_context(
ExecutionRequest::MessageFee { message, options },
Some(value.context.slot),
"getFeeForMessage",
)?,
)
.map_err(|_| invalid_response())
})
.await
}
/// Simulates exact zero-placeholder bytes with `sigVerify=false` and replacement off.
/// Source execution failures remain typed results; this performs no write, signing,
/// implicit blockhash refresh, account creation, funding or approval decision.
/// # Errors
/// Returns fixed provider, identity, malformed/bounded-source or deadline failures.
/// # Panics
/// On native targets, Tokio may panic without caller-provided I/O and time drivers.
pub async fn simulate_transaction(
&self,
transaction: UnsignedTransaction,
options: ReadOptions,
) -> Result<ExecutionObservation<Simulation>, Error> {
let budget = OperationBudget::new(self.config.http_config().limits())?;
budget
.run(async {
self.verify_genesis(&budget).await?;
let controls = SimulationOptions {
encoding: "base64",
commitment: options.commitment(),
min_context_slot: options.minimum_context_slot(),
sig_verify: false,
replace_recent_blockhash: false,
};
let value: SlotValue<SimulationWire> = self
.http
.read_rpc(
&budget,
"simulateTransaction",
&(STANDARD.encode(transaction.bytes()), controls),
error_policy,
)
.await?
.ok_or_else(invalid_response)?;
ExecutionObservation::simulation(
value.value.into_simulation()?,
self.execution_context(
ExecutionRequest::Simulation {
transaction,
options,
},
Some(value.context.slot),
"simulateTransaction",
)?,
)
.map_err(|_| invalid_response())
})
.await
}
/// Sends exact caller-signed bytes once after full genesis verification.
/// Every signature slot must be nonzero; cryptographic signature/intent checks and
/// approval are caller-owned. Solana bytes encode no genesis identity. Node
/// `maxRetries=0` and local one-shot transport prevent automatic resubmission.
/// Matching source first signature acknowledges the write without proving inclusion
/// or execution. Cancellation cannot establish whether a write reached the source.
/// # Errors
/// Before dispatch, returns ordinary fixed failures. Unresolved post-dispatch
/// failures, including RPC errors and mismatched acknowledgements, retain possible
/// submission as `SubmissionOutcomeUnknown` without exposing source diagnostics.
/// # Panics
/// On native targets, Tokio may panic without caller-provided I/O and time drivers.
pub async fn submit_signed(
&self,
transaction: SignedTransaction,
options: SubmitOptions,
) -> Result<ExecutionObservation<Submission>, Error> {
let budget = OperationBudget::new(self.config.http_config().limits())?;
budget.run(self.verify_genesis(&budget)).await?;
let signature = transaction.signature();
let body = encode_request(
1,
"sendTransaction",
&(
STANDARD.encode(transaction.bytes()),
SubmissionOptions::from(options),
),
)?;
let response = self.http.write_once(&[], &[], &body, &budget).await?;
budget
.run(async {
let bytes = response.into_success()?;
let actual: Signature =
decode_response(&bytes, 1, error_policy)?.ok_or_else(invalid_response)?;
if actual != signature {
return Err(invalid_response());
}
ExecutionObservation::submission(
Submission { signature: actual },
self.execution_context(
ExecutionRequest::Submission { signature, options },
None,
"sendTransaction",
)?,
)
.map_err(|_| invalid_response())
})
.await
.map_err(submission_unknown)
}
fn execution_context(
&self,
request: ExecutionRequest,
slot: Option<u64>,
method: &'static str,
) -> Result<ExecutionContext, Error> {
let retrieved_at = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|d| Timestamp::from_unix_seconds(d.as_secs()))
.map_err(|_| Error::Configuration)?;
ExecutionContext::new(
self.config.network().clone(),
request,
slot,
Source::new(
self.config.http_config().provider_id(),
method,
env!("CARGO_PKG_VERSION"),
)?,
retrieved_at,
)
.map_err(|_| invalid_response())
}
}
impl super::super::TransactionReader for SolanaClient {
fn network(&self) -> &crate::domain::solana::Network {
self.config.network()
}
async fn get_transaction(
&self,
s: Signature,
o: TransactionReadOptions,
) -> Result<ExecutionObservation<TransactionLookup>, Error> {
Self::get_transaction(self, s, o).await
}
async fn get_transaction_status(
&self,
s: Signature,
o: StatusOptions,
) -> Result<ExecutionObservation<StatusLookup>, Error> {
Self::get_transaction_status(self, s, o).await
}
}
impl super::super::BlockhashReader for SolanaClient {
fn network(&self) -> &crate::domain::solana::Network {
self.config.network()
}
async fn get_latest_blockhash(
&self,
o: ReadOptions,
) -> Result<ExecutionObservation<LatestBlockhash>, Error> {
Self::get_latest_blockhash(self, o).await
}
async fn is_blockhash_valid(
&self,
h: Hash,
o: ReadOptions,
) -> Result<ExecutionObservation<BlockhashValidity>, Error> {
Self::is_blockhash_valid(self, h, o).await
}
async fn get_block_height(
&self,
c: Commitment,
) -> Result<ExecutionObservation<BlockHeight>, Error> {
Self::get_block_height(self, c).await
}
}
impl super::super::ExecutionReader for SolanaClient {
fn network(&self) -> &crate::domain::solana::Network {
self.config.network()
}
async fn get_fee_for_message(
&self,
m: UnsignedMessage,
o: ReadOptions,
) -> Result<ExecutionObservation<MessageFee>, Error> {
Self::get_fee_for_message(self, m, o).await
}
async fn simulate_transaction(
&self,
t: UnsignedTransaction,
o: ReadOptions,
) -> Result<ExecutionObservation<Simulation>, Error> {
Self::simulate_transaction(self, t, o).await
}
}
impl super::super::SolanaSubmitter for SolanaClient {
fn network(&self) -> &crate::domain::solana::Network {
self.config.network()
}
async fn submit_signed(
&self,
t: SignedTransaction,
o: SubmitOptions,
) -> Result<ExecutionObservation<Submission>, Error> {
Self::submit_signed(self, t, o).await
}
}