Fix contact save

This commit is contained in:
Hanh 2022-11-27 11:48:22 +08:00
parent 6d56f8a9ef
commit 1f8b9fd7f6
4 changed files with 11 additions and 5 deletions

View File

@ -46,13 +46,16 @@ pub async fn build_tx_plan(
} else {
r.max_amount_per_note
};
while amount > 0 {
loop {
let a = min(amount, max_amount_per_note);
let memo_bytes: MemoBytes = r.memo.clone().into();
let order = Order::new(network, id_order, &r.address, a, memo_bytes);
orders.push(order);
amount -= a;
id_order += 1;
if amount == 0 {
break;
} // at least one note even when amount = 0
}
}
let utxos = fetch_utxos(coin, account, checkpoint_height, excluded_flags).await?;

View File

@ -20,7 +20,7 @@ pub struct RecipientShort {
pub amount: u64,
}
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct RecipientMemo {
pub address: String,
pub amount: u64,

View File

@ -298,7 +298,6 @@ pub fn build_tx_plan<F: FeeCalculator>(
) -> Result<TransactionPlan> {
let mut fee = 0;
println!("build_tx_plan");
for _ in 0..MAX_ATTEMPTS {
let balances = sum_utxos(utxos)?;
let (groups, amounts) = group_orders(&orders, fee)?;

View File

@ -173,10 +173,11 @@ pub fn decode_transaction(
}
}
}
contacts = contact_decoder.finalize()?;
contacts.extend(contact_decoder.finalize()?.into_iter());
}
if let Some(orchard_bundle) = tx.orchard_bundle() {
let mut contact_decoder = ContactDecoder::new(orchard_bundle.actions().len());
if let Some((orchard_ivk, orchard_ovk)) = decryption_keys.orchard_keys.clone() {
for action in orchard_bundle.actions().iter() {
let domain = OrchardDomain::for_action(action);
@ -197,7 +198,9 @@ pub fn decode_transaction(
action.cv_net(),
&action.encrypted_note().out_ciphertext,
) {
let memo = Memo::try_from(MemoBytes::from_bytes(&memo)?)?;
let memo_bytes = MemoBytes::from_bytes(&memo)?;
let _ = contact_decoder.add_memo(&memo_bytes); // ignore memo that is not for contacts, if we cannot decode it with ovk, we didn't make create this memo
let memo = Memo::try_from(memo_bytes)?;
oaddress = Some(orchard_as_unified(network, &pa).encode());
if memo != Memo::Empty {
tx_memo = memo;
@ -205,6 +208,7 @@ pub fn decode_transaction(
}
}
}
contacts.extend(&mut contact_decoder.finalize()?.into_iter());
}
let address = zaddress.or(oaddress).or(taddress).unwrap_or(String::new());