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
//! Module for interacting with node HTTP APIs.

use crate::rlp::{Bytes, Decodable};
use crate::transactions::Reserved;
use crate::transactions::{Clause, Transaction};
use crate::utils::unhex;
use crate::{Address, U256};
use reqwest::{Client, Url};
use serde::{Deserialize, Serialize};

/// Generic result of all asynchronous calls in this module.
pub type AResult<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;

/// Validation errors (not related to HTTP failures)
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ValidationError {
    /// Account storage keys start from one, there's no key 0.
    ZeroStorageKey,
    /// Transaction broadcast failed
    BroadcastFailed(String),
}

impl std::error::Error for ValidationError {}
impl std::fmt::Display for ValidationError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::ZeroStorageKey => f.write_str("Account storage key cannot be zero"),
            Self::BroadcastFailed(text) => {
                f.write_str("Failed to broadcast: ")?;
                f.write_str(text.strip_suffix('\n').unwrap_or(text))
            }
        }
    }
}

/// A simple HTTP REST client for a VeChain node.
pub struct ThorNode {
    /// API base url
    pub base_url: Url,
    /// Chain tag used for this network.
    pub chain_tag: u8,
}

#[serde_with::serde_as]
#[derive(Deserialize)]
struct RawTxResponse {
    #[serde_as(as = "unhex::Hex")]
    raw: Bytes,
    meta: Option<TransactionMeta>,
}

/// Extended transaction data
#[serde_with::serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ExtendedTransaction {
    /// Identifier of the transaction
    #[serde_as(as = "unhex::HexNum<32, U256>")]
    pub id: U256,
    /// The one who signed the transaction
    pub origin: Address,
    /// The delegator who paid the gas fee
    pub delegator: Option<Address>,
    /// Byte size of the transaction that is RLP encoded
    pub size: u32,
    /// Last byte of genesis block ID
    #[serde(rename = "chainTag")]
    pub chain_tag: u8,
    /// 8 bytes prefix of some block ID
    #[serde(rename = "blockRef")]
    #[serde_as(as = "unhex::HexNum<8, u64>")]
    pub block_ref: u64,
    /// Expiration relative to blockRef, in unit block
    pub expiration: u32,
    /// Transaction clauses
    pub clauses: Vec<Clause>,
    /// Coefficient used to calculate the final gas price
    #[serde(rename = "gasPriceCoef")]
    pub gas_price_coef: u8,
    /// Max amount of gas can be consumed to execute this transaction
    pub gas: u64,
    /// ID of the transaction on which the current transaction depends on. can be null.
    #[serde(rename = "dependsOn")]
    #[serde_as(as = "Option<unhex::HexNum<32, U256>>")]
    pub depends_on: Option<U256>,
    /// Transaction nonce
    #[serde_as(as = "unhex::HexNum<8, u64>")]
    pub nonce: u64,
}

impl ExtendedTransaction {
    pub fn as_transaction(self) -> Transaction {
        //! Convert to package-compatible [`Transaction`]
        let Self {
            chain_tag,
            block_ref,
            expiration,
            clauses,
            gas_price_coef,
            gas,
            depends_on,
            nonce,
            delegator,
            ..
        } = self;
        Transaction {
            chain_tag,
            block_ref,
            expiration,
            clauses,
            gas_price_coef,
            gas,
            depends_on,
            nonce,
            reserved: if delegator.is_some() {
                Some(Reserved::new_delegated())
            } else {
                None
            },
            signature: None,
        }
    }
}

#[serde_with::serde_as]
#[derive(Deserialize)]
struct ExtendedTransactionResponse {
    #[serde(flatten)]
    transaction: ExtendedTransaction,
    meta: Option<TransactionMeta>,
}

/// Transaction metadata
#[serde_with::serde_as]
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct TransactionMeta {
    /// Block identifier
    #[serde(rename = "blockID")]
    #[serde_as(as = "unhex::HexNum<32, U256>")]
    pub block_id: U256,
    /// Block number (height)
    #[serde(rename = "blockNumber")]
    pub block_number: u32,
    /// Block unix timestamp
    #[serde(rename = "blockTimestamp")]
    pub block_timestamp: u32,
}

