mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-27 10:58:37 +01:00
Wrong Slatepack address fix (#773)
This commit is contained in:
+2
-1
@@ -24,6 +24,7 @@ use crate::libwallet::{
|
||||
use crate::try_slatepack_sync_workflow;
|
||||
use crate::util::secp::key::SecretKey;
|
||||
use crate::util::Mutex;
|
||||
use libwallet::SlatepackAddress;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -343,7 +344,7 @@ where
|
||||
&self,
|
||||
slate: &Slate,
|
||||
dest_acct_name: Option<&str>,
|
||||
r_addr: Option<String>,
|
||||
r_addr: Option<SlatepackAddress>,
|
||||
) -> Result<Slate, Error> {
|
||||
let mut w_lock = self.wallet_inst.lock();
|
||||
let tor_config = r_addr
|
||||
|
||||
@@ -22,6 +22,7 @@ use crate::libwallet::{
|
||||
use crate::{Foreign, ForeignCheckMiddlewareFn};
|
||||
use easy_jsonrpc_mw;
|
||||
use grin_wallet_config::initial_setup_wallet;
|
||||
use libwallet::SlatepackAddress;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Public definition used to generate Foreign jsonrpc api.
|
||||
@@ -311,6 +312,16 @@ where
|
||||
) -> Result<VersionedSlate, Error> {
|
||||
let version = in_slate.version();
|
||||
let slate_from = Slate::from(in_slate);
|
||||
let dest = match dest {
|
||||
None => None,
|
||||
Some(a) => match SlatepackAddress::try_from(a.as_str()) {
|
||||
Ok(d) => Some(d),
|
||||
Err(_) => {
|
||||
error!("Error parsing Slatepack address: {}", a);
|
||||
None
|
||||
}
|
||||
},
|
||||
};
|
||||
let out_slate = Foreign::receive_tx(
|
||||
self,
|
||||
&slate_from,
|
||||
|
||||
+44
-44
@@ -703,6 +703,12 @@ where
|
||||
args: InitTxArgs,
|
||||
) -> Result<Slate, Error> {
|
||||
let send_args = args.send_args.clone();
|
||||
let dest = match send_args.as_ref() {
|
||||
Some(args) if !args.dest.is_empty() => {
|
||||
Some(SlatepackAddress::try_from(args.dest.as_str())?)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let (slate, tor_config) = {
|
||||
let mut w_lock = self.wallet_inst.lock();
|
||||
let tor_config = send_args
|
||||
@@ -721,10 +727,11 @@ where
|
||||
Error::TorConfig("Tor config was not loaded with send arguments".into())
|
||||
})?;
|
||||
let can_send = tc.send_tor(sa.skip_tor);
|
||||
if self.doctest_mode || !can_send {
|
||||
if self.doctest_mode || !can_send || dest.is_none() {
|
||||
return Ok(slate);
|
||||
}
|
||||
let res = try_slatepack_sync_workflow(&slate, &sa.dest, Some(tc), None, false);
|
||||
let res =
|
||||
try_slatepack_sync_workflow(&slate, &dest.unwrap(), Some(tc), None, false);
|
||||
match res {
|
||||
Ok(s) => {
|
||||
self.tx_lock_outputs(keychain_mask, &s)?;
|
||||
@@ -868,6 +875,12 @@ where
|
||||
args: InitTxArgs,
|
||||
) -> Result<Slate, Error> {
|
||||
let send_args = args.send_args.clone();
|
||||
let dest = match send_args.as_ref() {
|
||||
Some(args) if !args.dest.is_empty() => {
|
||||
Some(SlatepackAddress::try_from(args.dest.as_str())?)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let (slate, tor_config) = {
|
||||
let mut w_lock = self.wallet_inst.lock();
|
||||
let tor_config = send_args
|
||||
@@ -886,10 +899,11 @@ where
|
||||
Error::TorConfig("Tor config was not loaded with send arguments".into())
|
||||
})?;
|
||||
let can_send = tc.send_tor(sa.skip_tor);
|
||||
if self.doctest_mode || !can_send {
|
||||
if self.doctest_mode || !can_send || dest.is_none() {
|
||||
return Ok(slate);
|
||||
}
|
||||
let res = try_slatepack_sync_workflow(&slate, &sa.dest, Some(tc), None, true);
|
||||
let dest = dest.unwrap();
|
||||
let res = try_slatepack_sync_workflow(&slate, &dest, Some(tc), None, true);
|
||||
match res {
|
||||
Ok(s) => {
|
||||
// Update slate state.
|
||||
@@ -903,7 +917,7 @@ where
|
||||
}
|
||||
}
|
||||
// Output slatepack message to file.
|
||||
match output_slatepack_file(&self, keychain_mask, &s, &sa.dest) {
|
||||
match output_slatepack_file(&self, keychain_mask, &s, Some(dest)) {
|
||||
Ok(_) => {}
|
||||
Err(e) => error!("Error on saving output slatepack message: {}", e),
|
||||
}
|
||||
@@ -2563,7 +2577,7 @@ where
|
||||
/// attempt to send slate synchronously with TOR
|
||||
pub fn try_slatepack_sync_workflow(
|
||||
slate: &Slate,
|
||||
dest: &str,
|
||||
dest: &SlatepackAddress,
|
||||
tor_config: Option<TorConfig>,
|
||||
tor_sender: Option<TorSlateSender>,
|
||||
send_to_finalize: bool,
|
||||
@@ -2585,42 +2599,32 @@ pub fn try_slatepack_sync_workflow(
|
||||
};
|
||||
};
|
||||
|
||||
// Try parsing Slatepack address.
|
||||
match SlatepackAddress::try_from(dest) {
|
||||
Ok(address) => {
|
||||
let tor_addr = OnionV3Address::try_from(&address).map_err(|_| {
|
||||
Error::SlatepackAddress(format!(
|
||||
"Destination {} is not a valid Onion address.",
|
||||
dest
|
||||
))
|
||||
})?;
|
||||
// Try sending to the destination via Tor.
|
||||
let sender = match tor_sender {
|
||||
None => {
|
||||
if let Some(tc) = tor_config {
|
||||
match TorSlateSender::new(&tor_addr.to_http_str(), tc) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
debug!("Send (Tor): Cannot create TOR Slate sender {:?}", e);
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(Error::TorConfig("Tor config is not set".to_string()));
|
||||
let tor_addr = OnionV3Address::try_from(dest).map_err(|_| {
|
||||
Error::SlatepackAddress(format!(
|
||||
"Destination {} is not a valid Onion address.",
|
||||
dest
|
||||
))
|
||||
})?;
|
||||
let sender = match tor_sender {
|
||||
None => {
|
||||
if let Some(tc) = tor_config {
|
||||
match TorSlateSender::new(&tor_addr.to_http_str(), tc) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
debug!("Send (Tor): Cannot create TOR Slate sender {:?}", e);
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
Some(s) => s,
|
||||
};
|
||||
warn!("Attempting to send transaction via Tor");
|
||||
match send_sync(sender, "Tor") {
|
||||
Ok(_) => Ok(ret_slate),
|
||||
Err(e) => Err(e),
|
||||
} else {
|
||||
return Err(Error::TorConfig("Tor config is not set".to_string()));
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Destination {} is not a valid Slatepack address.", dest);
|
||||
Err(e)
|
||||
}
|
||||
Some(s) => s,
|
||||
};
|
||||
warn!("Attempting to send transaction via Tor");
|
||||
match send_sync(sender, "Tor") {
|
||||
Ok(_) => Ok(ret_slate),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2699,19 +2703,15 @@ fn output_slatepack_file<L, C, K>(
|
||||
api: &Owner<L, C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
slate: &Slate,
|
||||
dest: &str,
|
||||
dest: Option<SlatepackAddress>,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K> + 'static,
|
||||
C: NodeClient + 'static,
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
let address = match SlatepackAddress::try_from(dest) {
|
||||
Ok(a) => Some(a),
|
||||
Err(_) => None,
|
||||
};
|
||||
// encrypt for recipient by default
|
||||
let recipients = match address.clone() {
|
||||
let recipients = match dest {
|
||||
Some(a) => vec![a],
|
||||
None => vec![],
|
||||
};
|
||||
|
||||
@@ -1721,7 +1721,7 @@ pub trait OwnerRpc {
|
||||
"params": {
|
||||
"token": "d202964900000000d302964900000000d402964900000000d502964900000000",
|
||||
"secret_indices": [0],
|
||||
"message": "BEGINSLATEPACK. 8GQrdcwdLKJD28F 3a9siP7ZhZgAh7w BR2EiZHza5WMWmZ Cc8zBUemrrYRjhq j3VBwA8vYnvXXKU BDmQBN2yKgmR8mX UzvXHezfznA61d7 qFZYChhz94vd8Ew NEPLz7jmcVN2C3w wrfHbeiLubYozP2 uhLouFiYRrbe3fQ 4uhWGfT3sQYXScT dAeo29EaZJpfauh j8VL5jsxST2SPHq nzXFC2w9yYVjt7D ju7GSgHEp5aHz9R xstGbHjbsb4JQod kYLuELta1ohUwDD pvjhyJmsbLcsPei k5AQhZsJ8RJGBtY bou6cU7tZeFJvor 4LB9CBfFB3pmVWD vSLd5RPS75dcnHP nbXD8mSDZ8hJS2Q A9wgvppWzuWztJ2 dLUU8f9tLJgsRBw YZAs71HiVeg7. ENDSLATEPACK."
|
||||
"message": "BEGINSLATEPACK. t9EcGgrKr1GFCQB SK2jPCxME6Hgpqx bntpQm3zKFycoPY nW4UeoL4KQ7ExNK At6EQsvpz6MjUs8 6WG8KHEbMfqufJQ ZJTw2gkcdJmJjiJ f29oGgYqqXDZox4 ujPSjrtoxCN4h3e i1sZ8dYsm3dPeXL 7VQLsYNjAefciqj ZJXPm4Pqd7VDdd4 okGBGBu3YJvYzT6 arAxeCEx66us31h AJLcDweFwyWBkW5 J1DLiYAjt5ftFTo CjpfW9KjiLq2LM5 jepXWEHJPSDAYVK 4macDZUhRbJiG6E hrQcPrJBVC716mb Hw5E1PFrE6on5wq oEmrS4j9vaB5nw8 Z9ZyXvPc2LN7tER yt6pSHZeY9EpYdY zv4bthzfRfF8ePT TMeMpV2gpgyRXQa CPD2TR. ENDSLATEPACK."
|
||||
},
|
||||
"id": 1
|
||||
}
|
||||
@@ -1865,9 +1865,9 @@ pub trait OwnerRpc {
|
||||
"proof": {
|
||||
"amount": "60000000000",
|
||||
"excess": "09eac5f5872fa5e08e0c29fd900f1b8f77ff3ad1d0d1c46aeb202cbf92363fe0af",
|
||||
"recipient_address": "slatepack10qlk22rxjap2ny8qltc2tl996kenxr3hhwuu6hrzs6tdq08yaqgqnlumr7",
|
||||
"recipient_address": "tgrin10qlk22rxjap2ny8qltc2tl996kenxr3hhwuu6hrzs6tdq08yaqgqq6t83r",
|
||||
"recipient_sig": "02868f2d2b983981f8f98043701687a8531ed2de564ea3df48e9e7e0229ccbe8359efe506896df2efbe3528e977252c50e4a41ca3cc9896e7c5a30bbb1d33604",
|
||||
"sender_address": "slatepack1xtxavwfgs48ckf3gk8wwgcndmn0nt4tvkl8a7ltyejjcy2mc6nfskdvkdu",
|
||||
"sender_address": "tgrin1xtxavwfgs48ckf3gk8wwgcndmn0nt4tvkl8a7ltyejjcy2mc6nfs9gm2lp",
|
||||
"sender_sig": "c511764f3f61ed3d1cbca9514df8bc6811fad5662b1cb0e0587b9c9e49db9f33183cce71af6cb24b507fabf525a2bc405c6e84e63a60334edff0b451ae5e6102"
|
||||
}
|
||||
},
|
||||
@@ -2628,7 +2628,8 @@ pub fn run_doctest_owner(
|
||||
true => {
|
||||
let address = "783f6528669742a990e0faf0a5fca5d5b3330e37bbb9cd5c628696d03ce4e810";
|
||||
let address = OnionV3Address::try_from(address).unwrap();
|
||||
Some(SlatepackAddress::try_from(address).unwrap())
|
||||
let sp = SlatepackAddress::try_from(address).unwrap();
|
||||
Some(sp)
|
||||
}
|
||||
false => None,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user