rialo-api-types 0.8.0-alpha.0

API types for Rialo RPC endpoints
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
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
// Copyright (c) Subzero Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//! Request types for node RPC handlers
//!
//! These types provide strongly-typed deserialization for RPC request parameters
//! in node handlers, replacing manual parameter parsing.

use serde::{Deserialize, Serialize};
use validator::Validate;

use crate::{
    messages::send_transaction::SendTransactionConfig,
    validation::{
        validate_airdrop_amount_i64, validate_base58, validate_protocol_version, validate_pubkey,
        validate_signature, validate_transaction_data,
    },
    GetBlockRequest, GetSignatureStatusesRequest,
};

/// Request type for getSubscription RPC handler
#[derive(Debug, Deserialize, Serialize, Clone, Validate)]
pub struct GetSubscriptionRequest {
    #[serde(default)]
    #[validate(custom(function = validate_protocol_version))]
    pub version: u16,

    #[validate(length(min = 1, message = "Subscriber pubkey cannot be empty"))]
    #[validate(custom(function = validate_pubkey))]
    pub subscriber: String,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub nonce: Option<String>,
}

impl GetSubscriptionRequest {
    pub fn new(subscriber: String, nonce: Option<String>) -> Self {
        Self {
            version: 0,
            subscriber,
            nonce,
        }
    }
}

/// Request type for getTriggeredTransactions RPC handler
#[derive(Debug, Deserialize, Serialize, Clone, Validate)]
pub struct GetTriggeredTransactionsRequest {
    #[serde(default)]
    #[validate(custom(function = validate_protocol_version))]
    pub version: u16,

    #[validate(length(min = 1, message = "Subscription pubkey cannot be empty"))]
    #[validate(custom(function = validate_pubkey))]
    pub subscription_pubkey: String,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<String>,
}

impl GetTriggeredTransactionsRequest {
    pub fn new(subscription_pubkey: String, limit: Option<String>) -> Self {
        Self {
            version: 0,
            subscription_pubkey,
            limit,
        }
    }
}

/// Request type for sendTransaction RPC handler
#[derive(Debug, Deserialize, Serialize, Clone, Validate, PartialEq)]
pub struct SendTransactionRequest {
    #[validate(length(min = 1, message = "Transaction cannot be empty"))]
    #[validate(custom(function = validate_transaction_data))]
    pub transaction: String,

    #[validate(nested)]
    pub config: crate::messages::send_transaction::SendTransactionConfig,
}

impl SendTransactionRequest {
    pub fn new(
        transaction: String,
        config: crate::messages::send_transaction::SendTransactionConfig,
    ) -> Self {
        Self {
            transaction,
            config,
        }
    }
}

/// Request type for getTransaction RPC handler
#[derive(Debug, Deserialize, Serialize, Clone, Validate)]
pub struct GetTransactionRequest {
    #[validate(length(min = 1, message = "Signature cannot be empty"))]
    #[validate(custom(function = validate_signature))]
    pub signature: String,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub config: Option<serde_json::Value>,
}

impl GetTransactionRequest {
    pub fn new(signature: String, config: Option<serde_json::Value>) -> Self {
        Self { signature, config }
    }

    pub fn new_simple(signature: String) -> Self {
        Self {
            signature,
            config: Some(serde_json::json!({"encoding": "json"})),
        }
    }
}

/// Request type for isBlockhashValid RPC handler
#[derive(Debug, Deserialize, Serialize, Clone, Validate)]
pub struct IsBlockhashValidRequest {
    #[serde(default)]
    #[validate(custom(function = validate_protocol_version))]
    pub version: u16,

    #[validate(length(min = 1, message = "Blockhash cannot be empty"))]
    #[validate(custom(function = validate_base58))]
    pub blockhash: String,
}

impl IsBlockhashValidRequest {
    pub fn new(blockhash: String) -> Self {
        Self {
            version: 0,
            blockhash,
        }
    }

