spume 0.2.0

Lightweight, ergonomic Solana JSON-RPC wasm 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
use {
    crate::WasmClient,
    serde_json::json,
    solana_address::Address,
    solana_epoch_info::EpochInfo,
    solana_epoch_schedule::EpochSchedule,
    solana_rpc_client_types::{
        config::{
            CommitmentConfig, RpcAccountInfoConfig, RpcBlockConfig, RpcBlockProductionConfig,
            RpcContextConfig, RpcEncodingConfigWrapper, RpcEpochConfig, RpcGetVoteAccountsConfig,
            RpcLargestAccountsConfig, RpcLeaderScheduleConfig, RpcProgramAccountsConfig,
            RpcRequestAirdropConfig, RpcSendTransactionConfig, RpcSignatureStatusConfig,
            RpcSignaturesForAddressConfig, RpcSimulateTransactionConfig, RpcSupplyConfig,
            RpcTokenAccountsFilter, RpcTransactionConfig,
        },
        request::{RpcError, RpcRequest},
        response::{
            OptionalContext, Response, RpcAccountBalance, RpcBlockCommitment, RpcBlockProduction,
            RpcBlockhash, RpcConfirmedTransactionStatusWithSignature, RpcContactInfo, RpcIdentity,
            RpcInflationGovernor, RpcInflationRate, RpcInflationReward, RpcKeyedAccount,
            RpcLeaderSchedule, RpcPerfSample, RpcPrioritizationFee, RpcSimulateTransactionResult,
            RpcSnapshotSlotInfo, RpcSupply, RpcTokenAccountBalance, RpcVersionInfo,
            RpcVoteAccountStatus, UiAccount, UiConfirmedBlock, UiTokenAmount,
        },
    },
    solana_transaction_status_client_types::{
        EncodedConfirmedTransactionWithStatusMeta, TransactionStatus,
    },
};

type RpcResult<T> = Result<T, Box<RpcError>>;

impl WasmClient {
    /// Fetch all information associated with the account of the given address.
    pub async fn get_account_info(
        &self,
        address: &Address,
        config: Option<RpcAccountInfoConfig>,
    ) -> RpcResult<Response<Option<UiAccount>>> {
        self.provider
            .send(
                RpcRequest::GetAccountInfo,
                json!([address.to_string(), config]),
            )
            .await
    }

    /// Fetch the lamport balance of an account.
    pub async fn get_balance(
        &self,
        address: &Address,
        config: Option<RpcContextConfig>,
    ) -> RpcResult<Response<u64>> {
        self.provider
            .send(RpcRequest::GetBalance, json!([address.to_string(), config]))
            .await
    }

    /// Return the 20 largest accounts by lamport balance.
    pub async fn get_largest_accounts(
        &self,
        config: Option<RpcLargestAccountsConfig>,
    ) -> RpcResult<Response<Vec<RpcAccountBalance>>> {
        self.provider
            .send(RpcRequest::GetLargestAccounts, json!([config]))
            .await
    }

    /// Return the minimum balance required to make an account of `data_size` rent-exempt.
    pub async fn get_minimum_balance_for_rent_exemption(
        &self,
        data_size: u64,
        config: Option<CommitmentConfig>,
    ) -> RpcResult<u64> {
        self.provider
            .send(
                RpcRequest::GetMinimumBalanceForRentExemption,
                json!([data_size, config]),
            )
            .await
    }

    /// Fetch info for several accounts in a single request.
    pub async fn get_multiple_accounts(
        &self,
        addresses: &[Address],
        config: Option<RpcAccountInfoConfig>,
    ) -> RpcResult<Response<Vec<Option<UiAccount>>>> {
        let addresses: Vec<String> = addresses.iter().map(Address::to_string).collect();
        self.provider
            .send(RpcRequest::GetMultipleAccounts, json!([addresses, config]))
            .await
    }

