Interpret hex memos properly.

Fixes #38
This commit is contained in:
Aditya Kulkarni
2020-07-28 09:52:53 -07:00
parent 5675f5b359
commit 22bde5a404
4 changed files with 55 additions and 19 deletions

View File

@@ -2066,22 +2066,12 @@ impl LightWallet {
Some(s) => {
// If the string starts with an "0x", and contains only hex chars ([a-f0-9]+) then
// interpret it as a hex
let s_bytes = if s.to_lowercase().starts_with("0x") {
match hex::decode(&s[2..s.len()]) {
Ok(data) => data,
Err(_) => Vec::from(s.as_bytes())
}
} else {
Vec::from(s.as_bytes())
};
match Memo::from_bytes(&s_bytes) {
None => {
let e = format!("Error creating output. Memo {:?} is too long", s);
match utils::interpret_memo_string(&s) {
Ok(m) => Some(m),
Err(e) => {
error!("{}", e);
return Err(e);
},
Some(m) => Some(m)
}
}
}
};
@@ -2154,10 +2144,16 @@ impl LightWallet {
None => Memo::default(),
Some(s) => {
// If the address is not a z-address, then drop the memo
if LightWallet::is_shielded_address(&addr.to_string(), &self.config) {
Memo::from_bytes(s.as_bytes()).unwrap()
} else {
if !LightWallet::is_shielded_address(&addr.to_string(), &self.config) {
Memo::default()
} else {
match utils::interpret_memo_string(s) {
Ok(m) => m,
Err(e) => {
error!("{}", e);
Memo::default()
}
}
}
}
},