Skip to content

Commit

Permalink
2.1.x url fix (#237)
Browse files Browse the repository at this point in the history
* Fix URL Compatibility with 2.0.0 (#236)

* fix url scheme for consistency with 2.0.0

* rustfmt

* remove URL lib and go back to parsing strings for the dest url

* rustmft

* update version number
  • Loading branch information
yeastplume authored Oct 9, 2019
1 parent 0f2d8f8 commit dabdea9
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 79 deletions.
57 changes: 28 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_wallet"
version = "2.1.0-beta.3"
version = "2.1.0-beta.4"
authors = ["Grin Developers <mimblewimble@lists.launchpad.net>"]
description = "Simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format."
license = "Apache-2.0"
Expand Down Expand Up @@ -30,13 +30,13 @@ log = "0.4"
linefeed = "0.5"
semver = "0.9"

grin_wallet_api = { path = "./api", version = "2.1.0-beta.3" }
grin_wallet_impls = { path = "./impls", version = "2.1.0-beta.3" }
grin_wallet_libwallet = { path = "./libwallet", version = "2.1.0-beta.3" }
grin_wallet_controller = { path = "./controller", version = "2.1.0-beta.3" }
grin_wallet_config = { path = "./config", version = "2.1.0-beta.3" }
grin_wallet_api = { path = "./api", version = "2.1.0-beta.4" }
grin_wallet_impls = { path = "./impls", version = "2.1.0-beta.4" }
grin_wallet_libwallet = { path = "./libwallet", version = "2.1.0-beta.4" }
grin_wallet_controller = { path = "./controller", version = "2.1.0-beta.4" }
grin_wallet_config = { path = "./config", version = "2.1.0-beta.4" }

grin_wallet_util = { path = "./util", version = "2.1.0-beta.3" }
grin_wallet_util = { path = "./util", version = "2.1.0-beta.4" }

[build-dependencies]
built = "0.3"
Expand Down
10 changes: 5 additions & 5 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_wallet_api"
version = "2.1.0-beta.3"
version = "2.1.0-beta.4"
authors = ["Grin Developers <mimblewimble@lists.launchpad.net>"]
description = "Grin Wallet API"
license = "Apache-2.0"
Expand All @@ -23,10 +23,10 @@ chrono = { version = "0.4.4", features = ["serde"] }
ring = "0.13"
base64 = "0.9"

grin_wallet_libwallet = { path = "../libwallet", version = "2.1.0-beta.3" }
grin_wallet_config = { path = "../config", version = "2.1.0-beta.3" }
grin_wallet_impls = { path = "../impls", version = "2.1.0-beta.3" }
grin_wallet_util = { path = "../util", version = "2.1.0-beta.3" }
grin_wallet_libwallet = { path = "../libwallet", version = "2.1.0-beta.4" }
grin_wallet_config = { path = "../config", version = "2.1.0-beta.4" }
grin_wallet_impls = { path = "../impls", version = "2.1.0-beta.4" }
grin_wallet_util = { path = "../util", version = "2.1.0-beta.4" }

[dev-dependencies]
serde_json = "1"
Expand Down
4 changes: 2 additions & 2 deletions config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_wallet_config"
version = "2.1.0-beta.3"
version = "2.1.0-beta.4"
authors = ["Grin Developers <mimblewimble@lists.launchpad.net>"]
description = "Configuration for grin wallet , a simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format."
license = "Apache-2.0"
Expand All @@ -16,7 +16,7 @@ serde_derive = "1"
toml = "0.4"
dirs = "1.0.3"

grin_wallet_util = { path = "../util", version = "2.1.0-beta.3" }
grin_wallet_util = { path = "../util", version = "2.1.0-beta.4" }

[dev-dependencies]
pretty_assertions = "0.5.1"
12 changes: 6 additions & 6 deletions controller/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_wallet_controller"
version = "2.1.0-beta.3"
version = "2.1.0-beta.4"
authors = ["Grin Developers <mimblewimble@lists.launchpad.net>"]
description = "Controllers for grin wallet instantiation"
license = "Apache-2.0"
Expand Down Expand Up @@ -32,9 +32,9 @@ chrono = { version = "0.4.4", features = ["serde"] }
easy-jsonrpc-mw = "0.5.3"
lazy_static = "1"

grin_wallet_util = { path = "../util", version = "2.1.0-beta.3" }
grin_wallet_util = { path = "../util", version = "2.1.0-beta.4" }

grin_wallet_api = { path = "../api", version = "2.1.0-beta.3" }
grin_wallet_impls = { path = "../impls", version = "2.1.0-beta.3" }
grin_wallet_libwallet = { path = "../libwallet", version = "2.1.0-beta.3" }
grin_wallet_config = { path = "../config", version = "2.1.0-beta.3" }
grin_wallet_api = { path = "../api", version = "2.1.0-beta.4" }
grin_wallet_impls = { path = "../impls", version = "2.1.0-beta.4" }
grin_wallet_libwallet = { path = "../libwallet", version = "2.1.0-beta.4" }
grin_wallet_config = { path = "../config", version = "2.1.0-beta.4" }
9 changes: 4 additions & 5 deletions impls/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_wallet_impls"
version = "2.1.0-beta.3"
version = "2.1.0-beta.4"
authors = ["Grin Developers <mimblewimble@lists.launchpad.net>"]
description = "Concrete types derived from libwallet traits"
license = "Apache-2.0"
Expand All @@ -26,8 +26,7 @@ tokio-core = "0.1"
tokio-retry = "0.1"
uuid = { version = "0.7", features = ["serde", "v4"] }
chrono = { version = "0.4.4", features = ["serde"] }
url = "1.7.2"

grin_wallet_util = { path = "../util", version = "2.1.0-beta.3" }
grin_wallet_config = { path = "../config", version = "2.1.0-beta.3" }
grin_wallet_libwallet = { path = "../libwallet", version = "2.1.0-beta.3" }
grin_wallet_util = { path = "../util", version = "2.1.0-beta.4" }
grin_wallet_config = { path = "../config", version = "2.1.0-beta.4" }
grin_wallet_libwallet = { path = "../libwallet", version = "2.1.0-beta.4" }
33 changes: 18 additions & 15 deletions impls/src/adapters/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,26 @@ use crate::libwallet::{Error, ErrorKind, Slate};
use crate::SlateSender;
use serde::Serialize;
use serde_json::{json, Value};
use url::Url;

#[derive(Clone)]
pub struct HttpSlateSender {
base_url: Url,
base_url: String,
}

impl HttpSlateSender {
/// Create, return Err if scheme is not "http"
pub fn new(base_url: Url) -> Result<HttpSlateSender, SchemeNotHttp> {
if base_url.scheme() != "http" && base_url.scheme() != "https" {
pub fn new(base_url: &str) -> Result<HttpSlateSender, SchemeNotHttp> {
if !base_url.starts_with("http") && !base_url.starts_with("https") {
Err(SchemeNotHttp)
} else {
Ok(HttpSlateSender { base_url })
Ok(HttpSlateSender {
base_url: base_url.to_owned(),
})
}
}

/// Check version of the listening wallet
fn check_other_version(&self, url: &Url) -> Result<(), Error> {
fn check_other_version(&self, url: &str) -> Result<(), Error> {
let req = json!({
"jsonrpc": "2.0",
"method": "check_version",
Expand Down Expand Up @@ -95,13 +96,15 @@ impl HttpSlateSender {

impl SlateSender for HttpSlateSender {
fn send_tx(&self, slate: &Slate) -> Result<Slate, Error> {
let url: Url = self
.base_url
.join("/v2/foreign")
.expect("/v2/foreign is an invalid url path");
debug!("Posting transaction slate to {}", url);
let trailing = match self.base_url.ends_with('/') {
true => "",
false => "/",
};
let url_str = format!("{}{}v2/foreign", self.base_url, trailing);

self.check_other_version(&url)?;
debug!("Posting transaction slate to {}", url_str);

self.check_other_version(&url_str)?;

// Note: not using easy-jsonrpc as don't want the dependencies in this crate
let req = json!({
Expand All @@ -116,7 +119,7 @@ impl SlateSender for HttpSlateSender {
});
trace!("Sending receive_tx request: {}", req);

let res: String = post(&url, None, &req).map_err(|e| {
let res: String = post(&url_str, None, &req).map_err(|e| {
let report = format!("Posting transaction slate (is recipient listening?): {}", e);
error!("{}", report);
ErrorKind::ClientCallback(report)
Expand Down Expand Up @@ -152,12 +155,12 @@ impl Into<Error> for SchemeNotHttp {
}
}

pub fn post<IN>(url: &Url, api_secret: Option<String>, input: &IN) -> Result<String, api::Error>
pub fn post<IN>(url: &str, api_secret: Option<String>, input: &IN) -> Result<String, api::Error>
where
IN: Serialize,
{
// TODO: change create_post_request to accept a url instead of a &str
let req = api::client::create_post_request(url.as_str(), api_secret, input)?;
let req = api::client::create_post_request(url, api_secret, input)?;
let res = api::client::send_request(req)?;
Ok(res)
}
7 changes: 1 addition & 6 deletions impls/src/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,14 @@ pub trait SlateGetter {

/// select a SlateSender based on method and dest fields from, e.g., SendArgs
pub fn create_sender(method: &str, dest: &str) -> Result<Box<dyn SlateSender>, Error> {
use url::Url;

let invalid = || {
ErrorKind::WalletComms(format!(
"Invalid wallet comm type and destination. method: {}, dest: {}",
method, dest
))
};
Ok(match method {
"http" => {
let url: Url = dest.parse().map_err(|_| invalid())?;
Box::new(HttpSlateSender::new(url).map_err(|_| invalid())?)
}
"http" => Box::new(HttpSlateSender::new(dest).map_err(|_| invalid())?),
"keybase" => Box::new(KeybaseChannel::new(dest.to_owned())?),
"self" => {
return Err(ErrorKind::WalletComms(
Expand Down
6 changes: 3 additions & 3 deletions libwallet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_wallet_libwallet"
version = "2.1.0-beta.3"
version = "2.1.0-beta.4"
authors = ["Grin Developers <mimblewimble@lists.launchpad.net>"]
description = "Simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format."
license = "Apache-2.0"
Expand All @@ -25,5 +25,5 @@ lazy_static = "1"
strum = "0.15"
strum_macros = "0.15"

grin_wallet_util = { path = "../util", version = "2.1.0-beta.3" }
grin_wallet_config = { path = "../config", version = "2.1.0-beta.3" }
grin_wallet_util = { path = "../util", version = "2.1.0-beta.4" }
grin_wallet_config = { path = "../config", version = "2.1.0-beta.4" }
2 changes: 1 addition & 1 deletion util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_wallet_util"
version = "2.1.0-beta.3"
version = "2.1.0-beta.4"
authors = ["Grin Developers <mimblewimble@lists.launchpad.net>"]
description = "Util, for generic utilities and to re-export grin crates"
license = "Apache-2.0"
Expand Down

0 comments on commit dabdea9

Please sign in to comment.