    /// Fetch all accounts owned by the given program, optionally filtered.
    pub async fn get_program_accounts(
        &self,
        program_id: &Address,
        config: Option<RpcProgramAccountsConfig>,
    ) -> RpcResult<OptionalContext<Vec<RpcKeyedAccount>>> {
        self.provider
            .send(
                RpcRequest::GetProgramAccounts,
                json!([program_id.to_string(), config]),
            )
            .await
    }

    /// Return the SPL token balance held by a token account.
    pub async fn get_token_account_balance(
        &self,
        account: &Address,
        config: Option<RpcContextConfig>,
    ) -> RpcResult<Response<UiTokenAmount>> {
        self.provider
            .send(
                RpcRequest::GetTokenAccountBalance,
                json!([account.to_string(), config]),
            )
            .await
    }

    /// Fetch SPL token accounts delegated to the given address.
    pub async fn get_token_accounts_by_delegate(
        &self,
        delegate: &Address,
        filter: RpcTokenAccountsFilter,
        config: Option<RpcAccountInfoConfig>,
    ) -> RpcResult<Response<Vec<RpcKeyedAccount>>> {
        self.provider
            .send(
                RpcRequest::GetTokenAccountsByDelegate,
                json!([delegate.to_string(), filter, config]),
            )
            .await
    }

    /// Fetch SPL token accounts owned by the given address.
    pub async fn get_token_accounts_by_owner(
        &self,
        owner: &Address,
        filter: RpcTokenAccountsFilter,
        config: Option<RpcAccountInfoConfig>,
    ) -> RpcResult<Response<Vec<RpcKeyedAccount>>> {
        self.provider
            .send(
                RpcRequest::GetTokenAccountsByOwner,
                json!([owner.to_string(), filter, config]),
            )
            .await
    }

    /// Return the 20 largest token accounts for a given mint.
    pub async fn get_token_largest_accounts(
        &self,
        mint: &Address,
        config: Option<CommitmentConfig>,
    ) -> RpcResult<Response<Vec<RpcTokenAccountBalance>>> {
        self.provider
            .send(
                RpcRequest::GetTokenLargestAccounts,
                json!([mint.to_string(), config]),
            )
            .await
    }

    /// Return the total supply of an SPL token mint.
    pub async fn get_token_supply(
        &self,
        mint: &Address,
        config: Option<CommitmentConfig>,
    ) -> RpcResult<Response<UiTokenAmount>> {
        self.provider
            .send(
                RpcRequest::GetTokenSupply,
                json!([mint.to_string(), config]),
            )
            .await
    }

    /// Return the fee the cluster would charge to process a base64-encoded transaction message.
    pub async fn get_fee_for_message(
        &self,
        message: String,
        config: Option<RpcContextConfig>,
    ) -> RpcResult<Response<Option<u64>>> {
        self.provider
            .send(RpcRequest::GetFeeForMessage, json!([message, config]))
            .await
    }

    /// Fetch the latest blockhash and the last block height at which it is still valid.
    pub async fn get_latest_blockhash(
        &self,
        config: Option<RpcContextConfig>,
    ) -> RpcResult<Response<RpcBlockhash>> {
        self.provider
            .send(RpcRequest::GetLatestBlockhash, json!([config]))
            .await
    }

    /// Return recent per-slot prioritization fees, optionally restricted to accounts that must be
    /// writable.
    pub async fn get_recent_prioritization_fees(
        &self,
        addresses: Option<&[Address]>,
    ) -> RpcResult<Vec<RpcPrioritizationFee>> {
        // Omit the positional entirely when `None` — the RPC rejects `[null]`.
        let params = match addresses {
            Some(addresses) => {
                let addresses: Vec<String> = addresses.iter().map(Address::to_string).collect();
                json!([addresses])
            }
            None => json!([]),
        };
        self.provider
            .send(RpcRequest::GetRecentPrioritizationFees, params)
            .await
    }

