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
// use eframe::egui;
// use eframe::egui::Ui;
// use redgold_keys::transaction_support::TransactionSupport;
// use redgold_keys::util::btc_wallet::SingleKeyBitcoinWallet;
// use redgold_schema::helpers::easy_json::EasyJsonDeser;
// use redgold_schema::helpers::with_metadata_hashable::WithMetadataHashable;
// use redgold_schema::structs::{PublicKey, SupportedCurrency, Transaction};
// use redgold_schema::util::lang_util::JsonCombineResult;
// use crate::gui::app_loop::LocalState;
// use redgold_gui::common;
// use redgold_gui::common::data_item;
// use redgold_gui::tab::transact::states::WalletTab;
// use crate::gui::tabs::transact::{broadcast_tx, hardware_signing, prepare_tx};
// use redgold_gui::tab::transact::states::SendReceiveTabs;
// use redgold_schema::observability::errors::Loggable;
// pub fn prepared_view(ui: &mut Ui, ls: &mut LocalState, pk: &PublicKey, is_hot: bool) {
//
// if ui.button("Prepare Transaction").clicked() {
// if ls.wallet.send_currency_type == SupportedCurrency::Bitcoin {
// if let Ok(amount) = ls.wallet.amount_input.parse::<f64>() {
//
// let mut w = SingleKeyBitcoinWallet::new_wallet(
// pk.clone(), ls.node_config.network, true
// ).expect("w");
// let result = w.prepare_single(
// ls.wallet.destination_address.clone(),
// amount
// );
// ls.wallet.signing_flow_transaction_box_msg = Some(
// result.clone().json_or_combine()
// );
// let status = result.as_ref().map(|_x| "Transaction Prepared".to_string())
// .unwrap_or("Preparation Failed".to_string());
// ls.wallet.signing_flow_status = Some(status);
// ls.wallet.transaction_prepared_success = result.is_ok();
// }
// } else {
// match &ls.wallet.address_info {
// None => {
// ls.wallet.signing_flow_status = Some("Missing UTXO info".to_string());
// }
// Some(ai) => {
// let result = prepare_tx::prepare_transaction(
// ai,
// &ls.wallet.amount_input,
// &ls.wallet.destination_address,
// &ls.wallet,
// &ls.node_config
// );
// ls.wallet.update_unsigned_tx(Some(result.clone()));
// ls.wallet.signing_flow_transaction_box_msg = Some(
// result.clone().json_or_combine()
// );
// let status = result.map(|_x| "Transaction Prepared".to_string())
// .unwrap_or("Preparation Failed".to_string());
// ls.wallet.signing_flow_status = Some(status);
// }
// }
// }
// if ls.wallet.send_receive == SendReceiveTabs::Custom {
// ls.wallet.prepared_transaction = Some(
// ls.wallet.custom_tx_json.json_from::<Transaction>()
// )
// }
// }
// if let Some(p) = &ls.wallet.signing_flow_transaction_box_msg {
// // ui.with_layout(
// // Layout::centered_and_justified(Direction::TopDown)
// // ,|ui|
// ui.label("Rendered Transaction Information"); //);
// ui.spacing();
// let string1 = &mut p.clone();
// common::bounded_text_area(ui, string1);
// }
//
// if ls.wallet.send_currency_type != SupportedCurrency::Redgold && ls.wallet.transaction_prepared_success {
// // BTC
//
// if ui.button("Sign Transaction").clicked() {
// match &ls.wallet.send_currency_type {
// SupportedCurrency::Bitcoin => {
// if let Ok(amount) = ls.wallet.amount_input.parse::<f64>() {
// // TODO: Support single private key also
// let kp = ls.wallet.hot_mnemonic().keypair_at(ls.keytab_state.derivation_path_xpub_input_account.derivation_path());
// if let Ok(pk_hex) = kp.map(|kp| kp.to_private_hex()) {
// let mut w = SingleKeyBitcoinWallet::new_wallet(
// pk.clone(), ls.node_config.network, true
// ).expect("w");
// let result = w.prepare_single_sign(
// ls.wallet.destination_address.clone(),
// amount,
// pk_hex
// ).log_error();
//
// ls.wallet.signing_flow_transaction_box_msg = Some(
// result.clone().json_or_combine()
// );
// let status = result.as_ref().map(|_x| "Transaction Signed".to_string())
// .unwrap_or("Signing Failed".to_string());
// ls.wallet.signing_flow_status = Some(status);
// ls.wallet.transaction_sign_success = result.is_ok();
// }
// }
// }
// _ => {}
// }
// }
// if ls.wallet.transaction_sign_success {
// if let Some(h) = ls.wallet.signed_transaction_hash.clone() {
// data_item(ui, "TXID:", h);
// }
// if ui.button("Broadcast Transaction").clicked() {
// match &ls.wallet.send_currency_type {
// SupportedCurrency::Bitcoin => {
// if let Ok(amount) = ls.wallet.amount_input.parse::<f64>() {
// // TODO: Support single private key also
// let kp = ls.wallet.hot_mnemonic().keypair_at(ls.keytab_state.derivation_path_xpub_input_account.derivation_path());
// if let Ok(pk_hex) = kp.map(|kp| kp.to_private_hex()) {
// let mut w = SingleKeyBitcoinWallet::new_wallet(
// pk.clone(), ls.node_config.network, true
// ).expect("w");
// let result = w.prepare_single_sign_and_broadcast(
// ls.wallet.destination_address.clone(),
// amount,
// pk_hex
// ).log_error();
// if let Ok(r) = &result {
// ls.wallet.signed_transaction_hash = Some(r.clone());
// }
// let status = result.map(|_x| "Transaction Broadcast".to_string())
// .unwrap_or("Broadcast Failed".to_string());
// ls.wallet.signing_flow_status = Some(status);
// // ls.wallet_state.transaction_sign_success = result.is_ok();
// }
// }
// }
// _ => {}
// }
// }
// }
//
//
// }
//
// if let Some(res) = &ls.wallet.prepared_transaction {
// if let Some(t) = res.as_ref().ok() {
// ui.allocate_ui(egui::Vec2::new(500.0, 0.0), |ui| {
// ui.centered_and_justified(|ui| {
// data_item(ui, "Raw TX Hash:".to_string(), t.hash_hex());
// });
// });
// if ui.button("Sign Transaction").clicked() {
// if ls.wallet.send_currency_type == SupportedCurrency::Redgold {
// if !is_hot {
// hardware_signing::initiate_hardware_signing(
// t.clone(),
// ls.wallet.updates.sender.clone(),
// pk.clone().clone(),
// ls.keytab_state.derivation_path_xpub_input_account.derivation_path()
// );
// ls.wallet.signing_flow_status = Some("Awaiting hardware response...".to_string());
// } else {
// let kp = ls.wallet.hot_mnemonic().keypair_at(ls.wallet.derivation_path.clone()).expect("kp");
// let mut t2 = t.clone();
// let signed = t2.sign(&kp);
// ls.wallet.update_signed_tx(Some(signed));
// }
// }
// } else if ls.wallet.send_currency_type == SupportedCurrency::Bitcoin {
// match ls.wallet.tab {
// WalletTab::Hardware => {
// // error!("Hardware signing not supported yet for btc");
// }
// WalletTab::Software => {
// // error!("Software signing not yet supported for btc");
// // let mut w = SingleKeyBitcoinWallet::new_wallet(
// // pk.clone(), ls.node_config.network, true
// // ).expect("w");
// // let result = w.prepare_single_sign(
// // ls.wallet_state.destination_address.clone(),
// // ls.wallet_state.amount_input.parse::<f64>().expect("f64")
// // );
// // if let Ok(tx) = result {
// // let signed = w.sign_single(&tx);
// // ls.wallet_state.update_signed_tx(Some(signed));
// }
// }
// }
// }
// }
// if let Some(m) = &ls.wallet.signing_flow_status {
// ui.label(m);
// }
// if let Some(t) = &ls.wallet.signed_transaction {
// if let Some(t) = t.as_ref().ok() {
// data_item(ui, "Signed TX Hash:", ls.wallet.signed_transaction_hash.clone().unwrap_or("error".to_string()));
// if ui.button("Broadcast Transaction").clicked() {
// broadcast_tx::broadcast_transaction(
// ls.node_config.clone(),
// t.clone(),
// ls.wallet.updates.sender.clone(),
// );
// ls.wallet.signing_flow_status = Some("Awaiting broadcast response...".to_string());
// }
// }
// }
// }