mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 07:11:36 +02:00
Slate compatibility between versions (#35)
* wallet compatibilities * rustfmt
This commit is contained in:
@@ -15,9 +15,11 @@
|
||||
/// HTTP Wallet 'plugin' implementation
|
||||
use crate::api;
|
||||
use crate::libwallet::slate::Slate;
|
||||
use crate::libwallet::slate_versions::{v0, v1};
|
||||
use crate::libwallet::{Error, ErrorKind};
|
||||
use crate::WalletCommAdapter;
|
||||
use config::WalletConfig;
|
||||
use failure::ResultExt;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -47,15 +49,64 @@ impl WalletCommAdapter for HTTPWalletCommAdapter {
|
||||
let url = format!("{}/v1/wallet/foreign/receive_tx", dest);
|
||||
debug!("Posting transaction slate to {}", url);
|
||||
let slate = slate.serialize_to_version(Some(slate.version_info.orig_version))?;
|
||||
let res: Result<String, _> = api::client::post(url.as_str(), None, &slate);
|
||||
match res {
|
||||
Err(e) => {
|
||||
let report = format!("Posting transaction slate (is recipient listening?): {}", e);
|
||||
error!("{}", report);
|
||||
Err(ErrorKind::ClientCallback(report).into())
|
||||
// For compatibility with older clients
|
||||
let res: Slate = {
|
||||
if let None = slate.find("version_info") {
|
||||
let version = Slate::parse_slate_version(&slate)?;
|
||||
match version {
|
||||
1 => {
|
||||
let ver1: v1::SlateV1 =
|
||||
serde_json::from_str(&slate).context(ErrorKind::SlateDeser)?;
|
||||
let r: Result<v1::SlateV1, _> =
|
||||
api::client::post(url.as_str(), None, &ver1);
|
||||
match r {
|
||||
Err(e) => {
|
||||
let report = format!(
|
||||
"Posting transaction slate (is recipient listening?): {}",
|
||||
e
|
||||
);
|
||||
error!("{}", report);
|
||||
return Err(ErrorKind::ClientCallback(report).into());
|
||||
}
|
||||
Ok(s) => Slate::deserialize_upgrade(
|
||||
&serde_json::to_string(&s).context(ErrorKind::SlateDeser)?,
|
||||
)?,
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let ver0: v0::SlateV0 =
|
||||
serde_json::from_str(&slate).context(ErrorKind::SlateDeser)?;
|
||||
let r: Result<v0::SlateV0, _> =
|
||||
api::client::post(url.as_str(), None, &ver0);
|
||||
match r {
|
||||
Err(e) => {
|
||||
let report = format!(
|
||||
"Posting transaction slate (is recipient listening?): {}",
|
||||
e
|
||||
);
|
||||
error!("{}", report);
|
||||
return Err(ErrorKind::ClientCallback(report).into());
|
||||
}
|
||||
Ok(s) => Slate::deserialize_upgrade(
|
||||
&serde_json::to_string(&s).context(ErrorKind::SlateDeser)?,
|
||||
)?,
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let res: Result<String, _> = api::client::post(url.as_str(), None, &slate);
|
||||
match res {
|
||||
Err(e) => {
|
||||
let report =
|
||||
format!("Posting transaction slate (is recipient listening?): {}", e);
|
||||
error!("{}", report);
|
||||
return Err(ErrorKind::ClientCallback(report).into());
|
||||
}
|
||||
Ok(r) => Slate::deserialize_upgrade(&r)?,
|
||||
}
|
||||
}
|
||||
Ok(r) => Ok(Slate::deserialize_upgrade(&r)?),
|
||||
}
|
||||
};
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
fn send_tx_async(&self, _dest: &str, _slate: &Slate) -> Result<(), Error> {
|
||||
|
||||
Reference in New Issue
Block a user