This commit is contained in:
Hanh 2022-11-13 17:00:21 +08:00
parent 6e95f609ea
commit 56b70bcceb
9 changed files with 66 additions and 64 deletions

View File

@ -86,12 +86,6 @@ struct CResult_____c_char new_diversified_address(void);
struct CResult_u32 get_latest_height(void);
struct CResult_____c_char send_multi_payment(uint8_t coin,
uint32_t account,
char *recipients_json,
uint32_t anchor_offset,
int64_t port);
void skip_to_last_height(uint8_t coin);
struct CResult_u32 rewind_to(uint32_t height);

View File

@ -1,6 +1,6 @@
//! Contact Address book
use crate::api::payment_v2::build_sign_send_multi_payment;
use crate::api::payment_v2::{build_tx_plan, sign_and_broadcast};
use crate::api::recipient::RecipientMemo;
use crate::api::sync::get_latest_height;
use crate::coinconfig::CoinConfig;
@ -50,14 +50,14 @@ async fn save_contacts_tx(memos: &[Memo], anchor_offset: u32) -> anyhow::Result<
})
.collect();
let tx_id = build_sign_send_multi_payment(
let tx_plan = build_tx_plan(
c.coin,
c.id_account,
last_height,
&recipients,
anchor_offset,
Box::new(|_| {}),
)
.await?;
let tx_id = sign_and_broadcast(c.coin, c.id_account, &tx_plan).await?;
Ok(tx_id)
}

View File

@ -99,7 +99,7 @@ pub struct CResult<T> {
pub unsafe extern "C" fn init_wallet(db_path: *mut c_char) {
try_init_logger();
from_c_str!(db_path);
let _ = init_coin(0, &format!("{}/zec.db", &db_path));
let _ = init_coin(0, &format!("{}/zec-test.db", &db_path));
let _ = init_coin(1, &format!("{}/yec.db", &db_path));
let _ = init_coin(2, &format!("{}/arrr.db", &db_path));
}
@ -295,34 +295,34 @@ fn report_progress(progress: Progress, port: i64) {
}
}
#[tokio::main]
#[no_mangle]
pub async unsafe extern "C" fn send_multi_payment(
coin: u8,
account: u32,
recipients_json: *mut c_char,
anchor_offset: u32,
port: i64,
) -> CResult<*mut c_char> {
from_c_str!(recipients_json);
let res = async move {
let height = crate::api::sync::get_latest_height().await?;
let recipients = crate::api::recipient::parse_recipients(&recipients_json)?;
let res = crate::api::payment_v2::build_sign_send_multi_payment(
coin,
account,
height,
&recipients,
anchor_offset,
Box::new(move |progress| {
report_progress(progress, port);
}),
)
.await?;
Ok(res)
};
to_cresult_str(res.await)
}
// #[tokio::main]
// #[no_mangle]
// pub async unsafe extern "C" fn send_multi_payment(
// coin: u8,
// account: u32,
// recipients_json: *mut c_char,
// anchor_offset: u32,
// port: i64,
// ) -> CResult<*mut c_char> {
// from_c_str!(recipients_json);
// let res = async move {
// let height = crate::api::sync::get_latest_height().await?;
// let recipients = crate::api::recipient::parse_recipients(&recipients_json)?;
// let res = crate::api::payment_v2::build_sign_send_multi_payment(
// coin,
// account,
// height,
// &recipients,
// anchor_offset,
// Box::new(move |progress| {
// report_progress(progress, port);
// }),
// )
// .await?;
// Ok(res)
// };
// to_cresult_str(res.await)
// }
#[tokio::main]
#[no_mangle]

View File

@ -87,20 +87,15 @@ pub async fn sign_and_broadcast(
) -> anyhow::Result<String> {
let tx = sign_plan(coin, account, tx_plan)?;
let txid = broadcast_tx(&tx).await?;
let id_notes: Vec<_> = tx_plan
.spends
.iter()
.filter_map(|n| if n.id != 0 { Some(n.id) } else { None })
.collect();
mark_spent(coin, &id_notes)?;
Ok(txid)
}
pub async fn build_sign_send_multi_payment(
coin: u8,
account: u32,
last_height: u32,
recipients: &[RecipientMemo],
confirmations: u32,
progress_callback: PaymentProgressCallback,
) -> anyhow::Result<String> {
todo!()
}
/// Make a transaction that shields the transparent balance
pub async fn shield_taddr(coin: u8, account: u32) -> anyhow::Result<String> {
// let last_height = get_latest_height().await?;
@ -108,3 +103,10 @@ pub async fn shield_taddr(coin: u8, account: u32) -> anyhow::Result<String> {
// Ok(tx_id)
todo!()
}
fn mark_spent(coin: u8, ids: &[u32]) -> anyhow::Result<()> {
let c = CoinConfig::get(coin);
let mut db = c.db()?;
db.tx_mark_spend(ids)?;
Ok(())
}

View File

@ -577,6 +577,7 @@ impl DbAdapter {
witness,
};
Ok(UTXO {
id: id_note,
source,
amount: amount as u64,
})
@ -606,6 +607,7 @@ impl DbAdapter {
witness,
};
Ok(UTXO {
id: id_note,
source,
amount: amount as u64,
})

View File

@ -4,7 +4,7 @@ pub use crate::note_selection::types::{
};
pub use crate::note_selection::TransactionBuilderError::TxTooComplex;
pub use builder::{build_tx, get_secret_keys, TxBuilderContext};
pub use fee::{FeeCalculator, FeeZIP327};
pub use fee::{FeeCalculator, FeeFlat, FeeZIP327};
pub use optimize::build_tx_plan;
use std::str::FromStr;
pub use utxo::fetch_utxos;

View File

@ -94,6 +94,7 @@ pub struct PoolAllocation(pub [u64; 3]);
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct UTXO {
pub id: u32,
pub source: Source,
pub amount: u64,
}

View File

@ -39,6 +39,7 @@ async fn get_transparent_utxos(coin: u8, account: u32) -> anyhow::Result<Vec<UTX
index: utxo.index as u32,
};
UTXO {
id: 0,
source,
amount: utxo.value_zat as u64,
}

View File

@ -160,20 +160,22 @@ pub async fn sync_async<'a>(
progress.trial_decryptions += synchronizer.process(&blocks.0)? as u64;
}
// Orchard
log::info!("Orchard");
{
let decrypter = OrchardDecrypter::new(network);
let warper = WarpProcessor::new(OrchardHasher::new());
let mut synchronizer = OrchardSynchronizer::new(
decrypter,
warper,
orchard_vks.clone(),
db_builder.clone(),
"orchard".to_string(),
);
synchronizer.initialize(height)?;
progress.trial_decryptions += synchronizer.process(&blocks.0)? as u64;
if c.chain.has_unified() {
// Orchard
log::info!("Orchard");
{
let decrypter = OrchardDecrypter::new(network);
let warper = WarpProcessor::new(OrchardHasher::new());
let mut synchronizer = OrchardSynchronizer::new(
decrypter,
warper,
orchard_vks.clone(),
db_builder.clone(),
"orchard".to_string(),
);
synchronizer.initialize(height)?;
progress.trial_decryptions += synchronizer.process(&blocks.0)? as u64;
}
}
let db = db_builder.build()?;