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
// use crate::gui::app_loop::{LocalState, LocalStateAddons, PublicKeyStoredState};
// use eframe::egui::{ComboBox, Context, Ui};
// use itertools::Itertools;
// use redgold_common::external_resources::ExternalNetworkResources;
// use redgold_common_no_wasm::tx_new::TransactionBuilderSupport;
// use redgold_gui::common::{bounded_text_area, bounded_text_area_size, editable_text_input_copy};
// use redgold_schema::conf::local_stored_state::Identity;
// use redgold_schema::helpers::easy_json::EasyJson;
// use redgold_schema::servers::ServerOldFormat;
// use redgold_schema::structs::{PeerMetadata, Transaction};
// use redgold_schema::tx::tx_builder::TransactionBuilder;
// use redgold_schema::{error_info, RgResult, SafeOption};
// use std::collections::HashMap;
//
// #[derive(Clone)]
// pub struct IdentityState {
// selected_name: String,
// last_selected_name: String,
// selected_identity: Option<Identity>,
// identity_name_edit: String,
// edit_peer_id_index: String,
// edit_xpub_name: String,
// peer_tx: Option<Transaction>,
// updated_peer_tx: Option<Transaction>,
// peer_request_status: Option<String>,
// peer_generate_status: Option<String>
// }
//
// impl IdentityState {
// pub(crate) fn new() -> IdentityState {
// Self {
// selected_name: "Add New Identity".to_string(),
// last_selected_name: "".to_string(),
// selected_identity: None,
// identity_name_edit: "".to_string(),
// edit_peer_id_index: "0".to_string(),
// edit_xpub_name: "".to_string(),
// peer_tx: None,
// updated_peer_tx: None,
// peer_request_status: None,
// peer_generate_status: None,
// }
// }
// }
//
// pub fn identity_tab<E>(ui: &mut Ui, _ctx: &Context, ls: &mut LocalState<E>) where E: ExternalNetworkResources + Sync + Send + Clone {
// ui.heading("Identity");
// // ui.label("WIP TAB -- not yet implemented, for now update json config manually in config tab");
//
// ComboBox::from_label("Choose Identity")
// .selected_text(ls.identity_state.selected_name.clone())
// .show_ui(ui, |ui| {
// let option1 = ls.local_stored_state.identities.clone().unwrap_or(vec![]);
// for style in option1.iter().map(|x| x.name.clone()) {
// ui.selectable_value(&mut ls.identity_state.selected_name, style.clone(), style.to_string());
// }
// });
// if ls.identity_state.last_selected_name != ls.identity_state.selected_name {
// ls.local_stored_state.identities.as_ref().map(|x| x.iter().find(|p| p.name == ls.identity_state.selected_name).map(|x| {
// ls.identity_state.selected_identity = Some(x.clone());
// }));
// ls.identity_state.last_selected_name = ls.identity_state.selected_name.clone();
// if let Some(is) = &ls.identity_state.selected_identity {
// ls.identity_state.identity_name_edit = is.name.clone();
// ls.identity_state.edit_peer_id_index = is.peer_id_index.to_string();
// ls.identity_state.edit_xpub_name = is.xpub_name.clone();
// }
// }
// editable_text_input_copy(ui, "Identity Name: ", &mut ls.identity_state.identity_name_edit, 200.0);
// editable_text_input_copy(ui, "Peer Id Index: ", &mut ls.identity_state.edit_peer_id_index, 200.0);
// editable_text_input_copy(ui, "Xpub name: ", &mut ls.identity_state.edit_xpub_name, 200.0);
//
// if ui.button("Save Identity").clicked() {
// let result = ls.identity_state.edit_peer_id_index.parse::<i64>();
// if let Some(idx) = result.ok() {
// let i = Identity {
// name: ls.identity_state.identity_name_edit.clone(),
// peer_id_index: idx,
// xpub_name: ls.identity_state.edit_xpub_name.clone(),
// };
// ls.upsert_identity(i.clone());
// ls.identity_state.selected_identity = Some(i)
// }
// }
// //
// // if ui.button("Request Peer Tx").clicked() {
// // let id = &ls.identity_state.selected_identity;
// // let pk = id.as_ref()
// // .and_then(|i| ls.local_stored_state.public_key(i.xpub_name.clone()));
// // let u = ls.updates.sender.clone();
// // let c = ls.node_config.api_client();
// // tokio::spawn(async move {
// // // TODO: Replace this with get latest transaction matching pk address.
// // let option = c.client_wrapper().get_peers().await.ok();
// // let tx = option.as_ref()
// // .and_then(|r| r.get_peers_info_response.as_ref())
// // .and_then(|r| r.peer_info.iter().find(|p|
// // pk == p.latest_peer_transaction.as_ref()
// // .and_then(|p| p.peer_data().ok())
// // .and_then(|p| p.peer_id)
// // .and_then(|p| p.peer_id)
// // )).and_then(|p| p.latest_peer_transaction.clone());
// // u.send(StateUpdate{update: Box::new(move |ls2: &mut LocalState| {
// // if tx.is_none() {
// // ls2.identity_state.peer_request_status = Some("No peer tx found".to_string());
// // }
// // ls2.identity_state.peer_tx = tx.clone();
// // })}).unwrap();
// // });
// // };
//
// if let Some(tx) = &ls.identity_state.peer_request_status {
// ui.label(tx.clone());
// }
//
// if let Some(peer_tx_existing) = &ls.identity_state.peer_tx {
// ui.label("Existing Peer Transaction:");
// bounded_text_area(ui, &mut peer_tx_existing.json_or());
// }
//
// if ui.button("Generate New Peer Tx").clicked() {
// let res = generate_peer_tx(ls);
// if let Err(e) = res {
// ls.identity_state.peer_generate_status = Some(e.json_or());
// }
// }
//
// if let Some(status) = &ls.identity_state.peer_generate_status {
// ui.label(status.clone());
// }
//
// if let Some(tx) = &ls.identity_state.updated_peer_tx {
// ui.label("Updated Peer Transaction:");
// ui.horizontal(|ui|
// bounded_text_area_size(ui, &mut tx.json_or(), 600.0, 3));
// }
//
// }
//
// fn generate_peer_tx<E>(ls: &mut LocalState<E>) -> RgResult<()> where E: ExternalNetworkResources + Sync + Send + Clone {
// let tx = ls.identity_state.peer_tx.as_ref().ok_or(error_info("No peer tx"))?;
// let i = ls.identity_state.selected_identity.as_ref()
// .ok_or(error_info("No identity"))?;
// let p = ls.local_stored_state.public_key(i.xpub_name.clone())
// .ok_or(error_info("No public key for xpub"))?;
//
// let mut tb = TransactionBuilder::new(&ls.node_config);
// let mut pkmap = HashMap::default();
// pkmap.insert(i.peer_id_index, p);
// let iter = ls.local_stored_state.servers.clone().unwrap_or(vec![]);
// let s = iter.iter()
// .filter(|s| s.peer_id_index == i.peer_id_index)
// .map(|c| c.clone())
// .collect_vec();
// let mut peer_data = PeerMetadata::default();
// ServerOldFormat::peer_data(
// s,
// &mut peer_data,
// i.peer_id_index,
// pkmap,
// ls.node_config.executable_checksum.clone().expect("exe"),
// ls.node_config.network.clone(),
// None
// );
// let option = ls.local_stored_state.trust.clone().unwrap_or(vec![]);
// let t = option
// .iter().filter(|p| p.peer_id_index == i.peer_id_index)
// .map(|p| p.labels.clone())
// .flatten()
// .collect_vec();
// peer_data.labels = t;
// let utxo = tx.first_peer_utxo()?;
// let o = utxo.output.safe_get_msg("Missing utxo Output")?;
// let d = o.data.safe_get_msg("Missing data")?;
// let h = tx.height().ok().or(d.height).safe_get_msg("Missing height")?.clone();
// tb.with_unsigned_input(utxo.clone()).expect("");
// tb.with_output_peer_data(
// &utxo.address().expect(""),
// peer_data,
// h + 1
// );
// ls.identity_state.updated_peer_tx = Some(tb.transaction.clone());
// ls.identity_state.peer_generate_status = Some("Generated Success".to_string());
// Ok(())
// }