    pub fn new_simple(blockhash: String) -> Self {
        Self {
            version: 0,
            blockhash,
        }
    }
}

/// Request type for requestAirdrop RPC handler
#[derive(Debug, Deserialize, Serialize, Clone, Validate)]
pub struct RequestAirdropRequest {
    /// Public key of the account to airdrop to, in base58 encoding
    #[validate(length(min = 1, message = "Pubkey cannot be empty"))]
    #[validate(custom(function = validate_pubkey))]
    pub pubkey: String,

    /// Amount of kelvins to airdrop
    #[validate(custom(function = validate_airdrop_amount_i64))]
    pub kelvins: i64,
}

impl RequestAirdropRequest {
    pub fn new(pubkey: String, kelvins: i64) -> Self {
        Self { pubkey, kelvins }
    }
}

/// Generic RPC request wrapper that can handle both array and object parameter formats
#[derive(Debug, Clone)]
pub enum RpcRequestParams<T> {
    /// Single structured object parameter  
    Object(T),
    /// Array of parameters (for backward compatibility)
    Array(Vec<serde_json::Value>),
}

impl<T> RpcRequestParams<T>
where
    T: for<'de> serde::Deserialize<'de>,
{
    /// Try to deserialize from a JSON value
    pub fn from_value(value: serde_json::Value) -> Result<Self, serde_json::Error> {
        if value.is_array() {
            let array = value.as_array().unwrap().clone();
            Ok(RpcRequestParams::Array(array))
        } else {
            let object = serde_json::from_value::<T>(value)?;
            Ok(RpcRequestParams::Object(object))
        }
    }

    /// Get the structured object, converting from array if necessary
    pub fn into_object(self) -> Result<T, Box<dyn std::error::Error + Send + Sync>> {
        match self {
            RpcRequestParams::Object(obj) => Ok(obj),
            RpcRequestParams::Array(_array) => {
                // For now, return an error - specific handlers can implement array conversion
                Err("Array format not supported for this request type".into())
            }
        }
    }
}

/// Helper trait for converting array parameters to structured objects
pub trait FromArrayParams: Sized {
    /// Convert from array of JSON values to structured type
    fn from_array_params(
        params: &[serde_json::Value],
    ) -> Result<Self, Box<dyn std::error::Error + Send + Sync>>;
}

impl FromArrayParams for GetSubscriptionRequest {
    fn from_array_params(
        params: &[serde_json::Value],
    ) -> Result<Self, Box<dyn std::error::Error + Send + Sync>> {
        if params.is_empty() {
            return Err("Missing subscriber parameter".into());
        }

        let subscriber = params[0]
            .as_str()
            .ok_or("Subscriber must be a string")?
            .to_string();

        let nonce = if let Some(nonce_param) = params.get(1) {
            if nonce_param.is_null() {
                None
            } else if let Some(nonce_str) = nonce_param.as_str() {
                Some(nonce_str.to_string())
            } else {
                return Err("Nonce must be a string".into());
            }
        } else {
            None
        };

        Ok(GetSubscriptionRequest::new(subscriber, nonce))
    }
}

impl FromArrayParams for GetTriggeredTransactionsRequest {
    fn from_array_params(
        params: &[serde_json::Value],
    ) -> Result<Self, Box<dyn std::error::Error + Send + Sync>> {
        if params.is_empty() {
            return Err("Missing subscription_pubkey parameter".into());
        }

        let subscription_pubkey = params[0]
            .as_str()
            .ok_or("Subscription pubkey is not a string")?
            .to_string();

        let limit = params
            .get(1)
            .and_then(|v| v.as_str())
            .map(|s| s.to_string());

        Ok(GetTriggeredTransactionsRequest::new(
            subscription_pubkey,
            limit,
        ))
    }
}

