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
use core::convert::Into;
use std::{
    pin::Pin,
    sync::Arc,
    time::{SystemTime, UNIX_EPOCH},
};

use async_trait::async_trait;
use futures_core::Stream;
use m10_protos::sdk;
use m10_protos::sdk::signature::Algorithm;
use m10_signing::{PreparedTransaction, SignedRequest, Signer};

use crate::{
    account::AccountId, builders::*, error::M10Result, transfer_ext::EnhancedTransfer, types::*,
    DocumentId, EnhancedTransferStep,
};

#[async_trait]
pub trait M10CoreClient {
    type Signer: Signer;

    // Signing
    fn signer(&self) -> M10Result<Arc<Self::Signer>>;

    fn set_signer(&mut self, signer: Arc<Self::Signer>);

    async fn signed_transaction(
        &self,
        data: sdk::transaction_data::Data,
        context_id: Vec<u8>,
    ) -> M10Result<SignedRequest<sdk::TransactionRequestPayload>> {
        let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_micros() as u64;
        let req = sdk::TransactionRequestPayload {
            nonce: fastrand::u64(..),
            timestamp,
            context_id,
            data: Some(sdk::TransactionData { data: Some(data) }),
        };
        sign_prepared_or_raw(req, self.signer()?.as_ref()).await
    }

    // Transactions
    async fn create_transaction(
        &self,
        payload: sdk::RequestEnvelope,
    ) -> M10Result<sdk::TransactionResponse>;

    async fn bulk_create_transactions(
        &self,
        payload: sdk::BulkTransactions,
    ) -> M10Result<sdk::BulkTransactionsResponse>;

    async fn transfer(&self, data: sdk::CreateTransfer, context_id: Vec<u8>) -> M10Result<TxId> {
        let req = self.signed_transaction(data.into(), context_id).await?;
        let response = self.create_transaction(req.into()).await?;
        Ok(response.tx_id)
    }

    async fn create_account(
        &self,
        data: sdk::CreateLedgerAccount,
        context_id: Vec<u8>,
    ) -> M10Result<(TxId, AccountId)> {
        let req = self.signed_transaction(data.into(), context_id).await?;
        let response = self.create_transaction(req.into()).await?;
        let account_id = AccountId::try_from_be_slice(&response.account_created)?;
        Ok((response.tx_id, account_id))
    }

    async fn initiate_transfer(
        &self,
        data: sdk::CreateTransfer,
        context_id: Vec<u8>,
    ) -> M10Result<TxId> {
        let req = self
            .signed_transaction(
                sdk::transaction_data::Data::InitiateTransfer(data),
                context_id,
            )
            .await?;
        let response = self.create_transaction(req.into()).await?;
        Ok(response.tx_id)
    }

    async fn commit_transfer(
        &self,
        tx_id: TxId,
        accept: bool,
        context_id: Vec<u8>,
    ) -> M10Result<(TxId, bool)> {
        let req = self
            .signed_transaction(
                sdk::CommitTransfer {
                    pending_tx_id: tx_id,
                    new_state: if accept {
                        sdk::commit_transfer::TransferState::Accepted
                    } else {
                        sdk::commit_transfer::TransferState::Rejected
                    } as i32,
                }
                .into(),
                context_id,
            )
            .await?;
        let response = self.create_transaction(req.into()).await?;
        Ok((response.tx_id, response.transfer_committed.is_some()))
    }

    async fn freeze_account(
        &self,
        account_id: AccountId,
        frozen: bool,
        context_id: Vec<u8>,
    ) -> M10Result<TxId> {
        let req = self
            .signed_transaction(
                sdk::SetFreezeState {
                    account_id: account_id.to_vec(),
                    frozen,
                }
                .into(),
                context_id,
            )
            .await?;
        let response = self.create_transaction(req.into()).await?;
        Ok(response.tx_id)
    }

