celestia-client 0.3.0

Celestia client combining RPC and gRPC functionality.
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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
use std::sync::Arc;

use celestia_rpc::{HeaderClient, StateClient};

use crate::Error;
use crate::client::ClientInner;
use crate::proto::cosmos::bank::v1beta1::MsgSend;
use crate::proto::cosmos::staking::v1beta1::{
    MsgBeginRedelegate, MsgCancelUnbondingDelegation, MsgDelegate, MsgUndelegate,
};
use crate::tx::{GasEstimate, IntoProtobufAny, TxConfig, TxInfo, TxPriority};
use crate::types::Blob;
use crate::types::state::{
    AccAddress, Address, Coin, PageRequest, QueryDelegationResponse, QueryRedelegationsResponse,
    QueryUnbondingDelegationResponse, ValAddress,
};
use crate::utils::height_i64;

/// An async grpc call with [`crate::Error`]
pub type AsyncGrpcCall<Response> = celestia_grpc::grpc::AsyncGrpcCall<Response, crate::Error>;

/// State API for quering and submiting TXs to a consensus node.
pub struct StateApi {
    inner: Arc<ClientInner>,
}

impl StateApi {
    pub(crate) fn new(inner: Arc<ClientInner>) -> StateApi {
        StateApi { inner }
    }

    /// Retrieves the Celestia coin balance for the signer. To query balance without
    /// adding signer to the client, see [`StateApi::balance_for_address`].
    ///
    /// # Notes
    ///
    /// This returns the verified balance which is the one that was reported by
    /// the previous network block. In other words, if you transfer some coins,
    /// you need to wait 1 more block in order to see the new balance. If you want
    /// something more immediate then use [`StateApi::balance_unverified`].
    pub fn balance(&self) -> AsyncGrpcCall<u64> {
        let this = StateApi::new(self.inner.clone());

        AsyncGrpcCall::new(move |context| async move {
            let address = this.inner.address()?;
            this.balance_for_address(&address).context(&context).await
        })
    }

    /// Retrieves the Celestia coin balance for the signer. To query balance without
    /// adding signer to the client, see [`StateApi::balance_for_address_unverified`].
    pub fn balance_unverified(&self) -> AsyncGrpcCall<u64> {
        let this = StateApi::new(self.inner.clone());

        AsyncGrpcCall::new(move |context| async move {
            let address = this.inner.address()?;
            this.balance_for_address_unverified(&address)
                .context(&context)
                .await
        })
    }

    /// Retrieves the Celestia coin balance for the given address.
    ///
    /// # Notes
    ///
    /// This returns the verified balance which is the one that was reported by
    /// the previous network block. In other words, if you transfer some coins,
    /// you need to wait 1 more block in order to see the new balance. If you want
    /// something more immediate then use [`StateApi::balance_for_address_unverified`].
    ///
    /// This is the only method of [`StateApi`] that fallbacks to RPC endpoint
    /// when gRPC endpoint wasn't set.
    pub fn balance_for_address(&self, address: &AccAddress) -> AsyncGrpcCall<u64> {
        let inner = self.inner.clone();
        let address = Address::AccAddress(address.to_owned());

        AsyncGrpcCall::new(move |context| async move {
            let grpc = match inner.grpc() {
                Ok(grpc) => grpc,
                Err(_) => {
                    return Ok(inner
                        .rpc
                        .state_balance_for_address(&address)
                        .await?
                        .amount());
                }
            };

            let head = inner.rpc.header_network_head().await?;
            head.validate()?;

            Ok(grpc
                .get_verified_balance(&address, &head)
                .context(&context)
                .await?
                .amount())
        })
    }

    /// Retrieves the Celestia coin balance for the given address.
    pub fn balance_for_address_unverified(&self, address: &AccAddress) -> AsyncGrpcCall<u64> {
        let inner = self.inner.clone();
        let address = address.to_owned().into();

        AsyncGrpcCall::new(move |context| async move {
            Ok(inner
                .grpc()?
                .get_balance(&address, "utia")
                .context(&context)
                .await
                .map(|res| res.amount())?)
        })
    }

    /// Estimate gas price for given transaction priority based
    /// on the gas prices of the transactions in the last five blocks.
    ///
    /// If no transaction is found in the last five blocks, it returns the
    /// network min gas price.
    pub fn estimate_gas_price(&self, priority: TxPriority) -> AsyncGrpcCall<f64> {
        let inner = self.inner.clone();

        AsyncGrpcCall::new(move |context| async move {
            Ok(inner
                .grpc()?
                .estimate_gas_price(priority)
                .context(&context)
                .await?)
        })
    }

