-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathallot_mana.rs
46 lines (38 loc) · 1.51 KB
/
allot_mana.rs
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
// Copyright 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
use crate::{
client::{api::PreparedTransactionData, secret::SecretManage},
types::block::mana::ManaAllotment,
wallet::{
operations::transaction::{TransactionOptions, TransactionWithMetadata},
Wallet,
},
};
impl<S: 'static + SecretManage> Wallet<S>
where
crate::wallet::Error: From<S::Error>,
crate::client::Error: From<S::Error>,
{
pub async fn allot_mana(
&self,
allotments: impl IntoIterator<Item = impl Into<ManaAllotment>> + Send,
options: impl Into<Option<TransactionOptions>> + Send,
) -> crate::wallet::Result<TransactionWithMetadata> {
let options = options.into();
let prepared_transaction = self.prepare_allot_mana(allotments, options.clone()).await?;
self.sign_and_submit_transaction(prepared_transaction, options).await
}
pub async fn prepare_allot_mana(
&self,
allotments: impl IntoIterator<Item = impl Into<ManaAllotment>> + Send,
options: impl Into<Option<TransactionOptions>> + Send,
) -> crate::wallet::Result<PreparedTransactionData> {
log::debug!("[TRANSACTION] prepare_allot_mana");
let mut options = options.into().unwrap_or_default();
for allotment in allotments {
let ManaAllotment { account_id, mana } = allotment.into();
*options.mana_allotments.entry(account_id).or_default() += mana;
}
self.prepare_transaction(None, None, options).await
}
}