    async fn set_account_limit(
        &self,
        account_id: AccountId,
        limit: u64,
        context_id: Vec<u8>,
    ) -> M10Result<TxId> {
        let req = self
            .signed_transaction(
                sdk::SetBalanceLimit {
                    account_id: account_id.to_vec(),
                    balance_limit: limit,
                }
                .into(),
                context_id,
            )
            .await?;
        let response = self.create_transaction(req.into()).await?;
        Ok(response.tx_id)
    }

    async fn set_issuance_limit(
        &self,
        account_id: AccountId,
        limit: u64,
        context_id: Vec<u8>,
    ) -> M10Result<TxId> {
        let req = self
            .signed_transaction(
                sdk::SetIssuanceLimit {
                    account_id: account_id.to_vec(),
                    issuance_limit: limit,
                }
                .into(),
                context_id,
            )
            .await?;
        let response = self.create_transaction(req.into()).await?;
        Ok(response.tx_id)
    }

    async fn set_display_code(
        &self,
        account_id: AccountId,
        display_code: String,
        context_id: Vec<u8>,
    ) -> M10Result<TxId> {
        let req = self
            .signed_transaction(
                sdk::SetDisplayCode {
                    account_id: account_id.to_vec(),
                    display_code,
                }
                .into(),
                context_id,
            )
            .await?;
        let response = self.create_transaction(req.into()).await?;
        Ok(response.tx_id)
    }

    async fn set_min_commits(
        &self,
        account_id: AccountId,
        min_commits: u32,
        commit_thresholds: Vec<sdk::CommitThreshold>,
        context_id: Vec<u8>,
    ) -> M10Result<TxId> {
        let req = self
            .signed_transaction(
                sdk::SetMinCommits {
                    account_id: account_id.to_vec(),
                    min_commits,
                    commit_thresholds,
                }
                .into(),
                context_id,
            )
            .await?;
        let response = self.create_transaction(req.into()).await?;
        Ok(response.tx_id)
    }

    async fn set_account_instrument(
        &self,
        account_id: AccountId,
        code: String,
        decimals: u32,
        description: Option<String>,
        context_id: Vec<u8>,
        display_code: Option<String>,
    ) -> M10Result<TxId> {
        let req = self
            .signed_transaction(
                sdk::SetInstrument {
                    account_id: account_id.to_vec(),
                    code: code.clone(),
                    decimal_places: decimals,
                    description: description.unwrap_or_default(),
                    display_code: display_code.unwrap_or(code),
                }
                .into(),
                context_id,
            )
            .await?;
        let response = self.create_transaction(req.into()).await?;
        Ok(response.tx_id)
    }

    async fn action(&self, data: sdk::InvokeAction, context_id: Vec<u8>) -> M10Result<TxId> {
        let req = self.signed_transaction(data.into(), context_id).await?;
        let response = self.create_transaction(req.into()).await?;
        Ok(response.tx_id)
    }

    async fn documents(
        &self,
        data: sdk::DocumentOperations,
        context_id: Vec<u8>,
    ) -> M10Result<TxId> {
        let req = self.signed_transaction(data.into(), context_id).await?;
        let response = self.create_transaction(req.into()).await?;
        Ok(response.tx_id)
    }

    async fn create_token(
        &self,
        account: AccountId,
        value: u64,
        address: Option<Vec<u8>>,
        context_id: Vec<u8>,
    ) -> M10Result<(TxId, Option<sdk::OfflineToken>)> {
        let address = address.unwrap_or(self.signer()?.public_key().to_vec());
        let req = self
            .signed_transaction(
                sdk::CreateToken {
                    address,
                    account_id: account.to_vec(),
                    value,
                }
                .into(),
                context_id,
            )
            .await?;
        let response = self.create_transaction(req.into()).await?;
        Ok((response.tx_id, response.token))
    }

    async fn redeem_token(
        &self,
        token: sdk::RedeemableToken,
        account_id: AccountId,
        context_id: Vec<u8>,
    ) -> M10Result<TxId> {
        let req = self
            .signed_transaction(
                sdk::RedeemToken {
                    token: Some(token),
                    account_id: account_id.to_vec(),
                }
                .into(),
                context_id,
            )
            .await?;
        let response = self.create_transaction(req.into()).await?;
        Ok(response.tx_id)
    }