/// Transaction receipt
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Receipt {
    /// Amount of gas consumed by this transaction
    #[serde(rename = "gasUsed")]
    pub gas_used: u32,
    /// Address of account who paid used gas
    #[serde(rename = "gasPayer")]
    pub gas_payer: Address,
    /// Hex form of amount of paid energy
    pub paid: U256,
    /// Hex form of amount of reward
    pub reward: U256,
    /// true means the transaction was reverted
    pub reverted: bool,
    /// Outputs (if this transaction was a contract call)
    pub outputs: Vec<ReceiptOutput>,
}

#[derive(Clone, Debug, PartialEq, Deserialize)]
struct ReceiptResponse {
    #[serde(flatten)]
    body: Receipt,
    meta: ReceiptMeta,
}

/// Single output in the transaction receipt
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ReceiptOutput {
    /// Deployed contract address, if the corresponding clause is a contract deployment clause
    #[serde(rename = "contractAddress")]
    pub contract_address: Option<Address>,
    /// Emitted contract events
    pub events: Vec<Event>,
    /// Transfers executed during the contract call
    pub transfers: Vec<Transfer>,
}

/// Transaction receipt metadata
#[serde_with::serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ReceiptMeta {
    /// Block identifier
    #[serde(rename = "blockID")]
    #[serde_as(as = "unhex::HexNum<32, U256>")]
    pub block_id: U256,
    /// Block number (height)
    #[serde(rename = "blockNumber")]
    pub block_number: u32,
    /// Block unix timestamp
    #[serde(rename = "blockTimestamp")]
    pub block_timestamp: u32,
    /// Transaction identifier
    #[serde(rename = "txID")]
    #[serde_as(as = "unhex::HexNum<32, U256>")]
    pub tx_id: U256,
    /// Transaction origin (signer)
    #[serde(rename = "txOrigin")]
    pub tx_origin: Address,
}

/// Emitted contract event
#[serde_with::serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Event {
    /// The address of contract which produces the event
    pub address: Address,
    /// Event topics
    #[serde_as(as = "Vec<unhex::HexNum<32, U256>>")]
    pub topics: Vec<U256>,
    /// Event data
    #[serde_as(as = "unhex::Hex")]
    pub data: Bytes,
}

/// Single transfer during the contract call
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Transfer {
    /// Address that sends tokens
    pub sender: Address,
    /// Address that receives tokens
    pub recipient: Address,
    /// Amount of tokens
    pub amount: U256,
}

/// A blockchain block.
#[serde_with::serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BlockInfo {
    /// Block number (height)
    pub number: u32,
    /// Block identifier
    #[serde_as(as = "unhex::HexNum<32, U256>")]
    pub id: U256,
    /// RLP encoded block size in bytes
    pub size: u32,
    /// Parent block ID
    #[serde_as(as = "unhex::HexNum<32, U256>")]
    #[serde(rename = "parentID")]
    pub parent_id: U256,
    /// Block unix timestamp
    pub timestamp: u32,
    /// Block gas limit (max allowed accumulative gas usage of transactions)
    #[serde(rename = "gasLimit")]
    pub gas_limit: u32,
    /// Address of account to receive block reward
    pub beneficiary: Address,
    /// Accumulative gas usage of transactions
    #[serde(rename = "gasUsed")]
    pub gas_used: u32,
    /// Sum of all ancestral blocks' score
    #[serde(rename = "totalScore")]
    pub total_score: u32,
    /// Root hash of transactions in the block
    #[serde_as(as = "unhex::HexNum<32, U256>")]
    #[serde(rename = "txsRoot")]
    pub txs_root: U256,
    /// Supported txs features bitset
    #[serde(rename = "txsFeatures")]
    pub txs_features: u32,
    /// Root hash of accounts state
    #[serde_as(as = "unhex::HexNum<32, U256>")]
    #[serde(rename = "stateRoot")]
    pub state_root: U256,
    /// Root hash of transaction receipts
    #[serde_as(as = "unhex::HexNum<32, U256>")]
    #[serde(rename = "receiptsRoot")]
    pub receipts_root: U256,
    /// Is in trunk?
    #[serde(rename = "isTrunk")]
    pub is_trunk: bool,
    /// Is finalized?
    #[serde(rename = "isFinalized")]
    pub is_finalized: bool,
    /// Whether the block signer voted COM(Commit) in BFT
    pub com: bool,
    /// The one who signed this block
    pub signer: Address,
}