    /// Return confirmed transaction signatures involving the given address, most recent first.
    pub async fn get_signatures_for_address(
        &self,
        address: &Address,
        config: Option<RpcSignaturesForAddressConfig>,
    ) -> RpcResult<Vec<RpcConfirmedTransactionStatusWithSignature>> {
        self.provider
            .send(
                RpcRequest::GetSignaturesForAddress,
                json!([address.to_string(), config]),
            )
            .await
    }

    /// Return the processing status of one or more transaction signatures.
    pub async fn get_signature_statuses(
        &self,
        signatures: Vec<String>,
        config: Option<RpcSignatureStatusConfig>,
    ) -> RpcResult<Response<Vec<Option<TransactionStatus>>>> {
        self.provider
            .send(
                RpcRequest::GetSignatureStatuses,
                json!([signatures, config]),
            )
            .await
    }

    /// Fetch a confirmed transaction by its signature.
    pub async fn get_transaction(
        &self,
        signature: String,
        config: Option<RpcEncodingConfigWrapper<RpcTransactionConfig>>,
    ) -> RpcResult<Option<EncodedConfirmedTransactionWithStatusMeta>> {
        self.provider
            .send(RpcRequest::GetTransaction, json!([signature, config]))
            .await
    }

    /// Return the cumulative number of transactions processed by the cluster.
    pub async fn get_transaction_count(&self, config: Option<RpcContextConfig>) -> RpcResult<u64> {
        self.provider
            .send(RpcRequest::GetTransactionCount, json!([config]))
            .await
    }

    /// Report whether the given blockhash is still valid.
    pub async fn is_blockhash_valid(
        &self,
        blockhash: String,
        config: Option<RpcContextConfig>,
    ) -> RpcResult<Response<bool>> {
        self.provider
            .send(RpcRequest::IsBlockhashValid, json!([blockhash, config]))
            .await
    }

    /// Request an airdrop of lamports to an address (devnet/testnet only). Returns the signature.
    pub async fn request_airdrop(
        &self,
        address: &Address,
        lamports: u64,
        config: Option<RpcRequestAirdropConfig>,
    ) -> RpcResult<String> {
        self.provider
            .send(
                RpcRequest::RequestAirdrop,
                json!([address.to_string(), lamports, config]),
            )
            .await
    }

    /// Submit a signed transaction. Does not wait for confirmation; returns the signature.
    pub async fn send_transaction(
        &self,
        transaction: String,
        config: Option<RpcSendTransactionConfig>,
    ) -> RpcResult<String> {
        self.provider
            .send(RpcRequest::SendTransaction, json!([transaction, config]))
            .await
    }

    /// Simulate a transaction without submitting it. Returns logs, accounts, and any error.
    pub async fn simulate_transaction(
        &self,
        transaction: String,
        config: Option<RpcSimulateTransactionConfig>,
    ) -> RpcResult<Response<RpcSimulateTransactionResult>> {
        self.provider
            .send(
                RpcRequest::SimulateTransaction,
                json!([transaction, config]),
            )
            .await
    }

    /// Fetch a confirmed block by slot.
    pub async fn get_block(
        &self,
        slot: u64,
        config: Option<RpcEncodingConfigWrapper<RpcBlockConfig>>,
    ) -> RpcResult<UiConfirmedBlock> {
        self.provider
            .send(RpcRequest::GetBlock, json!([slot, config]))
            .await
    }

    /// Return per-stake vote commitment for a block at the given slot.
    pub async fn get_block_commitment(
        &self,
        slot: u64,
    ) -> RpcResult<RpcBlockCommitment<Vec<usize>>> {
        self.provider
            .send(
                RpcRequest::Custom {
                    method: "getBlockCommitment",
                },
                json!([slot]),
            )
            .await
    }

    /// Return the current block height of the node.
    pub async fn get_block_height(&self, config: Option<RpcContextConfig>) -> RpcResult<u64> {
        self.provider
            .send(RpcRequest::GetBlockHeight, json!([config]))
            .await
    }

