Skip to content

Commit e2cfaef

Browse files
ea-open-sourceDat Tran
authored andcommitted
get address from user if authkey changed
1 parent 4b40e86 commit e2cfaef

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

ol/txs/src/tx_params.rs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
//! Txs App submit_tx module
22
#![forbid(unsafe_code)]
3-
use crate::config::AppCfg;
3+
4+
use std::io;
5+
use std::path::PathBuf;
6+
47
use anyhow::Error;
8+
use reqwest::Url;
59

610
use diem_crypto::{
711
ed25519::{Ed25519PrivateKey, Ed25519PublicKey},
812
test_utils::KeyPair,
913
};
1014
use diem_global_constants::OPERATOR_KEY;
11-
1215
use diem_secure_storage::{CryptoStorage, Namespaced, OnDiskStorage, Storage};
1316
use diem_types::{account_address::AccountAddress, chain_id::NamedChain, waypoint::Waypoint};
1417
use diem_types::{chain_id::ChainId, transaction::authenticator::AuthenticationKey};
18+
use diem_wallet::WalletLibrary;
1519
use ol::node::client::find_a_remote_jsonrpc;
1620
use ol_keys::{scheme::KeyScheme, wallet};
17-
18-
use diem_wallet::WalletLibrary;
1921
use ol_types::{
2022
self,
2123
config::{TxCost, TxType},
2224
fixtures,
2325
};
24-
use reqwest::Url;
25-
use std::path::PathBuf;
26+
27+
use crate::config::AppCfg;
2628

2729
/// All the parameters needed for a client transaction.
2830
#[derive(Debug)]
@@ -109,6 +111,39 @@ impl TxParams {
109111
}
110112
};
111113

114+
println!("OPTIONAL: If you have changed your account's authkey \
115+
then input the old address below, enter to skip.");
116+
let mut account_address: Option<AccountAddress> = None;
117+
let mut input = String::new();
118+
loop {
119+
match io::stdin().read_line(&mut input) {
120+
Ok(_) => {
121+
if let Some('\n') = input.chars().next_back() {
122+
input.pop();
123+
}
124+
if let Some('\r') = input.chars().next_back() {
125+
input.pop();
126+
}
127+
if input.len() == 0 {
128+
break;
129+
}
130+
if let Ok(address) = AccountAddress::from_hex_literal(&format!("0x{}", input)) {
131+
account_address = Some(address);
132+
break;
133+
};
134+
println!("Invalid address. Try again!");
135+
input.clear();
136+
}
137+
Err(error) => println!("{}", error)
138+
}
139+
}
140+
if let Some(address) = account_address {
141+
tx_params.signer_address = address;
142+
if !is_operator {
143+
tx_params.owner_address = address;
144+
}
145+
}
146+
112147
if let Some(w) = waypoint {
113148
tx_params.waypoint = w
114149
}

0 commit comments

Comments
 (0)