    // Queries
    async fn get_block_height(&self) -> M10Result<u64>;

    async fn get_offline_key(&self) -> M10Result<Vec<u8>>;

    async fn get_account(&self, id: AccountId) -> M10Result<Account>;

    async fn get_indexed_account(&self, id: AccountId) -> M10Result<sdk::IndexedAccount>;

    async fn get_account_info(&self, id: AccountId) -> M10Result<AccountInfo>;

    async fn get_raw_account_info(&self, id: Vec<u8>) -> M10Result<sdk::AccountInfo>;

    async fn list_accounts(
        &self,
        filter: PageBuilder<Vec<u8>, AccountMetadataFilter>,
    ) -> M10Result<Vec<Account>>;

    async fn get_transfer(&self, tx_id: TxId) -> M10Result<Transfer>;

    async fn get_raw_transfer(&self, tx_id: TxId) -> M10Result<sdk::FinalizedTransfer>;

    async fn get_enhanced_transfer(&self, tx_id: TxId) -> M10Result<ExpandedTransfer>;

    async fn get_enhanced_transfers(
        &self,
        filter: TxnFilter<TransferFilter>,
    ) -> M10Result<Vec<ExpandedTransfer>>;

    async fn list_transfers(&self, filter: TxnFilter<TransferFilter>) -> M10Result<Vec<Transfer>>;

    async fn list_raw_transfers(
        &self,
        filter: TxnFilter<TransferFilter>,
    ) -> M10Result<sdk::FinalizedTransfers>;

    async fn get_action(&self, tx_id: TxId) -> M10Result<Action>;

    async fn list_actions(&self, filter: TxnFilter<ActionsFilter>) -> M10Result<Vec<Action>>;

    async fn list_transactions(
        &self,
        filter: TxnFilter<ContextFilter>,
    ) -> M10Result<Vec<Transaction>>;

    async fn group_transactions(
        &self,
        filter: TxnFilter<GroupingFilter>,
    ) -> M10Result<Vec<Vec<Transaction>>>;

    async fn get_bank(&self, id: Vec<u8>) -> M10Result<Bank>;

    async fn list_banks(&self, builder: PageBuilder<Vec<u8>>) -> M10Result<Vec<Bank>>;

    async fn get_role(&self, id: Vec<u8>) -> M10Result<Role>;

    async fn list_roles(&self, builder: PageBuilder<Vec<u8>, RoleFilter>) -> M10Result<Vec<Role>>;

    async fn get_role_binding(&self, id: Vec<u8>) -> M10Result<RoleBinding>;

    async fn list_role_bindings(
        &self,
        builder: PageBuilder<Vec<u8>, RoleBindingFilter>,
    ) -> M10Result<Vec<RoleBinding>>;

    async fn get_account_set(&self, id: Vec<u8>) -> M10Result<AccountSet>;

    async fn list_account_sets(
        &self,
        builder: PageBuilder<Vec<u8>, NameOrOwnerFilter>,
    ) -> M10Result<Vec<AccountSet>>;

    async fn get_account_metadata(&self, id: Vec<u8>) -> M10Result<AccountMetadata>;

    async fn list_account_metadata(
        &self,
        builder: PageBuilder<Vec<u8>, AccountMetadataFilter>,
    ) -> M10Result<Vec<AccountMetadata>>;

    // Transfer Enhancing
    async fn enhance_transfers(
        &self,
        transfers: Vec<sdk::FinalizedTransfer>,
    ) -> M10Result<Vec<EnhancedTransfer>> {
        futures_util::future::try_join_all(
            transfers
                .into_iter()
                .map(|transfer| self.enhance_transfer(transfer)),
        )
        .await
    }

