Fix API wallets calls (#1597)

* Add API Secret in wallet calls

* File node api secret default to same api secret and directly in http parameter
This commit is contained in:
Quentin Le Sceller
2018-09-27 15:45:48 -04:00
committed by hashmap
parent 5a83989cf6
commit a13c20ceb2
18 changed files with 91 additions and 90 deletions
+8 -4
View File
@@ -52,6 +52,7 @@ pub fn seed_exists(wallet_config: WalletConfig) -> bool {
pub fn instantiate_wallet(
wallet_config: WalletConfig,
passphrase: &str,
node_api_secret: Option<String>,
) -> Box<WalletInst<HTTPWalletClient, keychain::ExtKeychain>> {
if grin_wallet::needs_migrate(&wallet_config.data_file_dir) {
// Migrate wallet automatically
@@ -67,7 +68,7 @@ pub fn instantiate_wallet(
warn!(LOGGER, "If anything went wrong, you can try again by deleting the `db` directory and running a wallet command");
warn!(LOGGER, "If all is okay, you can move/backup/delete all files in the wallet directory EXCEPT FOR wallet.seed");
}
let client = HTTPWalletClient::new(&wallet_config.check_node_api_http_addr);
let client = HTTPWalletClient::new(&wallet_config.check_node_api_http_addr, node_api_secret);
let db_wallet = LMDBBackend::new(wallet_config.clone(), "", client).unwrap_or_else(|e| {
panic!(
"Error creating DB wallet: {} Config: {:?}",
@@ -102,13 +103,15 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
if wallet_args.is_present("show_spent") {
show_spent = true;
}
let node_api_secret = get_first_line(wallet_config.node_api_secret_path.clone());
// Derive the keychain based on seed from seed file and specified passphrase.
// Generate the initial wallet seed if we are running "wallet init".
if let ("init", Some(_)) = wallet_args.subcommand() {
WalletSeed::init_file(&wallet_config).expect("Failed to init wallet seed file.");
info!(LOGGER, "Wallet seed file created");
let client = HTTPWalletClient::new(&wallet_config.check_node_api_http_addr);
let client =
HTTPWalletClient::new(&wallet_config.check_node_api_http_addr, node_api_secret);
let _: LMDBBackend<HTTPWalletClient, keychain::ExtKeychain> =
LMDBBackend::new(wallet_config.clone(), "", client).unwrap_or_else(|e| {
panic!(
@@ -126,11 +129,11 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
let passphrase = wallet_args
.value_of("pass")
.expect("Failed to read passphrase.");
// Handle listener startup commands
{
let wallet = instantiate_wallet(wallet_config.clone(), passphrase);
let wallet = instantiate_wallet(wallet_config.clone(), passphrase, node_api_secret.clone());
let api_secret = get_first_line(wallet_config.api_secret_path.clone());
match wallet_args.subcommand() {
("listen", Some(listen_args)) => {
if let Some(port) = listen_args.value_of("port") {
@@ -174,6 +177,7 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
let wallet = Arc::new(Mutex::new(instantiate_wallet(
wallet_config.clone(),
passphrase,
node_api_secret,
)));
let res = controller::owner_single_use(wallet.clone(), |api| {
match wallet_args.subcommand() {
+2 -4
View File
@@ -63,13 +63,11 @@ pub fn create() -> Box<View> {
let mut s: ViewRef<SelectView<&str>> = c.find_id(MAIN_MENU).unwrap();
s.select_down(1)(c);
Some(EventResult::Consumed(None));
})
.on_pre_event('k', move |c| {
}).on_pre_event('k', move |c| {
let mut s: ViewRef<SelectView<&str>> = c.find_id(MAIN_MENU).unwrap();
s.select_up(1)(c);
Some(EventResult::Consumed(None));
})
.on_pre_event(Key::Tab, move |c| {
}).on_pre_event(Key::Tab, move |c| {
let mut s: ViewRef<SelectView<&str>> = c.find_id(MAIN_MENU).unwrap();
if s.selected_id().unwrap() == s.len() - 1 {
s.set_selection(0)(c);
+19 -38
View File
@@ -170,23 +170,17 @@ impl TUIStatusListener for TUIMiningView {
let table_view = TableView::<WorkerStats, StratumWorkerColumn>::new()
.column(StratumWorkerColumn::Id, "Worker ID", |c| {
c.width_percent(10)
})
.column(StratumWorkerColumn::IsConnected, "Connected", |c| {
}).column(StratumWorkerColumn::IsConnected, "Connected", |c| {
c.width_percent(10)
})
.column(StratumWorkerColumn::LastSeen, "Last Seen", |c| {
}).column(StratumWorkerColumn::LastSeen, "Last Seen", |c| {
c.width_percent(20)
})
.column(StratumWorkerColumn::PowDifficulty, "Pow Difficulty", |c| {
}).column(StratumWorkerColumn::PowDifficulty, "Pow Difficulty", |c| {
c.width_percent(10)
})
.column(StratumWorkerColumn::NumAccepted, "Num Accepted", |c| {
}).column(StratumWorkerColumn::NumAccepted, "Num Accepted", |c| {
c.width_percent(10)
})
.column(StratumWorkerColumn::NumRejected, "Num Rejected", |c| {
}).column(StratumWorkerColumn::NumRejected, "Num Rejected", |c| {
c.width_percent(10)
})
.column(StratumWorkerColumn::NumStale, "Num Stale", |c| {
}).column(StratumWorkerColumn::NumStale, "Num Stale", |c| {
c.width_percent(10)
});
@@ -194,28 +188,22 @@ impl TUIStatusListener for TUIMiningView {
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_config_status")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_is_running_status")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_num_workers_status")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_block_height_status")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_network_difficulty_status")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_network_hashrate")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_cuckoo_size_status")),
);
@@ -225,26 +213,22 @@ impl TUIStatusListener for TUIMiningView {
.child(BoxView::with_full_screen(
Dialog::around(table_view.with_id(TABLE_MINING_STATUS).min_size((50, 20)))
.title("Mining Workers"),
))
.with_id("mining_device_view");
)).with_id("mining_device_view");
let diff_status_view = LinearLayout::new(Orientation::Vertical)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Tip Height: "))
.child(TextView::new("").with_id("diff_cur_height")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Difficulty Adjustment Window: "))
.child(TextView::new("").with_id("diff_adjust_window")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Average Block Time: "))
.child(TextView::new("").with_id("diff_avg_block_time")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Average Difficulty: "))
.child(TextView::new("").with_id("diff_avg_difficulty")),
@@ -253,11 +237,9 @@ impl TUIStatusListener for TUIMiningView {
let diff_table_view = TableView::<DiffBlock, DiffColumn>::new()
.column(DiffColumn::BlockNumber, "Block Number", |c| {
c.width_percent(25)
})
.column(DiffColumn::Difficulty, "Network Difficulty", |c| {
}).column(DiffColumn::Difficulty, "Network Difficulty", |c| {
c.width_percent(25)
})
.column(DiffColumn::Time, "Block Time", |c| c.width_percent(25))
}).column(DiffColumn::Time, "Block Time", |c| c.width_percent(25))
.column(DiffColumn::Duration, "Duration", |c| c.width_percent(25));
let mining_difficulty_view = LinearLayout::new(Orientation::Vertical)
@@ -268,8 +250,7 @@ impl TUIStatusListener for TUIMiningView {
.with_id(TABLE_MINING_DIFF_STATUS)
.min_size((50, 20)),
).title("Mining Difficulty Data"),
))
.with_id("mining_difficulty_view");
)).with_id("mining_difficulty_view");
let view_stack = StackView::new()
.layer(mining_difficulty_view)
+3 -6
View File
@@ -86,21 +86,18 @@ impl TUIStatusListener for TUIPeerView {
.column(PeerColumn::Direction, "Direction", |c| c.width_percent(20))
.column(PeerColumn::TotalDifficulty, "Total Difficulty", |c| {
c.width_percent(20)
})
.column(PeerColumn::Version, "Version", |c| c.width_percent(20));
}).column(PeerColumn::Version, "Version", |c| c.width_percent(20));
let peer_status_view = BoxView::with_full_screen(
LinearLayout::new(Orientation::Vertical)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Total Peers: "))
.child(TextView::new(" ").with_id("peers_total")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Longest Chain: "))
.child(TextView::new(" ").with_id("longest_work_peer")),
)
.child(TextView::new(" "))
).child(TextView::new(" "))
.child(
Dialog::around(table_view.with_id(TABLE_PEER_STATUS).min_size((50, 20)))
.title("Connected Peers"),
+7 -14
View File
@@ -37,35 +37,28 @@ impl TUIStatusListener for TUIStatusView {
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Current Status: "))
.child(TextView::new("Starting").with_id("basic_current_status")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Connected Peers: "))
.child(TextView::new("0").with_id("connected_peers")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Chain Height: "))
.child(TextView::new(" ").with_id("chain_height")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Total Difficulty: "))
.child(TextView::new(" ").with_id("basic_total_difficulty")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("------------------------")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("basic_mining_config_status")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("basic_mining_status")),
)
.child(
).child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("basic_network_info")),
), //.child(logo_view)