impl FromArrayParams for SendTransactionRequest {
    fn from_array_params(
        params: &[serde_json::Value],
    ) -> Result<Self, Box<dyn std::error::Error + Send + Sync>> {
        if params.len() > 2 {
            return Err(format!(
                "Expected one or two request params, got {}",
                params.len()
            ))?;
        }
        let transaction = params
            .first()
            .ok_or_else(|| "Missing the transaction parameter".to_string())?
            .as_str()
            .ok_or("Transaction must be a string")?
            .to_string();

        let config = match params.get(1) {
            Some(value) => serde_json::from_value::<SendTransactionConfig>(value.clone())
                .map_err(|e| format!("Failed to parse config: {e}"))?,
            None => SendTransactionConfig::default(),
        };
        Ok(SendTransactionRequest::new(transaction, config))
    }
}

impl FromArrayParams for GetTransactionRequest {
    fn from_array_params(
        params: &[serde_json::Value],
    ) -> Result<Self, Box<dyn std::error::Error + Send + Sync>> {
        if params.is_empty() {
            return Err("Missing signature parameter".into());
        }

        let signature = params[0]
            .as_str()
            .ok_or("Signature must be a string")?
            .to_string();

        let config = if params.len() > 1 {
            Some(params[1].clone())
        } else {
            None
        };

        Ok(GetTransactionRequest::new(signature, config))
    }
}

impl FromArrayParams for IsBlockhashValidRequest {
    fn from_array_params(
        params: &[serde_json::Value],
    ) -> Result<Self, Box<dyn std::error::Error + Send + Sync>> {
        if params.is_empty() {
            return Err("Missing blockhash parameter".into());
        }

        let blockhash = params[0]
            .as_str()
            .ok_or("Blockhash must be a string")?
            .to_string();

        Ok(IsBlockhashValidRequest::new(blockhash))
    }
}

impl FromArrayParams for RequestAirdropRequest {
    fn from_array_params(
        params: &[serde_json::Value],
    ) -> Result<Self, Box<dyn std::error::Error + Send + Sync>> {
        if params.is_empty() {
            return Err("Missing pubkey parameter".into());
        }

        if params.len() < 2 {
            return Err("Missing kelvins parameter".into());
        }

        let pubkey = params[0]
            .as_str()
            .ok_or("Pubkey must be a string")?
            .to_string();

        let kelvins = params[1].as_i64().ok_or("Kelvins must be a number")?;

        Ok(RequestAirdropRequest::new(pubkey, kelvins))
    }
}

impl FromArrayParams for GetBlockRequest {
    fn from_array_params(
        params: &[serde_json::Value],
    ) -> Result<Self, Box<dyn std::error::Error + Send + Sync>> {
        if params.is_empty() {
            return Err("Missing the block height parameter".into());
        }
        if params.len() > 2 {
            return Err("Too many parameters: expected either one or two".into());
        }

        if params.len() == 1 && params[0].is_object() {
            return Ok(serde_json::from_value(params[0].clone())?);
        }

        let block_height = params[0]
            .as_u64()
            .ok_or("The first parameter must be the block height")?;

        let config = match params.get(1) {
            Some(value) => Some(
                serde_json::from_value(value.clone())
                    .map_err(|e| format!("Failed to parse the config parameter: {e}"))?,
            ),
            None => None,
        };

        Ok(GetBlockRequest {
            version: 0,
            block_height,
            config,
        })
    }
}

impl FromArrayParams for GetSignatureStatusesRequest {
    fn from_array_params(
        params: &[serde_json::Value],
    ) -> Result<Self, Box<dyn std::error::Error + Send + Sync>> {
        if params.is_empty() {
            return Err("Missing the signatures parameter".into());
        }
        if params.len() > 2 {
            return Err("Too many parameters: expected either one or two".into());
        }

        if params.len() == 1 && params[0].is_object() {
            return Ok(serde_json::from_value(params[0].clone())?);
        }

        let signatures: Vec<String> = serde_json::from_value(params[0].clone())
            .map_err(|e| format!("Failed to parse the signatures parameter: {e}"))?;

        let config = match params.get(1) {
            Some(value) => Some(
                serde_json::from_value(value.clone())
                    .map_err(|e| format!("Failed to parse the config parameter: {e}"))?,
            ),
            None => None,
        };

        Ok(GetSignatureStatusesRequest {
            version: 0,
            signatures,
            config,
        })
    }
}