    /// Return recent block production information, broken down by validator identity.
    pub async fn get_block_production(
        &self,
        config: Option<RpcBlockProductionConfig>,
    ) -> RpcResult<Response<RpcBlockProduction>> {
        self.provider
            .send(RpcRequest::GetBlockProduction, json!([config]))
            .await
    }

    /// List confirmed blocks in the inclusive slot range `[start_slot, end_slot]`.
    pub async fn get_blocks(
        &self,
        start_slot: u64,
        end_slot: Option<u64>,
        config: Option<RpcContextConfig>,
    ) -> RpcResult<Vec<u64>> {
        self.provider
            .send(RpcRequest::GetBlocks, json!([start_slot, end_slot, config]))
            .await
    }

    /// List up to `limit` confirmed blocks starting at `start_slot`.
    pub async fn get_blocks_with_limit(
        &self,
        start_slot: u64,
        limit: u64,
        config: Option<RpcContextConfig>,
    ) -> RpcResult<Vec<u64>> {
        self.provider
            .send(
                RpcRequest::GetBlocksWithLimit,
                json!([start_slot, limit, config]),
            )
            .await
    }

    /// Return the estimated UNIX production timestamp of a block, if available.
    pub async fn get_block_time(&self, slot: u64) -> RpcResult<Option<i64>> {
        self.provider
            .send(RpcRequest::GetBlockTime, json!([slot]))
            .await
    }

    /// Return the slot of the lowest confirmed block still retained by the node.
    pub async fn get_first_available_block(&self) -> RpcResult<u64> {
        self.provider
            .send(RpcRequest::GetFirstAvailableBlock, json!([]))
            .await
    }

    /// Return recent slot-time performance samples, up to `limit` (default 720).
    pub async fn get_recent_performance_samples(
        &self,
        limit: Option<u32>,
    ) -> RpcResult<Vec<RpcPerfSample>> {
        // Omit the positional entirely when `None` — the RPC rejects `[null]`.
        let params = match limit {
            Some(n) => json!([n]),
            None => json!([]),
        };
        self.provider
            .send(RpcRequest::GetRecentPerformanceSamples, params)
            .await
    }

    /// Return the lowest slot the node has information about.
    pub async fn minimum_ledger_slot(&self) -> RpcResult<u64> {
        self.provider
            .send(RpcRequest::MinimumLedgerSlot, json!([]))
            .await
    }

    /// Return information about all known cluster nodes.
    pub async fn get_cluster_nodes(&self) -> RpcResult<Vec<RpcContactInfo>> {
        self.provider
            .send(RpcRequest::GetClusterNodes, json!([]))
            .await
    }

    /// Return information about the current epoch.
    pub async fn get_epoch_info(&self, config: Option<RpcEpochConfig>) -> RpcResult<EpochInfo> {
        self.provider
            .send(RpcRequest::GetEpochInfo, json!([config]))
            .await
    }

    /// Return the cluster's epoch schedule parameters from the genesis config.
    pub async fn get_epoch_schedule(&self) -> RpcResult<EpochSchedule> {
        self.provider
            .send(RpcRequest::GetEpochSchedule, json!([]))
            .await
    }

    /// Return the cluster's genesis hash.
    pub async fn get_genesis_hash(&self) -> RpcResult<String> {
        self.provider
            .send(RpcRequest::GetGenesisHash, json!([]))
            .await
    }

    /// Return `"ok"` when the node is caught up with its peers.
    pub async fn get_health(&self) -> RpcResult<String> {
        self.provider.send(RpcRequest::GetHealth, json!([])).await
    }

    /// Return the highest full (and optional incremental) snapshot slot the node has stored.
    pub async fn get_highest_snapshot_slot(&self) -> RpcResult<RpcSnapshotSlotInfo> {
        self.provider
            .send(RpcRequest::GetHighestSnapshotSlot, json!([]))
            .await
    }

    /// Return the node's identity pubkey.
    pub async fn get_identity(&self) -> RpcResult<RpcIdentity> {
        self.provider.send(RpcRequest::GetIdentity, json!([])).await
    }