    async fn enhance_transfer(
        &self,
        transfer: sdk::FinalizedTransfer,
    ) -> M10Result<EnhancedTransfer> {
        let mut enhanced_steps = Vec::default();
        for transfer_step in &transfer.transfer_steps {
            enhanced_steps.push(self.enhance_transfer_step(transfer_step).await?);
        }
        Ok(EnhancedTransfer {
            enhanced_steps,
            transfer,
        })
    }

    async fn enhance_transfer_step(
        &self,
        transfer_step: &sdk::TransferStep,
    ) -> M10Result<EnhancedTransferStep> {
        let from = async {
            M10Result::Ok(
                self.get_raw_account_info(transfer_step.from_account_id.clone())
                    .await
                    .ok(),
            )
        };
        let to = async {
            Ok(self
                .get_raw_account_info(transfer_step.to_account_id.clone())
                .await
                .ok())
        };
        let (from, to) = futures_util::future::try_join(from, to).await?;
        let from_bank = async {
            if let Some(ref from) = from {
                if from.parent_account_id.is_empty() {
                    Ok(None)
                } else {
                    M10Result::Ok(
                        self.get_raw_account_info(from.parent_account_id.clone())
                            .await
                            .ok(),
                    )
                }
            } else {
                Ok(None)
            }
        };
        let to_bank = async {
            if let Some(ref to) = to {
                if to.parent_account_id.is_empty() {
                    Ok(None)
                } else {
                    M10Result::Ok(
                        self.get_raw_account_info(to.parent_account_id.clone())
                            .await
                            .ok(),
                    )
                }
            } else {
                Ok(None)
            }
        };
        let (from_bank, to_bank) = futures_util::future::try_join(from_bank, to_bank).await?;

        Ok(EnhancedTransferStep {
            from,
            to,
            from_bank,
            to_bank,
        })
    }

    // Observers
    async fn observe_accounts(
        &self,
        filter: AccountFilter,
    ) -> M10Result<Pin<Box<dyn Stream<Item = M10Result<Vec<AccountUpdate>>> + Send + Sync + 'static>>>;

    async fn observe_transfers(
        &self,
        filter: AccountFilter,
    ) -> M10Result<Pin<Box<dyn Stream<Item = M10Result<Vec<Transfer>>> + Send + Sync + 'static>>>;

    async fn observe_transactions(
        &self,
        filter: AccountFilter,
    ) -> M10Result<
        Pin<Box<dyn Stream<Item = M10Result<sdk::FinalizedTransactions>> + Send + Sync + 'static>>,
    >;

    async fn observe_actions(
        &self,
        filter: AccountFilter<NamedAction>,
    ) -> M10Result<Pin<Box<dyn Stream<Item = M10Result<Vec<Action>>> + Send + Sync + 'static>>>;

    async fn observe_raw_actions(
        &self,
        filter: AccountFilter<NamedAction>,
    ) -> M10Result<
        Pin<Box<dyn Stream<Item = M10Result<sdk::FinalizedTransactions>> + Send + Sync + 'static>>,
    >;

    async fn observe_resources(
        &self,
        request: sdk::ObserveResourcesRequest,
    ) -> M10Result<
        Pin<Box<dyn Stream<Item = M10Result<sdk::FinalizedTransactions>> + Send + Sync + 'static>>,
    >;

    async fn observe_metrics(
        &self,
        filter: AccountFilter,
    ) -> M10Result<
        Pin<Box<dyn Stream<Item = M10Result<sdk::TransactionMetrics>> + Send + Sync + 'static>>,
    >;
}

// Convenient functions with "impl" parameters.
// They had to be removed from the trait to make it object safe.

#[allow(clippy::borrowed_box)]
pub async fn signed_transaction<D: Into<sdk::transaction_data::Data>, S: Signer>(
    client: &Box<dyn M10CoreClient<Signer = S> + Send + Sync>,
    data: D,
    context_id: Vec<u8>,
) -> M10Result<SignedRequest<sdk::TransactionRequestPayload>> {
    client.signed_transaction(data.into(), context_id).await
}