#[cfg(test)]
mod tests {
    use serde_json::{from_value, json, to_value};

    use super::*;
    use crate::messages::send_transaction::{SendTransactionConfig, TransactionEncoding};

    #[test]
    fn test_get_subscription_request_serialization() {
        let request = GetSubscriptionRequest::new(
            "84astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDVcgri".to_string(),
            Some("test_nonce".to_string()),
        );

        let json = to_value(&request).unwrap();
        assert_eq!(
            json,
            json!({
                "version": 0,
                "subscriber": "84astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDVcgri",
                "nonce": "test_nonce"
            })
        );

        let deserialized: GetSubscriptionRequest = from_value(json).unwrap();
        assert_eq!(deserialized.version, 0);
        assert_eq!(deserialized.subscriber, request.subscriber);
        assert_eq!(deserialized.nonce, request.nonce);
    }

    #[test]
    fn test_get_triggered_transactions_request_serialization() {
        let request = GetTriggeredTransactionsRequest::new(
            "84astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDVcgri".to_string(),
            Some("10".to_string()),
        );

        let json = to_value(&request).unwrap();
        assert_eq!(
            json,
            json!({
                "version": 0,
                "subscription_pubkey": "84astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDVcgri",
                "limit": "10"
            })
        );

        let deserialized: GetTriggeredTransactionsRequest = from_value(json).unwrap();
        assert_eq!(deserialized.version, 0);
        assert_eq!(
            deserialized.subscription_pubkey,
            request.subscription_pubkey
        );
        assert_eq!(deserialized.limit, request.limit);
    }

    #[test]
    fn test_get_transaction_request_serialization() {
        let request = GetTransactionRequest::new_simple("signature123".to_string());

        let json = to_value(&request).unwrap();
        assert_eq!(
            json,
            json!({
                "signature": "signature123",
                "config": {"encoding": "json"}
            })
        );

        let deserialized: GetTransactionRequest = from_value(json).unwrap();
        assert_eq!(deserialized.signature, request.signature);
    }

    #[test]
    fn test_from_array_params_get_subscription() {
        let params = vec![
            json!("84astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDVcgri"),
            json!("test_nonce"),
        ];

        let request = GetSubscriptionRequest::from_array_params(&params).unwrap();
        assert_eq!(
            request.subscriber,
            "84astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDVcgri"
        );
        assert_eq!(request.nonce, Some("test_nonce".to_string()));
    }

    #[test]
    fn test_from_array_params_get_subscription_invalid_nonce() {
        let params = vec![
            json!("84astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDVcgri"),
            json!(123), // Invalid nonce - should be a string, not a number
        ];

        let result = GetSubscriptionRequest::from_array_params(&params);
        assert!(result.is_err());
        assert_eq!(result.unwrap_err().to_string(), "Nonce must be a string");
    }

    #[test]
    fn test_from_array_params_get_triggered_transactions() {
        let params = vec![
            json!("84astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDVcgri"),
            json!("5"),
        ];

        let request = GetTriggeredTransactionsRequest::from_array_params(&params).unwrap();
        assert_eq!(
            request.subscription_pubkey,
            "84astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDVcgri"
        );
        assert_eq!(request.limit, Some("5".to_string()));
    }

    #[test]
    fn test_from_array_params_get_transaction() {
        let params = vec![json!("signature123"), json!({"encoding": "json"})];

        let request = GetTransactionRequest::from_array_params(&params).unwrap();
        assert_eq!(request.signature, "signature123");
        assert!(request.config.is_some());
    }