    /// Return the leader schedule for the epoch containing `slot` (or the current epoch).
    pub async fn get_leader_schedule(
        &self,
        slot: Option<u64>,
        config: Option<RpcLeaderScheduleConfig>,
    ) -> RpcResult<Option<RpcLeaderSchedule>> {
        self.provider
            .send(RpcRequest::GetLeaderSchedule, json!([slot, config]))
            .await
    }

    /// Return the highest slot seen via the retransmit stage.
    pub async fn get_max_retransmit_slot(&self) -> RpcResult<u64> {
        self.provider
            .send(RpcRequest::GetMaxRetransmitSlot, json!([]))
            .await
    }

    /// Return the highest slot for which shreds have been inserted.
    pub async fn get_max_shred_insert_slot(&self) -> RpcResult<u64> {
        self.provider
            .send(RpcRequest::GetMaxShredInsertSlot, json!([]))
            .await
    }

    /// Return the slot the node is currently processing.
    pub async fn get_slot(&self, config: Option<RpcContextConfig>) -> RpcResult<u64> {
        self.provider
            .send(RpcRequest::GetSlot, json!([config]))
            .await
    }

    /// Return the identity of the current slot leader.
    pub async fn get_slot_leader(&self, config: Option<RpcContextConfig>) -> RpcResult<String> {
        self.provider
            .send(RpcRequest::GetSlotLeader, json!([config]))
            .await
    }

    /// Return the slot leaders for the half-open range `[start_slot, start_slot + limit)`.
    pub async fn get_slot_leaders(&self, start_slot: u64, limit: u64) -> RpcResult<Vec<String>> {
        self.provider
            .send(RpcRequest::GetSlotLeaders, json!([start_slot, limit]))
            .await
    }

    /// Return the node's software version.
    pub async fn get_version(&self) -> RpcResult<RpcVersionInfo> {
        self.provider.send(RpcRequest::GetVersion, json!([])).await
    }

    /// Return the current and delinquent vote accounts.
    pub async fn get_vote_accounts(
        &self,
        config: Option<RpcGetVoteAccountsConfig>,
    ) -> RpcResult<RpcVoteAccountStatus> {
        self.provider
            .send(RpcRequest::GetVoteAccounts, json!([config]))
            .await
    }

    /// Return the cluster's current inflation governor.
    pub async fn get_inflation_governor(
        &self,
        config: Option<CommitmentConfig>,
    ) -> RpcResult<RpcInflationGovernor> {
        self.provider
            .send(RpcRequest::GetInflationGovernor, json!([config]))
            .await
    }

    /// Return the specific inflation values for the current epoch.
    pub async fn get_inflation_rate(&self) -> RpcResult<RpcInflationRate> {
        self.provider
            .send(RpcRequest::GetInflationRate, json!([]))
            .await
    }

    /// Return inflation rewards earned by a list of addresses during an epoch.
    pub async fn get_inflation_reward(
        &self,
        addresses: &[Address],
        config: Option<RpcEpochConfig>,
    ) -> RpcResult<Vec<Option<RpcInflationReward>>> {
        let addresses: Vec<String> = addresses.iter().map(Address::to_string).collect();
        self.provider
            .send(RpcRequest::GetInflationReward, json!([addresses, config]))
            .await
    }

    /// Return the stake-program minimum delegation in lamports.
    pub async fn get_stake_minimum_delegation(
        &self,
        config: Option<CommitmentConfig>,
    ) -> RpcResult<Response<u64>> {
        self.provider
            .send(RpcRequest::GetStakeMinimumDelegation, json!([config]))
            .await
    }

    /// Return information about the cluster's circulating and non-circulating supply.
    pub async fn get_supply(
        &self,
        config: Option<RpcSupplyConfig>,
    ) -> RpcResult<Response<RpcSupply>> {
        self.provider
            .send(RpcRequest::GetSupply, json!([config]))
            .await
    }
}