// Routes signing through the digest path for P256 and Ed25519Ph, and falls back to
// raw signing for plain Ed25519 to preserve backward compatibility.
async fn sign_prepared_or_raw<S: Signer>(
    req: sdk::TransactionRequestPayload,
    signer: &S,
) -> M10Result<SignedRequest<sdk::TransactionRequestPayload>> {
    use m10_protos::prost::Message as _;

    match signer.algorithm() {
        Algorithm::Ed25519 => Ok(signer.sign_request(req).await?),
        algorithm => {
            let payload = req.encode_to_vec();
            let prepared = PreparedTransaction::new(payload, algorithm)?;
            prepared.verify_integrity()?;
            let sig_bytes = signer.sign_prepared_transaction(&prepared).await?;
            // Reject structurally invalid signature bytes before attaching to the envelope
            match algorithm {
                Algorithm::P256Sha256Asn1 => {
                    let _ = p256::ecdsa::Signature::from_der(&sig_bytes)
                        .map_err(|_| m10_signing::SigningError::MalFormedSignature)?;
                }
                Algorithm::Ed25519PhSha512 => {
                    if sig_bytes.len() != ed25519_dalek::SIGNATURE_LENGTH {
                        return Err(m10_signing::SigningError::MalFormedSignature.into());
                    }
                }
                Algorithm::Ed25519 => unreachable!("Ed25519 is handled in the outer match arm"),
            }
            let signature = sdk::Signature {
                algorithm: algorithm.into(),
                public_key: signer.public_key().to_vec(),
                signature: sig_bytes,
            };
            Ok(SignedRequest {
                request_envelope: sdk::RequestEnvelope {
                    payload: prepared.payload,
                    signature: Some(signature),
                },
                data: req,
            })
        }
    }
}

pub async fn signed_transaction_as<S: Signer>(
    data: sdk::transaction_data::Data,
    context_id: Vec<u8>,
    signer: Arc<S>,
) -> M10Result<SignedRequest<sdk::TransactionRequestPayload>> {
    let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_micros() as u64;
    let req = sdk::TransactionRequestPayload {
        nonce: fastrand::u64(..),
        timestamp,
        context_id,
        data: Some(sdk::TransactionData { data: Some(data) }),
    };
    sign_prepared_or_raw(req, signer.as_ref()).await
}

#[allow(clippy::borrowed_box)]
pub async fn create_transaction<S: Signer>(
    client: &Box<dyn M10CoreClient<Signer = S> + Send + Sync>,
    payload: impl Into<sdk::RequestEnvelope>,
) -> M10Result<sdk::TransactionResponse> {
    client.create_transaction(payload.into()).await
}

#[allow(clippy::borrowed_box)]
pub async fn bulk_create_transactions<S: Signer>(
    client: &Box<dyn M10CoreClient<Signer = S> + Send + Sync>,
    payload: impl Into<sdk::BulkTransactions>,
) -> M10Result<sdk::BulkTransactionsResponse> {
    client.bulk_create_transactions(payload.into()).await
}

#[allow(clippy::borrowed_box)]
pub async fn transfer<S: Signer>(
    client: &Box<dyn M10CoreClient<Signer = S> + Send + Sync>,
    builder: impl Into<Ctx<TransferBuilder>>,
) -> M10Result<TxId> {
    let builder = builder.into();
    let req = signed_transaction::<sdk::CreateTransfer, S>(
        client,
        builder.value.into(),
        builder.context_id,
    )
    .await?;
    let response = client.create_transaction(req.into()).await?;
    Ok(response.tx_id)
}

#[allow(clippy::borrowed_box)]
pub async fn create_account<S: Signer>(
    client: &Box<dyn M10CoreClient<Signer = S> + Send + Sync>,
    builder: impl Into<Ctx<AccountBuilder>>,
) -> M10Result<(TxId, AccountId)> {
    let builder = builder.into();
    let req = signed_transaction::<sdk::CreateLedgerAccount, S>(
        client,
        builder.value.into(),
        builder.context_id,
    )
    .await?;
    let response = client.create_transaction(req.into()).await?;
    let account_id = AccountId::try_from_be_slice(&response.account_created)?;
    Ok((response.tx_id, account_id))
}