    #[test]
    fn test_from_array_params_is_blockhash_valid() {
        let params = vec![json!("blockhash123")];

        let request = IsBlockhashValidRequest::from_array_params(&params).unwrap();
        assert_eq!(request.blockhash, "blockhash123");
    }

    #[test]
    fn test_from_array_params_request_airdrop() {
        let params = vec![
            json!("83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcgri"),
            json!(1000000),
        ];

        let request = RequestAirdropRequest::from_array_params(&params).unwrap();
        assert_eq!(
            request.pubkey,
            "83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcgri"
        );
        assert_eq!(request.kelvins, 1000000);
    }

    #[test]
    fn test_from_array_params_request_airdrop_missing_params() {
        let params = vec![json!("83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcgri")];

        let result = RequestAirdropRequest::from_array_params(&params);
        assert!(result.is_err());
        assert_eq!(result.unwrap_err().to_string(), "Missing kelvins parameter");
    }

    #[test]
    fn test_from_array_params_request_airdrop_invalid_type() {
        let params = vec![
            json!("83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcgri"),
            json!("thousand"), // String instead of number
        ];

        let result = RequestAirdropRequest::from_array_params(&params);
        assert!(result.is_err());
        assert_eq!(result.unwrap_err().to_string(), "Kelvins must be a number");
    }

    #[test]
    fn test_send_transaction_from_array_missing_optional_config() {
        let encoded_tx = "4hXTCkRzt9WyecNzV1XPgCDfGAZzQKNxLXgynz5QDuWWPSAZBZSHptvWRL3BjCvzUXRdKvHL2b7yGrRQcWyaqsaBCncVG7BFggS8w9snUts67BSh3EqKpXLUm5UMHfD7ZBe9GhARjbNQMLJ1QD3Spr6oMTBU6EhdB4RD8CP2xUxr2u3d6fos36PD98XS6oX8TQjLpsMwncs5DAMiD4nNnR8NBfyghGCWvCVifVwvA8B8TJxE1aiyiv2L429BCWfyzAme5sZW8rDb14NeCQHhZbtNqfXhcp2tAnaAT";
        let params = vec![json!(encoded_tx)];
        assert_eq!(
            SendTransactionRequest::from_array_params(&params)
                .expect("failed to parse a transaction from params"),
            SendTransactionRequest {
                transaction: encoded_tx.to_string(),
                config: SendTransactionConfig::default()
            }
        );
    }

    #[test]
    fn test_send_transaction_from_array_default_config() {
        let encoded_tx = "4hXTCkRzt9WyecNzV1XPgCDfGAZzQKNxLXgynz5QDuWWPSAZBZSHptvWRL3BjCvzUXRdKvHL2b7yGrRQcWyaqsaBCncVG7BFggS8w9snUts67BSh3EqKpXLUm5UMHfD7ZBe9GhARjbNQMLJ1QD3Spr6oMTBU6EhdB4RD8CP2xUxr2u3d6fos36PD98XS6oX8TQjLpsMwncs5DAMiD4nNnR8NBfyghGCWvCVifVwvA8B8TJxE1aiyiv2L429BCWfyzAme5sZW8rDb14NeCQHhZbtNqfXhcp2tAnaAT";
        let params = vec![json!(encoded_tx), json!({})];
        assert_eq!(
            SendTransactionRequest::from_array_params(&params)
                .expect("failed to parse a transaction from params"),
            SendTransactionRequest {
                transaction: encoded_tx.to_string(),
                config: SendTransactionConfig::default(),
            }
        );
    }