/// Transaction data included in the block extended details.
///
/// Combines [`ExtendedTransaction`] and [`Receipt`].
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BlockTransaction {
    /// Transaction details
    #[serde(flatten)]
    pub transaction: ExtendedTransaction,
    /// Transaction receipt
    #[serde(flatten)]
    pub receipt: Receipt,
}

#[serde_with::serde_as]
#[derive(Clone, Debug, PartialEq, Deserialize)]
struct BlockResponse {
    #[serde(flatten)]
    base: BlockInfo,
    #[serde_as(as = "Vec<unhex::HexNum<32, U256>>")]
    transactions: Vec<U256>,
}

#[serde_with::serde_as]
#[derive(Clone, Debug, PartialEq, Deserialize)]
struct BlockExtendedResponse {
    #[serde(flatten)]
    base: BlockInfo,
    transactions: Vec<BlockTransaction>,
}

/// Block reference: a way to identify the block on the chain.
#[derive(Clone, Debug)]
pub enum BlockReference {
    /// Latest: already approved by some node, but not finalized yet.
    Best,
    /// Finalized: block is frozen on chain.
    Finalized,
    /// Block ordinal number (1..)
    Number(u64),
    /// Block ID
    ID(U256),
}

impl BlockReference {
    fn as_query_param(&self) -> String {
        match self {
            BlockReference::Best => "best".to_string(),
            BlockReference::Finalized => "finalized".to_string(),
            BlockReference::Number(num) => format!("0x{:02x}", num),
            BlockReference::ID(id) => format!("0x{:064x}", id),
        }
    }
}

/// Account details
#[serde_with::serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct AccountInfo {
    /// VET balance
    #[serde_as(as = "unhex::HexNum<32, U256>")]
    pub balance: U256,
    /// VTHO balance
    #[serde_as(as = "unhex::HexNum<32, U256>")]
    pub energy: U256,
    /// Is a contract?
    #[serde(rename = "hasCode")]
    pub has_code: bool,
}

#[serde_with::serde_as]
#[derive(Clone, Debug, PartialEq, Deserialize)]
struct AccountCodeResponse {
    #[serde_as(as = "unhex::Hex")]
    code: Bytes,
}
#[serde_with::serde_as]
#[derive(Clone, Debug, PartialEq, Deserialize)]
struct AccountStorageResponse {
    #[serde_as(as = "unhex::HexNum<32, U256>")]
    value: U256,
}
#[serde_with::serde_as]
#[derive(Clone, Debug, PartialEq, Serialize)]
struct TransactionBroadcastRequest {
    #[serde_as(as = "unhex::Hex")]
    raw: Bytes,
}
#[serde_with::serde_as]
#[derive(Clone, Debug, PartialEq, Deserialize)]
struct TransactionIdResponse {
    #[serde_as(as = "unhex::HexNum<32, U256>")]
    id: U256,
}

/// Transaction execution simulation request
#[serde_with::serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct SimulateCallRequest {
    /// Clauses of transaction
    pub clauses: Vec<Clause>,
    /// Maximal amount of gas
    pub gas: u64,
    /// Gas price
    #[serde_as(as = "serde_with::DisplayFromStr")]
    #[serde(rename = "gasPrice")]
    pub gas_price: u64,
    /// Caller address
    pub caller: Address,
    /// ???
    #[serde_as(as = "serde_with::DisplayFromStr")]
    #[serde(rename = "provedWork")]
    pub proved_work: u64,
    /// Gas payer address
    #[serde(rename = "gasPayer")]
    pub gas_payer: Address,
    /// Expiration (in blocks)
    pub expiration: u32,
    /// Block reference to count expiration from.
    #[serde_as(as = "unhex::HexNum<8, u64>")]
    #[serde(rename = "blockRef")]
    pub block_ref: u64,
}