#[allow(clippy::borrowed_box)]
pub async fn initiate_transfer<S: Signer>(
    client: &Box<dyn M10CoreClient<Signer = S> + Send + Sync>,
    builder: impl Into<Ctx<TransferBuilder>>,
) -> M10Result<TxId> {
    let builder = builder.into();
    let req = signed_transaction(
        client,
        sdk::transaction_data::Data::InitiateTransfer(builder.value.into()),
        builder.context_id,
    )
    .await?;
    let response = client.create_transaction(req.into()).await?;
    Ok(response.tx_id)
}

#[allow(clippy::borrowed_box)]
pub async fn set_account_instrument<S: Signer>(
    client: &Box<dyn M10CoreClient<Signer = S> + Send + Sync>,
    account_id: AccountId,
    code: impl Into<String>,
    decimals: u32,
    description: Option<impl Into<String>>,
    context_id: Vec<u8>,
    display_code: impl Into<String>,
) -> M10Result<TxId> {
    let req = signed_transaction(
        client,
        sdk::SetInstrument {
            account_id: account_id.to_vec(),
            code: code.into(),
            decimal_places: decimals,
            description: description.map(|d| d.into()).unwrap_or_default(),
            display_code: display_code.into(),
        },
        context_id,
    )
    .await?;
    let response = client.create_transaction(req.into()).await?;
    Ok(response.tx_id)
}

#[allow(clippy::borrowed_box)]
pub async fn action<S: Signer>(
    client: &Box<dyn M10CoreClient<Signer = S> + Send + Sync>,
    builder: impl Into<Ctx<ActionBuilder>>,
) -> M10Result<TxId> {
    let builder = builder.into();
    let req = signed_transaction::<sdk::InvokeAction, S>(
        client,
        builder.value.into(),
        builder.context_id,
    )
    .await?;
    let response = client.create_transaction(req.into()).await?;
    Ok(response.tx_id)
}

#[allow(clippy::borrowed_box)]
pub async fn documents<S: Signer>(
    client: &Box<dyn M10CoreClient<Signer = S> + Send + Sync>,
    builder: impl Into<Ctx<DocumentBuilder>>,
) -> M10Result<TxId> {
    let builder = builder.into();
    let req = signed_transaction::<sdk::DocumentOperations, S>(
        client,
        builder.value.into(),
        builder.context_id,
    )
    .await?;
    let response = client.create_transaction(req.into()).await?;
    Ok(response.tx_id)
}

#[allow(clippy::borrowed_box)]
pub async fn get_bank<S: Signer>(
    client: &Box<dyn M10CoreClient<Signer = S> + Send + Sync>,
    id: impl DocumentId,
) -> M10Result<Bank> {
    client.get_bank(id.into_vec()).await
}

#[allow(clippy::borrowed_box)]
pub async fn get_role<S: Signer>(
    client: &Box<dyn M10CoreClient<Signer = S> + Send + Sync>,
    id: impl DocumentId,
) -> M10Result<Role> {
    client.get_role(id.into_vec()).await
}

#[allow(clippy::borrowed_box)]
pub async fn get_role_binding<S: Signer>(
    client: &Box<dyn M10CoreClient<Signer = S> + Send + Sync>,
    id: impl DocumentId,
) -> M10Result<RoleBinding> {
    client.get_role_binding(id.into_vec()).await
}

#[allow(clippy::borrowed_box)]
pub async fn get_account_set<S: Signer>(
    client: &Box<dyn M10CoreClient<Signer = S> + Send + Sync>,
    id: impl DocumentId,
) -> M10Result<AccountSet> {
    client.get_account_set(id.into_vec()).await
}