    #[test]
    fn test_send_transaction_from_array_config() {
        let encoded_tx = "4hXTCkRzt9WyecNzV1XPgCDfGAZzQKNxLXgynz5QDuWWPSAZBZSHptvWRL3BjCvzUXRdKvHL2b7yGrRQcWyaqsaBCncVG7BFggS8w9snUts67BSh3EqKpXLUm5UMHfD7ZBe9GhARjbNQMLJ1QD3Spr6oMTBU6EhdB4RD8CP2xUxr2u3d6fos36PD98XS6oX8TQjLpsMwncs5DAMiD4nNnR8NBfyghGCWvCVifVwvA8B8TJxE1aiyiv2L429BCWfyzAme5sZW8rDb14NeCQHhZbtNqfXhcp2tAnaAT";
        let params = vec![
            json!(encoded_tx),
            json!({
                "encoding": "base58",
            }),
        ];
        assert_eq!(
            SendTransactionRequest::from_array_params(&params)
                .expect("failed to parse a transaction from params"),
            SendTransactionRequest {
                transaction: encoded_tx.to_string(),
                config: SendTransactionConfig::new(TransactionEncoding::Base58),
            }
        );
    }

    #[test]
    fn test_send_transaction_from_array_too_many_params() {
        let encoded_tx = "4hXTCkRzt9WyecNzV1XPgCDfGAZzQKNxLXgynz5QDuWWPSAZBZSHptvWRL3BjCvzUXRdKvHL2b7yGrRQcWyaqsaBCncVG7BFggS8w9snUts67BSh3EqKpXLUm5UMHfD7ZBe9GhARjbNQMLJ1QD3Spr6oMTBU6EhdB4RD8CP2xUxr2u3d6fos36PD98XS6oX8TQjLpsMwncs5DAMiD4nNnR8NBfyghGCWvCVifVwvA8B8TJxE1aiyiv2L429BCWfyzAme5sZW8rDb14NeCQHhZbtNqfXhcp2tAnaAT";
        let params = vec![json!(encoded_tx), json!({}), json!({})];
        SendTransactionRequest::from_array_params(&params).unwrap_err();
    }

    #[test]
    fn test_from_array_params_get_block_basic() {
        let params = vec![json!(123456)];

        let request = GetBlockRequest::from_array_params(&params).unwrap();
        assert_eq!(request.block_height, 123456);
        assert!(request.config.is_none());
    }

    #[test]
    fn test_from_array_params_get_block_with_config() {
        let params = vec![
            json!(123456),
            json!({
                "transactionDetails": "full"
            }),
        ];

        let request = GetBlockRequest::from_array_params(&params).unwrap();
        assert_eq!(request.block_height, 123456);
        assert!(request.config.is_some());
    }

    #[test]
    fn test_from_array_params_get_block_single_object() {
        let params = vec![json!({
            "version": 0,
            "blockHeight": 789012,
            "config": {
                "transactionDetails": "signatures"
            }
        })];

        let request = GetBlockRequest::from_array_params(&params).unwrap();
        assert_eq!(request.block_height, 789012);
        assert!(request.config.is_some());
    }

    #[test]
    #[should_panic(expected = "block height")]
    fn test_from_array_params_get_block_empty_params() {
        GetBlockRequest::from_array_params(&[]).unwrap();
    }

    #[test]
    #[should_panic(expected = "Too many parameters")]
    fn test_from_array_params_get_block_too_many_params() {
        GetBlockRequest::from_array_params(&[json!(123456), json!({}), json!({})]).unwrap();
    }

    #[test]
    #[should_panic(expected = "block height")]
    fn test_from_array_params_get_block_invalid_height_type() {
        GetBlockRequest::from_array_params(&[json!("not_a_number")]).unwrap();
    }

    #[test]
    #[should_panic(expected = "config parameter")]
    fn test_from_array_params_get_block_invalid_config() {
        GetBlockRequest::from_array_params(&[
            json!(123456),
            json!("invalid_config"), // Should be an object, not a string
        ])
        .unwrap();
    }