    /// Estimate gas price for transaction with given priority and estimate gas usage
    /// for provided serialised transaction.
    ///
    /// The gas price estimation is based on the gas prices of the transactions
    /// in the last five blocks. If no transaction is found in the last five blocks,
    /// it returns the network min gas price.
    ///
    /// The gas used is estimated using the state machine simulation.
    pub fn estimate_gas_price_and_usage(
        &self,
        priority: TxPriority,
        tx_bytes: Vec<u8>,
    ) -> AsyncGrpcCall<GasEstimate> {
        let inner = self.inner.clone();

        AsyncGrpcCall::new(move |context| async move {
            Ok(inner
                .grpc()?
                .estimate_gas_price_and_usage(priority, tx_bytes)
                .context(&context)
                .await?)
        })
    }

    /// Submit given message to celestia network.
    ///
    /// # Example
    /// ```no_run
    /// # use celestia_client::{Client, Result};
    /// # use celestia_client::tx::TxConfig;
    /// # async fn docs() -> Result<()> {
    /// use celestia_proto::cosmos::bank::v1beta1::MsgSend;
    /// use celestia_types::state::{Address, Coin};
    ///
    /// let client = Client::builder()
    ///     .rpc_url("ws://localhost:26658")
    ///     .grpc_url("http://localhost:9090")
    ///     .private_key_hex("393fdb5def075819de55756b45c9e2c8531a8c78dd6eede483d3440e9457d839")
    ///     .build()
    ///     .await?;
    ///
    /// let msg = MsgSend {
    ///     from_address: client.address()?.to_string(),
    ///     to_address: "celestia169s50psyj2f4la9a2235329xz7rk6c53zhw9mm".to_string(),
    ///     amount: vec![Coin::utia(12345).into()],
    /// };
    ///
    /// client
    ///     .state()
    ///     .submit_message(msg, TxConfig::default())
    ///     .await?;
    /// # Ok(())
    /// # }
    /// ```
    pub fn submit_message<M>(&self, message: M, cfg: TxConfig) -> AsyncGrpcCall<TxInfo>
    where
        M: IntoProtobufAny + Send + 'static,
    {
        let inner = self.inner.clone();

        AsyncGrpcCall::new(move |context| async move {
            Ok(inner
                .grpc()?
                .submit_message(message, cfg)
                .context(&context)
                .await?)
        })
    }

    /// Sends the given amount of coins from signer's wallet to the given account address.
    pub fn transfer(
        &self,
        to_address: &AccAddress,
        amount: u64,
        cfg: TxConfig,
    ) -> AsyncGrpcCall<TxInfo> {
        let this = StateApi::new(self.inner.clone());
        let to_address = to_address.to_string();

        AsyncGrpcCall::new(move |context| async move {
            // remap error to one more appropriate in this context
            let from_address = this.inner.address().map_err(|_| Error::ReadOnlyMode)?;

            let msg = MsgSend {
                from_address: from_address.to_string(),
                to_address,
                amount: vec![Coin::utia(amount).into()],
            };

            this.submit_message(msg, cfg).context(&context).await
        })
    }

    /// Builds, signs and submits a PayForBlob transaction.
    ///
    /// # Note
    ///
    /// This is the same as [`BlobApi::submit`].
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use celestia_client::{Client, Result};
    /// # use celestia_client::tx::TxConfig;
    /// # async fn docs() -> Result<()> {
    /// use celestia_types::nmt::Namespace;
    /// use celestia_types::state::{Address, Coin};
    /// use celestia_types::{AppVersion, Blob};
    ///
    /// let client = Client::builder()
    ///     .rpc_url("ws://localhost:26658")
    ///     .grpc_url("http://localhost:9090")
    ///     .private_key_hex("393fdb5def075819de55756b45c9e2c8531a8c78dd6eede483d3440e9457d839")
    ///     .build()
    ///     .await?;
    ///
    /// let ns = Namespace::new_v0(b"abcd").unwrap();
    /// let blob = Blob::new(ns, "some data".into(), None, AppVersion::V3).unwrap();
    ///
    /// client
    ///     .state()
    ///     .submit_pay_for_blob(&[blob], TxConfig::default())
    ///     .await?;
    /// # Ok(())
    /// # }
    /// ```
    ///
    /// [`BlobApi::submit`]: crate::api::BlobApi::submit
    pub fn submit_pay_for_blob(&self, blobs: &[Blob], cfg: TxConfig) -> AsyncGrpcCall<TxInfo> {
        let inner = self.inner.clone();
        let blobs = blobs.to_vec();

        AsyncGrpcCall::new(move |context| async move {
            Ok(inner
                .grpc()?
                .submit_blobs(&blobs, cfg)
                .context(&context)
                .await?)
        })
    }

