mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
Web wallet api updates (#1155)
* CORS for webwallet * rustfmt * automatically start up wallet web api (owner) listener
This commit is contained in:
parent
973d46e6aa
commit
05073c5c02
5 changed files with 38 additions and 5 deletions
|
@ -75,7 +75,7 @@ impl From<io::Error> for ConfigError {
|
|||
/// as they tend to be quite nested in the code
|
||||
/// Most structs optional, as they may or may not
|
||||
/// be needed depending on what's being run
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct GlobalConfig {
|
||||
/// Keep track of the file we've read
|
||||
pub config_file_path: Option<PathBuf>,
|
||||
|
@ -91,7 +91,7 @@ pub struct GlobalConfig {
|
|||
/// level GlobalConfigContainer options might want to keep
|
||||
/// internal state that we don't necessarily
|
||||
/// want serialised or deserialised
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct ConfigMembers {
|
||||
/// Server config
|
||||
#[serde(default)]
|
||||
|
|
|
@ -65,6 +65,9 @@ run_tui = true
|
|||
#Whether to run the wallet listener with the server by default
|
||||
run_wallet_listener = true
|
||||
|
||||
# Whether to run the web-wallet API (will only run on localhost)
|
||||
run_wallet_owner_api = true
|
||||
|
||||
#Whether to run a test miner. This is only for developer testing (chaintype
|
||||
#usertesting) at cuckoo 16, and will only mine into the default wallet port.
|
||||
#real mining should use the standalone grin-miner
|
||||
|
|
|
@ -182,6 +182,9 @@ pub struct ServerConfig {
|
|||
/// Whether to run the wallet listener with the server by default
|
||||
pub run_wallet_listener: Option<bool>,
|
||||
|
||||
/// Whether to run the web wallet owner listener
|
||||
pub run_wallet_owner_api: Option<bool>,
|
||||
|
||||
/// Whether to run the test miner (internal, cuckoo 16)
|
||||
pub run_test_miner: Option<bool>,
|
||||
|
||||
|
@ -207,6 +210,7 @@ impl Default for ServerConfig {
|
|||
skip_sync_wait: None,
|
||||
run_tui: None,
|
||||
run_wallet_listener: Some(false),
|
||||
run_wallet_owner_api: Some(false),
|
||||
run_test_miner: Some(false),
|
||||
test_miner_wallet_url: None,
|
||||
}
|
||||
|
|
|
@ -371,7 +371,7 @@ fn server_command(server_args: Option<&ArgMatches>, mut global_config: GlobalCon
|
|||
info!(
|
||||
LOGGER,
|
||||
"Starting the Grin server from configuration file at {}",
|
||||
global_config.config_file_path.unwrap().to_str().unwrap()
|
||||
global_config.config_file_path.as_ref().unwrap().to_str().unwrap()
|
||||
);
|
||||
global::set_mining_mode(
|
||||
global_config
|
||||
|
@ -414,7 +414,7 @@ fn server_command(server_args: Option<&ArgMatches>, mut global_config: GlobalCon
|
|||
}
|
||||
|
||||
if let Some(true) = server_config.run_wallet_listener {
|
||||
let mut wallet_config = global_config.members.unwrap().wallet;
|
||||
let mut wallet_config = global_config.members.as_ref().unwrap().wallet.clone();
|
||||
if let Err(_) = wallet::WalletSeed::from_file(&wallet_config) {
|
||||
wallet::WalletSeed::init_file(&wallet_config)
|
||||
.expect("Failed to create wallet seed file.");
|
||||
|
@ -436,6 +436,27 @@ fn server_command(server_args: Option<&ArgMatches>, mut global_config: GlobalCon
|
|||
});
|
||||
});
|
||||
}
|
||||
if let Some(true) = server_config.run_wallet_owner_api {
|
||||
let mut wallet_config = global_config.members.unwrap().wallet;
|
||||
if let Err(_) = wallet::WalletSeed::from_file(&wallet_config) {
|
||||
wallet::WalletSeed::init_file(&wallet_config)
|
||||
.expect("Failed to create wallet seed file.");
|
||||
};
|
||||
|
||||
let _ = thread::Builder::new()
|
||||
.name("wallet_owner_listener".to_string())
|
||||
.spawn(move || {
|
||||
let wallet = FileWallet::new(wallet_config.clone(), "").unwrap_or_else(|e| {
|
||||
panic!("Error creating wallet: {:?} Config: {:?}", e, wallet_config)
|
||||
});
|
||||
wallet::controller::owner_listener(wallet, "127.0.0.1:13420").unwrap_or_else(|e| {
|
||||
panic!(
|
||||
"Error creating wallet api listener: {:?} Config: {:?}",
|
||||
e, wallet_config
|
||||
)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// start the server in the different run modes (interactive or daemon)
|
||||
if let Some(a) = server_args {
|
||||
|
|
|
@ -202,7 +202,12 @@ where
|
|||
IronError::new(Fail::compat(e), status::BadRequest)
|
||||
})?;
|
||||
let mut api = APIOwner::new(&mut *wallet);
|
||||
let resp_json = self.handle_request(req, &mut api);
|
||||
let mut resp_json = self.handle_request(req, &mut api);
|
||||
resp_json
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.headers
|
||||
.set_raw("access-control-allow-origin", vec![b"*".to_vec()]);
|
||||
api.wallet
|
||||
.close()
|
||||
.map_err(|e| IronError::new(Fail::compat(e), status::BadRequest))?;
|
||||
|
|
Loading…
Reference in a new issue