Bug fix - check max memo length

This commit is contained in:
Hanh 2022-12-06 19:01:05 +08:00
parent f55fc98ae0
commit 695a2106fa
3 changed files with 13 additions and 37 deletions

View File

@ -29,18 +29,18 @@ pub struct RecipientMemo {
}
impl RecipientMemo {
pub fn from_recipient(from: &str, r: &Recipient) -> Self {
pub fn from_recipient(from: &str, r: &Recipient) -> anyhow::Result<Self> {
let memo = if !r.reply_to && r.subject.is_empty() {
r.memo.clone()
} else {
encode_memo(from, r.reply_to, &r.subject, &r.memo)
};
RecipientMemo {
Ok(RecipientMemo {
address: r.address.clone(),
amount: r.amount,
memo: Memo::from_str(&memo).unwrap(),
memo: Memo::from_str(&memo)?,
max_amount_per_note: r.max_amount_per_note,
}
})
}
}
@ -107,9 +107,9 @@ pub fn parse_recipients(recipients: &str) -> anyhow::Result<Vec<RecipientMemo>>
let c = CoinConfig::get_active();
let AccountData { address, .. } = c.db()?.get_account_info(c.id_account)?;
let recipients: Vec<Recipient> = serde_json::from_str(recipients)?;
let recipient_memos: Vec<_> = recipients
let recipient_memos: anyhow::Result<Vec<_>> = recipients
.iter()
.map(|r| RecipientMemo::from_recipient(&address, r))
.collect();
Ok(recipient_memos)
recipient_memos
}

View File

@ -15,7 +15,7 @@ use thiserror::Error;
use warp_api_ffi::api::payment_uri::PaymentURI;
use warp_api_ffi::api::recipient::{Recipient, RecipientMemo, RecipientShort};
use warp_api_ffi::{
build_tx, get_secret_keys, AccountData, AccountInfo, AccountRec, CoinConfig, KeyPack,
build_tx, get_secret_keys, AccountData, AccountRec, CoinConfig, KeyPack,
RaptorQDrops, TransactionPlan, TxRec,
};
@ -104,7 +104,6 @@ async fn main() -> anyhow::Result<()> {
split_data,
merge_data,
derive_keys,
instant_sync,
get_tx_plan,
build_from_plan,
],
@ -191,9 +190,7 @@ pub fn get_unified_address(t: u8, s: u8, o: u8) -> Result<String, Error> {
let address = warp_api_ffi::api::account::get_unified_address(
c.coin,
c.id_account,
t != 0,
s != 0,
o != 0,
t & s << 1 & o << 2,
)?;
Ok(address)
}
@ -242,7 +239,7 @@ pub async fn create_offline_tx(payment: Json<Payment>) -> Result<Json<Transactio
let AccountData { address, .. } = db.get_account_info(c.id_account)?;
address
};
let recipients: Vec<_> = payment
let recipients: anyhow::Result<Vec<_>> = payment
.recipients
.iter()
.map(|p| RecipientMemo::from_recipient(&from, p))
@ -251,7 +248,7 @@ pub async fn create_offline_tx(payment: Json<Payment>) -> Result<Json<Transactio
c.coin,
c.id_account,
latest,
&recipients,
&recipients?,
0,
payment.confirmations,
)
@ -285,7 +282,7 @@ pub async fn pay(payment: Json<Payment>, config: &State<Config>) -> Result<Strin
let AccountData { address, .. } = db.get_account_info(c.id_account)?;
address
};
let recipients: Vec<_> = payment
let recipients: anyhow::Result<Vec<_>> = payment
.recipients
.iter()
.map(|p| RecipientMemo::from_recipient(&from, p))
@ -294,7 +291,7 @@ pub async fn pay(payment: Json<Payment>, config: &State<Config>) -> Result<Strin
c.coin,
c.id_account,
latest,
&recipients,
&recipients?,
0,
payment.confirmations,
)
@ -413,27 +410,6 @@ pub fn derive_keys(
Ok(Json(result))
}
#[post("/instant_sync")]
pub async fn instant_sync() -> Result<(), Error> {
let c = CoinConfig::get_active();
let fvk = {
let db = c.db()?;
let AccountData { fvk, .. } = db.get_account_info(c.id_account)?;
fvk
};
let client = reqwest::Client::new();
let response = client
.post(format!("https://zec.hanh00.fun/api/scan_fvk?fvk={}", fvk))
.send()
.await?;
// let r = response.text().await?;
// println!("{}", r);
let account_info: AccountInfo = response.json().await?;
let mut db = c.db().unwrap();
db.import_from_syncdata(&account_info)?;
Ok(())
}
#[derive(Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct Config {

View File

@ -728,7 +728,7 @@ fn test_tx_plan() {
&Network::MainNetwork,
"",
0,
None,
&None,
&utxos,
&orders,
&TransactionBuilderConfig {