    /// Cancels signer's pending undelegation from a validator.
    pub fn cancel_unbonding_delegation(
        &self,
        validator_address: &ValAddress,
        amount: u64,
        creation_height: u64,
        cfg: TxConfig,
    ) -> AsyncGrpcCall<TxInfo> {
        let this = StateApi::new(self.inner.clone());
        let validator_address = validator_address.to_string();

        AsyncGrpcCall::new(move |context| async move {
            let delegator_address = this.inner.address()?;

            let msg = MsgCancelUnbondingDelegation {
                delegator_address: delegator_address.to_string(),
                validator_address,
                amount: Some(Coin::utia(amount).into()),
                creation_height: height_i64(creation_height)?,
            };

            this.submit_message(msg, cfg).context(&context).await
        })
    }

    /// Sends signer's delegated tokens to a new validator for redelegation.
    pub fn begin_redelegate(
        &self,
        src_validator_address: &ValAddress,
        dest_validator_address: &ValAddress,
        amount: u64,
        cfg: TxConfig,
    ) -> AsyncGrpcCall<TxInfo> {
        let this = StateApi::new(self.inner.clone());
        let validator_src_address = src_validator_address.to_string();
        let validator_dst_address = dest_validator_address.to_string();

        AsyncGrpcCall::new(move |context| async move {
            let delegator_address = this.inner.address()?;

            let msg = MsgBeginRedelegate {
                delegator_address: delegator_address.to_string(),
                validator_src_address,
                validator_dst_address,
                amount: Some(Coin::utia(amount).into()),
            };

            this.submit_message(msg, cfg).context(&context).await
        })
    }

    /// Undelegates signer's delegated tokens, unbonding them from the current validator.
    pub fn undelegate(
        &self,
        validator_address: &ValAddress,
        amount: u64,
        cfg: TxConfig,
    ) -> AsyncGrpcCall<TxInfo> {
        let this = StateApi::new(self.inner.clone());
        let validator_address = validator_address.to_string();

        AsyncGrpcCall::new(move |context| async move {
            let delegator_address = this.inner.address()?;

            let msg = MsgUndelegate {
                delegator_address: delegator_address.to_string(),
                validator_address,
                amount: Some(Coin::utia(amount).into()),
            };

            this.submit_message(msg, cfg).context(&context).await
        })
    }

    /// Sends signer's liquid tokens to a validator for delegation.
    pub fn delegate(
        &self,
        validator_address: &ValAddress,
        amount: u64,
        cfg: TxConfig,
    ) -> AsyncGrpcCall<TxInfo> {
        let this = StateApi::new(self.inner.clone());
        let validator_address = validator_address.to_string();

        AsyncGrpcCall::new(move |context| async move {
            let delegator_address = this.inner.address()?;

            let msg = MsgDelegate {
                delegator_address: delegator_address.to_string(),
                validator_address,
                amount: Some(Coin::utia(amount).into()),
            };

            this.submit_message(msg, cfg).context(&context).await
        })
    }

    /// Retrieves the delegation information between signer and a validator.
    pub fn query_delegation(
        &self,
        validator_address: &ValAddress,
    ) -> AsyncGrpcCall<QueryDelegationResponse> {
        let this = StateApi::new(self.inner.clone());
        let validator_address = *validator_address;

        AsyncGrpcCall::new(move |context| async move {
            let delegator_address = this.inner.address()?;

            Ok(this
                .inner
                .grpc()?
                .query_delegation(&delegator_address, &validator_address)
                .context(&context)
                .await?)
        })
    }

    /// Retrieves the unbonding status between signer and a validator.
    pub fn query_unbonding(
        &self,
        validator_address: &ValAddress,
    ) -> AsyncGrpcCall<QueryUnbondingDelegationResponse> {
        let this = StateApi::new(self.inner.clone());
        let validator_address = *validator_address;

        AsyncGrpcCall::new(move |context| async move {
            let delegator_address = this.inner.address()?;

            Ok(this
                .inner
                .grpc()?
                .query_unbonding(&delegator_address, &validator_address)
                .context(&context)
                .await?)
        })
    }