/// Transaction execution simulation request
#[serde_with::serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct SimulateCallResponse {
    /// Output data
    #[serde_as(as = "unhex::Hex")]
    pub data: Bytes,
    /// Emitted events
    pub events: Vec<Event>,
    /// Executed transfers
    pub transfers: Vec<Transfer>,
    /// Gas spent
    #[serde(rename = "gasUsed")]
    pub gas_used: u64,
    /// Will be reverted?
    pub reverted: bool,
    /// Error description returned by VM
    #[serde(rename = "vmError")]
    pub vm_error: String,
}

impl ThorNode {
    /// Chain tag for mainnet
    pub const MAINNET_CHAIN_TAG: u8 = 0x4A;
    /// REST API URL for mainnet (one possible)
    pub const MAINNET_BASE_URL: &'static str = "https://mainnet.vecha.in/";
    /// Chain tag for testnet
    pub const TESTNET_CHAIN_TAG: u8 = 0x27;
    /// REST API URL for testnet (one possible)
    pub const TESTNET_BASE_URL: &'static str = "https://testnet.vecha.in/";

    pub fn mainnet() -> Self {
        //! Mainnet parameters
        Self {
            base_url: Self::MAINNET_BASE_URL.parse().unwrap(),
            chain_tag: Self::MAINNET_CHAIN_TAG,
        }
    }

    pub fn testnet() -> Self {
        //! Testnet parameters
        Self {
            base_url: Self::TESTNET_BASE_URL.parse().unwrap(),
            chain_tag: Self::TESTNET_CHAIN_TAG,
        }
    }

    pub async fn fetch_transaction(
        &self,
        transaction_id: U256,
    ) -> AResult<Option<(Transaction, Option<TransactionMeta>)>> {
        //! Retrieve a [`Transaction`] from node by its ID.
        //!
        //! Returns [`None`] for nonexistent transactions.
        //!
        //! Meta can be [`None`] if a transaction was broadcasted, but
        //! not yet included into a block.
        //!
        //! This method exists for interoperability with [`Transaction`]
        //! from other parts of library. You can get more info from node
        //! with [`ThorNode::fetch_extended_transaction`].
        let client = Client::new();
        let path = format!("/transactions/0x{:064x}", transaction_id);
        let response = client
            .get(self.base_url.join(&path)?)
            .query(&[("raw", "true")])
            .send()
            .await?
            .text()
            .await?;
        if response.strip_suffix('\n').unwrap_or(&response) == "null" {
            Ok(None)
        } else {
            let decoded: RawTxResponse = serde_json::from_str(&response)?;
            let tx = Transaction::decode(&mut &decoded.raw[..])?;
            Ok(Some((tx, decoded.meta)))
        }
    }

    pub async fn fetch_extended_transaction(
        &self,
        transaction_id: U256,
    ) -> AResult<Option<(ExtendedTransaction, Option<TransactionMeta>)>> {
        //! Retrieve a [`Transaction`] from node by its ID.
        //!
        //! Returns [`None`] for nonexistent transactions.
        //!
        //! Meta can be [`None`] if a transaction was broadcasted, but
        //! not yet included into a block.
        //!
        //! This method returns more data than [`ThorNode::fetch_transaction`],
        //! but is not interoperable with [`Transaction`].
        let client = Client::new();
        let path = format!("/transactions/0x{:064x}", transaction_id);
        let response = client
            .get(self.base_url.join(&path)?)
            .send()
            .await?
            .text()
            .await?;
        if response.strip_suffix('\n').unwrap_or(&response) == "null" {
            Ok(None)
        } else {
            let decoded: ExtendedTransactionResponse = serde_json::from_str(&response)?;
            Ok(Some((decoded.transaction, decoded.meta)))
        }
    }

    pub async fn fetch_transaction_receipt(
        &self,
        transaction_id: U256,
    ) -> AResult<Option<(Receipt, ReceiptMeta)>> {
        //! Retrieve a transaction receipt from node given a transaction ID.
        //!
        //! Returns [`None`] for nonexistent or not mined transactions.
        let client = Client::new();
        let path = format!("/transactions/0x{:064x}/receipt", transaction_id);
        let response = client
            .get(self.base_url.join(&path)?)
            .send()
            .await?
            .text()
            .await?;
        if response.strip_suffix('\n').unwrap_or(&response) == "null" {
            Ok(None)
        } else {
            let decoded: ReceiptResponse = serde_json::from_str(&response)?;
            Ok(Some((decoded.body, decoded.meta)))
        }
    }

