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
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
use std::fmt::{Debug, Formatter, Result};
use serde::Serialize;
#[cfg(feature = "participation")]
use {
crate::types::api::plugins::participation::types::{ParticipationEventId, ParticipationEventStatus},
crate::wallet::account::operations::participation::{AccountParticipationOverview, ParticipationEventWithNodes},
std::collections::HashMap,
};
#[cfg(feature = "ledger_nano")]
use crate::client::secret::LedgerNanoStatus;
use crate::{
client::{
api::{PreparedTransactionDataDto, SignedTransactionDataDto},
NodeInfoWrapper,
},
types::block::{
output::{dto::OutputDto, OutputId},
payload::transaction::TransactionId,
BlockId,
},
wallet::{
account::{
operations::transaction::high_level::minting::mint_native_token::MintTokenTransactionDto,
types::{address::AccountAddress, AccountBalanceDto, TransactionDto},
OutputDataDto,
},
message_interface::dtos::{AccountDetailsDto, AddressWithUnspentOutputsDto},
Error,
},
};
/// The response message.
#[derive(Serialize)]
#[serde(tag = "type", content = "payload", rename_all = "camelCase")]
pub enum Response {
/// Response for
/// [`CreateAccount`](crate::wallet::message_interface::Message::CreateAccount),
/// [`GetAccount`](crate::wallet::message_interface::Message::GetAccount)
Account(AccountDetailsDto),
/// Response for [`GetAccountIndexes`](crate::wallet::message_interface::Message::GetAccountIndexes)
AccountIndexes(Vec<u32>),
/// Response for [`GetAccounts`](crate::wallet::message_interface::Message::GetAccounts)
Accounts(Vec<AccountDetailsDto>),
/// Response for [`Addresses`](crate::wallet::message_interface::AccountMethod::Addresses)
Addresses(Vec<AccountAddress>),
/// Response for
/// [`AddressesWithUnspentOutputs`](crate::wallet::message_interface::AccountMethod::AddressesWithUnspentOutputs)
AddressesWithUnspentOutputs(Vec<AddressWithUnspentOutputsDto>),
/// Response for
/// [`RetryTransactionUntilIncluded`](crate::wallet::message_interface::AccountMethod::RetryTransactionUntilIncluded)
BlockId(BlockId),
/// Response for
/// [`BuildAliasOutput`](crate::wallet::message_interface::AccountMethod::BuildAliasOutput)
/// [`BuildBasicOutput`](crate::wallet::message_interface::AccountMethod::BuildBasicOutput)
/// [`BuildFoundryOutput`](crate::wallet::message_interface::AccountMethod::BuildFoundryOutput)
/// [`BuildNftOutput`](crate::wallet::message_interface::AccountMethod::BuildNftOutput)
/// [`GetFoundryOutput`](crate::wallet::message_interface::AccountMethod::GetFoundryOutput)
/// [`PrepareOutput`](crate::wallet::message_interface::AccountMethod::PrepareOutput)
Output(OutputDto),
/// Response for
/// [`MinimumRequiredStorageDeposit`](crate::wallet::message_interface::AccountMethod::MinimumRequiredStorageDeposit)
MinimumRequiredStorageDeposit(String),
/// Response for
/// [`GetOutputsWithAdditionalUnlockConditions`](crate::wallet::message_interface::AccountMethod::GetOutputsWithAdditionalUnlockConditions)
OutputIds(Vec<OutputId>),
/// Response for [`GetOutput`](crate::wallet::message_interface::AccountMethod::GetOutput)
OutputData(Option<Box<OutputDataDto>>),
/// Response for
/// [`Outputs`](crate::wallet::message_interface::AccountMethod::Outputs),
/// [`UnspentOutputs`](crate::wallet::message_interface::AccountMethod::UnspentOutputs)
OutputsData(Vec<OutputDataDto>),
/// Response for
/// [`PrepareSendAmount`](crate::wallet::message_interface::AccountMethod::PrepareSendAmount),
/// [`PrepareTransaction`](crate::wallet::message_interface::AccountMethod::PrepareTransaction)
PreparedTransaction(PreparedTransactionDataDto),
/// Response for
/// [`GetTransaction`](crate::wallet::message_interface::AccountMethod::GetTransaction),
Transaction(Option<Box<TransactionDto>>),
/// Response for
/// [`Transactions`](crate::wallet::message_interface::AccountMethod::Transactions),
/// [`PendingTransactions`](crate::wallet::message_interface::AccountMethod::PendingTransactions)
Transactions(Vec<TransactionDto>),
/// Response for
/// [`SignTransactionEssence`](crate::wallet::message_interface::AccountMethod::SignTransactionEssence)
/// [`SubmitAndStoreTransaction`](crate::wallet::message_interface::AccountMethod::SubmitAndStoreTransaction)
SignedTransactionData(SignedTransactionDataDto),
/// GenerateAddress response.
/// Response for [`GenerateAddresses`](crate::wallet::message_interface::AccountMethod::GenerateAddresses)
GeneratedAddress(Vec<AccountAddress>),
/// Response for
/// [`GetBalance`](crate::wallet::message_interface::AccountMethod::GetBalance),
/// [`SyncAccount`](crate::wallet::message_interface::AccountMethod::SyncAccount)
Balance(AccountBalanceDto),
/// Response for
/// [`GetLedgerNanoStatus`](crate::wallet::message_interface::Message::GetLedgerNanoStatus),
#[cfg(feature = "ledger_nano")]
#[cfg_attr(docsrs, doc(cfg(feature = "ledger_nano")))]
LedgerNanoStatus(LedgerNanoStatus),
/// Response for
/// [`GetIncomingTransactionData`](crate::wallet::message_interface::AccountMethod::GetIncomingTransactionData),
IncomingTransactionData(Option<Box<(TransactionId, TransactionDto)>>),
/// Response for
/// [`IncomingTransactions`](crate::wallet::message_interface::AccountMethod::IncomingTransactions),
IncomingTransactionsData(Vec<(TransactionId, TransactionDto)>),
/// Response for
/// [`ConsolidateOutputs`](crate::wallet::message_interface::AccountMethod::ConsolidateOutputs)
/// [`ClaimOutputs`](crate::wallet::message_interface::AccountMethod::ClaimOutputs)
/// [`CreateAliasOutput`](crate::wallet::message_interface::AccountMethod::CreateAliasOutput)
/// [`SendAmount`](crate::wallet::message_interface::AccountMethod::SendAmount),
/// [`MintNfts`](crate::wallet::message_interface::AccountMethod::MintNfts),
/// [`SendAmount`](crate::wallet::message_interface::AccountMethod::SendAmount),
/// [`SendNativeTokens`](crate::wallet::message_interface::AccountMethod::SendNativeTokens),
/// [`SendNft`](crate::wallet::message_interface::AccountMethod::SendNft),
/// [`SendOutputs`](crate::wallet::message_interface::AccountMethod::SendOutputs)
/// [`SubmitAndStoreTransaction`](crate::wallet::message_interface::AccountMethod::SubmitAndStoreTransaction)
/// [`Vote`](crate::wallet::message_interface::AccountMethod::Vote)
/// [`StopParticipating`](crate::wallet::message_interface::AccountMethod::StopParticipating)
/// [`IncreaseVotingPower`](crate::wallet::message_interface::AccountMethod::IncreaseVotingPower)
/// [`DecreaseVotingPower`](crate::wallet::message_interface::AccountMethod::DecreaseVotingPower)
SentTransaction(TransactionDto),
/// Response for
/// [`MintNativeToken`](crate::wallet::message_interface::AccountMethod::MintNativeToken),
MintTokenTransaction(MintTokenTransactionDto),
/// Response for
/// [`IsStrongholdPasswordAvailable`](crate::wallet::message_interface::Message::IsStrongholdPasswordAvailable)
StrongholdPasswordIsAvailable(bool),
/// An error occurred.
Error(Error),
/// A panic occurred.
Panic(String),
/// Response for [`GenerateMnemonic`](crate::wallet::message_interface::Message::GenerateMnemonic)
GeneratedMnemonic(String),
/// Response for [`GetNodeInfo`](crate::wallet::message_interface::Message::GetNodeInfo)
NodeInfo(NodeInfoWrapper),
/// Response for
/// [`GetParticipationEvent`](crate::wallet::message_interface::AccountMethod::GetParticipationEvent)
#[cfg(feature = "participation")]
#[cfg_attr(docsrs, doc(cfg(feature = "participation")))]
ParticipationEvent(Option<ParticipationEventWithNodes>),
/// Response for
/// [`GetParticipationEventIds`](crate::wallet::message_interface::AccountMethod::GetParticipationEventIds)
#[cfg(feature = "participation")]
#[cfg_attr(docsrs, doc(cfg(feature = "participation")))]
ParticipationEventIds(Vec<ParticipationEventId>),
/// Response for
/// [`GetParticipationEventStatus`](crate::wallet::message_interface::AccountMethod::GetParticipationEventStatus)
#[cfg(feature = "participation")]
#[cfg_attr(docsrs, doc(cfg(feature = "participation")))]
ParticipationEventStatus(ParticipationEventStatus),
/// Response for
/// [`GetParticipationEvents`](crate::wallet::message_interface::AccountMethod::GetParticipationEvents)
/// [`RegisterParticipationEvent`](crate::wallet::message_interface::AccountMethod::RegisterParticipationEvents)
#[cfg(feature = "participation")]
#[cfg_attr(docsrs, doc(cfg(feature = "participation")))]
ParticipationEvents(HashMap<ParticipationEventId, ParticipationEventWithNodes>),
/// Response for
/// [`GetParticipationOverview`](crate::wallet::message_interface::AccountMethod::GetParticipationOverview)
#[cfg(feature = "participation")]
#[cfg_attr(docsrs, doc(cfg(feature = "participation")))]
AccountParticipationOverview(AccountParticipationOverview),
/// Response for [`Bech32ToHex`](crate::wallet::message_interface::Message::Bech32ToHex)
HexAddress(String),
/// Response for [`HexToBech32`](crate::wallet::message_interface::Message::HexToBech32)
/// Response for [`GenerateAddress`](crate::wallet::message_interface::Message::GenerateAddress)
Bech32Address(String),
/// Response for
/// [`RequestFundsFromFaucet`](crate::wallet::message_interface::AccountMethod::RequestFundsFromFaucet)
Faucet(String),
/// Response for
/// [`Backup`](crate::wallet::message_interface::Message::Backup),
/// [`ClearStrongholdPassword`](crate::wallet::message_interface::Message::ClearStrongholdPassword),
/// [`DeregisterParticipationEvent`](crate::wallet::message_interface::AccountMethod::DeregisterParticipationEvent),
/// [`RestoreBackup`](crate::wallet::message_interface::Message::RestoreBackup),
/// [`VerifyMnemonic`](crate::wallet::message_interface::Message::VerifyMnemonic),
/// [`SetClientOptions`](crate::wallet::message_interface::Message::SetClientOptions),
/// [`SetStrongholdPassword`](crate::wallet::message_interface::Message::SetStrongholdPassword),
/// [`SetStrongholdPasswordClearInterval`](crate::wallet::message_interface::Message::SetStrongholdPasswordClearInterval),
/// [`StoreMnemonic`](crate::wallet::message_interface::Message::StoreMnemonic),
/// [`StartBackgroundSync`](crate::wallet::message_interface::Message::StartBackgroundSync),
/// [`StopBackgroundSync`](crate::wallet::message_interface::Message::StopBackgroundSync),
/// [`EmitTestEvent`](crate::wallet::message_interface::Message::EmitTestEvent),
Ok(()),
}
// Custom Debug implementation to not log secrets
impl Debug for Response {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self {
Self::Account(account) => write!(f, "Account({account:?})"),
Self::AccountIndexes(account_indexes) => write!(f, "AccountIndexes({account_indexes:?})"),
Self::Accounts(accounts) => write!(f, "Accounts({accounts:?})"),
Self::Addresses(addresses) => write!(f, "Addresses({addresses:?})"),
Self::AddressesWithUnspentOutputs(addresses) => {
write!(f, "AddressesWithUnspentOutputs({addresses:?})")
}
Self::BlockId(block_id) => write!(f, "BlockId({block_id:?})"),
Self::Output(output) => write!(f, "Output({output:?})"),
Self::MinimumRequiredStorageDeposit(amount) => write!(f, "MinimumRequiredStorageDeposit({amount:?})"),
Self::OutputIds(output_ids) => write!(f, "OutputIds({output_ids:?})"),
Self::OutputData(output) => write!(f, "OutputData({output:?})"),
Self::OutputsData(outputs) => write!(f, "OutputsData{outputs:?}"),
Self::PreparedTransaction(transaction_data) => {
write!(f, "PreparedTransaction({transaction_data:?})")
}
Self::Transaction(transaction) => write!(f, "Transaction({transaction:?})"),
Self::Transactions(transactions) => write!(f, "Transactions({transactions:?})"),
Self::SignedTransactionData(signed_transaction_data) => {
write!(f, "SignedTransactionData({signed_transaction_data:?})")
}
Self::GeneratedAddress(addresses) => write!(f, "GeneratedAddress({addresses:?})"),
Self::Balance(balance) => write!(f, "Balance({balance:?})"),
Self::IncomingTransactionData(transaction_data) => {
write!(f, "IncomingTransactionData({transaction_data:?})")
}
Self::IncomingTransactionsData(transactions_data) => {
write!(f, "IncomingTransactionsData({transactions_data:?})")
}
Self::SentTransaction(transaction) => write!(f, "SentTransaction({transaction:?})"),
Self::MintTokenTransaction(mint_transaction) => {
write!(f, "MintTokenTransaction({mint_transaction:?})")
}
Self::StrongholdPasswordIsAvailable(is_available) => {
write!(f, "StrongholdPasswordIsAvailable({is_available:?})")
}
Self::Error(error) => write!(f, "Error({error:?})"),
Self::Panic(panic_msg) => write!(f, "Panic({panic_msg:?})"),
Self::GeneratedMnemonic(_) => write!(f, "GeneratedMnemonic(<omitted>)"),
#[cfg(feature = "ledger_nano")]
Self::LedgerNanoStatus(ledger_nano_status) => write!(f, "LedgerNanoStatus({ledger_nano_status:?})"),
Self::NodeInfo(info) => write!(f, "NodeInfo({info:?})"),
Self::HexAddress(hex_address) => write!(f, "Hex encoded address({hex_address:?})"),
Self::Bech32Address(bech32_address) => write!(f, "Bech32 encoded address({bech32_address:?})"),
Self::Ok(()) => write!(f, "Ok(())"),
#[cfg(feature = "participation")]
Self::ParticipationEvent(event) => write!(f, "ParticipationEvent({event:?})"),
#[cfg(feature = "participation")]
Self::ParticipationEventStatus(event_status) => write!(f, "ParticipationEventStatus({event_status:?})"),
#[cfg(feature = "participation")]
Self::ParticipationEvents(events) => write!(f, "ParticipationEvents({events:?})"),
#[cfg(feature = "participation")]
Self::ParticipationEventIds(event_ids) => write!(f, "ParticipationEventIds({event_ids:?})"),
#[cfg(feature = "participation")]
Self::AccountParticipationOverview(overview) => {
write!(f, "AccountParticipationOverview({overview:?})")
}
Self::Faucet(response) => write!(f, "Faucet({response:?})"),
}
}
}