    /// Retrieves the status of the redelegations between signer and a validator.
    pub fn query_redelegations(
        &self,
        src_validator_address: &ValAddress,
        dest_validator_address: &ValAddress,
    ) -> AsyncGrpcCall<QueryRedelegationsResponse> {
        let this = StateApi::new(self.inner.clone());
        let src_validator_address = *src_validator_address;
        let dest_validator_address = *dest_validator_address;

        AsyncGrpcCall::new(move |context| async move {
            let delegator_address = this.inner.address()?;

            let mut full_resp = QueryRedelegationsResponse {
                responses: Vec::new(),
                pagination: None,
            };

            let mut next_key = Vec::new();

            loop {
                let mut resp = this
                    .inner
                    .grpc()?
                    .query_redelegations(
                        &delegator_address,
                        &src_validator_address,
                        &dest_validator_address,
                        Some(PageRequest {
                            key: next_key,
                            ..Default::default()
                        }),
                    )
                    .context(&context)
                    .await?;

                full_resp.responses.append(&mut resp.responses);

                match resp.pagination {
                    Some(pagination) => next_key = pagination.next_key,
                    None => break,
                }
            }

            Ok(full_resp)
        })
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    use celestia_grpc::TxConfig;
    use k256::ecdsa::SigningKey;
    use lumina_utils::test_utils::async_test;

    use crate::Error;
    use crate::test_utils::{
        ensure_serializable_deserializable, new_client, new_read_only_client, new_rpc_only_client,
        node0_address, validator_address,
    };

    #[async_test]
    async fn transfer() {
        let client = new_client().await;

        let random_key = SigningKey::random(&mut rand::rngs::OsRng);
        let random_acc = random_key.verifying_key().into();

        client
            .state()
            .transfer(&random_acc, 123, TxConfig::default())
            .await
            .unwrap();

        assert_eq!(
            client
                .state()
                .balance_for_address_unverified(&random_acc)
                .await
                .unwrap(),
            123
        );

        let client_ro = new_read_only_client().await;
        let e = client_ro
            .state()
            .transfer(&random_acc, 123, TxConfig::default())
            .await
            .unwrap_err();

        assert!(matches!(e, Error::ReadOnlyMode));
    }

    #[async_test]
    async fn delegation() {
        let client = new_client().await;
        let validator_addr = validator_address();
        let client_addr = client.address().unwrap();

        // Test delegation
        client
            .state()
            .delegate(&validator_addr, 100, TxConfig::default())
            .await
            .unwrap();

        let del = client
            .state()
            .query_delegation(&validator_addr)
            .await
            .unwrap();

        assert_eq!(del.response.balance, 100);
        assert_eq!(del.response.delegation.delegator_address, client_addr);
        assert_eq!(del.response.delegation.validator_address, validator_addr);
        assert_eq!(del.response.delegation.shares, 100.into());

        // Test unbonding
        let unbond_tx_height = client
            .state()
            .undelegate(&validator_addr, 10, TxConfig::default())
            .await
            .unwrap()
            .height
            .value();

        let unbond = client
            .state()
            .query_unbonding(&validator_addr)
            .await
            .unwrap();

        assert_eq!(unbond.unbond.delegator_address, client_addr);
        assert_eq!(unbond.unbond.validator_address, validator_addr);
        assert_eq!(unbond.unbond.entries.len(), 1);
        assert_eq!(
            unbond.unbond.entries[0].creation_height.value(),
            unbond_tx_height
        );
        assert_eq!(unbond.unbond.entries[0].initial_balance, 10);
        assert_eq!(unbond.unbond.entries[0].balance, 10);

        let del = client
            .state()
            .query_delegation(&validator_addr)
            .await
            .unwrap();

        assert_eq!(del.response.balance, 90);
        assert_eq!(del.response.delegation.delegator_address, client_addr);
        assert_eq!(del.response.delegation.validator_address, validator_addr);
        assert_eq!(del.response.delegation.shares, 90.into());

        // Test partial cancel unbonding
        client
            .state()
            .cancel_unbonding_delegation(&validator_addr, 3, unbond_tx_height, TxConfig::default())
            .await
            .unwrap();

        let unbond = client
            .state()
            .query_unbonding(&validator_addr)
            .await
            .unwrap();

        assert_eq!(unbond.unbond.delegator_address, client_addr);
        assert_eq!(unbond.unbond.validator_address, validator_addr);
        assert_eq!(unbond.unbond.entries.len(), 1);
        assert_eq!(
            unbond.unbond.entries[0].creation_height.value(),
            unbond_tx_height
        );
        assert_eq!(unbond.unbond.entries[0].initial_balance, 7);
        assert_eq!(unbond.unbond.entries[0].balance, 7);

        let del = client
            .state()
            .query_delegation(&validator_addr)
            .await
            .unwrap();

        assert_eq!(del.response.balance, 93);
        assert_eq!(del.response.delegation.delegator_address, client_addr);
        assert_eq!(del.response.delegation.validator_address, validator_addr);
        assert_eq!(del.response.delegation.shares, 93.into());

        // Test fully cancel unbonding
        client
            .state()
            .cancel_unbonding_delegation(&validator_addr, 7, unbond_tx_height, TxConfig::default())
            .await
            .unwrap();

        let err = client
            .state()
            .query_unbonding(&validator_addr)
            .await
            .unwrap_err();

        assert_eq!(err.as_grpc_status().unwrap().code(), tonic::Code::NotFound);

        let del = client
            .state()
            .query_delegation(&validator_addr)
            .await
            .unwrap();

        assert_eq!(del.response.balance, 100);
        assert_eq!(del.response.delegation.delegator_address, client_addr);
        assert_eq!(del.response.delegation.validator_address, validator_addr);
        assert_eq!(del.response.delegation.shares, 100.into());
    }

    #[async_test]
    async fn balance_for_address() {
        let client_ro = new_read_only_client().await;

        // Read only mode allows calling `balance_for_address`
        let addr = node0_address();
        let balance = client_ro.state().balance_for_address(&addr).await.unwrap();
        assert!(balance > 0);

        // Read only mode allows calling `balance_for_address_unverified`.
        let balance = client_ro
            .state()
            .balance_for_address_unverified(&addr)
            .await
            .unwrap();
        assert!(balance > 0);

        // Read only mode does not allow calling `balance`
        let e = client_ro.state().balance().await.unwrap_err();
        assert!(matches!(e, Error::NoAssociatedAddress));

        // Read only mode does not allow calling `balance_unverified`
        let e = client_ro.state().balance().await.unwrap_err();
        assert!(matches!(e, Error::NoAssociatedAddress));

        let client_rpc = new_rpc_only_client().await;

        // RPC only mode allows calling `balance_for_address`
        let balance = client_rpc.state().balance_for_address(&addr).await.unwrap();
        assert!(balance > 0);

        // RPC only mode does not allow calling `balance_for_address_unverified`.
        let e = client_rpc
            .state()
            .balance_for_address_unverified(&addr)
            .await
            .unwrap_err();
        assert!(matches!(e, Error::GrpcEndpointNotSet));
    }

    #[allow(dead_code)]
    #[allow(unused_variables)]
    #[allow(unreachable_code)]
    #[allow(clippy::diverging_sub_expression)]
    async fn enforce_serde_bounds() {
        // intentionally no-run, compile only test
        let api = StateApi::new(unimplemented!());

        let cfg = ensure_serializable_deserializable(TxConfig::default());
        let val_addr: ValAddress = ensure_serializable_deserializable(unimplemented!());
        let acc_addr: AccAddress = ensure_serializable_deserializable(unimplemented!());

        ensure_serializable_deserializable(api.balance().await.unwrap());

        ensure_serializable_deserializable(api.balance_unverified().await.unwrap());

        ensure_serializable_deserializable(api.balance_for_address(&acc_addr).await.unwrap());

        ensure_serializable_deserializable(
            api.balance_for_address_unverified(&acc_addr).await.unwrap(),
        );

        ensure_serializable_deserializable(api.estimate_gas_price(TxPriority::Low).await.unwrap());

        ensure_serializable_deserializable(
            api.estimate_gas_price_and_usage(TxPriority::Low, Vec::new())
                .await
                .unwrap(),
        );

        ensure_serializable_deserializable(api.submit_message((), cfg).await.unwrap());

        ensure_serializable_deserializable(api.transfer(&acc_addr, 0, cfg).await.unwrap());

        let blobs: Vec<_> = ensure_serializable_deserializable(unimplemented!());
        ensure_serializable_deserializable(api.submit_pay_for_blob(&blobs, cfg).await.unwrap());

        ensure_serializable_deserializable(
            api.cancel_unbonding_delegation(&val_addr, 0, 0, cfg)
                .await
                .unwrap(),
        );

        ensure_serializable_deserializable(
            api.begin_redelegate(&val_addr, &val_addr, 0, cfg)
                .await
                .unwrap(),
        );

        ensure_serializable_deserializable(api.undelegate(&val_addr, 0, cfg).await.unwrap());

        ensure_serializable_deserializable(api.delegate(&val_addr, 0, cfg).await.unwrap());

        ensure_serializable_deserializable(api.query_delegation(&val_addr).await.unwrap());

        ensure_serializable_deserializable(api.query_unbonding(&val_addr).await.unwrap());

        ensure_serializable_deserializable(
            api.query_redelegations(&val_addr, &val_addr).await.unwrap(),
        );
    }
}