    pub async fn fetch_block(
        &self,
        block_ref: BlockReference,
    ) -> AResult<Option<(BlockInfo, Vec<U256>)>> {
        //! Retrieve a block from node by given identifier.
        //!
        //! Returns [`None`] for nonexistent blocks.
        let client = Client::new();
        let path = format!("/blocks/{}", block_ref.as_query_param());
        let response = client
            .get(self.base_url.join(&path)?)
            .send()
            .await?
            .text()
            .await?;
        if response.strip_suffix('\n').unwrap_or(&response) == "null" {
            Ok(None)
        } else {
            let decoded: BlockResponse = serde_json::from_str(&response)?;
            Ok(Some((decoded.base, decoded.transactions)))
        }
    }

    pub async fn fetch_block_expanded(
        &self,
        block_ref: BlockReference,
    ) -> AResult<Option<(BlockInfo, Vec<BlockTransaction>)>> {
        //! Retrieve a block from node by given identifier together with extended
        //! transaction details.
        //!
        //! Returns [`None`] for nonexistent blocks.
        let client = Client::new();
        let path = format!("/blocks/{}", block_ref.as_query_param());
        let response = client
            .get(self.base_url.join(&path)?)
            .query(&[("expanded", "true")])
            .send()
            .await?
            .text()
            .await?;
        if response.strip_suffix('\n').unwrap_or(&response) == "null" {
            Ok(None)
        } else {
            let decoded: BlockExtendedResponse = serde_json::from_str(&response)?;
            Ok(Some((decoded.base, decoded.transactions)))
        }
    }

    pub async fn broadcast_transaction(&self, transaction: &Transaction) -> AResult<U256> {
        //! Broadcast a new [`Transaction`] to the node.
        let client = Client::new();
        let response = client
            .post(self.base_url.join("/transactions")?)
            .json(&TransactionBroadcastRequest {
                raw: transaction.to_broadcastable_bytes()?,
            })
            .send()
            .await?
            .text()
            .await?;
        let decoded: TransactionIdResponse = serde_json::from_str(&response)
            .map_err(|_| ValidationError::BroadcastFailed(response.to_string()))?;
        Ok(decoded.id)
    }

    pub async fn fetch_account(&self, address: Address) -> AResult<AccountInfo> {
        //! Retrieve account details.
        let client = Client::new();
        let path = format!("/accounts/{}", address.to_hex());
        Ok(client
            .get(self.base_url.join(&path)?)
            .send()
            .await?
            .json::<AccountInfo>()
            .await?)
    }

    pub async fn fetch_account_code(&self, address: Address) -> AResult<Option<Bytes>> {
        //! Retrieve account code.
        //!
        //! Returns [`None`] for non-contract accounts.
        let client = Client::new();
        let path = format!("/accounts/{}/code", address.to_hex());
        let response = client
            .get(self.base_url.join(&path)?)
            .send()
            .await?
            .json::<AccountCodeResponse>()
            .await?;
        if response.code.is_empty() {
            Ok(None)
        } else {
            Ok(Some(response.code))
        }
    }

    pub async fn fetch_account_storage(&self, address: Address, key: U256) -> AResult<U256> {
        //! Retrieve account storage at key.
        //!
        //! Returns [`None`] for non-contract accounts or for missing storage keys.
        if key == 0.into() {
            return Err(Box::new(ValidationError::ZeroStorageKey));
        }
        let client = Client::new();
        let path = format!("/accounts/{}/storage/0x{:064x}", address.to_hex(), key);
        let response = client
            .get(self.base_url.join(&path)?)
            .send()
            .await?
            .json::<AccountStorageResponse>()
            .await?;
        Ok(response.value)
    }

    pub async fn simulate_execution(
        &self,
        request: SimulateCallRequest,
    ) -> AResult<Vec<SimulateCallResponse>> {
        //! Simulate a transaction execution.
        let client = Client::new();
        let response = client
            .post(self.base_url.join("/accounts/*")?)
            .json(&request)
            .send()
            .await?
            .json::<Vec<SimulateCallResponse>>()
            .await?;
        Ok(response)
    }
}