wasm_client_solana 0.11.1

A wasm compatible solana rpc and pubsub client
Documentation
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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
use std::collections::HashMap;
use std::fmt;
use std::net::SocketAddr;
use std::result::Result;
use std::str::FromStr;

use derive_more::derive::Deref;
use derive_more::derive::DerefMut;
use serde::Deserialize;
use serde::Deserializer;
use serde::Serialize;
use serde::Serializer;
use serde_with::DisplayFromStr;
use serde_with::serde_as;
use serde_with::skip_serializing_none;
use solana_clock::Epoch;
use solana_clock::Slot;
use solana_clock::UnixTimestamp;
use solana_fee_calculator::FeeCalculator;
use solana_fee_calculator::FeeRateGovernor;
use solana_hash::Hash;
use solana_inflation::Inflation;
use solana_pubkey::Pubkey;
use solana_signature::Signature;
use solana_transaction_error::TransactionError;
use solana_transaction_error::TransactionResult;
use thiserror::Error;

use crate::Context;
use crate::impl_websocket_notification;
use crate::solana_account_decoder::UiAccount;
use crate::solana_account_decoder::parse_token::UiTokenAmount;
use crate::solana_transaction_status::ConfirmedTransactionStatusWithSignature;
use crate::solana_transaction_status::TransactionConfirmationStatus;
use crate::solana_transaction_status::UiConfirmedBlock;
use crate::solana_transaction_status::UiInnerInstructions;
use crate::solana_transaction_status::UiTransactionReturnData;

/// Wrapper for rpc return types of methods that provide responses both with and
/// without context. Main purpose of this is to fix methods that lack context
/// information in their return type, without breaking backwards compatibility.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OptionalContext<T> {
	Context(Response<T>),
	NoContext(T),
}

impl<T> OptionalContext<T> {
	pub fn parse_value(self) -> T {
		match self {
			Self::Context(response) => response.value,
			Self::NoContext(value) => value,
		}
	}
}

#[skip_serializing_none]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcResponseContext {
	pub slot: Slot,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub api_version: Option<RpcApiVersion>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RpcApiVersion(semver::Version);

impl std::ops::Deref for RpcApiVersion {
	type Target = semver::Version;

	fn deref(&self) -> &Self::Target {
		&self.0
	}
}

impl Default for RpcApiVersion {
	fn default() -> Self {
		Self(solana_version::Version::default().as_semver_version())
	}
}

impl Serialize for RpcApiVersion {
	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
	where
		S: Serializer,
	{
		serializer.serialize_str(&self.to_string())
	}
}

impl<'de> Deserialize<'de> for RpcApiVersion {
	fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
	where
		D: Deserializer<'de>,
	{
		let s: String = Deserialize::deserialize(deserializer)?;
		Ok(RpcApiVersion(
			semver::Version::from_str(&s).map_err(serde::de::Error::custom)?,
		))
	}
}