    #[test]
    #[should_panic(expected = "config parameter")]
    fn test_from_array_params_get_block_null_config() {
        GetBlockRequest::from_array_params(&[json!(123456), json!(null)]).unwrap();
    }

    #[test]
    fn test_from_array_params_get_signature_statuses_basic() {
        let signatures = vec![
            "5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW",
            "4hXTCkRzt9WyecNzV1XPgCDfGAZzQKNxLXgynz5QDuWWPSAZBZSHptvWRL3BjCvzUXRdKvHL2b7yGrRQcWyaqsaB"
        ];
        let params = vec![json!(signatures)];

        let request = GetSignatureStatusesRequest::from_array_params(&params).unwrap();
        assert_eq!(request.signatures, signatures);
        assert!(request.config.is_none());
    }

    #[test]
    fn test_from_array_params_get_signature_statuses_with_config() {
        let signatures = vec![
            "5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW"
        ];
        let config = json!({"searchTransactionHistory": true});
        let params = vec![json!(signatures), config.clone()];

        let request = GetSignatureStatusesRequest::from_array_params(&params).unwrap();
        assert_eq!(request.signatures, signatures);
        assert!(request.config.is_some());
    }

    #[test]
    fn test_from_array_params_get_signature_statuses_single_object() {
        let signatures = vec![
            "5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW"
        ];
        let params = vec![json!({
            "version": 0,
            "signatures": signatures,
            "config": {"searchTransactionHistory": false}
        })];

        let request = GetSignatureStatusesRequest::from_array_params(&params).unwrap();
        assert_eq!(request.signatures, signatures);
        assert!(request.config.is_some());
    }

    #[test]
    fn test_from_array_params_get_signature_statuses_empty_signatures() {
        let request = GetSignatureStatusesRequest::from_array_params(&[json!([])]).unwrap();
        assert!(request.signatures.is_empty());
        assert!(request.config.is_none());
    }

    #[test]
    #[should_panic(expected = "Missing the signatures parameter")]
    fn test_from_array_params_get_signature_statuses_empty_params() {
        GetSignatureStatusesRequest::from_array_params(&[]).unwrap();
    }

    #[test]
    #[should_panic(expected = "Too many parameters")]
    fn test_from_array_params_get_signature_statuses_too_many_params() {
        GetSignatureStatusesRequest::from_array_params(&[json!(["sig1"]), json!({}), json!({})])
            .unwrap();
    }

    #[test]
    #[should_panic(expected = "Failed to parse the signatures parameter")]
    fn test_from_array_params_get_signature_statuses_invalid_signatures_type() {
        GetSignatureStatusesRequest::from_array_params(&[json!("not an array")]).unwrap();
    }

    #[test]
    #[should_panic(expected = "Failed to parse the config parameter")]
    fn test_from_array_params_get_signature_statuses_invalid_config() {
        GetSignatureStatusesRequest::from_array_params(&[
            json!(["5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW"]),
            json!("invalid config")
        ]).unwrap();
    }

    #[test]
    fn test_from_array_params_get_signature_statuses_multiple_signatures() {
        let signatures: Vec<&str> = (0..100).map(|i| {
            if i % 2 == 0 {
                "5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW"
            } else {
                "4hXTCkRzt9WyecNzV1XPgCDfGAZzQKNxLXgynz5QDuWWPSAZBZSHptvWRL3BjCvzUXRdKvHL2b7yGrRQcWyaqsaB"
            }
        }).collect();
        let params = vec![json!(signatures)];

        let request = GetSignatureStatusesRequest::from_array_params(&params).unwrap();
        assert_eq!(request.signatures.len(), 100);
        assert!(request.config.is_none());
    }

    #[test]
    #[should_panic(expected = "Failed to parse the config parameter")]
    fn test_from_array_params_get_signature_statuses_null_config() {
        GetSignatureStatusesRequest::from_array_params(&[
            json!(["5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW"]),
            json!(null)]
        ).unwrap();
    }
}