impl RpcResponseContext {
	pub fn new(slot: Slot) -> Self {
		Self {
			slot,
			api_version: Some(RpcApiVersion::default()),
		}
	}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Response<T> {
	pub context: RpcResponseContext,
	pub value: T,
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RpcBlockCommitment<T> {
	pub commitment: Option<T>,
	pub total_stake: u64,
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcBlockhashFeeCalculator {
	#[serde_as(as = "DisplayFromStr")]
	pub blockhash: Hash,
	pub fee_calculator: FeeCalculator,
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcBlockhash {
	#[serde_as(as = "DisplayFromStr")]
	pub blockhash: Hash,
	pub last_valid_block_height: u64,
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcFees {
	#[serde_as(as = "DisplayFromStr")]
	pub blockhash: Hash,
	pub fee_calculator: FeeCalculator,
	pub last_valid_slot: Slot,
	pub last_valid_block_height: u64,
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct DeprecatedRpcFees {
	#[serde_as(as = "DisplayFromStr")]
	pub blockhash: Hash,
	pub fee_calculator: FeeCalculator,
	pub last_valid_slot: Slot,
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Fees {
	#[serde_as(as = "DisplayFromStr")]
	pub blockhash: Hash,
	pub fee_calculator: FeeCalculator,
	pub last_valid_block_height: u64,
}

#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcFeeCalculator {
	pub fee_calculator: FeeCalculator,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcFeeRateGovernor {
	pub fee_rate_governor: FeeRateGovernor,
}

#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RpcInflationGovernor {
	pub initial: f64,
	pub terminal: f64,
	pub taper: f64,
	pub foundation: f64,
	pub foundation_term: f64,
}

impl PartialEq for RpcInflationGovernor {
	fn eq(&self, other: &Self) -> bool {
		approx_eq(self.initial, other.initial)
			&& approx_eq(self.terminal, other.terminal)
			&& approx_eq(self.taper, other.taper)
			&& approx_eq(self.foundation, other.foundation)
			&& approx_eq(self.foundation_term, other.foundation_term)
	}
}

impl Eq for RpcInflationGovernor {}

pub fn approx_eq(a: f64, b: f64) -> bool {
	const EPSILON: f64 = 1e-6;
	(a - b).abs() < EPSILON
}

impl From<Inflation> for RpcInflationGovernor {
	fn from(inflation: Inflation) -> Self {
		Self {
			initial: inflation.initial,
			terminal: inflation.terminal,
			taper: inflation.taper,
			foundation: inflation.foundation,
			foundation_term: inflation.foundation_term,
		}
	}
}

#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RpcInflationRate {
	pub total: f64,
	pub validator: f64,
	pub foundation: f64,
	pub epoch: Epoch,
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcKeyedAccount {
	#[serde_as(as = "DisplayFromStr")]
	pub pubkey: Pubkey,
	pub account: UiAccount,
}

#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
pub struct SlotInfo {
	pub slot: Slot,
	pub parent: Slot,
	pub root: Slot,
}

#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct SlotTransactionStats {
	pub num_transaction_entries: u64,
	pub num_successful_transactions: u64,
	pub num_failed_transactions: u64,
	pub max_transactions_per_entry: u64,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all = "camelCase", tag = "type")]
pub enum SlotUpdate {
	FirstShredReceived {
		slot: Slot,
		timestamp: u64,
	},
	Completed {
		slot: Slot,
		timestamp: u64,
	},
	CreatedBank {
		slot: Slot,
		parent: Slot,
		timestamp: u64,
	},
	Frozen {
		slot: Slot,
		timestamp: u64,
		stats: SlotTransactionStats,
	},
	Dead {
		slot: Slot,
		timestamp: u64,
		err: String,
	},
	OptimisticConfirmation {
		slot: Slot,
		timestamp: u64,
	},
	Root {
		slot: Slot,
		timestamp: u64,
	},
}

impl SlotUpdate {
	pub fn slot(&self) -> Slot {
		match self {
			Self::FirstShredReceived { slot, .. }
			| Self::Completed { slot, .. }
			| Self::CreatedBank { slot, .. }
			| Self::Frozen { slot, .. }
			| Self::Dead { slot, .. }
			| Self::OptimisticConfirmation { slot, .. }
			| Self::Root { slot, .. } => *slot,
		}
	}
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase", untagged)]
pub enum RpcSignatureResult {
	ProcessedSignature(ProcessedSignatureResult),
	ReceivedSignature(ReceivedSignatureResult),
}

#[serde_as]
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcLogsResponse {
	#[serde_as(as = "DisplayFromStr")]
	pub signature: Signature, // Signature as base58 string
	pub err: Option<TransactionError>,
	pub logs: Vec<String>,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct LogsNotificationResponse {
	pub context: Context,
	pub value: RpcLogsResponse,
}

impl_websocket_notification!(LogsNotificationResponse, "logs");

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ProcessedSignatureResult {
	pub err: Option<TransactionError>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum ReceivedSignatureResult {
	ReceivedSignature,
}

#[serde_as]
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcContactInfo {
	/// Pubkey of the node as a base-58 string
	#[serde_as(as = "DisplayFromStr")]
	pub pubkey: Pubkey,
	/// Gossip port
	pub gossip: Option<SocketAddr>,
	/// Tvu UDP port
	pub tvu: Option<SocketAddr>,
	/// Tpu UDP port
	pub tpu: Option<SocketAddr>,
	/// Tpu QUIC port
	pub tpu_quic: Option<SocketAddr>,
	/// Tpu UDP forwards port
	pub tpu_forwards: Option<SocketAddr>,
	/// Tpu QUIC forwards port
	pub tpu_forwards_quic: Option<SocketAddr>,
	/// Tpu UDP vote port
	pub tpu_vote: Option<SocketAddr>,
	/// Server repair UDP port
	pub serve_repair: Option<SocketAddr>,
	/// JSON RPC port
	pub rpc: Option<SocketAddr>,
	/// `WebSocket` `PubSub` port
	pub pubsub: Option<SocketAddr>,
	/// Software version
	pub version: Option<String>,
	/// First 4 bytes of the `FeatureSet` identifier
	pub feature_set: Option<u32>,
	/// Shred version
	pub shred_version: Option<u16>,
}

/// Map of leader base58 identity pubkeys to the slot indices relative to the
/// first epoch slot
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, Deref, DerefMut)]
pub struct RpcLeaderSchedule(#[serde(with = "pubkey_string_map")] pub HashMap<Pubkey, Vec<usize>>);

mod pubkey_string_map {
	use std::result::Result;

	use serde::ser::SerializeMap;

	use super::*;

	pub fn serialize<S>(map: &HashMap<Pubkey, Vec<usize>>, serializer: S) -> Result<S::Ok, S::Error>
	where
		S: Serializer,
	{
		let mut ser_map = serializer.serialize_map(Some(map.len()))?;
		for (k, v) in map {
			ser_map.serialize_entry(&k.to_string(), v)?;
		}
		ser_map.end()
	}

	pub fn deserialize<'de, D>(deserializer: D) -> Result<HashMap<Pubkey, Vec<usize>>, D::Error>
	where
		D: Deserializer<'de>,
	{
		let string_map: HashMap<String, Vec<usize>> = HashMap::deserialize(deserializer)?;
		string_map
			.into_iter()
			.map(|(k, v)| Ok((Pubkey::from_str(&k).map_err(serde::de::Error::custom)?, v)))
			.collect()
	}
}

#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcBlockProductionRange {
	pub first_slot: Slot,
	pub last_slot: Slot,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcBlockProduction {
	/// Map of leader base58 identity pubkeys to a tuple of `(number of leader
	/// slots, number of blocks produced)`
	pub by_identity: HashMap<String, (usize, usize)>,
	pub range: RpcBlockProductionRange,
}

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub struct RpcVersionInfo {
	/// The current version of solana-core
	pub solana_core: String,
	/// first 4 bytes of the `FeatureSet` identifier
	pub feature_set: Option<u32>,
}

impl fmt::Debug for RpcVersionInfo {
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		write!(f, "{}", self.solana_core)
	}
}

impl fmt::Display for RpcVersionInfo {
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		if let Some(version) = self.solana_core.split_whitespace().next() {
			// Display just the semver if possible
			write!(f, "{version}")
		} else {
			write!(f, "{}", self.solana_core)
		}
	}
}

#[serde_as]
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub struct RpcIdentity {
	/// The current node identity pubkey
	#[serde_as(as = "DisplayFromStr")]
	pub identity: Pubkey,
}

#[serde_as]
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcVote {
	/// Vote account address, as base-58 encoded string
	#[serde_as(as = "DisplayFromStr")]
	pub vote_pubkey: Pubkey,
	pub slots: Vec<Slot>,
	#[serde_as(as = "DisplayFromStr")]
	pub hash: Hash,
	pub timestamp: Option<UnixTimestamp>,
	#[serde_as(as = "DisplayFromStr")]
	pub signature: Signature,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcVoteAccountStatus {
	pub current: Vec<RpcVoteAccountInfo>,
	pub delinquent: Vec<RpcVoteAccountInfo>,
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcVoteAccountInfo {
	/// Vote account address, as base-58 encoded string
	#[serde_as(as = "DisplayFromStr")]
	pub vote_pubkey: Pubkey,
	/// The validator identity, as base-58 encoded string
	#[serde_as(as = "DisplayFromStr")]
	pub node_pubkey: Pubkey,
	/// The current stake, in lamports, delegated to this vote account
	pub activated_stake: u64,
	/// An 8-bit integer used as a fraction (`commission/MAX_U8`) for rewards
	/// payout
	pub commission: u8,
	/// Whether this account is staked for the current epoch
	pub epoch_vote_account: bool,
	/// Latest history of earned credits for up to
	/// `MAX_RPC_VOTE_ACCOUNT_INFO_EPOCH_CREDITS_HISTORY` epochs   each tuple
	/// is (Epoch, credits, `prev_credits`)
	pub epoch_credits: Vec<(Epoch, u64, u64)>,
	/// Most recent slot voted on by this vote account (0 if no votes exist)
	#[serde(default)]
	pub last_vote: u64,

	/// Current root slot for this vote account (0 if no root slot exists)
	#[serde(default)]
	pub root_slot: Slot,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcSignatureConfirmation {
	pub confirmations: usize,
	pub status: TransactionResult<()>,
}

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcSimulateTransactionResult {
	pub err: Option<TransactionError>,
	pub logs: Option<Vec<String>>,
	pub accounts: Option<Vec<Option<UiAccount>>>,
	pub units_consumed: Option<u64>,
	pub return_data: Option<UiTransactionReturnData>,
	pub inner_instructions: Option<Vec<UiInnerInstructions>>,
	pub replacement_blockhash: Option<RpcBlockhash>,
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcStorageTurn {
	#[serde_as(as = "DisplayFromStr")]
	pub blockhash: Hash,
	pub slot: Slot,
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcAccountBalance {
	#[serde_as(as = "DisplayFromStr")]
	pub address: Pubkey,
	pub lamports: u64,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcSupply {
	pub total: u64,
	pub circulating: u64,
	pub non_circulating: u64,
	pub non_circulating_accounts: Vec<String>,
}

#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum StakeActivationState {
	Activating,
	Active,
	Deactivating,
	Inactive,
}

#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcStakeActivation {
	pub state: StakeActivationState,
	pub active: u64,
	pub inactive: u64,
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct RpcTokenAccountBalance {
	#[serde_as(as = "DisplayFromStr")]
	pub address: Pubkey,
	#[serde(flatten)]
	pub amount: UiTokenAmount,
}

#[serde_as]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcConfirmedTransactionStatusWithSignature {
	#[serde_as(as = "DisplayFromStr")]
	pub signature: Signature,
	pub slot: Slot,
	pub err: Option<TransactionError>,
	pub memo: Option<String>,
	pub block_time: Option<UnixTimestamp>,
	/// The transaction index within the block.
	pub index: u32,
	pub confirmation_status: Option<TransactionConfirmationStatus>,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcPerfSample {
	pub slot: Slot,
	pub num_transactions: u64,
	pub num_non_vote_transaction: u64,
	pub num_slots: u64,
	pub sample_period_secs: u16,
}

impl RpcPerfSample {
	pub fn num_vote_transactions(&self) -> u64 {
		self.num_transactions - self.num_non_vote_transaction
	}
}

#[skip_serializing_none]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcInflationReward {
	pub epoch: Epoch,
	pub effective_slot: Slot,
	pub amount: u64,            // lamports
	pub post_balance: u64,      // lamports
	pub commission: Option<u8>, // Vote account commission when the reward was credited
}

#[derive(Clone, Copy, Deserialize, Serialize, Debug, Error, Eq, PartialEq)]
pub enum RpcBlockUpdateError {
	#[error("block store error")]
	BlockStoreError,

	#[error("unsupported transaction version ({0})")]
	UnsupportedTransactionVersion(u8),
}

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RpcBlockUpdate {
	pub slot: Slot,
	pub block: Option<UiConfirmedBlock>,
	pub err: Option<RpcBlockUpdateError>,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct BlockNotificationResponse {
	pub context: Context,
	pub value: RpcBlockUpdate,
}

impl_websocket_notification!(BlockNotificationResponse, "block");

impl From<ConfirmedTransactionStatusWithSignature> for RpcConfirmedTransactionStatusWithSignature {
	fn from(value: ConfirmedTransactionStatusWithSignature) -> Self {
		let ConfirmedTransactionStatusWithSignature {
			signature,
			slot,
			err,
			memo,
			block_time,
			index,
		} = value;
		Self {
			signature,
			slot,
			err,
			memo,
			block_time,
			index,
			confirmation_status: None,
		}
	}
}

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
pub struct RpcSnapshotSlotInfo {
	pub full: Slot,
	pub incremental: Option<Slot>,
}

#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RpcPrioritizationFee {
	pub slot: Slot,
	pub prioritization_fee: u64,
}